/* app.css — Revenant Rx application UI
   Resurrection / Halloween theme: candlelight palette on dark background.
   CSS custom properties use --rv- prefix.
   Print styles are in print.css.
*/
/* The hidden attribute must win over component display rules (.banner etc.). */
[hidden] { display: none !important; }


/* ============================================================
   Custom Properties — Candlelight Palette
   ============================================================ */

:root {
  /* Background tones */
  --rv-bg:          #0d0804;
  --rv-bg-surface:  #1a0f06;
  --rv-bg-raised:   #261508;
  --rv-bg-card:     #2e1a08;

  /* Warm candlelight amber */
  --rv-amber-bright: #f5c842;
  --rv-amber:        #d4961a;
  --rv-amber-dim:    #9e6a0a;
  --rv-amber-dark:   #5c3c05;

  /* Bone / parchment text */
  --rv-text-primary:   #f0e8d0;
  --rv-text-secondary: #b89c74;
  --rv-text-muted:     #7a6040;

  /* Accent */
  --rv-accent:       #c94c1a;
  --rv-accent-hover: #e05a20;

  /* Semantic */
  --rv-warning-bg:   #3d2000;
  --rv-warning-text: #f5c842;
  --rv-info-bg:      #1a2d10;
  --rv-info-text:    #8dc66b;
  --rv-danger:       #9b1c1c;
  --rv-danger-hover: #b22222;

  /* Focus ring — high contrast for AA compliance */
  --rv-focus: #f5c842;

  /* Typography */
  --rv-font: 'Noto Sans JP', 'Noto Sans', 'Hiragino Sans', 'Yu Gothic UI', system-ui, sans-serif;
  --rv-font-mono: 'Fira Code', 'Consolas', monospace;

  /* Spacing */
  --rv-gap: 1rem;
  --rv-radius: 6px;
  --rv-radius-lg: 12px;

  /* Transition */
  --rv-transition: 180ms ease;
}

/* ============================================================
   Reset & Base
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  background-color: var(--rv-bg);
  color: var(--rv-text-primary);
  font-family: var(--rv-font);
  font-size: 1rem;
  line-height: 1.6;
  min-height: 100vh;
}

/* ============================================================
   Focus styles — visible for keyboard navigation
   ============================================================ */

:focus-visible {
  outline: 2px solid var(--rv-focus);
  outline-offset: 3px;
  border-radius: 2px;
}

/* ============================================================
   Screen-reader only utility
   ============================================================ */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================================
   App Header
   ============================================================ */

.app-header {
  background: linear-gradient(180deg, #110800 0%, var(--rv-bg-surface) 100%);
  border-bottom: 1px solid var(--rv-amber-dark);
  padding: 1.5rem 1rem 1.25rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

/* Candle flicker pseudo-element */
.app-header::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(ellipse 60% 40% at 50% -10%, rgba(212, 150, 26, 0.12) 0%, transparent 70%);
  pointer-events: none;
}

.header-inner {
  position: relative;
  z-index: 1;
  max-width: 700px;
  margin: 0 auto;
}

.app-title {
  font-size: clamp(1.5rem, 4vw, 2.4rem);
  font-weight: 700;
  color: var(--rv-amber-bright);
  letter-spacing: 0.04em;
  line-height: 1.2;
}

.title-rx {
  font-size: 1.1em;
  opacity: 0.85;
  margin-right: 0.1em;
}

.title-sub {
  display: block;
  font-size: 0.45em;
  font-weight: 400;
  color: var(--rv-text-secondary);
  letter-spacing: 0.06em;
  margin-top: 0.3em;
}

.app-tagline {
  font-size: 0.85rem;
  color: var(--rv-text-muted);
  margin-top: 0.6rem;
  line-height: 1.5;
}

/* ============================================================
   Disclaimer Banner
   ============================================================ */

.disclaimer-banner {
  background: var(--rv-warning-bg);
  color: var(--rv-warning-text);
  border-top: 1px solid var(--rv-amber-dark);
  border-bottom: 1px solid var(--rv-amber-dark);
  padding: 0.65rem 1rem;
  font-size: 0.82rem;
  line-height: 1.5;
  text-align: center;
}

/* ============================================================
   Banners / Alerts
   ============================================================ */

.banner {
  padding: 0.65rem 1rem;
  font-size: 0.88rem;
  line-height: 1.5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.banner-warning {
  background: #3d2800;
  color: #f5c842;
  border-bottom: 1px solid #7a5000;
}

.banner-info {
  background: var(--rv-info-bg);
  color: var(--rv-info-text);
  border-bottom: 1px solid #2a4a18;
}

.overflow-warning {
  background: #2d0a0a;
  color: #f88;
  border: 1px solid #7a1a1a;
  margin: 0.75rem 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--rv-radius);
  font-size: 0.88rem;
}

.overflow-warning ul {
  margin: 0.4rem 0 0.4rem 1.4rem;
}

.status-message {
  background: #102010;
  color: #8dc66b;
  padding: 0.5rem 1rem;
  font-size: 0.88rem;
  border-bottom: 1px solid #2a4a18;
  transition: opacity var(--rv-transition);
}

/* ============================================================
   Main layout
   ============================================================ */

.app-main {
  max-width: 760px;
  margin: 0 auto;
  padding: 1.5rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* ============================================================
   Section titles
   ============================================================ */

.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--rv-amber);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--rv-amber-dark);
  padding-bottom: 0.4rem;
}

/* ============================================================
   Form
   ============================================================ */

.form-section {
  background: var(--rv-bg-surface);
  border: 1px solid var(--rv-amber-dark);
  border-radius: var(--rv-radius-lg);
  padding: 1.25rem 1.25rem 1.5rem;
}

.field-group {
  border: 1px solid #3a2200;
  border-radius: var(--rv-radius);
  padding: 1rem 1rem 1.25rem;
  margin-bottom: 1.25rem;
  background: var(--rv-bg-raised);
}

.field-group legend {
  color: var(--rv-amber);
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 0 0.4em;
}

.field-row {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-top: 0.9rem;
}

.field-row:first-of-type {
  margin-top: 0.75rem;
}

label {
  font-size: 0.85rem;
  color: var(--rv-text-secondary);
  font-weight: 500;
}

.optional {
  color: var(--rv-text-muted);
  font-weight: 400;
  font-size: 0.8em;
}

.field-hint {
  font-size: 0.75rem;
  color: var(--rv-text-muted);
}

input[type="text"],
input[type="date"],
select,
textarea {
  background: var(--rv-bg-card);
  color: var(--rv-text-primary);
  border: 1px solid var(--rv-amber-dark);
  border-radius: var(--rv-radius);
  padding: 0.5rem 0.65rem;
  font-family: var(--rv-font);
  font-size: 0.95rem;
  width: 100%;
  transition: border-color var(--rv-transition);
  appearance: none;
  -webkit-appearance: none;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23b89c74' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  padding-right: 2rem;
}

input[type="text"]:hover,
input[type="date"]:hover,
select:hover,
textarea:hover {
  border-color: var(--rv-amber-dim);
}

input[type="text"]:focus,
input[type="date"]:focus,
select:focus,
textarea:focus {
  border-color: var(--rv-amber);
  outline: none;
  box-shadow: 0 0 0 2px rgba(245, 200, 66, 0.25);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

::placeholder {
  color: var(--rv-text-muted);
  opacity: 0.7;
}

/* Repeating rows */

.repeating-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.repeating-row {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  background: var(--rv-bg-card);
  border: 1px solid #3a2200;
  border-radius: var(--rv-radius);
  padding: 0.5rem 0.6rem;
}

.row-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  flex: 1;
}

.row-fields input,
.row-fields select {
  flex: 1 1 120px;
  min-width: 80px;
}

.btn-remove {
  background: transparent;
  border: 1px solid #5a2020;
  color: #c06060;
  border-radius: 50%;
  width: 1.8rem;
  height: 1.8rem;
  font-size: 0.75rem;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--rv-transition), color var(--rv-transition);
  align-self: center;
}

.btn-remove:hover {
  background: var(--rv-danger);
  color: white;
  border-color: var(--rv-danger);
}

/* ============================================================
   Buttons
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.5rem 1.1rem;
  border-radius: var(--rv-radius);
  font-family: var(--rv-font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--rv-transition), color var(--rv-transition), border-color var(--rv-transition);
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--rv-amber);
  color: #0d0804;
  border-color: var(--rv-amber);
}

.btn-primary:hover {
  background: var(--rv-amber-bright);
  border-color: var(--rv-amber-bright);
}

.btn-secondary {
  background: var(--rv-bg-raised);
  color: var(--rv-text-primary);
  border-color: var(--rv-amber-dark);
}

.btn-secondary:hover {
  background: var(--rv-bg-card);
  border-color: var(--rv-amber-dim);
}

.btn-danger {
  background: transparent;
  color: #c06060;
  border-color: #5a2020;
}

.btn-danger:hover {
  background: var(--rv-danger);
  color: white;
  border-color: var(--rv-danger);
}

.btn-add {
  background: transparent;
  color: var(--rv-amber-dim);
  border: 1px dashed var(--rv-amber-dark);
  font-size: 0.85rem;
  padding: 0.4rem 0.8rem;
  margin-top: 0.3rem;
}

.btn-add:hover {
  color: var(--rv-amber);
  border-color: var(--rv-amber-dim);
  background: rgba(212, 150, 26, 0.06);
}

.btn-print-inline {
  margin-left: 0.5rem;
  font-size: 0.8rem;
  padding: 0.25rem 0.65rem;
  background: transparent;
  color: inherit;
  border: 1px solid currentColor;
  border-radius: var(--rv-radius);
  cursor: pointer;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rv-amber-dark);
}

/* ============================================================
   Tombstone empty state
   ============================================================ */

.tombstone-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding: 2rem 1rem;
}

.tombstone-stone {
  width: 160px;
  background: #2a2a2a;
  border-radius: 50% 50% 0 0 / 30% 30% 0 0;
  padding: 1.5rem 1rem 1.25rem;
  text-align: center;
  border: 2px solid #444;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.05);
  position: relative;
}

.tombstone-stone::after {
  content: '';
  position: absolute;
  bottom: -8px;
  left: -12px;
  right: -12px;
  height: 10px;
  background: #333;
  border-radius: 2px;
  border: 1px solid #444;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

.tombstone-rip {
  font-size: 0.85rem;
  color: var(--rv-text-muted);
  letter-spacing: 0.15em;
  margin-bottom: 0.4rem;
}

.tombstone-epitaph {
  font-size: 0.85rem;
  color: #aaa;
  line-height: 1.6;
}

.tombstone-last-seen {
  color: var(--rv-text-muted);
  font-size: 0.8em;
  font-style: italic;
}

.tombstone-hint {
  color: var(--rv-text-muted);
  font-size: 0.85rem;
  text-align: center;
  max-width: 400px;
  line-height: 1.6;
}

/* ============================================================
   Card Preview
   ============================================================ */

#card-preview-section {
  background: var(--rv-bg-surface);
  border: 1px solid var(--rv-amber-dark);
  border-radius: var(--rv-radius-lg);
  padding: 1.25rem;
}

.card-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  margin: 0 auto;
  max-width: 360px;
}

/* ============================================================
   Card faces (screen preview — not print)
   These are overridden in print.css for actual printing.
   ============================================================ */

.card-face {
  width: 340px;
  min-height: 215px;
  background: #faf8f0;
  color: #111;
  font-family: 'Noto Sans JP', 'Noto Sans', sans-serif;
  font-size: 11px;
  line-height: 1.4;
  padding: 10px 12px;
  box-sizing: border-box;
  border: 1px solid #aaa;
}

.card-front {
  border-radius: 8px 8px 0 0;
}

.card-back {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 0 0 8px 8px;
  min-height: 215px;
}

.card-fold {
  width: 340px;
  height: 2px;
  background: repeating-linear-gradient(90deg, #999 0, #999 6px, transparent 6px, transparent 12px);
  border: none;
  position: relative;
}

.card-fold::before {
  content: '— fold —';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--rv-bg-surface);
  font-size: 9px;
  color: var(--rv-text-muted);
  padding: 0 4px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 1px solid #ccc;
  padding-bottom: 4px;
  margin-bottom: 4px;
  gap: 4px;
}

.card-name {
  font-size: 12px;
  font-weight: bold;
  flex: 1;
  overflow-wrap: break-word;
  color: #111;
}

.card-blood {
  font-size: 14px;
  font-weight: bold;
  color: #111;
  flex-shrink: 0;
}

.card-section {
  margin-top: 5px;
}

.card-section-title {
  font-size: 8px;
  font-weight: bold;
  text-transform: uppercase;
  color: #333;
  border-bottom: 0.5px solid #ccc;
  margin-bottom: 2px;
  letter-spacing: 0.04em;
}

.card-row {
  font-size: 9px;
  line-height: 1.4;
  color: #111;
  overflow-wrap: break-word;
  word-break: break-all;
}

.card-label {
  font-weight: bold;
  font-size: 8px;
  color: #333;
}

.card-disclaimer {
  font-size: 7px;
  color: #666;
  margin-top: 5px;
  padding-top: 3px;
  border-top: 0.5px solid #ccc;
}

.card-qr {
  width: 130px;
  height: 130px;
  display: block;
  image-rendering: pixelated;
}

.card-scan-note {
  font-size: 9px;
  color: #333;
  text-align: center;
  line-height: 1.6;
}

/* ============================================================
   Card restore animation (Generate button)
   ============================================================ */

@keyframes rv-card-restore {
  0% {
    filter: sepia(1) brightness(0.5) contrast(0.8);
    transform: scale(0.97) rotate(-0.5deg);
    opacity: 0.6;
  }
  40% {
    filter: sepia(0.5) brightness(0.9);
    transform: scale(1.01) rotate(0.3deg);
    opacity: 0.9;
  }
  100% {
    filter: sepia(0) brightness(1) contrast(1);
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

.card-restore-active {
  animation: rv-card-restore 0.6s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

@media (prefers-reduced-motion: reduce) {
  .card-restore-active {
    animation: none;
    filter: none;
    transform: none;
    opacity: 1;
  }
}

/* ============================================================
   Footer
   ============================================================ */

.app-footer {
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--rv-text-muted);
  font-size: 0.78rem;
  border-top: 1px solid var(--rv-amber-dark);
  line-height: 1.7;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 480px) {
  .action-row {
    flex-direction: column;
  }
  .btn {
    width: 100%;
    justify-content: center;
  }
  .row-fields {
    flex-direction: column;
  }
}
