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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: 1.5;
}

/* Desktop backdrop: thin tint pattern so the column doesn't float in empty space (PRD section 6). */
@media (min-width: 600px) and (min-height: 600px) {
  body {
    background-color: var(--surface);
    background-image:
      radial-gradient(var(--brand-tint-20) 1.5px, transparent 1.5px),
      radial-gradient(var(--brand-tint-10) 1.5px, transparent 1.5px);
    background-size: 28px 28px;
    background-position: 0 0, 14px 14px;
  }
}

.app-shell {
  width: 100%;
  max-width: var(--column-max);
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

/* Phone frame on desktop */
@media (min-width: 600px) and (min-height: 600px) {
  .app-shell {
    min-height: min(880px, calc(100dvh - 48px));
    margin: 24px auto;
    border: 2px solid var(--brand-tint-30);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 60px var(--brand-tint-20);
    overflow: hidden;
  }
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: var(--space-5) var(--space-4);
}

.site-footer {
  padding: var(--space-4);
  border-top: 1px solid var(--brand-tint-20);
  font-size: var(--text-xs);
  text-align: center;
}
.site-footer p { margin: 0; }
.site-footer .handle { font-weight: 700; margin-bottom: var(--space-1); }

h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 800; }

:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-min);
  padding: 0 var(--space-5);
  border-radius: var(--radius-md);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform var(--dur) ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--brand); color: var(--on-brand); border: 2px solid var(--brand); }
.btn-secondary { background: var(--surface); color: var(--ink); border: 2px solid var(--brand); }

.status {
  margin: auto 0;
  text-align: center;
}

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

/* Dev-only diagnostics (?debug=1); never shown to real users. */
.debug-panel {
  margin-top: var(--space-4);
  padding: var(--space-3);
  border: 1px dashed var(--brand);
  border-radius: var(--radius-sm);
  font: var(--text-xs) / 1.5 ui-monospace, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.btn-block { width: 100%; }

/* Screen transition */
.screen-enter { animation: screen-in var(--dur) ease-out both; }
@keyframes screen-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.screen-body { flex: 1; display: flex; flex-direction: column; gap: var(--space-4); }

/* Character placeholder until real assets land */
.char {
  flex: none;
  display: grid;
  place-items: center;
  background: var(--char-bg, var(--brand-tint-10));
  border: 2px solid var(--brand);
  border-radius: 50%;
}
.char-bust { width: 48px; height: 48px; }
.char-loading { width: 120px; height: 120px; }
.char-placeholder-level { font-weight: 800; font-size: var(--text-md); }
.char-loading .char-placeholder-level { font-size: var(--text-2xl); }
.char[style*='--level-5'] .char-placeholder-level { color: var(--on-brand); }

/* Intro */
.badge {
  align-self: flex-start;
  margin: 0;
  padding: var(--space-1) var(--space-3);
  border-radius: 999px;
  background: var(--brand);
  color: var(--on-brand);
  font-size: var(--text-sm);
  font-weight: 700;
}
.intro-title { font-size: var(--text-2xl); }
.intro-subtitle { margin: 0; font-size: var(--text-md); }
.intro-stats { margin: 0; font-size: var(--text-sm); font-weight: 700; }
.teaser-heading { font-size: var(--text-lg); margin-top: var(--space-2); }
.intro-actions { margin-top: auto; padding-top: var(--space-4); }

/* Quiz */
.quiz-top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.btn-back {
  min-height: 44px;
  padding: 0 var(--space-2);
  margin-left: calc(-1 * var(--space-2));
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  font-size: var(--text-sm);
  cursor: pointer;
}
.progress-text { font-size: var(--text-sm); font-weight: 700; font-variant-numeric: tabular-nums; }
.progress { height: 8px; border-radius: 999px; background: var(--brand-tint-10); overflow: hidden; }
.progress-fill { height: 100%; background: var(--brand); border-radius: inherit; transition: width var(--dur) ease; }
.question-stem { font-size: var(--text-lg); line-height: 1.35; margin-top: var(--space-2); }
.options { display: grid; gap: var(--space-3); }
.option {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: var(--tap-min);
  padding: var(--space-3);
  border: 2px solid var(--brand-tint-30);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--dur) ease, background-color var(--dur) ease;
}
@media (hover: hover) {
  .option:hover { border-color: var(--brand); }
}
.option[aria-pressed='true'] { border-color: var(--brand); background: var(--brand-tint-10); }
.option-key {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--brand);
  font-weight: 800;
  font-size: var(--text-sm);
}
.option[aria-pressed='true'] .option-key { background: var(--brand); color: var(--on-brand); }
.option-text { flex: 1; }

/* Loading */
.loading { align-items: center; justify-content: center; text-align: center; }
.loading-title { font-size: var(--text-xl); }
.loading-text { margin: 0; }
.loading-dots { display: flex; gap: var(--space-2); }
.loading-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--brand);
  animation: dot 900ms ease-in-out infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 150ms; }
.loading-dots span:nth-child(3) { animation-delay: 300ms; }
@keyframes dot {
  0%, 100% { opacity: 0.25; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-4px); }
}
@media (prefers-reduced-motion: reduce) {
  .loading-dots span { animation: none; opacity: 0.6; }
}

[lang='ja'] { font-family: var(--font-jp); }

/* Result card (PRD section 5). Level colour frames the card; text panels stay on --surface for contrast. */
.card {
  --card-bg: var(--card);
  --card-ink: var(--ink);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--card-bg);
  color: var(--ink);
  border: 2px solid var(--brand-tint-30);
}
/* Same white card for every level (owner revision); the level shows in the text and the art, not the background. */

.card-head { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); text-align: center; color: var(--card-ink); }
.card-head p { margin: 0; }
.card-opener { font-weight: 700; }
.card-name { font-size: var(--text-2xl); letter-spacing: 0.01em; overflow-wrap: anywhere; }
.card-subline { font-size: var(--text-sm); }
.card-level { font-weight: 800; font-size: var(--text-sm); text-transform: uppercase; letter-spacing: 0.08em; }
.card-lives { font-size: var(--text-md); }
.card-lives-label { font-weight: 400; }

.char-full { width: 180px; height: 220px; border-radius: var(--radius-lg); margin: var(--space-2) 0; }
.char-full .char-placeholder-level { font-size: 64px; }

.hashtags { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-2); }
.hashtags li {
  padding: var(--space-1) var(--space-3);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  font-size: var(--text-sm);
}
.rarity { font-size: var(--text-sm); font-weight: 700; }
.tier {
  display: inline-block;
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.card-panel {
  margin: 0;
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--brand-tint-20); /* keeps panels visible on the Level 1 card, whose background is also --surface */
  background: var(--surface);
  color: var(--ink);
}
.card-label {
  margin-bottom: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink);
}
.card-text { margin: 0; }
.card-radar { padding: var(--space-2); }
.radar { display: block; width: 100%; height: auto; overflow: visible; }
.radar-ring { fill: none; stroke: var(--brand-tint-20); stroke-width: 1; }
.radar-ring-outer { stroke: var(--brand-tint-40); }
.radar-spoke { stroke: var(--brand-tint-20); stroke-width: 1; }
.radar-shape { fill: var(--brand-tint-30); stroke: var(--brand); stroke-width: 2; stroke-linejoin: round; }
.radar-dot { fill: var(--brand); }
.radar-label { font-family: var(--font-body); fill: var(--ink); }
.radar-axis { font-size: 13px; font-weight: 700; }
.radar-score { font-size: 13px; font-weight: 400; }

.path-list { margin: 0; padding-left: 1.25em; display: grid; gap: var(--space-1); font-weight: 700; }

.card-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.pd-value { margin: 0 0 var(--space-2); font-size: var(--text-xl); font-weight: 800; line-height: 1; }
.meter { height: 8px; border-radius: 999px; background: var(--brand-tint-10); overflow: hidden; }
.meter-fill { height: 100%; background: var(--brand); }
.spot-name { margin: 0; font-weight: 800; font-size: var(--text-md); overflow-wrap: break-word; }
.spot-name [lang='ja'] { display: inline-block; white-space: nowrap; } /* keep the kanji place name in one piece */
.spot-tagline { margin: var(--space-1) 0 0; font-size: var(--text-sm); }

.pairs { list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.pair { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); text-align: center; }
.pair-label { margin: 0; font-size: var(--text-xs); font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink); }
.pair .char-teaser { width: 100%; height: 200px; background: none; border: 0; border-radius: 0; }
.pair .char-teaser img { object-fit: contain; }

.card-foot { text-align: center; font-weight: 700; font-size: var(--text-sm); color: var(--card-ink); }

.result-actions { display: grid; gap: var(--space-3); }
.gallery { display: grid; gap: var(--space-6); }

/* Share bar and CTA (PRD section 5 order) */
.result-actions { margin-top: var(--space-2); }
.btn[disabled] { opacity: 0.55; cursor: progress; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.btn-row .btn { padding: 0 var(--space-3); }
.btn-ghost { background: none; border: 2px solid transparent; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
a.btn { text-decoration: none; }
.btn[data-copied='true']::after { content: ' ✓'; white-space: pre; }
.share-nudge { margin: 0; text-align: center; font-weight: 700; }
.link-field {
  width: 100%;
  min-height: 44px;
  padding: 0 var(--space-3);
  border: 2px solid var(--brand-tint-30);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: var(--text-sm);
}
.inline-card { display: grid; gap: var(--space-3); }
.inline-card-note { margin: 0; font-weight: 700; text-align: center; }
.inline-card-img { width: 100%; height: auto; border-radius: var(--radius-md); -webkit-touch-callout: default; user-select: auto; }
.friend-title { margin: 0; font-size: var(--text-lg); font-weight: 800; text-align: center; }

/* Feedback (PRD section 14) */
.feedback { border: 2px solid var(--brand-tint-30); border-radius: var(--radius-md); padding: 0 var(--space-4); }
.feedback-summary { min-height: var(--tap-min); display: flex; align-items: center; font-weight: 800; cursor: pointer; }
.feedback[open] { padding-bottom: var(--space-4); }
.feedback-form { display: grid; gap: var(--space-4); }
.feedback-field { display: grid; gap: var(--space-2); margin: 0; padding: 0; border: 0; }
.feedback-field legend, .feedback-field > label { font-weight: 700; margin-bottom: var(--space-2); padding: 0; }
.feedback-choice { display: flex; align-items: center; gap: var(--space-3); min-height: 44px; }
.feedback-choice input { width: 22px; height: 22px; accent-color: var(--brand); }
.feedback select, .feedback textarea {
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 2px solid var(--brand-tint-30);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
.feedback textarea { resize: vertical; }
.feedback-count { justify-self: end; font-size: var(--text-xs); }
.feedback-thanks { margin: 0 0 var(--space-4); font-weight: 700; }

/* Real character art (config.characterAssets). Placeholder styles above stay for the fallback. */
.char img { display: block; width: 100%; height: 100%; }
.char:has(img) { border: 0; display: block; } /* block, not grid, so the img's 100% height resolves to the box */
.char-full:has(img) { background: none; border-radius: 0; width: 220px; height: 300px; }
.char-full img { object-fit: contain; filter: drop-shadow(0 6px 10px rgb(0 0 0 / 0.12)); }
.char-bust:has(img), .char-loading:has(img) { overflow: hidden; border: 2px solid var(--brand); }
.char-bust img, .char-loading img { object-fit: cover; }
.char-loading:has(img) { width: 160px; height: 160px; }

/* Intro lineup: five characters, large, slightly overlapping, centre one in front (owner revision). */
.lineup {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  height: 300px;
  margin-top: calc(-1 * var(--space-2));
}
.lineup-item {
  flex: 0 0 34%; /* 5 × 34% − 10 × 7.5% = 95% of the column: no horizontal scroll */
  height: 100%;
  margin: 0 -7.5%;
  position: relative;
  z-index: calc(3 - max(var(--i) - 2, 2 - var(--i)));
  transform: scale(calc(1 - 0.08 * max(var(--i) - 2, 2 - var(--i))));
  transform-origin: bottom center;
}
.lineup .char-teaser { width: 100%; height: 100%; background: none; border: 0; border-radius: 0; }
.lineup .char-teaser img { object-fit: contain; object-position: bottom; animation: bob 2.8s ease-in-out infinite; animation-delay: calc(var(--i) * -0.55s); }
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
@media (prefers-reduced-motion: reduce) {
  .lineup .char-teaser img { animation: none; }
}
