/* Ice Breaker Games -- one stylesheet, phone first, scales up to a laptop. */

:root {
  --bg: #070b16;
  --bg-2: #0e1528;
  --panel: rgba(255, 255, 255, .06);
  --panel-2: rgba(255, 255, 255, .09);
  --line: rgba(255, 255, 255, .14);
  --text: #eaf0ff;
  --muted: rgba(234, 240, 255, .58);
  --accent: #4dd6ff;
  --accent-2: #7c5cff;
  --good: #38e08a;
  --bad: #ff5a6e;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  user-select: none;
  -webkit-user-select: none;
}

#app { position: fixed; inset: 0; }

/* ------------------------------------------------------------- screens -- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  background:
    radial-gradient(120% 80% at 50% 0%, #16224a 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-2), var(--bg));
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bot);
}
.screen.active { display: flex; }

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.pad { padding: 14px 14px calc(28px + var(--safe-bot)); }

/* ---------------------------------------------------------------- bars -- */
.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 11, 22, .7);
  backdrop-filter: blur(8px);
}
.bar h2 { margin: 0; font-size: 1.05rem; font-weight: 700; letter-spacing: .2px; }
.spacer { flex: 1; }

.pill {
  font-size: .8rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  white-space: nowrap;
}

/* ------------------------------------------------------------- buttons -- */
.btn {
  font: inherit;
  font-weight: 700;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 18px;
  cursor: pointer;
  transition: transform .08s ease, filter .15s ease;
  touch-action: manipulation;
}
.btn:active { transform: scale(.97); filter: brightness(1.15); }
.btn:disabled { opacity: .45; pointer-events: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: #06101f;
  box-shadow: 0 8px 28px rgba(77, 214, 255, .28);
}
.btn-tour {
  background: linear-gradient(135deg, #ffd166, #ff8a5b);
  border: none;
  color: #2a1600;
  box-shadow: 0 8px 28px rgba(255, 168, 91, .26);
}
.btn-danger {
  background: linear-gradient(135deg, #ff8a94, #ff5a6e);
  border: none;
  color: #2a0006;
  box-shadow: none;
}
.btn-big { width: 100%; padding: 18px; font-size: 1.15rem; border-radius: 18px; }
.btn-ghost { width: 100%; background: transparent; }
.btn-icon { padding: 8px 14px; font-size: 1.2rem; border-radius: 12px; }

/* ---------------------------------------------------------------- menu -- */
.menu-wrap {
  margin: auto;
  width: min(440px, 100%);
  padding: 24px 22px calc(24px + var(--safe-bot));
  text-align: center;
}
.ice { font-size: 4.2rem; line-height: 1; animation: bob 3.4s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-10px) rotate(4deg); } }

.title {
  margin: 6px 0 2px;
  font-size: clamp(2.3rem, 11vw, 3.4rem);
  line-height: .98;
  font-weight: 900;
  letter-spacing: -1.5px;
  background: linear-gradient(135deg, #b7ecff, #4dd6ff 45%, #7c5cff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.title span { display: block; }
.tagline { color: var(--muted); margin: 6px 0 22px; font-size: .95rem; }

.namefield { display: block; text-align: left; margin-bottom: 16px; }
.namefield span { display: block; font-size: .78rem; color: var(--muted); margin-bottom: 6px; padding-left: 4px; }
.namefield input {
  width: 100%;
  font: inherit;
  font-weight: 700;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  outline: none;
}
.namefield input:focus { border-color: var(--accent); }

#btn-join { margin-bottom: 10px; }
.conn { font-size: .75rem; color: var(--muted); margin-top: 18px; }
.conn.ok { color: var(--good); }
.conn.bad { color: var(--bad); }

/* -------------------------------------------------------- instructions -- */
.steps, .tips { padding-left: 20px; }
.steps li, .tips li { margin-bottom: 12px; }
.hl { color: var(--accent); font-weight: 800; }
h3 { margin: 22px 0 8px; font-size: 1rem; }
.muted { color: var(--muted); font-size: .88rem; }
.center { text-align: center; }

.fam-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.fam-chip {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 8px;
  text-align: center;
  font-size: .8rem;
  font-weight: 700;
}
.fam-chip i { display: block; font-size: 1.4rem; font-style: normal; }
.fam-chip small { display: block; color: var(--muted); font-weight: 500; }

/* --------------------------------------------------------------- lobby -- */
.room-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.room-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: transform .08s ease, border-color .15s ease;
}
.room-card:active { transform: scale(.985); }
.room-card.empty { border-color: var(--accent); background: linear-gradient(135deg, rgba(77, 214, 255, .13), rgba(124, 92, 255, .1)); }
.room-card.full, .room-card.busy { opacity: .55; }
.room-card .rc-main { flex: 1; min-width: 0; }
.room-card .rc-name { font-weight: 800; font-size: 1.05rem; }
.room-card .rc-sub { font-size: .8rem; color: var(--muted); }
.room-card .rc-count { font-weight: 800; font-size: 1.1rem; }
.dots { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .35); }
.badge-new { font-size: .68rem; background: var(--accent); color: #06101f; padding: 2px 8px; border-radius: 999px; font-weight: 800; }

/* ---------------------------------------------------------------- room -- */
.players { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin-bottom: 16px; }
.pcard {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: .88rem;
  font-weight: 700;
  min-width: 0;
}
.pcard .swatch { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.pcard .pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .crown { margin-left: auto; }
.pcard.me { border-color: var(--accent); }

.host-panel { margin-top: 8px; }
.host-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
/* Two big buttons side by side have to survive a 320px phone. */
.host-actions .btn-big { padding: 16px 8px; font-size: 1rem; border-radius: 16px; }
.host-hint { margin: 0 0 14px; font-size: .78rem; }
.picker-head { margin-bottom: 10px; }
#game-search {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}
#game-search:focus { border-color: var(--accent); }

.fam-filter { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; }
.fam-filter button {
  flex: none;
  font: inherit;
  font-size: .78rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.fam-filter button.on { color: #06101f; background: var(--accent); border-color: transparent; }

.game-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 8px; }
.gcard {
  text-align: left;
  /* A bare <button> takes the UA font and paints its label black, which left
     the game name unreadable on the dark card. .btn does the same two lines. */
  font: inherit;
  color: var(--text);
  padding: 12px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: transform .08s ease, border-color .12s;
}
.gcard:active { transform: scale(.97); border-color: var(--accent); }
.gcard .gi { font-size: 1.7rem; line-height: 1.2; }
.gcard .gn { font-weight: 800; font-size: .92rem; color: #fff; }
.gcard .gt { font-size: .74rem; color: var(--muted); }

.guest-panel .waitcard {
  margin-top: 20px;
  padding: 26px 18px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  text-align: center;
}
.spin { font-size: 2.6rem; animation: spin 2.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------- brief -- */
.brief-wrap {
  margin: auto;
  width: min(480px, 100%);
  padding: 22px 20px calc(22px + var(--safe-bot));
  text-align: center;
}
.brief-icon { font-size: 4rem; line-height: 1; }
#brief-name { margin: 8px 0 4px; font-size: clamp(1.6rem, 7vw, 2.2rem); font-weight: 900; }
.brief-tag { color: var(--muted); margin: 0 0 18px; }
.brief-steps { text-align: left; padding-left: 22px; margin: 0 0 22px; }
.brief-steps li { margin-bottom: 12px; font-size: 1.02rem; font-weight: 600; }
.ready-line { color: var(--muted); font-size: .85rem; margin: 12px 0 6px; }
.ready-dots { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.ready-dots .dot { width: 14px; height: 14px; opacity: .3; }
.ready-dots .dot.on { opacity: 1; box-shadow: 0 0 10px currentColor; }

/* ---------------------------------------------------------------- play -- */
/* The canvas gets its own box between the two chrome strips rather than
   spanning the screen — the scoreboard and the timer used to sit on top of
   live gameplay, hiding whatever fell behind them. */
#screen-play { padding: 0; }
.play-field { position: relative; flex: 1; min-height: 0; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hud-top {
  flex: none;
  padding: 4px 10px 2px;
  padding-top: calc(4px + var(--safe-top));
  pointer-events: none;
}
.hud-board {
  display: flex;
  gap: 10px;
  /* Leader first, so if the room is wide the tail clips rather than the top.
     The min-height keeps the strip a fixed size: if it grew when the first
     scores landed, the canvas would resize mid-round without a resize event. */
  min-height: 17px;
  overflow: hidden;
  font-size: .72rem;
  font-weight: 700;
}
.hud-board div { white-space: nowrap; text-shadow: 0 2px 6px rgba(0, 0, 0, .9); }

.hud {
  flex: none;
  padding: 6px 10px calc(6px + var(--safe-bot));
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
  background: rgba(4, 7, 15, .8);
  border-top: 1px solid var(--line);
}
.hud-score {
  font-size: 1.5rem;
  font-weight: 900;
  text-shadow: 0 2px 8px rgba(0, 0, 0, .8);
  font-variant-numeric: tabular-nums;
}
.hud-time {
  position: relative;
  flex: 1;
  height: 26px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .5);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: .85rem;
}
.hud-time-fill { position: absolute; inset: 0; right: auto; background: linear-gradient(90deg, var(--accent), var(--accent-2)); opacity: .55; transition: width .25s linear; }
.hud-time span { position: relative; }

.countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Light enough to read the scenery through — the numeral carries its own
     shadow instead of relying on a heavy scrim. */
  background: rgba(4, 7, 15, .42);
  font-size: 22vh;
  font-weight: 900;
  line-height: 1;
  text-align: center;
  padding: 0 16px;
  z-index: 5;
}
/* A single digit can take the full height; a word cannot — "TIME!" at 22vh is
   wider than a phone screen, so it is capped against the viewport width too. */
.countdown.word { font-size: min(13vh, 20vw); letter-spacing: 1px; }
.countdown span {
  animation: pulse .6s ease-out;
  text-shadow: 0 6px 26px rgba(0, 0, 0, .8), 0 2px 6px rgba(0, 0, 0, .9);
  white-space: nowrap;
}
@keyframes pulse { from { transform: scale(1.7); opacity: .2; } to { transform: scale(1); opacity: 1; } }

/* ------------------------------------------------------------- results -- */
.res-title { display: flex; align-items: center; gap: 10px; font-size: 1.35rem; margin: 6px 0 14px; }
.res-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.res-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.res-row.first { background: linear-gradient(135deg, rgba(255, 209, 102, .22), rgba(255, 138, 91, .12)); border-color: rgba(255, 209, 102, .5); }
.res-row.me { border-color: var(--accent); }
.res-row .rank { font-weight: 900; width: 26px; }
.res-row .swatch { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.res-row .nm { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.res-row .sc { font-weight: 900; font-variant-numeric: tabular-nums; }
.res-list.small .res-row { padding: 9px 12px; font-size: .9rem; }
#btn-next { margin: 14px 0 8px; }

/* ---------------------------------------------------------- tournament -- */
.tour-banner {
  display: inline-block;
  margin-bottom: 14px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 800;
  color: #ffd79a;
  background: rgba(255, 209, 102, .12);
  border: 1px solid rgba(255, 209, 102, .4);
}
#res-tour { display: block; width: fit-content; }

.champion {
  text-align: center;
  padding: 18px 14px;
  margin-bottom: 14px;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(255, 209, 102, .22), rgba(255, 138, 91, .1));
  border: 1px solid rgba(255, 209, 102, .5);
}
.champion .ch-crown { font-size: 2.6rem; line-height: 1; animation: bob 3.4s ease-in-out infinite; }
.champion .ch-name { font-size: 1.5rem; font-weight: 900; color: var(--ch, var(--text)); }
.champion .ch-sub { font-size: .85rem; font-weight: 700; color: var(--muted); }

/* --------------------------------------------------------------- toast -- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bot));
  transform: translateX(-50%);
  background: rgba(12, 18, 34, .96);
  border: 1px solid var(--line);
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 700;
  font-size: .9rem;
  z-index: 50;
  max-width: 88vw;
  text-align: center;
}
.hidden { display: none !important; }

/* Wider screens get a comfortable reading column; the canvas still fills. */
@media (min-width: 720px) {
  .scroll.pad { padding-left: max(14px, calc((100vw - 900px) / 2)); padding-right: max(14px, calc((100vw - 900px) / 2)); }
}
