/* ==========================================================================
   Sho Fi Games — shared theme
   Tokens, base elements, and the small set of components every page uses.
   Game-specific styles live next to each game.
   ========================================================================== */

:root {
  color-scheme: light dark;

  /* Palette: warm sand, deep sea-blue, tomato red, olive green. */
  --sand: #f7ecd6;
  --sea: #10506f;
  --tomato: #cf3a27;
  --olive: #5f7023;
  --sun: #f2b632;
  --ink: #2a1c12;

  /* Semantic tokens. These are the ones that flip in dark mode. */
  --bg: var(--sand);
  --bg-dot: rgb(42 28 18 / .07);
  --surface: #fffaf0;
  --surface-2: #f0e2c4;
  --text: var(--ink);
  --muted: #6a5847;
  --line: var(--ink);
  --link: var(--sea);
  --focus: var(--sea);
  --footer-bg: var(--sea);
  --footer-text: #fdf6e6;
  --backdrop: rgb(42 28 18 / .55);

  --tap: 48px;
  --radius: 20px 17px 22px 16px / 17px 21px 16px 20px; /* slightly wonky on purpose */
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system,
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1c25;
    --bg-dot: rgb(247 236 214 / .05);
    --surface: #1a2f3d;
    --surface-2: #24404f;
    --text: #f7ecd6;
    --muted: #b9ad97;
    --line: #05090c;
    --link: #7cc8ea;
    --focus: var(--sun);
    --footer-bg: #081219;
    --backdrop: rgb(0 0 0 / .65);
  }
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font: 400 1rem/1.5 var(--font);
  color: var(--text);
  background: var(--bg) radial-gradient(var(--bg-dot) 1.5px, transparent 1.6px) 0 0 / 22px 22px;
  -webkit-tap-highlight-color: transparent;
}

main { flex: 1; }

h1, h2, h3, p, ul, ol, fieldset { margin: 0; padding: 0; }
ul, ol { list-style: none; }
fieldset { border: 0; min-width: 0; }
h1, h2, h3 { line-height: 1.15; font-weight: 900; letter-spacing: -.01em; }
h2 { font-size: 1.5rem; }
a { color: var(--link); }
img, svg { max-width: 100%; height: auto; }
button, input { font: inherit; color: inherit; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.wrap { width: min(100% - 2rem, 56rem); margin-inline: auto; }
.muted { color: var(--muted); }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

/* ---------- Buttons ---------- */

.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-height: var(--tap);
  padding: .6rem 1.25rem;
  font: 800 1.05rem/1.1 var(--font);
  color: var(--btn-fg);
  text-decoration: none;
  background: var(--btn-bg);
  border: 3px solid var(--line);
  border-radius: 16px 18px 15px 19px;
  box-shadow: 0 4px 0 var(--line);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn--tomato { --btn-bg: var(--tomato); --btn-fg: #fff; }
.btn--sea { --btn-bg: var(--sea); --btn-fg: #fff; }
.btn--olive { --btn-bg: var(--olive); --btn-fg: #fff; }
.btn--sun { --btn-bg: var(--sun); --btn-fg: var(--ink); }
.btn--big { min-height: 56px; padding-inline: 1.75rem; font-size: 1.25rem; }
.btn--block { width: 100%; }

/* Square icon-only button (sound toggle, close, dice). */
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  font-size: 1.25rem;
  line-height: 1;
  background: var(--surface);
  border: 3px solid var(--line);
  border-radius: 15px 17px 14px 18px;
  box-shadow: 0 3px 0 var(--line);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .08s ease, box-shadow .08s ease;
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }

/* ---------- Header ---------- */

.site-header { padding: max(.75rem, env(safe-area-inset-top)) 0 .25rem; }
.site-header__row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.site-header__tools { display: flex; align-items: center; gap: .5rem; min-width: 0; min-height: var(--tap); }
.site-header__tools .icon-btn { flex: none; }
.brand { flex: none; }

.brand__name { font-size: clamp(1.3rem, 5.4vw, 2.1rem); font-weight: 900; letter-spacing: -.03em; white-space: nowrap; }
/* The padding makes the logo a full-size tap target; the margin gives the space back. */
.brand__name a { display: inline-block; padding-block: .75rem; margin-block: -.75rem; color: var(--text); text-decoration: none; }
.brand__name span {
  display: inline-block;
  padding: .05em .4em .1em;
  color: #fff;
  background: var(--tomato);
  border: 3px solid var(--line);
  border-radius: 12px 14px 11px 15px;
  transform: rotate(-3deg);
}
.brand__tag { margin-top: .2rem; font-size: .9rem; font-weight: 700; color: var(--muted); }

/* Profile chip: avatar + nickname, opens the picker. */
.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  min-width: 0;
  min-height: var(--tap);
  max-width: 11rem;
  padding-block: .25rem;
  padding-inline: .5rem .8rem;
  font-weight: 800;
  background: var(--surface);
  border: 3px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--line);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .08s ease, box-shadow .08s ease;
}
.chip:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.chip__avatar { font-size: 1.4rem; line-height: 1; }
.chip__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* A little dot until the player has confirmed their name. */
.chip.is-new::after {
  content: "";
  position: absolute;
  top: -4px;
  inset-inline-end: -2px;
  width: 14px;
  height: 14px;
  background: var(--tomato);
  border: 3px solid var(--line);
  border-radius: 50%;
}
/* On phones the header also holds the sound and language buttons: avatar only. */
@media (max-width: 30rem) {
  .chip { flex: none; padding-inline: .5rem; }
  .chip__name { display: none; }
}
/* The smallest phones: tighten the header so logo and buttons share one row. */
@media (max-width: 22.5rem) {
  .site-header__row { gap: .5rem; }
  .site-header__tools { gap: .35rem; }
  .site-header__tools .icon-btn { width: 44px; height: 44px; }
  .chip { min-height: 44px; }
  .brand__name { font-size: 1.1rem; }
}

/* Language toggle: shows the language you would switch to. */
.lang-btn { font-size: 1rem; font-weight: 900; }

/* ---------- Host speech bubble ---------- */

.host { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 1.1rem; }
.host__teta { width: clamp(88px, 26vw, 150px); filter: drop-shadow(0 4px 0 rgb(0 0 0 / .12)); }

.bubble {
  position: relative;
  padding: .9rem 1.1rem 1rem;
  background: var(--surface);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 4px 4px 0 var(--line);
}
.bubble::before {
  content: "";
  position: absolute;
  left: -11px;
  top: calc(50% - 9px);
  width: 18px;
  height: 18px;
  background: var(--surface);
  border: solid var(--line);
  border-width: 0 0 3px 3px;
  transform: rotate(45deg);
}
.bubble__big { font-size: clamp(1.6rem, 7vw, 2.4rem); font-weight: 900; line-height: 1.05; letter-spacing: -.02em; color: var(--tomato); }
.bubble__big + p { margin-top: .3rem; }

@media (prefers-color-scheme: dark) {
  .bubble__big { color: #ff8a75; }
}

/* ---------- Cards and tags ---------- */

.card {
  background: var(--surface);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 4px 4px 0 var(--line);
}

.tags { display: flex; flex-wrap: wrap; gap: .35rem; }
.tag {
  padding: .1rem .55rem;
  font-size: .75rem;
  font-weight: 800;
  letter-spacing: .02em;
  white-space: nowrap;
  background: var(--surface-2);
  border: 2px solid var(--line);
  border-radius: 999px;
}
.tag--count { color: #fff; background: var(--sea); }
.tag--soon { color: var(--ink); background: var(--sun); transform: rotate(-3deg); }

/* ---------- Forms ---------- */

.field { display: block; }
.field__label { display: block; margin-bottom: .3rem; font-weight: 800; }
.field__row { display: flex; gap: .5rem; }
.input {
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: var(--tap);
  padding: .55rem .85rem;
  font-size: 1.1rem; /* 16px+ so iOS does not zoom on focus */
  font-weight: 700;
  background: var(--surface);
  border: 3px solid var(--line);
  border-radius: 14px 16px 13px 17px;
}
.input::placeholder { color: var(--muted); opacity: .8; }

/* ---------- Dialog sheet (profile picker, later: game prompts) ---------- */

.sheet {
  width: min(100% - 1.5rem, 26rem);
  max-height: calc(100dvh - 1.5rem);
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 6px 6px 0 var(--line);
  overflow: auto;
}
.sheet::backdrop { background: var(--backdrop); }
.sheet[open] { animation: sheet-in .18s ease-out; }
.sheet__body { display: grid; gap: 1rem; padding: 1.25rem; }
.sheet__actions { display: flex; gap: .75rem; justify-content: flex-end; }
.sheet__actions .btn--tomato { flex: 1; }

@keyframes sheet-in {
  from { opacity: 0; transform: translateY(12px) scale(.97); }
}

/* Emoji avatar picker: radio inputs dressed up as big tappable tiles. */
.avatar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: .35rem; }
.avatar-grid legend { margin-bottom: .3rem; font-weight: 800; }
.avatar-grid label { position: relative; display: block; cursor: pointer; }
.avatar-grid input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.avatar-grid span {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-height: 44px;
  font-size: 1.6rem;
  line-height: 1;
  border: 3px solid transparent;
  border-radius: 14px;
  transition: transform .1s ease;
}
.avatar-grid input:checked + span { background: var(--sun); border-color: var(--line); transform: rotate(-4deg) scale(1.06); }
.avatar-grid input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- Countdown: a number and a shrinking bar (createTimer in common.js) ---------- */

.timebar { height: 10px; background: var(--surface-2); border: 2px solid var(--line); border-radius: 999px; overflow: hidden; }
.timebar__fill { display: block; height: 100%; background: var(--olive); transform-origin: 0 50%; transition: transform .2s linear; }
[dir="rtl"] .timebar__fill { transform-origin: 100% 50%; }
.timebar.is-low .timebar__fill { background: var(--tomato); }
.clock { font-size: 2.6rem; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.clock.is-low { color: var(--tomato); }

/* ---------- Celebration: emoji raining down after a win (celebrate() in common.js) ---------- */

.confetti { position: fixed; inset: 0; z-index: 60; overflow: hidden; pointer-events: none; }
.confetti span { position: absolute; top: -3rem; line-height: 1; animation: confetti-fall 2.4s ease-in forwards; }
@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(260deg); }
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.25rem + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: calc(100% - 2rem);
  padding: .6rem 1rem;
  font-weight: 800;
  color: #fff;
  background: var(--ink);
  border: 3px solid var(--line);
  border-radius: 999px;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Footer ---------- */

.site-footer {
  position: relative;
  margin-top: 3.5rem;
  padding: 1.5rem 0 calc(1.5rem + env(safe-area-inset-bottom));
  font-size: .95rem;
  text-align: center;
  color: var(--footer-text);
  background: var(--footer-bg);
}
/* Little waves on top of the sea-colored footer. */
.site-footer::before {
  content: "";
  position: absolute;
  inset: -13px 0 auto;
  height: 14px;
  background: radial-gradient(ellipse at 50% 100%, var(--footer-bg) 68%, transparent 70%) 0 0 / 36px 14px repeat-x;
}
.site-footer a { color: inherit; font-weight: 800; }
.site-footer p + p { margin-top: .35rem; opacity: .85; }

/* ---------- "Coming soon" placeholder used by game pages not built yet ---------- */

.soon { display: grid; gap: 1.5rem; align-content: start; justify-items: start; padding-top: 2rem; }
.soon h1 { font-size: clamp(1.6rem, 7vw, 2.4rem); }
.soon h1 + p { margin-top: .4rem; }

/* ---------- Right-to-left and Arabic ---------- */

/* Layout mirrors by itself (flex, grid and logical properties). These are the leftovers. */
[dir="rtl"] .bubble::before { left: auto; right: -11px; transform: rotate(225deg); }

/* The logo and room codes stay left-to-right. */
.brand__name { direction: ltr; }
[dir="rtl"] .brand__name { text-align: right; }

/* Arabic letters join up, so spacing them out breaks words; they also need more line height. */
html[lang="ar"] body :not(.code-input):not(.room-code__value) { letter-spacing: normal; }
html[lang="ar"] body { line-height: 1.7; }
html[lang="ar"] :is(h1, h2, h3, .bubble__big) { line-height: 1.4; }
html[lang="ar"] .btn { line-height: 1.4; }
/* Arabic reads smaller than Latin at the same size, so the smallest text gets a bump. */
html[lang="ar"] .tag { font-size: .85rem; }
html[lang="ar"] :is(.room-code__label, .room-code__hint) { font-size: .9rem; }

/* ---------- Motion preferences ---------- */

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

/* ==========================================================================
   Room lobby (shared/lobby.js): create/join, room code, players, ready, start
   ========================================================================== */

.btn--small { min-height: 44px; padding: .35rem .9rem; font-size: .9rem; box-shadow: 0 3px 0 var(--line); }

.lobby { display: grid; gap: 1.1rem; max-width: 30rem; margin-inline: auto; padding-top: 1rem; }
.lobby__line { font-size: 1.1rem; font-weight: 700; line-height: 1.3; }
.lobby__entry, .lobby__room { display: grid; gap: 1rem; }
.lobby__or { font-weight: 800; text-align: center; color: var(--muted); }
.lobby__error {
  padding: .6rem .9rem;
  font-weight: 700;
  color: #fff;
  background: var(--tomato);
  border: 3px solid var(--line);
  border-radius: 14px 16px 13px 17px;
}
.lobby__share { display: flex; flex-wrap: wrap; gap: .75rem; }
.lobby__share .btn { flex: 1 1 auto; padding-inline: .9rem; font-size: 1rem; white-space: nowrap; }
.lobby__actions { display: grid; gap: .6rem; }
.lobby__actions[hidden] { display: none; }
/* In a game night: which night this game belongs to. */
.lobby__night { display: grid; gap: .4rem; padding: .7rem .9rem; font-weight: 700; background: var(--surface-2); }
.lobby__night[hidden] { display: none; }
.lobby__night-lead:empty { display: none; }
.lobby__night .btn { justify-self: start; }

/* Game night, during a game: the host's way to stop it, in a corner over the game. */
.night-stop { position: fixed; inset-inline-end: max(.75rem, env(safe-area-inset-right)); bottom: max(.75rem, env(safe-area-inset-bottom)); z-index: 55; display: grid; justify-items: end; gap: .5rem; max-width: min(20rem, calc(100% - 1.5rem)); }
.night-stop[hidden], .night-stop__ask[hidden] { display: none; }
.night-stop__btn { opacity: .9; }
.night-stop__ask { display: grid; gap: .6rem; padding: .8rem .9rem; font-weight: 700; }
.night-stop__row { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; }
.lobby__hint { font-weight: 700; text-align: center; color: var(--muted); }
.lobby__room > .btn--small { justify-self: center; }
.lobby .btn.is-on { --btn-bg: var(--surface); --btn-fg: var(--text); }

/* Room codes are always Latin letters, read left to right, in every language. */
.code-input { font-size: 1.5rem; font-weight: 900; letter-spacing: .3em; text-align: center; text-transform: uppercase; direction: ltr; }
.code-input::placeholder { letter-spacing: .3em; opacity: .35; }

/* Connection status strip: connecting, waking the server, reconnecting. */
.net {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding-block: .5rem;
  padding-inline: .9rem .5rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--sun);
  border: 3px solid var(--line);
  border-radius: 14px 16px 13px 17px;
}

.room-code {
  display: grid;
  justify-items: center;
  width: 100%;
  padding: .7rem 1rem .8rem;
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .08s ease, box-shadow .08s ease;
}
.room-code:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--line); }
.room-code__label { font-size: .8rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.room-code__value { font-size: clamp(2.6rem, 14vw, 3.6rem); font-weight: 900; line-height: 1.05; letter-spacing: .18em; margin-right: -.18em; direction: ltr; }
.room-code__hint { font-size: .8rem; color: var(--muted); }

.players__title { display: flex; align-items: baseline; justify-content: space-between; font-size: 1.2rem; }
.players__count { font-size: 1rem; color: var(--muted); }
.players { display: grid; gap: .5rem; }
.player {
  display: flex;
  align-items: center;
  gap: .6rem;
  min-height: var(--tap);
  padding: .35rem .75rem;
  font-weight: 800;
  background: var(--surface);
  border: 3px solid var(--line);
  border-radius: 14px 16px 13px 17px;
}
.player.is-you { background: var(--surface-2); }
.player.is-away { opacity: .55; border-style: dashed; }
.player__avatar { font-size: 1.5rem; line-height: 1; }
.player__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player__name small { font-weight: 700; color: var(--muted); }
.player__badges { display: flex; gap: .3rem; font-size: 1.15rem; line-height: 1; }
