* { box-sizing: border-box; }

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

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

:root {
  --bg: #14151a;
  --panel: #1e2028;
  --panel2: #262933;
  --text: #e8e9ed;
  --dim: #9aa0ae;
  --accent: #ff9f43;
  --accent-text: #1a1206;
  --danger: #ff5e57;
  --good: #2ecc71;
  --movie: #4aa3ff;
  --actor: #c56cf0;
  --border: #3a3f4d;
  --letter-dim: #7e8798;
  --shadow: rgba(0, 0, 0, 0.5);
  --timer-text: #fff;
  --accent-ink: #ff9f43; /* accent when used as text on --bg/--panel */
  --radius: 10px;
}

:root[data-theme='light'] {
  --bg: #f2f3f6;
  --panel: #ffffff;
  --panel2: #e7e9ef;
  --text: #1d2026;
  --dim: #5d6572;
  --accent: #e8862c;
  --accent-text: #241503;
  --danger: #c2352f;
  --good: #27a45c;
  --movie: #1e6fc4;
  --actor: #8f36c9;
  --border: #c9cdd8;
  --letter-dim: #767e8e;
  --shadow: rgba(30, 35, 50, 0.18);
  --timer-text: #1d2026;
  --accent-ink: #a4590c;
}

/* Never allow the page itself to pan sideways (iOS Safari finds ways);
   anything wide scrolls inside its own container, like the chain.
   touch-action is the gesture-level backstop: horizontal flings can only
   ever scroll an inner scroller, never the page. */
html, body {
  overflow-x: hidden;
  overflow-x: clip;
  touch-action: pan-y pinch-zoom;
}

body {
  margin: 0;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.45;
  transition: background 0.2s, color 0.2s;
}

/* Theme toggle: a plain header button in the room; on pages without a
   header (home, how-to-play) the .corner variant pins it top-right. */
bomb-theme { display: contents; }
.theme-btn { font-size: 1rem; }
bomb-theme.corner .theme-btn {
  position: fixed;
  top: 10px;
  right: 12px;
  z-index: 50;
}

/* iOS can ignore overflow clipping on the root while touch-panning, but it
   honors it on inner elements — clip the app wrapper as well. */
bomb-app {
  flex: 1;
  overflow-x: hidden;
  overflow-x: clip;
}

.site-footer {
  text-align: center;
  color: var(--dim);
  font-size: 0.78rem;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.site-footer a { color: var(--accent-ink); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.tmdb-logo { height: 13px; display: block; }

/* Custom elements default to inline, which lets Safari size them by their
   content — a long nowrap chain then drags the whole page wide. Make every
   wrapper an honest block that is allowed to shrink. */
bomb-app, bomb-home, bomb-room, bomb-players, bomb-chain,
bomb-timer, bomb-action, bomb-banner {
  display: block;
  min-width: 0;
  max-width: 100%;
}

button {
  font: inherit;
  border: 0;
  border-radius: var(--radius);
  padding: 0.6em 1.2em;
  background: var(--panel2);
  color: var(--text);
  cursor: pointer;
}
button:hover { filter: brightness(1.15); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); font-weight: 700; }
button.danger { background: var(--danger); color: #fff; font-weight: 600; }
button.ghost { background: transparent; color: var(--dim); padding: 0.4em 0.6em; }
a.ghost {
  color: var(--dim);
  text-decoration: none;
  padding: 0.4em 0.6em;
  border-radius: var(--radius);
}
a.ghost:hover { color: var(--text); }
.howto-link { font-weight: 700; }

input {
  font: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55em 0.8em;
  background: var(--panel);
  color: var(--text);
  width: 100%;
}
input:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* ---------- home ---------- */
.home {
  max-width: 380px;
  margin: 0 auto;
  padding: 12vh 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.home h1 { font-size: 3.2rem; margin: 0; letter-spacing: 0.08em; }
.home .tagline { color: var(--dim); margin: 0 0 10px; }
.home label { text-align: left; font-size: 0.9rem; color: var(--dim); display: block; }
.home label input { margin-top: 4px; }
.home .or { color: var(--dim); font-size: 0.85rem; }
.join-row { display: flex; gap: 8px; }
.join-row input { text-transform: uppercase; letter-spacing: 0.3em; font-weight: 700; }

/* ---------- how to play ---------- */
.rules {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.rules > * { min-width: 0; } /* let cards shrink below the nowrap example's width */
.rules h1 { margin: 0; }
.rules .tagline { color: var(--dim); margin: 0 0 6px; }
.rules .card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.rules h2 { margin: 0 0 8px; font-size: 1.05rem; color: var(--accent-ink); }
.rules p { margin: 8px 0 0; }
.rules p:first-of-type { margin-top: 0; }
.rules ul, .rules ol { margin: 0; padding-left: 1.3em; }
.rules li { margin: 6px 0; }
/* Example chain, stacked vertically like the in-game chain. */
.rules ol.example {
  background: var(--panel2);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin: 8px 0 0;
  list-style: none;
  font-weight: 600;
}
.rules .example li { margin: 2px 0; }
.rules .example .movie { color: var(--movie); }
.rules .example .actor { color: var(--actor); }
.rules .example .more { color: var(--dim); }
.rules .back { color: var(--accent-ink); text-decoration: none; font-weight: 600; }
.rules .back:hover { text-decoration: underline; }
.home .howto { color: var(--dim); font-size: 0.9rem; }
.home .howto a { color: var(--accent-ink); }

/* ---------- room ---------- */
.room {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.room header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.room .brand { font-weight: 800; letter-spacing: 0.06em; white-space: nowrap; }
.room header button, .room header a.ghost { white-space: nowrap; }
.room .code {
  background: var(--panel2);
  border-radius: 6px;
  padding: 2px 10px;
  letter-spacing: 0.25em;
  font-weight: 700;
}
.room .conn { color: var(--danger); font-size: 0.85rem; margin-left: auto; }
.room header .ghost:last-child { margin-left: 0; }
.room .conn:empty { margin-left: auto; }

/* players */
.players {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.player {
  background: var(--panel);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 8px 12px;
  min-width: 130px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.player.turn { border-color: var(--accent); box-shadow: 0 0 12px rgba(255, 159, 67, 0.25); }
.player.is-me .pname::after { content: " (you)"; color: var(--dim); font-weight: 400; font-size: 0.8em; }
.player.away { opacity: 0.55; }
.player.dead { opacity: 0.45; filter: grayscale(0.8); }
.pname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.letters { display: flex; gap: 4px; }
.letter {
  width: 1.5em;
  text-align: center;
  border-radius: 4px;
  background: var(--panel2);
  color: var(--letter-dim);
  font-weight: 800;
  font-size: 0.85rem;
}
.letter.lit { background: var(--danger); color: #fff; }
.specs { color: var(--dim); font-size: 0.85rem; }

/* chain — a vertical list capped in height; long games scroll inside the
   card (vertical nesting is the overflow pattern iOS handles correctly). */
.chain {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 8px 14px;
  list-style: none;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 3em;
  max-height: 10.5em; /* ~5 rows, then it scrolls to the newest */
  overflow-y: auto;
}
.chain.empty { color: var(--dim); font-style: italic; justify-content: center; }
.clink {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0;
}
.cname { font-weight: 600; min-width: 0; } /* long titles wrap, never widen */
.clink.movie .cname { color: var(--movie); }
.clink.actor .cname { color: var(--actor); }
.cname small { color: var(--dim); font-weight: 400; }
.cwho { color: var(--dim); font-size: 0.8rem; flex: 0 0 auto; }

/* timer */
.timer {
  position: relative;
  height: 22px;
  background: var(--panel);
  border-radius: 999px;
  overflow: hidden;
}
.timer.hidden { display: none; }
.timer .bar {
  height: 100%;
  background: var(--good);
  transition: width 0.2s linear;
}
.timer.urgent .bar { background: var(--danger); }
.timer .secs {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--timer-text);
  text-shadow: 0 1px 2px var(--shadow);
}

/* action area */
.action {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}
.action p { margin: 0; }
.action .big { font-size: 1.2rem; font-weight: 700; }
.action .prompt strong { color: var(--accent-ink); }
.action .subject {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-ink);
  max-width: 100%;
  overflow-wrap: anywhere; /* survive even absurdly long titles */
}
.action.mine { border: 2px solid var(--accent); }
.codebig { letter-spacing: 0.3em; font-size: 1.5em; color: var(--accent-ink); }
.action .oneshot { color: var(--danger); font-weight: 600; font-size: 0.9rem; }
.action .hint { color: var(--dim); font-size: 0.85rem; }

/* mode picker */
.modes { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
button.mode {
  background: var(--panel2);
  border: 2px solid transparent;
  max-width: 240px;
  text-align: left;
  font-weight: 600;
}
button.mode small {
  display: block;
  color: var(--dim);
  font-weight: 400;
  margin-top: 2px;
}
button.mode.sel { border-color: var(--accent); }
button.mode:disabled { opacity: 0.7; cursor: default; }
button.mode.sel:disabled { opacity: 1; }

/* search */
/* The custom element needs its own width — as a centered flex item it would
   otherwise shrink to the input's intrinsic (tiny) default size. */
bomb-search { display: block; width: min(420px, 100%); }
.search { position: relative; width: 100%; }
.results {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  position: absolute;
  width: 100%;
  background: var(--panel2);
  border-radius: var(--radius);
  overflow: hidden;
  z-index: 5;
  box-shadow: 0 8px 24px var(--shadow);
  text-align: left;
}
.results.hidden { display: none; }
.results li { padding: 8px 12px; cursor: pointer; }
.results li.hi, .results li:hover { background: var(--accent); color: var(--accent-text); }
.results li small { opacity: 0.7; }
.results li.err { color: var(--danger); cursor: default; }

/* banners */
.banner {
  border-radius: var(--radius);
  padding: 10px 14px;
  font-weight: 600;
  text-align: center;
}
.banner.error { background: rgba(255, 94, 87, 0.15); color: var(--danger); }
.banner.miss { background: rgba(255, 159, 67, 0.12); color: var(--accent); }

/* Bigger touch targets on phones and tablets. */
@media (pointer: coarse) {
  .results li { padding: 12px 14px; }
  button.ghost, a.ghost { padding: 0.55em 0.8em; }
}

@media (max-width: 480px) {
  .home h1 { font-size: 2.4rem; }
  .player { min-width: 45%; }
  .room header { gap: 7px; }
  .brand .bword { display: none; } /* room code beats logo for space */
}
