:root {
  --fog: #F2F0FF;
  --ink: #1D1A3B;
  --paper: #FFFFFF;
  --muted: #6E6A8F;
  --quick: #FF7A3D;
  --secret: #6A4CFF;
  --guess: #00B59B;
  --tell: #FF4D8D;
  --danger: #C42B2B;
  --warn-bg: #FFE9A8;

  --accent: var(--secret);
  --on-accent: #FFFFFF;

  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-ui: 'Figtree', system-ui, sans-serif;
  --radius-card: 28px;
  --radius-btn: 18px;
}

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

html, body { margin: 0; }

body {
  background: var(--fog);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.shell {
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 12px)
    calc(env(safe-area-inset-right) + 16px)
    calc(env(safe-area-inset-bottom) + 20px)
    calc(env(safe-area-inset-left) + 16px);
  display: flex;
  flex-direction: column;
}

/* One grid cell: during a question change the leaving and entering screens overlap. */
#app { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr); overflow-x: clip; }
#app > .screen { grid-area: 1 / 1; }
.screen-enter { animation: slide-in 350ms cubic-bezier(.2,.8,.2,1) both; }
.screen-leave { animation: slide-out 300ms ease-in both; pointer-events: none; }

@keyframes slide-in {
  from { opacity: 0; transform: translateX(56px); }
  to { opacity: 1; transform: none; }
}
@keyframes slide-out {
  to { opacity: 0; transform: translateX(-56px); }
}

/* Mode shape: large, slow, behind everything; the only ambient motion on the page. */
.bg-shape {
  position: fixed;
  top: -70px;
  right: -90px;
  width: 300px;
  height: 300px;
  z-index: 0;
  pointer-events: none;
}
.shape { width: 100%; height: 100%; animation: spin 90s linear infinite; }
.shape path { fill: var(--accent); opacity: 0.16; transition: fill 400ms ease; }
.shell { position: relative; z-index: 1; }

@keyframes spin { to { transform: rotate(360deg); } }

.topbar { display: flex; justify-content: flex-end; min-height: 44px; }

.screen { flex: 1; display: flex; flex-direction: column; gap: 24px; }

.bottom { margin-top: auto; }

.stack { display: flex; flex-direction: column; gap: 12px; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.muted { color: var(--muted); font-size: 14px; margin: 0; }

/* Type */
.title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(48px, 15vw, 68px);
  line-height: 0.95;
  letter-spacing: -0.02em;
  margin: 0;
}
.title-sm { font-family: var(--font-display); font-weight: 700; font-size: 30px; margin: 0; }
.lead { font-size: 18px; max-width: 30ch; margin: 16px 0 0; }
.question {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  line-height: 1.15;
  margin: 0 0 8px;
}

/* Welcome */
.welcome-head { padding-top: 12vh; }
.chip {
  display: inline-block;
  margin: 20px 0 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--paper);
  font-weight: 600;
  letter-spacing: 0.08em;
}

/* Form */
.field {
  width: 100%;
  min-height: 56px;
  padding: 0 18px;
  border: 2px solid transparent;
  border-radius: var(--radius-btn);
  background: var(--paper);
  color: var(--ink);
  font: 500 18px var(--font-ui);
}
.field::placeholder { color: var(--muted); }
.field:focus-visible { outline: none; border-color: var(--accent); }
.field-code { text-transform: uppercase; letter-spacing: 0.2em; font-weight: 700; }
.form-error { color: var(--danger); font-size: 14px; font-weight: 600; margin: 0; }

/* Buttons */
.btn {
  min-height: 56px;
  padding: 0 20px;
  border: 0;
  border-radius: var(--radius-btn);
  font: 700 17px var(--font-ui);
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn:focus-visible, .menu-btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.btn-primary { min-height: 64px; background: var(--accent); color: var(--on-accent); font-size: 18px; }
.btn-secondary { background: var(--paper); color: var(--ink); }
.btn-link { background: none; color: var(--ink); text-decoration: underline; text-underline-offset: 4px; min-height: 48px; }
.btn-danger { background: var(--paper); color: var(--danger); border: 2px solid var(--danger); }
.is-waiting { animation: pulse 1.6s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.4; } }

/* Lobby */
.lobby-code { display: flex; flex-direction: column; align-items: center; gap: 4px; padding-top: 6vh; }
.code {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(52px, 17vw, 76px);
  letter-spacing: 0.08em;
  line-height: 1;
}
.share { display: flex; flex-direction: column; gap: 10px; text-align: center; }
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.player {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px;
  border-radius: 22px;
  background: var(--paper);
}
.player-empty { background: transparent; border: 2px dashed #CFCBEA; }
.player-empty .player-name { color: var(--muted); }
.player-label { font-size: 13px; color: var(--muted); }
.player-name { font-family: var(--font-display); font-weight: 700; font-size: 22px; overflow-wrap: anywhere; }
.player-ready { font-size: 14px; font-weight: 700; color: var(--guess); }
.player-me {
  position: absolute; top: 12px; right: 12px;
  font-size: 12px; font-weight: 700; color: var(--muted);
}
.wait { text-align: center; color: var(--muted); margin: 0; animation: pulse 1.6s ease-in-out infinite; }

/* Mode accents: one color per mode, carried by badge, main button and selection. */
body[data-mode='quick'] { --accent: var(--quick); --on-accent: var(--ink); }
body[data-mode='secret'] { --accent: var(--secret); --on-accent: #FFFFFF; }
body[data-mode='guess'] { --accent: var(--guess); --on-accent: var(--ink); }
body[data-mode='tell'] { --accent: var(--tell); --on-accent: var(--ink); }

.center { text-align: center; }

/* Question */
.screen-question { gap: 18px; }
.question-head { display: flex; flex-direction: column; gap: 14px; }
.progress { display: flex; align-items: center; gap: 12px; }
.progress-track { flex: 1; height: 6px; border-radius: 3px; background: #DDD9F5; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 3px; background: var(--ink); transition: width 350ms ease; }
.progress-text { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.badge {
  align-self: flex-start;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  font-size: 14px;
}
.card { padding: 28px 24px; border-radius: var(--radius-card); background: var(--paper); }
.question-card { display: flex; flex-direction: column; gap: 10px; }
.status { margin: 0; text-align: center; font-weight: 600; color: var(--muted); }
.is-waiting-text { animation: pulse 1.6s ease-in-out infinite; }

/* Quick-choice options */
.options { display: flex; flex-direction: column; gap: 12px; }
.option {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 72px;
  padding: 0 20px;
  border: 3px solid transparent;
  border-radius: 22px;
  background: var(--paper);
  color: var(--ink);
  font: 700 19px var(--font-ui);
  text-align: left;
  cursor: pointer;
  transition: transform 120ms ease, background-color 160ms ease, border-color 160ms ease;
}
.option:active:not(:disabled) { transform: scale(0.97); }
.option:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.option:disabled { cursor: default; }
.option:disabled:not(.is-selected) { opacity: 0.45; }
.option.is-selected { background: var(--accent); color: var(--on-accent); border-color: var(--ink); }
.option-emoji { font-size: 28px; line-height: 1; }
.option-label { flex: 1; }
.option-check { font-size: 20px; }

/* Reveal: the moment the whole screen serves */
.reveal { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; perspective: 900px; }
.flip { display: flex; flex-direction: column; gap: 8px; text-align: center; }
.flip-name { font-weight: 700; font-size: 15px; overflow-wrap: anywhere; }
/* Both faces share one grid cell, so the card grows with long text answers. */
.flip-inner {
  display: grid;
  min-height: 168px;
  transform-style: preserve-3d;
  transform: rotateY(180deg);
}
.is-flipping .flip-inner { animation: flip 600ms cubic-bezier(.2,.7,.2,1) var(--delay, 0ms) both; }
.flip-face {
  grid-area: 1 / 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 12px;
  border-radius: 24px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.reveal-stack { grid-template-columns: 1fr; }
.flip-wide .flip-inner { min-height: 96px; }
.flip-wide .flip-name { text-align: left; }
.flip-wide .flip-back { align-items: stretch; justify-content: flex-start; padding: 16px 18px; text-align: left; }
.flip-wide .flip-front { font-size: 40px; }
.face-text { display: flex; flex-direction: column; gap: 2px; }
.face-text-label { font-size: 13px; font-weight: 700; color: var(--muted); }
.face-text-body { margin: 0; font-size: 17px; font-weight: 500; white-space: pre-wrap; overflow-wrap: anywhere; }
.flip-front {
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 56px;
}
.flip-back { background: var(--paper); border: 3px solid var(--accent); transform: rotateY(180deg); }
.flip-emoji { font-size: 44px; line-height: 1; }
.flip-label { font-family: var(--font-display); font-weight: 700; font-size: 19px; line-height: 1.15; }

@keyframes flip {
  from { transform: rotateY(0deg); }
  to { transform: rotateY(180deg); }
}

.verdict {
  margin: 4px 0 0;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  color: var(--muted);
}
.verdict.is-same { font-size: 40px; font-weight: 800; color: var(--ink); }
.verdict.is-entering { animation: pop 420ms cubic-bezier(.2,.9,.3,1.4) 650ms both; }

@keyframes pop {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: scale(1); }
}

/* Text answers */
.fields { display: flex; flex-direction: column; gap: 12px; }
.field-wrap { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-weight: 700; font-size: 14px; }
.field-text { min-height: 96px; padding: 14px 16px; resize: vertical; line-height: 1.4; font-size: 17px; }
.field:disabled { opacity: 0.6; }

.stage { margin: 0; font-weight: 700; color: var(--muted); }
.locked-note {
  margin: 8px 0 0;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
}

/* Guess reveal */
.pair { display: flex; flex-direction: column; gap: 10px; padding-bottom: 6px; }
.pair + .pair { border-top: 2px dashed #DDD9F5; padding-top: 16px; }
.rating { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.rating-btn {
  min-height: 52px;
  border: 3px solid transparent;
  border-radius: 16px;
  background: var(--paper);
  color: var(--ink);
  font: 700 15px var(--font-ui);
  cursor: pointer;
}
.rating-btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.rating-btn.is-selected { background: var(--accent); color: var(--on-accent); border-color: var(--ink); }
.chip-verdict {
  align-self: center;
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 800;
  background: var(--paper);
}
.chip-verdict.v-bildi { background: var(--accent); color: var(--on-accent); }
.chip-verdict.v-iskaladi { color: var(--muted); }
.score-line { margin: 0; text-align: center; font-weight: 700; font-size: 15px; }

/* Tell */
.turns { display: flex; justify-content: center; gap: 8px; }
.turn {
  padding: 6px 12px;
  border-radius: 999px;
  border: 2px solid #DDD9F5;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}
.turn.is-active { border-color: var(--accent); color: var(--ink); }
.turn.is-done { background: var(--paper); border-color: var(--paper); color: var(--ink); }
.tell-title {
  margin: 12px 0 0;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 32px;
  line-height: 1.1;
}
.ring { position: relative; width: min(68vw, 240px); aspect-ratio: 1; margin: 0 auto; }
.ring-svg { width: 100%; height: 100%; display: block; }
.ring-track { fill: none; stroke: #DDD9F5; stroke-width: 14; }
.ring-progress { fill: none; stroke: var(--accent); stroke-width: 14; stroke-linecap: round; transition: stroke-dashoffset 250ms linear; }
.ring-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.ring-time {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 56px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.ring-label { font-size: 14px; font-weight: 600; color: var(--muted); text-align: center; max-width: 70%; }
.ring.is-paused .ring-progress { stroke: var(--muted); }
.ring.is-ending { animation: beat 1s ease-in-out infinite; }

@keyframes beat {
  50% { transform: scale(1.04); }
}

.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;
}

/* Locked previews */
.previews { display: flex; flex-direction: column; gap: 10px; }
.preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 20px;
  background: var(--paper);
  border: 2px dashed var(--accent);
}
.preview-title { font-size: 13px; font-weight: 700; color: var(--muted); min-width: 88px; }
.preview-body { display: flex; align-items: center; gap: 8px; }
.preview-body .flip-emoji { font-size: 26px; }
.preview-body .flip-label { font-size: 17px; }
.preview-text { flex-direction: column; align-items: stretch; }
.preview-text .preview-body { flex-direction: column; align-items: stretch; gap: 8px; }

/* Results */
.screen-results { gap: 28px; padding-bottom: 12px; }
.results-head { padding-top: 2vh; }
.results-title {
  margin: 4px 0 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(36px, 11vw, 52px);
  line-height: 1;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}
.results-block { display: flex; flex-direction: column; gap: 12px; }
.block-title { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 22px; }
.compat-ring { position: relative; width: min(64vw, 230px); aspect-ratio: 1; margin: 0 auto; }
.compat-track { fill: none; stroke: #DDD9F5; stroke-width: 18; }
.compat-arc {
  fill: none;
  stroke: var(--secret);
  stroke-width: 18;
  stroke-linecap: round;
  stroke-dashoffset: var(--target);
  animation: fill-arc 1100ms cubic-bezier(.2,.8,.2,1) 200ms both;
}
@keyframes fill-arc { from { stroke-dashoffset: var(--full); } }
.compat-number {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 60px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.bar-row { display: flex; flex-direction: column; gap: 6px; }
.bar-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.bar-name { font-weight: 700; overflow-wrap: anywhere; }
.bar-value { font-family: var(--font-display); font-weight: 800; font-size: 22px; font-variant-numeric: tabular-nums; }
.bar-track { height: 14px; border-radius: 7px; background: #DDD9F5; overflow: hidden; }
.bar-fill {
  width: var(--w);
  height: 100%;
  border-radius: 7px;
  background: var(--guess);
  animation: grow 900ms cubic-bezier(.2,.8,.2,1) 500ms both;
}
@keyframes grow { from { width: 0; } }
.closing {
  margin: 4px 0 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 24px;
  line-height: 1.2;
}

/* Pass: quiet, small, spaced away from the main action */
.btn-pass {
  align-self: center;
  min-height: 48px;
  margin-top: 6px;
  padding: 0 18px;
  border: 0;
  background: none;
  color: var(--muted);
  font: 600 15px var(--font-ui);
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}
.btn-pass:disabled { opacity: 0.5; cursor: default; }
.btn-pass:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; border-radius: 12px; }
.face-pass { color: var(--muted); }
.chip-verdict.v-none { color: var(--muted); background: transparent; border: 2px dashed #CFCBEA; }

.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 20; }

/* Host menu */
.menu-btn {
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--muted);
  font-size: 24px; line-height: 1; cursor: pointer;
}

/* Banner */
.banner {
  position: sticky; top: 0; z-index: 10;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  background: var(--warn-bg); color: var(--ink);
  font-weight: 600; font-size: 14px; text-align: center;
}
.banner[hidden] { display: none; }

/* Dialog */
.dialog {
  width: min(92vw, 400px);
  border: 0; border-radius: var(--radius-card);
  padding: 24px; background: var(--paper); color: var(--ink);
}
.dialog::backdrop { background: rgb(29 26 59 / 0.45); }
.dialog-title { font-family: var(--font-display); font-weight: 700; font-size: 22px; margin: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
