:root {
  --paper: #f4ecd8;
  --paper-dark: #e9dfc4;
  --ink: #2b2417;
  --ink-soft: #5a5142;
  --red: #a3312a;
  --red-dark: #7c2420;
  --green: #3c6e47;
  --gold: #b8862f;
  --line: #cbbf9e;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Courier New", Courier, ui-monospace, monospace;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-image:
    radial-gradient(circle at 20% 10%, rgba(163, 49, 42, 0.05), transparent 40%),
    radial-gradient(circle at 80% 90%, rgba(184, 134, 47, 0.07), transparent 40%);
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding: calc(20px + var(--safe-top)) 20px calc(32px + var(--safe-bottom));
  position: relative;
  overflow-x: hidden;
}

.screen {
  display: none;
  flex-direction: column;
  gap: 14px;
  animation: fadeIn 0.35s ease;
}
.screen.active { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; margin: 0; line-height: 1.2; }
h1.title { font-size: 1.7rem; text-align: center; margin-top: 8px; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.05rem; color: var(--red-dark); margin-bottom: 4px; }

p { margin: 0; line-height: 1.5; }
.muted { color: var(--ink-soft); font-size: 0.92rem; }
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  color: var(--red-dark);
  font-weight: bold;
  margin: 0;
}

/* Landing */
#screen-landing { text-align: center; align-items: center; padding-top: 24px; }
.stamp-corner {
  position: absolute;
  top: calc(14px + var(--safe-top));
  right: 14px;
  border: 2px solid var(--red);
  color: var(--red);
  padding: 3px 8px;
  font-size: 0.65rem;
  font-weight: bold;
  letter-spacing: 0.1em;
  transform: rotate(8deg);
  border-radius: 4px;
}
.crest { font-size: 3rem; }
.case-code {
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
  margin-top: 10px;
}
.subtitle {
  font-style: italic;
  color: var(--ink-soft);
  max-width: 34ch;
  margin: 6px auto 10px;
}
.footnote {
  margin-top: 18px;
  letter-spacing: 0.2em;
  font-size: 0.75rem;
  color: var(--gold);
  font-weight: bold;
}

/* Buttons */
.btn {
  border: none;
  border-radius: var(--radius);
  padding: 16px 20px;
  font-size: 1rem;
  font-weight: bold;
  font-family: inherit;
  cursor: pointer;
  width: 100%;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary {
  background: var(--red);
  color: var(--paper);
  box-shadow: 0 4px 0 var(--red-dark);
}
.btn-primary:active:not(:disabled) { box-shadow: 0 2px 0 var(--red-dark); }
.btn-secondary {
  background: var(--paper-dark);
  color: var(--ink);
  border: 1.5px solid var(--line);
}
.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  text-decoration: underline;
  box-shadow: none;
  padding: 10px;
}

/* Personality picker */
.personality-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 8px 0; }
.personality-card {
  background: var(--paper-dark);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-family: inherit;
}
.personality-card .avatar { font-size: 2.4rem; }
.personality-card .name { font-weight: bold; font-size: 1.05rem; }
.personality-card:active { transform: scale(0.97); }
.personality-card.selected { border-color: var(--red); background: #f8e9d8; }

/* Terms */
.warning {
  margin: 0;
  padding: 12px 14px;
  border-left: 4px solid var(--red);
  background: var(--paper-dark);
  font-style: italic;
  font-size: 0.9rem;
  border-radius: 0 8px 8px 0;
}
.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--paper-dark);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font-size: 0.88rem;
  cursor: pointer;
}
.check-row input { margin-top: 3px; width: 18px; height: 18px; flex-shrink: 0; accent-color: var(--red); }

/* Agreement */
.level {
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--paper-dark);
}
.option-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 6px;
  font-size: 0.87rem;
  cursor: pointer;
  border-radius: 8px;
}
.option-row:active { background: rgba(163,49,42,0.08); }
.option-row input { margin-top: 3px; width: 17px; height: 17px; flex-shrink: 0; accent-color: var(--red); }
.error { color: var(--red); font-size: 0.85rem; min-height: 1.2em; text-align: center; }

/* Loading */
#screen-loading { align-items: center; justify-content: center; min-height: 60vh; text-align: center; gap: 22px; }
.spinner {
  width: 56px; height: 56px;
  border: 5px solid var(--line);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-line { font-family: Georgia, serif; font-style: italic; font-size: 1.05rem; min-height: 1.4em; }
.progress-track { width: 80%; height: 8px; background: var(--paper-dark); border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
.progress-fill { height: 100%; width: 0%; background: var(--red); transition: width 0.5s ease; }

/* Results */
.verdict-stamp {
  align-self: center;
  border: 3px solid var(--red);
  color: var(--red);
  font-family: Georgia, serif;
  font-weight: bold;
  font-size: 1rem;
  letter-spacing: 0.08em;
  padding: 6px 16px;
  border-radius: 8px;
  transform: rotate(-4deg);
  margin: 4px 0;
}
.verdict-stamp.winner { border-color: var(--green); color: var(--green); }
.winner-line { text-align: center; }
#winner-sub { text-align: center; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-card {
  background: var(--paper-dark);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
}
.stat-card .label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); }
.stat-card .value { font-family: Georgia, serif; font-size: 1.25rem; font-weight: bold; margin-top: 4px; }
.stat-card .sub { font-size: 0.7rem; color: var(--ink-soft); margin-top: 2px; }
.stat-card.wide { grid-column: 1 / -1; text-align: left; }
.stat-card.wide .value { font-size: 1rem; font-weight: normal; font-style: italic; }

.balance-card {
  background: #f8e9d8;
  border: 2px dashed var(--gold);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.balance-card .value { font-family: Georgia, serif; font-size: 1.3rem; font-weight: bold; color: var(--red-dark); }

.hidden { display: none !important; }

.agreement-reveal {
  border-top: 2px dashed var(--line);
  padding-top: 14px;
  margin-top: 4px;
}
.agreement-reveal h3 { text-align: center; }
.reveal-card {
  background: var(--paper-dark);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-top: 8px;
  font-size: 0.88rem;
}
.reveal-card .who { font-weight: bold; margin-bottom: 6px; }
.reveal-card.pending { opacity: 0.6; font-style: italic; }

@media (min-width: 480px) {
  .app { padding-top: 40px; }
}
