:root {
  --navy: #0d1b4c;
  --navy-deep: #081335;
  --navy-card: #14245a;
  --cream: #fef3e0;
  --cream-card: #fffaf0;
  --yellow: #ffd233;
  --yellow-soft: #ffeeb2;
  --yellow-ink: #6b5300;
  --blue: #27b5ff;
  --blue-soft: #cbedff;
  --blue-ink: #005c8a;
  --pink: #ff5fa2;
  --pink-soft: #fff0f6;
  --pink-ink: #c70055;
  --purple: #7b3ff2;
  --lavender: #cdb6e6;
  --role-indicator: #7b3ff2;
  --role-indicator-soft: #e1d9f2;
  --role-indicator-ink: #3a0a99;
  --role-fodder: #27b5ff;
  --role-fodder-soft: #cbedff;
  --role-fodder-ink: #005c8a;
  --role-definition: #ff5fa2;
  --role-definition-soft: #fff0f6;
  --role-definition-ink: #c70055;
  --font-display: "Playfair Display", Georgia, serif;
  --font-body: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --radius-card: 20px;
  --radius-chip: 999px;
  --content-width: 34rem;
  --page-gutter: clamp(1rem, 4vw, 1.5rem);
  --shadow-card: 0 6px 22px rgba(19, 42, 92, 0.10), 0 2px 6px rgba(19, 42, 92, 0.06);
  --shadow-lift: 0 10px 30px rgba(19, 42, 92, 0.16);
}

*, *::before, *::after { box-sizing: border-box; }
html { margin: 0; padding: 0; min-height: 100%; background: #eee6f5; -webkit-text-size-adjust: 100%; }
body { margin: 0; padding: 0; min-height: 100vh; min-height: 100dvh; font-family: var(--font-body); color: var(--navy); background: #eee6f5; line-height: 1.5; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
button, input { font: inherit; }
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
img { max-width: 100%; }
#root { min-height: 100vh; min-height: 100dvh; display: flex; justify-content: center; }
#root, .shell { background: transparent; }

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

.stage { position: fixed; inset: 0; z-index: 0; pointer-events: none; background: #eee6f5; }
.stage-inner { position: relative; width: 100%; height: 100%; min-height: 100svh; overflow: hidden; background: #eee6f5 url(./watercolour-bg.webp) center center / cover no-repeat; }
.stage-inner::after { content: ""; position: absolute; inset: 0; background: rgba(255,250,240,.05); }
.stage-inner .side-overlay { position: absolute; z-index: 1; top: auto; bottom: max(-10px, calc(env(safe-area-inset-bottom) * -1)); width: clamp(6.75rem, 29vw, 8.25rem); height: auto; max-height: 76svh; object-fit: contain; opacity: .72; filter: saturate(.94); }
.stage-inner .side-overlay.left { left: -8px; transform-origin: left bottom; }
.stage-inner .side-overlay.right { right: -8px; transform-origin: right bottom; }

.shell { position: relative; z-index: 2; width: 100%; max-width: var(--content-width); overflow-x: clip; padding: max(.35rem, env(safe-area-inset-top)) var(--page-gutter) calc(2.5rem + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: stretch; }

.brand { display: flex; flex-direction: column; align-items: center; gap: 2px; margin: .2rem 0 .6rem; }
.brand img { height: auto; filter: drop-shadow(0 4px 10px rgba(19,42,92,.16)); }
.app-logo { display: block; width: min(86vw, 25rem); height: auto; margin: .25rem auto .45rem; }
.brand.compact .app-logo { width: min(55vw, 13.75rem); margin: .25rem auto .5rem; }
.brand.compact img { width: auto; }

.eyebrow-line, .brand .eyebrow { text-align: center; font-weight: 800; letter-spacing: .24em; font-size: .72rem; color: var(--purple); text-transform: uppercase; text-shadow: 0 1px 0 rgba(255,249,238,.8), 0 0 14px rgba(255,249,238,.75); }
.eyebrow-line { margin: .6rem 0 .5rem; }
.brand .eyebrow { margin-top: .5rem; }

.card { position: relative; padding: 1.1rem; border-radius: var(--radius-card); background: rgba(255,250,240,.96); box-shadow: var(--shadow-card); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); }
.clue-card { padding: 1.35rem 1.1rem; border: 1.5px solid rgba(123,95,201,.25); text-align: center; }
.clue-card::before, .clue-card::after { content: "❦"; position: absolute; color: var(--lavender); font-size: .9rem; opacity: .8; }
.clue-card::before { top: .55rem; left: .75rem; }
.clue-card::after { right: .75rem; bottom: .55rem; }
.clue-text { margin: 0; color: var(--navy-deep); font-family: var(--font-display); font-weight: 700; font-size: clamp(1.4rem, 6.1vw, 1.9rem); line-height: 1.35; overflow-wrap: anywhere; }
.clue-enum { font-family: var(--font-display); font-weight: 600; opacity: .58; white-space: nowrap; }

.seg { box-sizing: border-box; padding: 0 .12em; border: 1.5px solid transparent; border-radius: 8px; background: transparent; color: inherit; transition: background-color .5s ease, color .5s ease, border-color .5s ease; }
.seg-indicator.on { background: var(--role-indicator-soft); color: var(--role-indicator-ink); border-color: var(--role-indicator); }
.seg-fodder.on { background: var(--role-fodder-soft); color: var(--role-fodder-ink); border-color: var(--role-fodder); }
.seg-definition.on { background: var(--role-definition-soft); color: var(--role-definition-ink); border-color: var(--role-definition); }

.section-title { position: relative; z-index: 2; width: fit-content; margin: 1.25rem .35rem .6rem; padding: .05rem .2rem; color: var(--navy-deep); font-family: var(--font-display); font-weight: 700; font-size: clamp(1.45rem, 6vw, 1.75rem); line-height: 1.2; text-shadow: 0 1px 0 rgba(255,249,238,.95), 0 0 12px rgba(255,249,238,.95), 0 0 24px rgba(255,249,238,.85); scroll-margin-top: 1rem; }
.clue-list { display: flex; flex-direction: column; gap: .7rem; }
.clue-item { display: flex; align-items: center; justify-content: space-between; gap: .75rem; width: 100%; min-height: 5.1rem; padding: 1rem 1.1rem; cursor: pointer; border: 1.5px solid rgba(205,182,230,.72); border-radius: 1.2rem; background: rgba(255,250,240,.97); color: var(--navy); font-family: var(--font-body); text-align: left; box-shadow: 0 4px 14px rgba(19,42,92,.08); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease; }
.clue-item:active { transform: scale(.985); }
.clue-item:focus-visible { outline: 3px solid var(--purple); outline-offset: 3px; }
.clue-item .t { color: var(--navy-deep); font-weight: 800; font-size: clamp(1rem, 4.4vw, 1.1rem); }
.clue-item .sub { margin-top: .15rem; font-weight: 600; font-size: .8rem; opacity: .68; }
.tick { color: #2f8150; font-size: 1.2rem; font-weight: 800; }

.stars { color: var(--yellow); letter-spacing: 2px; font-size: .82rem; }
.stars .off { color: rgba(19,42,92,.18); }

.boxes-wrap { position: relative; width: fit-content; max-width: 100%; margin: 1.25rem auto .35rem; }
.boxes-input { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: transparent; opacity: 0; font-size: 1.5rem; caret-color: transparent; text-transform: uppercase; }
.boxes-input:focus-visible + .boxes-row { outline: 3px solid rgba(123,63,242,.45); outline-offset: .4rem; border-radius: 12px; }
.boxes-row { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: .4rem; }
.boxes-group { display: flex; gap: .4rem; }
.boxes-sep { min-width: .6rem; color: var(--purple); font-family: var(--font-display); font-size: 1.5rem; text-align: center; }
.box { display: inline-flex; align-items: center; justify-content: center; width: clamp(2rem, 9.4vw, 2.65rem); height: clamp(2.55rem, 11.5vw, 3.1rem); border: 2px solid var(--lavender); border-radius: .72rem; background: #fff; color: var(--navy-deep); font-family: var(--font-display); font-weight: 700; font-size: clamp(1.25rem, 6vw, 1.65rem); transition: border-color .15s ease, transform .12s ease, background-color .2s ease; }
.box.filled { border-color: var(--purple); background: #fff; }
.box.active { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(123,95,201,.22); }
.box.locked { background: var(--yellow-soft); border-color: var(--yellow); }
.boxes-wrap.wrong .box { border-color: var(--pink); animation: shake .45s ease; }
.boxes-wrap.correct .box { border-color: #3fa66a; background: #ebf7ef; animation: pop .35s ease; }

.btn { width: 100%; min-height: 3rem; padding: .85rem 1.5rem; cursor: pointer; border: 0; border-radius: var(--radius-chip); font-family: var(--font-body); font-weight: 800; font-size: 1.05rem; transition: transform .12s ease, box-shadow .12s ease, opacity .15s; }
.btn:active { transform: scale(.98); }
.btn:focus-visible, .hint-btn:focus-visible { outline: 3px solid var(--purple); outline-offset: 3px; }
.btn-primary { background: var(--navy-deep); color: #fff; box-shadow: var(--shadow-card); }
.btn-soft { border: 2px solid var(--lavender); background: #fff; color: var(--purple); }
.btn-ghost { padding: .65rem; background: rgba(255,250,240,.78); color: var(--purple); font-weight: 800; }
.btn[disabled], .hint-btn[disabled] { cursor: default; opacity: .45; }
.actions { display: flex; flex-direction: column; gap: .65rem; margin-top: 1.1rem; }

.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .3rem .8rem; border-radius: var(--radius-chip); font-weight: 800; font-size: .8rem; letter-spacing: .02em; }
.chip-type { background: var(--yellow-soft); color: var(--yellow-ink); }
.chip-role-indicator { background: var(--role-indicator-soft); color: var(--role-indicator-ink); }
.chip-role-fodder { background: var(--role-fodder-soft); color: var(--role-fodder-ink); }
.chip-role-definition { background: var(--role-definition-soft); color: var(--role-definition-ink); }
.msg { min-height: 1.5rem; margin: .75rem 0 0; text-align: center; font-weight: 700; text-shadow: 0 1px 0 rgba(255,249,238,.8), 0 0 14px rgba(255,249,238,.75); }
.msg.gentle { color: var(--pink-ink); }
.msg.happy { color: #2c7a4b; }
.nudge { margin-top: .85rem; padding: .85rem 1rem; border-radius: 1rem; background: var(--blue-soft); color: var(--blue-ink); font-weight: 600; animation: rise .35s ease; }
.step-card, .hint-card { margin-top: .85rem; animation: rise .4s ease; }
.step-card .chip, .hint-card .chip { margin-bottom: .6rem; }
.step-card p, .hint-card p { margin: 0; font-size: 1rem; line-height: 1.55; font-weight: 600; }
.step-indicator, .hint-card-indicator { border-left: 5px solid var(--role-indicator); }
.step-fodder, .hint-card-fodder { border-left: 5px solid var(--role-fodder); }
.step-definition, .hint-card-definition { border-left: 5px solid var(--role-definition); }
.synthesis-card { margin-top: .85rem; padding: 1.1rem; border: 2px dashed rgba(232,93,138,.65); border-radius: var(--radius-card); background: var(--navy-card); color: #fdf3e3; animation: rise .4s ease; }
.synthesis-card p { margin: 0; font-size: 1rem; line-height: 1.6; font-weight: 600; }
.answer-banner { margin: .25rem 0 .2rem; color: var(--navy-deep); font-family: var(--font-display); font-weight: 700; font-size: clamp(1.55rem, 7vw, 1.9rem); text-align: center; text-shadow: 0 1px 0 rgba(255,249,238,.85), 0 0 14px rgba(255,249,238,.75); }
.tagline { margin: 0 0 .4rem; color: var(--purple); font-family: var(--font-display); font-style: italic; font-size: 1rem; text-align: center; text-shadow: 0 1px 0 rgba(255,249,238,.8), 0 0 14px rgba(255,249,238,.75); }
.loading, .error-note { margin-top: 3.75rem; padding: 1rem; border-radius: 1rem; background: rgba(255,250,240,.86); text-align: center; font-weight: 700; }
.error-note { color: var(--pink-ink); }
.back-row { display: flex; justify-content: flex-start; margin-bottom: .35rem; }
.hint-bar { display: flex; justify-content: center; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.hint-btn { min-height: 2.75rem; padding: .6rem .9rem; cursor: pointer; border: 2px solid var(--lavender); border-radius: var(--radius-chip); background: rgba(255,255,255,.96); color: var(--navy-deep); font-family: var(--font-body); font-weight: 800; font-size: .85rem; transition: transform .12s ease, opacity .15s; }
.hint-btn:active { transform: scale(.96); }
.hint-indicator.used { background: var(--role-indicator-soft); border-color: var(--role-indicator); color: var(--role-indicator-ink); }
.hint-fodder.used { background: var(--role-fodder-soft); border-color: var(--role-fodder); color: var(--role-fodder-ink); }
.hint-definition.used { background: var(--role-definition-soft); border-color: var(--role-definition); color: var(--role-definition-ink); }

@keyframes shake { 20% { transform: translateX(-5px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }
@keyframes pop { 50% { transform: scale(1.08); } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 360px) {
  :root { --page-gutter: .8rem; }
  .app-logo { width: 88vw; }
  .stage-inner .side-overlay { width: 6.5rem; opacity: .62; }
  .clue-item { min-height: 4.8rem; padding: .9rem; }
  .card { padding: 1rem; }
  .boxes-row, .boxes-group { gap: .28rem; }
}

@media (min-width: 43.75rem) {
  :root { --content-width: 39rem; --page-gutter: 2rem; }
  .shell { padding-top: .75rem; }
  .app-logo { width: min(74vw, 31rem); margin-top: .5rem; }
  .stage-inner .side-overlay { top: 0; bottom: 0; width: auto; height: 100%; max-height: none; opacity: .96; filter: none; }
  .stage-inner .side-overlay.left { left: 0; }
  .stage-inner .side-overlay.right { right: 0; }
  .clue-item { min-height: 5.5rem; padding: 1rem 1.2rem; }
  .section-title { margin-top: 1.5rem; }
}

@media (min-width: 68rem) {
  :root { --content-width: 41rem; }
  .app-logo { width: 33rem; }
  .clue-item:hover { transform: translateY(-2px); border-color: rgba(123,63,242,.42); box-shadow: 0 9px 24px rgba(19,42,92,.12); }
  .btn-primary:hover { box-shadow: var(--shadow-lift); }
  .btn-soft:hover, .hint-btn:hover { border-color: var(--purple); }
}

@media (orientation: landscape) and (max-height: 34rem) {
  .app-logo { width: min(58vw, 23rem); margin-bottom: .2rem; }
  .brand { margin-bottom: .2rem; }
  .stage-inner .side-overlay { opacity: .55; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media (prefers-contrast: more) {
  .clue-item, .card { border: 2px solid var(--navy); }
  .stars .off { color: rgba(19,42,92,.42); }
}
