:root {
  color-scheme: dark;
  --ink: #f7efe5;
  --muted: #bdb4aa;
  --muted-strong: #e3d8cc;
  --background: #171716;
  --surface: #22211f;
  --surface-soft: #2b2926;
  --border: rgba(247, 239, 229, 0.12);
  --accent: #df8156;
  --accent-bright: #f19a6d;
  --accent-soft: rgba(223, 129, 86, 0.15);
  --success: #8fbf8a;
  --danger: #e39b89;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, rgba(223, 129, 86, 0.12), transparent 34rem),
    var(--background);
  color: var(--ink);
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; }

.intro-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: calc(1.25rem + env(safe-area-inset-top)) 1rem calc(1.25rem + env(safe-area-inset-bottom));
  color: #27221e;
  background:
    radial-gradient(circle at 50% -10%, rgba(158, 58, 65, 0.13), transparent 25rem),
    #f8f3ec;
}

.intro-panel { width: min(100%, 31rem); text-align: center; }
.intro-logo-wrap { overflow: hidden; border: 1px solid rgba(158, 58, 65, 0.16); border-radius: 1.4rem; background: #fff; box-shadow: 0 20px 55px rgba(93, 57, 45, 0.13); }
.intro-logo { width: 100%; display: block; aspect-ratio: 2 / 1; object-fit: contain; }
.intro-copy { padding: 1.35rem 0.5rem 0; }
.intro-event {
  display: inline-block;
  max-width: 100%;
  margin: 0 0 0.9rem;
  padding: 0.65rem 0.9rem;
  border: 1px solid rgba(158, 58, 65, 0.36);
  border-radius: 0.8rem;
  color: #76212c;
  background: linear-gradient(135deg, #ffe7d6, #f6d5d6);
  box-shadow: 0 5px 20px rgba(158, 58, 65, 0.13);
  font-size: clamp(0.88rem, 3.7vw, 1.08rem);
  font-weight: 900;
  letter-spacing: 0.045em;
  line-height: 1.3;
  text-transform: uppercase;
}
.intro-copy h2 { margin-bottom: 1.2rem; color: #27221e; font-size: clamp(1.85rem, 8vw, 2.65rem); }
.intro-start { width: 100%; margin-top: 1rem; color: #fff; background: #9e3a41; }
.intro-start:hover { background: #b34a52; }
.intro-note { margin: 0.9rem 0 0; color: #83766e; font-size: 0.75rem; line-height: 1.45; }
.intro-copyright { margin: 0.65rem 0 0; color: #83766e; font-size: 0.72rem; line-height: 1.4; }

.language-picker { display: grid; gap: 0.38rem; text-align: left; }
.language-picker label { font-size: 0.8rem; font-weight: 800; }
.language-picker select {
  width: 100%;
  min-height: 2.8rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid rgba(158, 58, 65, 0.32);
  border-radius: 0.72rem;
  color: #27221e;
  background: #fff;
  cursor: pointer;
}
.language-picker select:focus-visible { outline: 3px solid rgba(158, 58, 65, 0.45); outline-offset: 2px; }
.language-picker--intro { max-width: 20rem; margin: 0 auto; }
.language-picker--intro label { color: #61534e; }
.language-picker--compact select {
  min-height: 2.35rem;
  max-width: 10rem;
  padding: 0.35rem 0.55rem;
  border-color: rgba(241, 154, 109, 0.35);
  color: var(--ink);
  background: var(--surface-soft);
  font-size: 0.78rem;
}
.language-picker--compact select:focus-visible { outline-color: rgba(241, 154, 109, 0.7); }

.topbar {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: calc(0.8rem + env(safe-area-inset-top)) 1rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-lockup { display: flex; align-items: center; gap: 0.75rem; }
.topbar-tools { display: flex; align-items: center; justify-content: flex-end; gap: 0.8rem; }
.brand-mark {
  width: 2.55rem;
  height: 2.55rem;
  display: grid;
  place-items: center;
  border: 1px solid rgba(241, 154, 109, 0.55);
  border-radius: 0.85rem 0.85rem 0.85rem 0.25rem;
  color: var(--accent-bright);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.eyebrow {
  margin: 0 0 0.18rem;
  color: var(--accent-bright);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 1rem; letter-spacing: -0.02em; }
h2 { margin-bottom: 0.7rem; font-size: clamp(1.65rem, 6vw, 2.2rem); line-height: 1.06; letter-spacing: -0.045em; }

.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted-strong);
  font-size: 0.75rem;
  white-space: nowrap;
}

.status-dot { width: 0.5rem; height: 0.5rem; border-radius: 999px; background: var(--success); box-shadow: 0 0 0 0.22rem rgba(143, 191, 138, 0.12); }
.connection-status.offline .status-dot { background: var(--danger); box-shadow: 0 0 0 0.22rem rgba(227, 155, 137, 0.12); }
.connection-status.offline { color: var(--danger); }

main { width: min(100%, 980px); margin: 0 auto; padding: 0 1rem calc(2rem + env(safe-area-inset-bottom)); }
.screen { padding: 0.35rem 0 2rem; }
.hidden { display: none !important; }

.instructions-card {
  max-width: 46rem;
  margin: 1rem auto 0;
  padding: clamp(1.2rem, 4vw, 2rem);
  border: 1px solid var(--border);
  border-radius: 1.4rem;
  background: linear-gradient(145deg, rgba(43, 41, 38, 0.96), rgba(32, 31, 29, 0.99));
  box-shadow: var(--shadow);
}
.instructions-card h2 { margin: 0.45rem 0 0.65rem; }
.instructions-lead { margin-bottom: 1.35rem; color: var(--muted-strong); font-size: 1rem; line-height: 1.5; }
.instructions-steps { display: grid; gap: 0.7rem; margin: 0; padding: 0; list-style: none; }
.instructions-steps li { display: flex; align-items: flex-start; gap: 0.8rem; padding: 0.9rem; border: 1px solid var(--border); border-radius: 0.9rem; background: rgba(247, 239, 229, 0.035); }
.instructions-number { flex: 0 0 auto; display: grid; place-items: center; width: 2.15rem; height: 2.15rem; border-radius: 0.65rem; color: var(--accent-bright); background: var(--accent-soft); font-size: 0.8rem; font-weight: 900; }
.instructions-steps h3 { margin: 0 0 0.25rem; font-size: 1rem; }
.instructions-steps p { margin: 0; color: var(--muted-strong); font-size: 0.9rem; line-height: 1.45; }
.instructions-tip { margin: 1rem 0; padding: 0.9rem; border-left: 3px solid var(--accent-bright); border-radius: 0.45rem; color: var(--muted-strong); background: var(--accent-soft); font-size: 0.84rem; line-height: 1.5; }
.instructions-start { width: 100%; }

.progress-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 0.45rem 0 0.45rem; color: var(--muted-strong); font-size: 0.95rem; font-weight: 700; }
.progress-caption { color: var(--muted-strong); font-size: 0.8rem; font-weight: 600; }
.progress-track { height: 0.32rem; overflow: hidden; border-radius: 999px; background: rgba(247, 239, 229, 0.1); }
.progress-track span { display: block; width: 5%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent-bright)); transition: width 300ms ease; }

.clue-card, .camera-card, .result-card {
  margin-top: 0.9rem;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 1.4rem;
  background: linear-gradient(145deg, rgba(43, 41, 38, 0.92), rgba(32, 31, 29, 0.97));
  box-shadow: var(--shadow);
}

.clue-heading { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.7rem; }
.point-badge, .location-tag {
  display: inline-flex;
  align-items: center;
  min-height: 1.7rem;
  padding: 0.3rem 0.62rem;
  border-radius: 999px;
  font-size: 0.73rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.point-badge { background: var(--accent-soft); color: var(--accent-bright); }
.location-tag { color: var(--muted); font-weight: 600; text-transform: none; letter-spacing: 0; }
.clue-copy, .camera-heading p, .result-card p { color: var(--muted-strong); font-size: 1.03rem; line-height: 1.45; }

.reference-figure { margin: 0.8rem 0 0.5rem; }
.image-frame { position: relative; overflow: hidden; height: clamp(12rem, 30vh, 15rem); border-radius: 1rem; background: #111; }
.image-frame img { width: 100%; height: 100%; display: block; object-fit: contain; }
.image-open-button { width: 100%; padding: 0; border: 0; color: inherit; text-align: left; cursor: zoom-in; }
.image-open-button:focus-visible { outline: 3px solid rgba(241, 154, 109, 0.7); outline-offset: 4px; }
.image-label { position: absolute; top: 0.75rem; left: 0.75rem; padding: 0.35rem 0.55rem; border-radius: 0.45rem; color: #fff; background: rgba(23, 23, 22, 0.76); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
figcaption { margin-top: 0.5rem; color: var(--muted); font-size: 0.78rem; }
.reference-thumbs { display: flex; gap: 0.45rem; margin: 0.65rem 0 1.15rem; overflow-x: auto; }
.reference-thumb { width: 3.7rem; height: 4.9rem; flex: 0 0 auto; overflow: hidden; padding: 0; border: 1px solid var(--border); border-radius: 0.55rem; background: #111; opacity: 0.66; }
.reference-thumb.active { border-color: var(--accent-bright); opacity: 1; box-shadow: 0 0 0 0.16rem var(--accent-soft); }
.reference-thumb img { width: 100%; height: 100%; object-fit: cover; }
.hint-card { display: grid; gap: 0.8rem; margin: 1rem 0 1.15rem; padding: 0.9rem; border: 1px solid rgba(241, 154, 109, 0.25); border-radius: 0.9rem; background: rgba(223, 129, 86, 0.07); }
.hint-card h3 { margin: 0.2rem 0 0.25rem; font-size: 1rem; letter-spacing: -0.02em; }
.hint-card p { margin: 0; color: var(--muted-strong); font-size: 0.86rem; line-height: 1.45; }
.hint-kicker { color: var(--accent-bright); font-size: 0.7rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.hint-button { min-height: 2.75rem; }
.hint-content { padding-top: 0.75rem; border-top: 1px solid rgba(241, 154, 109, 0.2); }
.hint-content p { white-space: pre-line; }

.action-stack, .camera-actions { display: grid; gap: 0.5rem; }
.button { min-height: 2.9rem; display: inline-flex; align-items: center; justify-content: center; gap: 0.55rem; padding: 0.7rem 1rem; border: 1px solid transparent; border-radius: 0.9rem; font-weight: 800; transition: transform 160ms ease, background 160ms ease, border-color 160ms ease; }
.button:active { transform: translateY(1px) scale(0.99); }
.button:focus-visible, .text-button:focus-visible, .reference-thumb:focus-visible { outline: 3px solid rgba(241, 154, 109, 0.6); outline-offset: 3px; }
.button-primary { color: #241612; background: var(--accent-bright); }
.button-primary:hover { background: #ffab7c; }
.button-secondary { color: var(--ink); border-color: var(--border); background: transparent; }
.button-secondary:hover { background: rgba(247, 239, 229, 0.06); }
.button-icon { font-size: 1.1rem; }
.image-lightbox { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: calc(4.5rem + env(safe-area-inset-top)) 1rem calc(1rem + env(safe-area-inset-bottom)); background: rgba(8, 8, 8, 0.97); }
.image-lightbox.hidden { display: none !important; }
.lightbox-image { width: auto; max-width: 100%; max-height: calc(100vh - 6rem); max-height: calc(100dvh - 6rem); object-fit: contain; border-radius: 0.75rem; box-shadow: 0 18px 55px rgba(0, 0, 0, 0.45); }
.lightbox-close { position: absolute; top: calc(0.8rem + env(safe-area-inset-top)); right: 1rem; z-index: 1; min-height: 2.6rem; padding: 0.55rem 0.85rem; border: 1px solid var(--border); border-radius: 0.8rem; color: var(--ink); background: rgba(34, 33, 31, 0.92); font-weight: 800; }
.lightbox-close:focus-visible { outline: 3px solid rgba(241, 154, 109, 0.7); outline-offset: 3px; }
body.lightbox-open { overflow: hidden; }

.text-button { padding: 0; border: 0; color: var(--accent-bright); background: transparent; font-size: 0.82rem; font-weight: 800; }
.camera-heading { margin-bottom: 1.2rem; }
.camera-heading h2 { margin-top: 0.75rem; }
.camera-stage { position: relative; overflow: hidden; min-height: 20rem; aspect-ratio: 3 / 4; border-radius: 1rem; background: #0e0e0d; }
.camera-stage video, .captured-stage-image { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.camera-stage video { object-fit: cover; }
.captured-stage-image { object-fit: contain; }
.camera-placeholder { position: absolute; inset: 0; display: grid; place-content: center; gap: 0.5rem; padding: 2rem; color: var(--muted); text-align: center; }
.camera-placeholder strong { color: var(--ink); font-size: 1rem; }
.camera-placeholder-icon { color: var(--accent-bright); font-size: 3.4rem; line-height: 1; }
.camera-guide { position: absolute; inset: 11% 10%; border: 1px solid rgba(255, 255, 255, 0.5); border-radius: 1rem; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.12); pointer-events: none; }
.file-button { text-align: center; }
#photoInput { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.camera-error { margin: 0.8rem 0 0; padding: 0.75rem; border: 1px solid rgba(227, 155, 137, 0.35); border-radius: 0.7rem; color: var(--danger); background: rgba(227, 155, 137, 0.08); font-size: 0.86rem; line-height: 1.4; }
.camera-actions, .capture-preview { margin-top: 0.7rem; }
.capture-preview { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 0.5rem; }
.capture-preview .button { min-width: 0; width: 100%; }
.validation-status { grid-column: 1 / -1; margin: 0.2rem 0 0; color: var(--muted-strong); font-size: 0.9rem; line-height: 1.4; text-align: center; }

.result-card { padding: 2rem 1.2rem; text-align: center; }
.result-symbol { width: 4rem; height: 4rem; display: grid; place-items: center; margin: 0 auto 1.2rem; border: 1px solid rgba(143, 191, 138, 0.38); border-radius: 1.25rem 1.25rem 1.25rem 0.4rem; color: var(--success); background: rgba(143, 191, 138, 0.1); font-size: 2rem; }
.result-card h2 { margin-top: 1rem; }
.result-card .button { width: 100%; margin-top: 1rem; }
.result-summary { display: grid; gap: 0.25rem; margin-top: 1.2rem; padding: 0.85rem; border-radius: 0.85rem; background: rgba(247, 239, 229, 0.06); color: var(--muted); font-size: 0.78rem; }
.result-summary strong { color: var(--ink); font-size: 0.98rem; }
.finish-card .eyebrow { display: block; margin-bottom: 0.25rem; }
.finish-stats { margin: 1rem 0; padding: 0.9rem; border: 1px solid var(--border); border-radius: 0.85rem; color: var(--muted-strong); font-size: 0.9rem; line-height: 1.5; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

@media (min-width: 700px) {
  .topbar { padding-top: 2rem; }
  main { padding-bottom: 4rem; }
  .clue-card, .camera-card, .result-card { padding: 1.5rem; }
  .clue-card { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(18rem, 1.1fr); column-gap: 2rem; align-items: start; }
  .clue-heading, .clue-card h2, .clue-copy, .clue-card .hint-card, .clue-card .action-stack { grid-column: 1; }
  .clue-heading { margin-top: 0.4rem; }
  .reference-figure { grid-column: 2; grid-row: 1 / span 5; margin-top: 0; }
  .reference-thumbs { grid-column: 2; grid-row: 6; }
  .clue-card .action-stack { margin-top: 1rem; }
  .camera-card { max-width: 46rem; margin-left: auto; margin-right: auto; }
  .camera-actions { grid-template-columns: 1fr 1fr; }
  .camera-actions .button-primary { grid-column: 1 / -1; }
  .result-card { max-width: 34rem; margin-left: auto; margin-right: auto; }
}

@media (max-width: 540px) {
  .topbar { flex-wrap: wrap; }
  .topbar-tools { width: 100%; justify-content: space-between; }
  .language-picker--compact select { width: min(10rem, 45vw); }
}

@media (max-width: 699px) {
  body.camera-open { overflow: hidden; }
  #cameraView {
    position: fixed;
    inset: 0;
    z-index: 20;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: calc(0.75rem + env(safe-area-inset-top)) 0.75rem calc(0.75rem + env(safe-area-inset-bottom));
    background: var(--background);
  }
  #cameraView .progress-header { flex: 0 0 auto; margin: 0 0 0.7rem; }
  .camera-card {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    width: 100%;
    max-width: 32rem;
    margin: 0 auto;
    padding: 0.7rem;
  }
  .camera-heading { flex: 0 0 auto; margin-bottom: 0.6rem; }
  .camera-heading h2 { margin: 0.4rem 0 0.25rem; font-size: clamp(1.35rem, 6vw, 1.75rem); }
  .camera-heading p { margin-bottom: 0; font-size: 0.85rem; line-height: 1.3; }
  .camera-stage { flex: 1 1 auto; min-height: 0; aspect-ratio: auto; }
  .camera-actions, .capture-preview { flex: 0 0 auto; }
  .camera-actions .button, .capture-preview .button { min-height: 2.8rem; }
  .camera-error { flex: 0 0 auto; margin-top: 0.55rem; }
  .capture-preview .button { padding-inline: 0.35rem; font-size: 0.89rem; line-height: 1.15; }
  #instructionsView { padding-bottom: calc(6rem + env(safe-area-inset-bottom)); }
  .instructions-start {
    position: fixed;
    right: 1rem;
    bottom: calc(0.75rem + env(safe-area-inset-bottom));
    left: 1rem;
    z-index: 5;
    width: auto;
    max-width: 44rem;
    margin: 0 auto;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  }
}

@media (max-width: 699px) and (max-height: 720px) {
  body, .app-shell, .intro-screen { min-height: calc(100vh - 1px); }
  main { padding-bottom: calc(0.5rem + env(safe-area-inset-bottom)); }
  .screen { padding-bottom: 0.35rem; }
  .clue-card { margin-top: 0.6rem; padding: 0.75rem; }
  .clue-card h2 { font-size: 1.55rem; margin-bottom: 0.4rem; }
  .clue-copy { font-size: 1rem; line-height: 1.4; }
  .image-frame { height: clamp(14rem, 36vh, 20rem); }
  .button { min-height: 2.65rem; padding-block: 0.55rem; }
  #gameView.has-hints .image-frame { height: clamp(11.5rem, 31vh, 15rem); }
  #gameView.has-hints .hint-card { gap: 0; margin: 0.35rem 0 0.4rem; padding: 0.35rem; }
  #gameView.has-hints .hint-card > div:first-child { display: none; }
  #gameView.has-hints .hint-button { min-height: 2.25rem; padding-block: 0.35rem; font-size: 0.9rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
