/* ============================================================
   Heads Up — Charades
   Dark, high-contrast party-game UI. Mobile first, landscape
   gameplay, very large word typography.
   ============================================================ */

:root {
  --ink: #f6f4ff;
  --ink-dim: #a8a4c4;
  --bg: #08080f;
  --bg-2: #0e0e1b;
  --surface: rgba(255, 255, 255, 0.05);
  --surface-2: rgba(255, 255, 255, 0.09);
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.22);
  --hot: #ff4d8d;
  --hot-2: #ffa04d;
  --violet: #7b5cff;
  --correct: #1bd97b;
  --wrong: #ff4560;
  --radius: 18px;
  --radius-lg: 28px;
  --shadow: 0 24px 70px -28px rgba(0, 0, 0, 0.95);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}

body {
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

h1, h2, h3, p, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button { font: inherit; color: inherit; }
input { font: inherit; }

#app { position: relative; height: 100%; }

/* ---------- Screens ---------- */

.screen {
  position: absolute;
  inset: 0;
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
.screen.is-active { display: block; }

.screen--plain,
.screen--setup { padding: calc(var(--safe-t) + 22px) calc(var(--safe-r) + 18px) calc(var(--safe-b) + 22px) calc(var(--safe-l) + 18px); }

.screen--stage {
  overflow: hidden;
  padding: 0;
  display: none;
}
.screen--stage.is-active { display: block; }

.screen--overlay {
  background: rgba(6, 6, 12, 0.94);
  backdrop-filter: blur(12px);
  z-index: 40;
  padding: calc(var(--safe-t) + 20px) calc(var(--safe-r) + 20px) calc(var(--safe-b) + 20px) calc(var(--safe-l) + 20px);
}
.screen--overlay .loader { justify-content: center; }

/* ============================================================
   SETUP
   ============================================================ */

.setup__glow {
  position: absolute;
  top: -30vh;
  left: 50%;
  translate: -50% 0;
  width: min(150vw, 900px);
  height: 62vh;
  background:
    radial-gradient(60% 60% at 30% 40%, rgba(123, 92, 255, 0.42), transparent 70%),
    radial-gradient(55% 55% at 72% 30%, rgba(255, 77, 141, 0.35), transparent 72%);
  filter: blur(30px);
  pointer-events: none;
}

.setup__inner {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand__kicker {
  text-transform: uppercase;
  letter-spacing: 0.34em;
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--ink-dim);
}
.brand__title {
  font-size: clamp(2.6rem, 12vw, 3.9rem);
  line-height: 0.98;
  letter-spacing: -0.035em;
  font-weight: 800;
  margin-top: 6px;
}
.brand__dot { color: var(--hot); }
.brand__sub { color: var(--ink-dim); font-size: 0.98rem; margin-top: 10px; max-width: 34ch; }

.card {
  background: linear-gradient(170deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field { display: flex; flex-direction: column; gap: 8px; border: 0; margin: 0; padding: 0; }
.field--fieldset { gap: 10px; }
.field__label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 700;
  color: var(--ink-dim);
  padding: 0;
}
.field__input {
  width: 100%;
  min-height: 56px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1.5px solid var(--line-strong);
  background: rgba(6, 6, 14, 0.72);
  color: var(--ink);
  font-size: 1.05rem;
  -webkit-user-select: text;
  user-select: text;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
.field__input::placeholder { color: #6f6b90; }
.field__input:focus {
  border-color: var(--hot);
  box-shadow: 0 0 0 4px rgba(255, 77, 141, 0.22);
}
.field__hint { font-size: 0.8rem; color: var(--ink-dim); margin-top: -6px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.16s ease, border-color 0.16s ease;
}
.chip:hover { background: var(--surface-2); }
.chip:active { transform: scale(0.96); }
.chip.is-on { border-color: var(--hot); background: rgba(255, 77, 141, 0.16); }

/* segmented controls */
.segmented { display: grid; grid-auto-flow: column; gap: 8px; }
.segmented__option { display: block; position: relative; }
.segmented__option input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.segmented__box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-height: 62px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: rgba(6, 6, 14, 0.6);
  font-weight: 700;
  transition: border-color 0.16s ease, background 0.16s ease, transform 0.12s ease;
}
.segmented__box strong { font-size: 1.3rem; letter-spacing: -0.02em; }
.segmented__box small { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink-dim); }
.segmented__box--text { min-height: 48px; font-size: 0.9rem; padding: 0 10px; }
.segmented__option input:checked + .segmented__box {
  border-color: var(--hot);
  background: linear-gradient(170deg, rgba(255, 77, 141, 0.24), rgba(255, 160, 77, 0.12));
}
.segmented__option input:focus-visible + .segmented__box {
  outline: 3px solid #ffd36e;
  outline-offset: 2px;
}

/* buttons */
.btn {
  position: relative;
  border: 0;
  border-radius: 999px;
  padding: 15px 22px;
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 0.01em;
  cursor: pointer;
  min-height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform 0.12s ease, filter 0.16s ease, opacity 0.16s ease;
}
.btn:active { transform: scale(0.975); }
.btn--primary {
  background: linear-gradient(115deg, var(--hot), var(--hot-2));
  color: #1a0510;
  box-shadow: 0 18px 40px -18px rgba(255, 77, 141, 0.85);
}
.btn--primary[disabled] { filter: grayscale(0.5) brightness(0.8); cursor: progress; }
.btn--ghost {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  color: var(--ink);
  font-weight: 700;
}
.btn--ghost:hover { background: var(--surface-2); }
.btn--xl { width: 100%; padding: 20px 24px; font-size: 1.15rem; }

.btn__spinner { display: none; width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid rgba(26, 5, 16, 0.35); border-top-color: #1a0510; animation: spin 0.7s linear infinite; }
.btn.is-busy .btn__spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.alert {
  border: 1px solid rgba(255, 69, 96, 0.5);
  background: rgba(255, 69, 96, 0.12);
  color: #ffc9d1;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 0.88rem;
}

.howto { display: grid; gap: 8px; }
.howto li {
  display: flex;
  gap: 12px;
  align-items: center;
  color: var(--ink-dim);
  font-size: 0.88rem;
}
.howto li span {
  flex: 0 0 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 0.76rem;
  font-weight: 800;
}

/* ============================================================
   LOADING / READY / ERROR
   ============================================================ */

.screen--plain .loader { justify-content: flex-start; }

.loader,
.over {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 14px 0;
}
.loader { justify-content: center; align-items: stretch; }
.screen--plain .loader { justify-content: center; }

.loader__orbit {
  position: relative;
  width: 74px;
  height: 74px;
  margin-bottom: 4px;
}
.loader__orbit i {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid transparent;
  border-top-color: var(--hot);
  animation: spin 1.1s cubic-bezier(0.5, 0.1, 0.4, 0.9) infinite;
}
.loader__orbit i:nth-child(2) { inset: 12px; border-top-color: var(--hot-2); animation-duration: 1.5s; animation-direction: reverse; }
.loader__orbit i:nth-child(3) { inset: 24px; border-top-color: var(--violet); animation-duration: 1.9s; }
.loader__orbit i:nth-child(4) { inset: 34px; border-top: 0; background: var(--ink); opacity: 0.85; animation: none; }

.loader__badge {
  width: 66px; height: 66px; border-radius: 22px;
  display: grid; place-items: center;
  font-size: 2rem; font-weight: 800;
  background: rgba(255, 69, 96, 0.16);
  border: 1px solid rgba(255, 69, 96, 0.5);
  color: #ff8b9c;
}

.screen__title { font-size: clamp(1.5rem, 6vw, 2rem); font-weight: 800; letter-spacing: -0.02em; }
.screen__sub { color: var(--ink-dim); }
.screen__sub strong { color: var(--ink); }
.screen__fine { color: #7d799e; font-size: 0.8rem; margin-top: 4px; }

.skeleton { display: grid; gap: 10px; margin-top: 8px; }
.skeleton li {
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(90deg, rgba(255,255,255,0.05), rgba(255,255,255,0.12), rgba(255,255,255,0.05));
  background-size: 220% 100%;
  animation: shimmer 1.5s linear infinite;
}
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }

.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  padding: 8px 15px;
  border-radius: 999px;
  background: linear-gradient(170deg, rgba(255, 77, 141, 0.28), rgba(123, 92, 255, 0.2));
  border: 1px solid var(--line-strong);
  font-weight: 700;
  font-size: 0.9rem;
}
.pill--muted { background: var(--surface); color: var(--ink-dim); font-weight: 600; }

.ready { justify-content: center; }
.ready__coach {
  font-size: 1.05rem;
  border-left: 3px solid var(--hot);
  padding: 4px 0 4px 14px;
  color: #e7e4ff;
}
.ready__toggle { display: flex; flex-direction: column; gap: 8px; }
.ready__toggle .segmented { max-width: 420px; }
.status { font-size: 0.82rem; color: var(--ink-dim); }
.status.is-warn { color: #ffcf7a; }

.row { display: flex; flex-wrap: wrap; gap: 10px; }
.row .btn { flex: 1 1 46%; }
.row--stack { flex-direction: column; }
.row--stack .btn { flex: 1 1 auto; width: 100%; }

/* ============================================================
   COUNTDOWN
   ============================================================ */

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 10px;
  padding: 24px;
}
.countdown__hint { color: var(--ink-dim); font-size: clamp(0.8rem, 2.4vmin, 1.05rem); letter-spacing: 0.06em; text-transform: uppercase; font-weight: 700; }
.countdown__num {
  font-size: min(46vmin, 40vh);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -0.05em;
  background: linear-gradient(120deg, var(--hot), var(--hot-2) 55%, var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: pop 0.6s cubic-bezier(0.2, 0.9, 0.25, 1);
}
.countdown__num.is-cal { font-size: min(14vmin, 12vh); background: none; color: var(--ink); letter-spacing: -0.02em; }
.countdown__cal { color: var(--hot-2); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; font-size: clamp(0.75rem, 2.2vmin, 1rem); }
@keyframes pop { from { transform: scale(0.66); opacity: 0; } 60% { transform: scale(1.06); opacity: 1; } to { transform: scale(1); } }

/* ============================================================
   GAMEPLAY — landscape, full bleed, huge word
   ============================================================ */

.screen--game {
  background:
    radial-gradient(90% 90% at 50% 12%, rgba(123, 92, 255, 0.16), transparent 70%),
    var(--bg);
}

.hit {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  border: 0;
  background: transparent;
  padding: 0;
  z-index: 1;
  cursor: pointer;
}
.hit--skip { left: 0; }
.hit--correct { right: 0; }
.hit:active { background: rgba(255, 255, 255, 0.045); }
.hit__label {
  position: absolute;
  bottom: calc(var(--safe-b) + 10px);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: clamp(0.72rem, 1.9vmin, 0.95rem);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 800;
  opacity: 0.5;
}
.hit__label b { font-size: 1.1em; }
.hit__label em { font-style: normal; }
.hit--skip .hit__label { left: calc(var(--safe-l) + 16px); color: #ff9aa9; }
.hit--correct .hit__label { right: calc(var(--safe-r) + 16px); color: #7bf0b6; }
.hit__label em { display: none; }
@media (min-width: 620px) { .hit__label em { display: inline; } }

.hud {
  position: absolute;
  top: calc(var(--safe-t) + 8px);
  left: calc(var(--safe-l) + 14px);
  right: calc(var(--safe-r) + 14px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  z-index: 3;
  pointer-events: none;
}
.hud__item { display: flex; flex-direction: column; line-height: 1; gap: 3px; opacity: 0.86; }
.hud__item--progress { text-align: right; align-items: flex-end; }
.hud__value { font-size: clamp(0.95rem, 2.6vmin, 1.35rem); font-weight: 800; font-variant-numeric: tabular-nums; }
.hud__label { font-size: 0.58rem; text-transform: uppercase; letter-spacing: 0.2em; color: var(--ink-dim); }
.hud__item--time .hud__value { color: var(--hot-2); }
.hud__pause {
  pointer-events: auto;
  border: 0;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  min-width: 46px;
  min-height: 46px;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  opacity: 0.55;
  cursor: pointer;
}
.hud__pause:active { opacity: 1; }

.word {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12vh 8vw;
  z-index: 2;
  pointer-events: none;
}
.word__text {
  font-size: min(30vh, 40vw);
  font-weight: 900;
  line-height: 0.92;
  letter-spacing: -0.04em;
  text-align: center;
  text-wrap: balance;
  color: #fff;
  text-shadow: 0 0 70px rgba(123, 92, 255, 0.5);
  transition: transform 0.16s ease, opacity 0.16s ease;
  word-break: normal;
  overflow-wrap: anywhere;
}
.word__text.is-swap { transform: translateY(14px) scale(0.9); opacity: 0; }

.tilt-hint {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + 10px);
  translate: -50% 0;
  z-index: 3;
  font-size: clamp(0.66rem, 1.8vmin, 0.85rem);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-dim);
  white-space: nowrap;
}

.flash {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  background: transparent;
}
.flash.is-correct { animation: flashOk 0.42s ease-out; }
.flash.is-wrong { animation: flashNo 0.42s ease-out; }
@keyframes flashOk {
  0% { opacity: 0.94; background: radial-gradient(120% 120% at 70% 50%, var(--correct), rgba(27, 217, 123, 0.25)); }
  100% { opacity: 0; background: radial-gradient(120% 120% at 70% 50%, var(--correct), transparent); }
}
@keyframes flashNo {
  0% { opacity: 0.94; background: radial-gradient(120% 120% at 30% 50%, var(--wrong), rgba(255, 69, 96, 0.25)); }
  100% { opacity: 0; background: radial-gradient(120% 120% at 30% 50%, var(--wrong), transparent); }
}

/* ============================================================
   GAME OVER
   ============================================================ */

.over { gap: 18px; }
.over__title {
  font-size: clamp(2rem, 9vw, 3rem);
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 1;
}
.over__topic { color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.2em; font-size: 0.74rem; font-weight: 700; margin-top: -8px; }

.score {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(170deg, var(--surface-2), rgba(6, 6, 14, 0.5));
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.score__big { display: flex; align-items: baseline; gap: 10px; }
.score__num {
  font-size: clamp(3.4rem, 16vw, 5rem);
  font-weight: 900;
  line-height: 0.85;
  letter-spacing: -0.05em;
  background: linear-gradient(120deg, var(--correct), #8ef0ff, var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.score__cap { text-transform: uppercase; letter-spacing: 0.22em; font-size: 0.7rem; font-weight: 800; color: var(--ink-dim); }
.score__grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.score__grid > div {
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.score__grid span { font-weight: 800; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.score__grid small { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-dim); }

.history { display: flex; flex-direction: column; gap: 10px; }
.history__title { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.2em; color: var(--ink-dim); font-weight: 800; }
.history__list { display: grid; gap: 6px; }
.history__list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-weight: 600;
}
.history__list li.is-correct { border-color: rgba(27, 217, 123, 0.45); }
.history__list li.is-wrong { border-color: rgba(255, 69, 96, 0.4); }
.history__list .mark { font-weight: 900; font-size: 1.05rem; }
.history__list li.is-correct .mark { color: var(--correct); }
.history__list li.is-wrong .mark { color: var(--wrong); }
.history__list .word-name { flex: 1 1 auto; overflow-wrap: anywhere; }
.history__list .src { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink-dim); }

/* ------------------------------------------------------------
   Forced landscape. Browsers — iOS Safari above all — cannot lock
   screen orientation, so when the phone is held portrait during a
   round we rotate the stage 90° ourselves. The word then reads
   sideways across the long edge, exactly like the native board.
   ------------------------------------------------------------ */
body.force-landscape .screen--stage,
body.force-landscape #screen-pause {
  position: fixed;
  inset: auto;
  top: 50%;
  left: 50%;
  width: 100vh;
  height: 100vw;
  min-height: 0;
  transform: translate(-50%, -50%) rotate(90deg);
  transform-origin: center;
}

/* --stage-angle is measured from gravity: +90 or -90 depending on which way the
   player rolled the phone to their forehead. Getting this from the sensor is the
   difference between the word reading correctly and reading upside down. */
body.force-landscape .screen--stage,
body.force-landscape #screen-pause {
  transform: translate(-50%, -50%) rotate(var(--stage-angle, 90deg));
}

/* Phone held upside down: flip the stage so the word still faces the room. */
body.force-flip .screen--stage,
body.force-flip #screen-pause {
  transform: rotate(180deg);
  transform-origin: center;
}

/* Inside the rotated stage, vh/vw would point at the physical portrait
   viewport — swap them so sizes track the rotated stage. */
body.force-landscape .word { padding: 44px 56px; }
body.force-landscape .word__text { font-size: min(30vw, 40vh); }

.segmented__box--text b { font-size: 0.82rem; font-weight: 800; }
.segmented__box--text em { font-style: normal; font-size: 0.64rem; letter-spacing: 0.04em; color: var(--ink-dim); }
.segmented__option input:checked + .segmented__box--text em { color: rgba(255, 255, 255, 0.72); }
.segmented__box--text { display: flex; flex-direction: column; gap: 1px; line-height: 1.15; }

.ready__note {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--ink-dim);
}

.rotate__icon {
  width: 76px; height: 52px;
  border: 3px solid var(--hot);
  border-radius: 10px;
  display: grid; place-items: center;
  animation: rotateHint 1.6s ease-in-out infinite;
}
@keyframes rotateHint { 0%, 45% { transform: rotate(0deg); } 60%, 100% { transform: rotate(90deg); } }

/* ============================================================
   LANDSCAPE GAMEPLAY TWEAKS
   ============================================================ */

@media (orientation: landscape) and (max-height: 560px) {
  .word { padding: 8vh 10vw; }
  .word__text { font-size: min(34vh, 26vw); }
  .countdown__num { font-size: min(40vh, 34vw); }
  .hit__label { bottom: calc(var(--safe-b) + 6px); }
}

@media (min-width: 760px) {
  .screen--setup .setup__inner { max-width: 620px; }
}

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