/* Layout: mobile-first. Screen-level layouts switch on viewport width AND height;
   components adapt with container queries. The page never scrolls horizontally. */

:root {
  --gap: clamp(0.4rem, 1.4vmin, 1rem);
  --pad: clamp(0.5rem, 2vmin, 1.5rem);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

.screen {
  min-height: 100dvh;
  padding: calc(var(--pad) + var(--safe-t)) calc(var(--pad) + var(--safe-r)) calc(var(--pad) + var(--safe-b)) calc(var(--pad) + var(--safe-l));
}

.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.row-between { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.icon-spacer { width: 2.75rem; flex: none; }
.form-problem { color: var(--danger); font-weight: 700; min-height: 0; }
.form-problem:empty { display: none; }
.tag {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 800;
  white-space: nowrap;
}
.tag-you { background: var(--accent); color: var(--accent-text); }
.tag-warn { background: var(--danger); color: #fff; }
.theme-retro .tag-warn { color: #0b0820; }

.spinner {
  display: inline-block;
  width: 1em; height: 1em;
  border: 0.18em solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -0.15em;
  margin-right: 0.4em;
}
.spinner.big { width: 2.5rem; height: 2.5rem; margin: 0 auto 1rem; display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.narrow-wrap {
  width: 100%;
  max-width: 36rem;
  margin: 0 auto;
  min-height: calc(100dvh - 2 * var(--pad) - var(--safe-t) - var(--safe-b));
  display: grid;
  align-content: center;
}

/* ============ Menu ============ */
.menu-wrap {
  width: 100%;
  max-width: 34rem;
  margin: 0 auto;
  display: grid;
  gap: var(--gap);
  align-content: center;
  min-height: calc(100dvh - 2 * var(--pad) - var(--safe-t) - var(--safe-b));
}
.brand { display: grid; justify-items: center; gap: 0.2rem; text-align: center; color: var(--on-bg); }
.brand-dice { display: flex; gap: 0.6rem; margin-bottom: 0.25rem; }
.brand-dice .die-svg { width: clamp(2.4rem, 9vmin, 4.5rem); height: auto; aspect-ratio: 1; filter: drop-shadow(var(--die-shadow)); }
.brand-dice > :nth-child(1) { transform: rotate(-12deg); }
.brand-dice > :nth-child(2) { transform: translateY(-0.4rem) rotate(6deg); }
.brand-dice > :nth-child(3) { transform: rotate(14deg); }
.brand-title { font-size: clamp(2.6rem, 11vmin, 5.5rem); text-shadow: 0 0.06em 0 rgba(0, 0, 0, 0.25); }
.theme-retro .brand-title { color: var(--accent); text-shadow: 0 0 0.25em var(--accent), 0 0 0.6em rgba(255, 62, 165, 0.6); }
.theme-playful .brand-title { color: #fff; -webkit-text-stroke: 0.04em var(--on-bg); text-shadow: 0 0.08em 0 var(--on-bg); }
.brand-tag { font-weight: 700; color: var(--on-bg-muted); letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.85rem; }

.menu-panel { display: grid; gap: 1.25rem; container-type: inline-size; }
.menu-profile { display: grid; gap: 1rem; }
.menu-cols { display: grid; gap: 1.25rem; }
.menu-section { display: grid; gap: 0.6rem; align-content: start; }
.menu-section h2 { font-size: 1.25rem; }
.or { text-align: center; color: var(--text-muted); font-size: 0.85rem; display: flex; align-items: center; gap: 0.75rem; }
.or::before, .or::after { content: ''; flex: 1; border-top: 1px solid var(--surface-line); }
.join-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.5rem; }
.local-grid { display: grid; gap: 0.5rem; }
.menu-foot { display: flex; justify-content: center; flex-wrap: wrap; gap: 0.5rem; border-top: 1px solid var(--surface-line); padding-top: 0.75rem; }
.menu-foot .btn { color: var(--text); }

@container (min-width: 30rem) {
  .menu-profile { grid-template-columns: minmax(0, 1fr) auto; align-items: start; }
  .local-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 52rem) {
  .menu-wrap { max-width: 56rem; }
  .menu-panel .menu-cols { grid-template-columns: 1fr 1fr; gap: 2rem; }
  .menu-section + .menu-section { border-left: 1px solid var(--surface-line); padding-left: 2rem; }
  .local-grid { grid-template-columns: 1fr; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .menu-wrap { max-width: 56rem; grid-template-columns: minmax(10rem, 0.6fr) 1.4fr; align-items: center; }
  .brand-title { font-size: 2.6rem; }
  .menu-panel .menu-cols { grid-template-columns: 1fr 1fr; }
}

/* ============ Setup ============ */
.setup-panel { display: grid; gap: 1rem; }
.setup-panel .dialog-head h2 { flex: 1; text-align: center; }
.back-btn { background: var(--surface-2); color: var(--text); }
.setup-players { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; container-type: inline-size; }
.setup-row {
  display: grid;
  grid-template-columns: 1.6rem minmax(0, 1fr) 2.75rem;
  grid-template-areas: 'num name remove' 'num type color';
  gap: 0.4rem;
  align-items: center;
  padding: 0.5rem;
  border-radius: var(--radius);
  background: var(--surface-2);
  border-left: 0.35rem solid var(--c);
}
.setup-num { grid-area: num; font-weight: 800; text-align: center; color: var(--text-muted); }
.setup-row > .input { grid-area: name; }
.setup-row > .select:not(.color-select), .setup-you { grid-area: type; }
.setup-row > .color-select { grid-area: color; width: 2.75rem; padding: 0; color: transparent; background: var(--c); border-color: var(--surface); }
.setup-row > .color-select option { color: var(--text); background: var(--surface); }
.setup-row > .icon-btn, .setup-row > .icon-spacer { grid-area: remove; }
.setup-row .icon-btn { background: transparent; color: var(--text-muted); }
.setup-you { font-weight: 700; color: var(--text-muted); padding-left: 0.5rem; }
@container (min-width: 32rem) {
  .setup-row { grid-template-columns: 1.6rem minmax(0, 1fr) 11rem 2.75rem 2.75rem; grid-template-areas: 'num name type color remove'; }
}

/* ============ Lobby ============ */
.lobby-wrap { width: 100%; max-width: 64rem; margin: 0 auto; display: grid; gap: var(--gap); }
.lobby-head { display: flex; align-items: center; gap: 0.75rem; }
.lobby-head .back-btn { background: var(--chip-bg); color: var(--chip-text); }
.lobby-title { font-size: clamp(1.4rem, 4vmin, 2.2rem); color: var(--on-bg); }
.lobby-grid { display: grid; gap: var(--gap); }
.lobby-grid .panel { display: grid; gap: 0.75rem; align-content: start; }
.lobby-grid h2 { font-size: 1.2rem; }
.room-code {
  font-family: var(--font-num);
  font-size: clamp(2.4rem, 9vmin, 4rem);
  font-weight: 800;
  letter-spacing: 0.25em;
  line-height: 1;
  color: var(--accent);
  text-align: center;
  padding-left: 0.25em;
}
.lobby-share { text-align: center; }
.share-link { font-size: 0.85rem; text-align: center; }
.share-actions { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }
.seat-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; }
.seat {
  display: grid;
  grid-template-columns: 1rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.25rem 0.6rem;
  min-height: 3rem;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius);
  background: var(--surface-2);
}
.seat-dot { width: 1rem; height: 1rem; border-radius: 50%; background: var(--pc); border: 2px solid var(--surface-line); }
.seat-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-open .seat-name { color: var(--text-muted); font-style: italic; font-weight: 400; }
.seat-badges { display: flex; gap: 0.25rem; flex-wrap: wrap; justify-content: flex-end; }
.seat-select { grid-column: 2 / -1; }
.lobby-start { display: grid; gap: 0.5rem; max-width: 28rem; width: 100%; margin: 0 auto; }
.lobby-start .muted { color: var(--on-bg-muted); }
@media (min-width: 46rem) {
  .lobby-grid { grid-template-columns: 1fr 1fr; }
  .seat-select { grid-column: auto; width: auto; }
  .seat { grid-template-columns: 1rem minmax(0, 1fr) auto auto; }
}
@media (min-width: 72rem) {
  .lobby-grid { grid-template-columns: 1fr 1.2fr 1fr; }
  .lobby-share { grid-row: span 2; align-content: center; }
}

/* ============ Results ============ */
.results-panel { display: grid; gap: 1rem; }
.results-title { font-size: clamp(1.8rem, 6vmin, 3rem); text-align: center; color: var(--accent); }
.standings { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.standing {
  display: grid;
  grid-template-columns: 2.5rem minmax(0, 1fr) auto;
  grid-template-areas: 'rank name total' 'rank detail detail';
  align-items: center;
  gap: 0 0.75rem;
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  background: var(--surface-2);
  border-left: 0.4rem solid var(--pc);
}
.standing.winner { background: var(--sc-active-bg); }
.standing-rank { grid-area: rank; font-size: 1.4rem; text-align: center; font-weight: 800; }
.standing-name { grid-area: name; font-weight: 800; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.standing-total { grid-area: total; font-family: var(--font-num); font-size: 1.6rem; font-weight: 800; }
.standing-detail { grid-area: detail; color: var(--text-muted); font-size: 0.85rem; }
.results-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; justify-content: center; }
.results-actions .btn { flex: 1 1 10rem; }

/* ============ Dialog extras ============ */
.menu-list { display: grid; gap: 0.5rem; }
.theme-pick { border: 0; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.theme-pick legend { font-weight: 700; margin-bottom: 0.5rem; padding: 0; }
.theme-card {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas: 'sw name' 'sw desc';
  gap: 0 0.75rem;
  align-items: center;
  min-height: 3.2rem;
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}
.theme-card input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.theme-card:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.theme-card:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.theme-name { grid-area: name; font-weight: 800; }
.theme-desc { grid-area: desc; font-size: 0.85rem; color: var(--text-muted); }
.theme-swatch { grid-area: sw; display: flex; gap: 2px; }
.theme-swatch span { width: 1rem; height: 2.2rem; border-radius: 3px; }
.theme-classic-preview .theme-swatch span:nth-child(1) { background: #1d5a37; }
.theme-classic-preview .theme-swatch span:nth-child(2) { background: #fbf6e8; border: 1px solid #c9b78f; }
.theme-classic-preview .theme-swatch span:nth-child(3) { background: #b3261e; }
.theme-playful-preview .theme-swatch span:nth-child(1) { background: #ffd84d; }
.theme-playful-preview .theme-swatch span:nth-child(2) { background: #6a3df5; }
.theme-playful-preview .theme-swatch span:nth-child(3) { background: #ff3d8b; }
.theme-retro-preview .theme-swatch span:nth-child(1) { background: #0b0820; border: 1px solid #3ef2ff; }
.theme-retro-preview .theme-swatch span:nth-child(2) { background: #3ef2ff; }
.theme-retro-preview .theme-swatch span:nth-child(3) { background: #ff3ea5; }
.settings-group { display: grid; gap: 0.5rem; padding-top: 0.75rem; border-top: 1px solid var(--surface-line); }
.switch-desc { display: block; font-weight: 400; font-size: 0.8rem; color: var(--text-muted); }
.settings-note { font-size: 0.85rem; color: var(--text-muted); }

/* ============ Pass-and-play ============ */
.pass-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: calc(var(--pad) + var(--safe-t)) var(--pad) calc(var(--pad) + var(--safe-b));
  background: var(--bg-image), var(--bg);
}
.pass-panel { display: grid; gap: 1rem; text-align: center; justify-items: center; max-width: 28rem; }
.pass-kicker { color: var(--text-muted); font-weight: 700; }
.pass-name { font-family: var(--font-display); font-size: clamp(2rem, 9vmin, 4rem); font-weight: var(--display-weight); color: var(--accent); overflow-wrap: anywhere; }

/* ====================================================================
   GAME SCREEN
   ==================================================================== */
.screen.game {
  --chat-w: min(22rem, 92vw);
  display: grid;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  gap: var(--gap);
  padding: calc(0.4rem + var(--safe-t)) calc(0.5rem + var(--safe-r)) calc(0.5rem + var(--safe-b)) calc(0.5rem + var(--safe-l));
  /* Compact portrait (phones) */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: 'top' 'banner' 'board' 'play';
  max-width: 100%;
  margin: 0 auto;
}
@supports not (height: 100dvh) { .screen.game { height: 100vh; } }
html.kb-open .screen.game { height: var(--vvh, 100dvh); }

.g-top { grid-area: top; display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.g-banner { grid-area: banner; display: grid; gap: 0.35rem; }
.g-banner:empty { display: none; }
.g-board { grid-area: board; min-height: 0; min-width: 0; display: flex; container-type: inline-size; container-name: board; }
.g-play { grid-area: play; min-width: 0; container-type: inline-size; container-name: play; }
.g-chat { grid-area: chat; }

/* Connection dot on the menu button */
.menu-btn .conn-dot { position: absolute; top: 0.35rem; right: 0.35rem; width: 0.55rem; height: 0.55rem; border-radius: 50%; background: transparent; }
.game[data-conn='online'].has-chat .conn-dot { background: #2fd06b; box-shadow: 0 0 0 2px var(--bg); }
.game[data-conn='reconnecting'] .conn-dot, .game[data-conn='connecting'] .conn-dot { background: #ffb020; }
.game[data-conn='offline'] .conn-dot { background: #ff4d4f; }

/* ---------- Player strip ---------- */
.pstrip {
  flex: 1;
  min-width: 0;
  container-type: inline-size;
  container-name: strip;
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 0.3rem;
}
.pchip {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  min-height: 2.75rem;
  padding: 0.25rem 0.4rem;
  border-radius: var(--radius);
  background: var(--chip-bg);
  color: var(--chip-text);
  border: 2px solid transparent;
  transition: background 0.2s, color 0.2s;
}
.pchip.is-active { background: var(--chip-active-bg); color: var(--chip-active-text); border-color: var(--pc); box-shadow: var(--shadow); }
.pchip-avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.7rem; height: 1.7rem;
  border-radius: 50%;
  background: var(--pc);
  color: #fff;
  font-weight: 900;
  font-size: 0.85rem;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.4);
}
.theme-retro .pchip-avatar { border-radius: 2px; font-family: var(--font-display); }
.pchip.is-active .pchip-avatar { animation: pulse 1.6s ease-in-out infinite; }
.pchip.thinking .pchip-avatar::after {
  content: '';
  position: absolute;
  width: 1.7rem; height: 1.7rem;
  border-radius: 50%;
  border: 2px dashed currentColor;
  animation: spin 2.2s linear infinite;
}
.pchip-text { display: grid; min-width: 0; line-height: 1.1; }
.pchip-name { font-weight: 700; font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pchip-total { font-family: var(--font-num); font-weight: 800; font-size: 1rem; }
.pchip-flag { position: absolute; top: -0.35rem; right: 0.2rem; font-size: 0.6rem; font-weight: 800; padding: 0 0.25rem; border-radius: var(--radius-pill); background: var(--surface); color: var(--text); }
.pchip-flag:empty { display: none; }
.pchip.offline { opacity: 0.65; }
.pchip.is-me .pchip-name::after { content: ' (you)'; font-weight: 400; opacity: 0.8; }
@keyframes pulse { 50% { transform: scale(1.12); } }
/* Narrow strip with many players: drop the avatar so names stay readable */
@container strip (max-width: 17rem) {
  .pstrip:has(> :nth-child(4)) .pchip-avatar { display: none; }
  .pstrip:has(> :nth-child(4)) .pchip { border-left: 0.3rem solid var(--pc); padding-inline: 0.3rem 0.2rem; }
  .pstrip:has(> :nth-child(4)) .pchip-name { font-size: 0.72rem; }
  .pstrip:has(> :nth-child(4)) .pchip-total { font-size: 0.9rem; }
}
@container strip (max-width: 13rem) {
  .pstrip:has(> :nth-child(3)) .pchip-avatar { display: none; }
  .pstrip:has(> :nth-child(3)) .pchip { border-left: 0.3rem solid var(--pc); padding-inline: 0.3rem 0.2rem; }
}
.reaction-float {
  position: absolute;
  left: 50%;
  bottom: 50%;
  font-size: 1.8rem;
  pointer-events: none;
  animation: float-up 1.8s ease-out forwards;
  z-index: 5;
}
@keyframes float-up {
  0% { transform: translate(-50%, 0) scale(0.5); opacity: 0; }
  15% { transform: translate(-50%, -0.5rem) scale(1.2); opacity: 1; }
  100% { transform: translate(-50%, -4.5rem) scale(1); opacity: 0; }
}

/* ---------- Banner ---------- */
.banner-line {
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
}
.banner-line.warn { background: #ffe9a8; color: #3a2a00; }
.banner-line.decide { display: grid; gap: 0.4rem; }
.banner-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.banner-actions .btn { flex: 1 1 9rem; }
.countdown { font-family: var(--font-num); }

/* ---------- Scorecard ---------- */
.sc-wrap {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
  border-radius: var(--radius-lg);
  background: var(--sc-bg);
  box-shadow: var(--shadow-lg);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.theme-retro .sc-wrap { border: 2px solid var(--border); }
.theme-playful .sc-wrap { border: 3px solid var(--btn-border); }
.scorecard {
  --cat-w: 3.1rem;
  --col-w: 3.3rem;
  --row-h: 2rem;
  width: 100%;
  height: 100%;
  border-collapse: separate;
  border-spacing: 0;
  color: var(--sc-text);
  font-variant-numeric: tabular-nums;
  table-layout: fixed;
}
.scorecard th, .scorecard td {
  height: var(--row-h);
  padding: 0 0.25rem;
  border-bottom: 1px solid var(--sc-line);
  text-align: center;
  background: var(--sc-bg);
}
.scorecard thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--sc-head-bg);
  height: 2.4rem;
  font-size: 0.8rem;
}
.scorecard .sc-cat {
  position: sticky;
  left: 0;
  z-index: 2;
  width: var(--cat-w);
  text-align: left;
  padding-left: 0.5rem;
  font-weight: 700;
  font-size: 0.85rem;
  background: var(--sc-head-bg);
  border-right: 1px solid var(--sc-line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scorecard thead .sc-corner { z-index: 4; }
.sc-player { width: var(--col-w); padding: 0 0.2rem; border-top: 0.3rem solid var(--pc); }
.sc-pname { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; }

/* Active player's column: highlighted, and pinned so it never scrolls out of view. */
.scorecard .is-active { background: var(--sc-active-bg); }
.scorecard td.is-active, .scorecard th.sc-player.is-active { position: sticky; left: var(--cat-w); right: 0; z-index: 1; }
.scorecard thead th.sc-player.is-active { z-index: 3; }
.sc-player.is-active { box-shadow: inset 0 0 0 2px var(--pc); }

.sc-val { font-family: var(--font-num); font-weight: 700; font-size: 1.05rem; }
td.zero .sc-val { color: var(--sc-zero); }
.sc-sumrow th, .sc-sumrow td { background: var(--sc-head-bg); font-size: 0.85rem; }
.sc-sumrow .sc-val { font-size: 0.95rem; }
.sc-total th, .sc-total td { border-top: 2px solid var(--sc-text); border-bottom: 0; }
.sc-total .sc-val { font-size: 1.25rem; font-weight: 900; }
td.made .sc-val { color: var(--good); }
.sc-bonus td .sc-val { color: var(--good); }
.theme-classic .scorecard tbody td { background-image: none; }

.sc-pick {
  width: 100%;
  height: calc(var(--row-h) - 0.25rem);
  min-height: 1.75rem;
  min-width: 2.4rem;
  padding: 0;
  border: 2px dashed var(--sc-pick-border);
  border-radius: calc(var(--radius) * 0.8);
  background: var(--sc-pick-bg);
  color: var(--sc-pick-text);
  font-family: var(--font-num);
  font-weight: 800;
  font-size: 1.05rem;
  touch-action: manipulation;
}
.sc-pick.zero { color: var(--sc-zero); border-color: var(--sc-line); border-style: dotted; }
.sc-pick.best { background: var(--sc-best-bg); color: var(--sc-best-text); border-style: solid; border-color: var(--sc-best-bg); }
.sc-pick:disabled { cursor: default; opacity: 0.7; }
.sc-pick:focus-visible { outline-offset: -3px; }
@media (hover: hover) {
  .sc-pick:not(:disabled):hover { border-style: solid; filter: brightness(1.05); transform: scale(1.04); }
}
td.flash { animation: flash 1s ease-out; }
@keyframes flash { 0% { background: var(--held-ring); } 100% { background: inherit; } }

@media (pointer: coarse) {
  .sc-pick { min-height: 44px; min-width: 44px; height: 44px; }
  .scorecard { --row-h: 46px; }
}

/* Category labels: abbreviated by default (full names stay available to screen
   readers); full names once the board is wide enough for this many players. */
.scorecard .lbl-full {
  position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.scorecard .lbl-short { display: inline; font-family: var(--font-num); }
@container board (min-width: 19rem) {
  .scorecard:is(.players-1, .players-2) { --cat-w: 7.6rem; --col-w: 4.2rem; }
  .scorecard:is(.players-1, .players-2) .lbl-full { position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto; }
  .scorecard:is(.players-1, .players-2) .lbl-short { display: none; }
}
@container board (min-width: 23rem) {
  .scorecard.players-3 { --cat-w: 7.6rem; --col-w: 4.2rem; }
  .scorecard.players-3 .lbl-full { position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto; }
  .scorecard.players-3 .lbl-short { display: none; }
}
@container board (min-width: 27rem) {
  .scorecard.players-4 { --cat-w: 7.8rem; --col-w: 4.2rem; }
  .scorecard.players-4 .lbl-full { position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto; }
  .scorecard.players-4 .lbl-short { display: none; }
}
@container board (min-width: 40rem) {
  .scorecard { --cat-w: 10rem; --col-w: 5.5rem; }
  .scorecard .sc-cat { font-size: 0.9rem; }
  .scorecard thead th { font-size: 0.95rem; }
}

/* ---------- Play area (dice + roll) ---------- */
.play-inner { display: grid; gap: 0.45rem; justify-items: center; width: 100%; }
.turn-line {
  font-weight: 800;
  text-align: center;
  font-size: 0.95rem;
  color: var(--on-bg);
  min-height: 1.4em;
  display: flex;
  align-items: center;
  gap: 0.4em;
}
.turn-line::before { content: ''; width: 0.8em; height: 0.8em; border-radius: 50%; background: var(--pc, transparent); flex: none; }
.theme-retro .turn-line { font-family: var(--font-display); letter-spacing: 0.04em; font-weight: 400; }
.timer-bar { width: min(100%, 24rem); height: 0.35rem; border-radius: 99px; background: var(--chip-bg); overflow: hidden; }
.timer-bar span { display: block; height: 100%; width: 100%; transform-origin: left; transform: scaleX(var(--frac, 1)); background: var(--good); transition: transform 0.25s linear; }
.timer-bar.low span { background: var(--danger); }
.tray { width: 100%; display: flex; justify-content: center; }
.dice {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(0.35rem, 2.5cqi, 1.1rem);
  width: min(100%, 34rem);
  padding: 0.35rem 0.25rem 0.75rem;
}
.actions { width: min(100%, 24rem); }
.btn-roll { width: 100%; min-height: 3.2rem; font-size: 1.2rem; flex-direction: row; }
.roll-sub { font-size: 0.8em; font-weight: 600; opacity: 0.85; }
.roll-sub:not(:empty)::before { content: '· '; }
.my-turn .btn-roll:not(:disabled) { animation: nudge 2.4s ease-in-out infinite; }
@keyframes nudge { 0%, 85%, 100% { transform: none; } 90% { transform: scale(1.04); } 95% { transform: scale(0.99); } }
.hint { font-size: 0.85rem; color: var(--on-bg-muted); text-align: center; min-height: 1.2em; }
.joker-note {
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 800;
  font-size: 0.85rem;
  text-align: center;
  animation: pop-in 0.3s var(--ease-pop);
}
.shake-offer { display: flex; gap: 0.3rem; justify-content: center; align-items: center; width: min(100%, 24rem); }
.shake-offer .btn { min-height: 44px; padding: 0.3rem 0.7rem; font-size: 0.85rem; box-shadow: none; }
.shake-offer .btn:first-child { flex: 1; }
.shake-offer .btn-ghost { color: var(--on-bg); }
.g-play:has(.shake-offer:not([hidden])) .hint { display: none; }

/* ---------- Chat ---------- */
.g-chat {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 0.5rem;
  padding: 0.75rem;
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  min-height: 0;
}
.chat-head { display: flex; align-items: center; justify-content: space-between; }
.chat-head h2 { font-size: 1.1rem; }
.chat-head .icon-btn { background: var(--surface-2); color: var(--text); }
.chat-log { list-style: none; margin: 0; padding: 0 0.25rem; overflow-y: auto; overscroll-behavior: contain; display: grid; align-content: start; gap: 0.35rem; min-height: 4rem; }
.chat-msg { overflow-wrap: anywhere; font-size: 0.95rem; }
.chat-name { font-weight: 800; color: var(--pc); margin-right: 0.4em; }
.theme-classic .chat-name, .theme-playful .chat-name { filter: brightness(0.75); }
.react-row { display: grid; grid-template-columns: repeat(4, minmax(44px, 1fr)); gap: 0.25rem; }
.react-btn { min-width: 44px; min-height: 44px; border: 0; border-radius: var(--radius); background: var(--surface-2); font-size: 1.3rem; padding: 0; }
@media (hover: hover) { .react-btn:hover { transform: scale(1.12); } }
.chat-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.4rem; }
.chat-form .btn { padding-inline: 0.8rem; }

/* Compact: chat is a bottom sheet */
.game .g-chat {
  position: fixed;
  left: calc(0.5rem + var(--safe-l));
  right: calc(0.5rem + var(--safe-r));
  bottom: calc(var(--kb, 0px) + 0.5rem + var(--safe-b));
  z-index: 40;
  max-height: min(70dvh, calc(var(--vvh, 100dvh) - 4rem));
  height: 26rem;
  transform: translateY(calc(100% + 2rem + var(--safe-b)));
  visibility: hidden;
  transition: transform 0.25s var(--ease-pop), visibility 0s linear 0.25s;
}
.game.chat-open .g-chat { transform: none; visibility: visible; transition: transform 0.25s var(--ease-pop); }

/* ====== Short landscape (phones on their side) ====== */
@media (orientation: landscape) and (max-height: 500px) {
  .screen.game {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: 'top top' 'banner banner' 'play board';
    gap: 0.4rem 0.6rem;
    padding-top: calc(0.3rem + var(--safe-t));
  }
  .g-play { container-type: size; display: grid; align-items: center; }
  .play-inner { gap: 0.3rem; }
  .dice { gap: 2.5cqi; width: min(100%, calc(5 * 19cqh + 4 * 2.5cqi)); padding-bottom: 0.5rem; }
  .turn-line { font-size: 0.85rem; }
  .hint { display: none; }
  .btn-roll { min-height: 2.9rem; font-size: 1.05rem; }
  .pchip { min-height: 2.75rem; padding-block: 0.1rem; }
  .pchip-avatar { width: 1.4rem; height: 1.4rem; }
  .game .g-chat { left: auto; width: min(22rem, 60vw); top: calc(0.5rem + var(--safe-t)); height: auto; max-height: none; transform: translateX(calc(100% + 2rem + var(--safe-r))); }
  .game.chat-open .g-chat { transform: none; }
}

/* ====== Medium (tablets, small laptops) ====== */
@media (min-width: 700px) and (min-height: 501px) {
  .screen.game {
    grid-template-columns: minmax(18rem, 1fr) minmax(0, 1.35fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: 'top top' 'banner banner' 'play board';
    gap: var(--gap) calc(var(--gap) * 1.5);
    padding: calc(var(--pad) + var(--safe-t)) calc(var(--pad) + var(--safe-r)) calc(var(--pad) + var(--safe-b)) calc(var(--pad) + var(--safe-l));
    max-width: 110rem;
  }
  .g-play { container-type: size; display: grid; align-items: center; }
  .play-inner { gap: 0.8rem; }
  .dice { width: min(100%, calc(5 * 17cqh + 4 * 1rem)); gap: clamp(0.5rem, 2.5cqi, 1.25rem); }
  .turn-line { font-size: 1.15rem; }
  .btn-roll { min-height: 3.6rem; font-size: 1.35rem; }
  .actions { width: min(100%, 22rem); }
  .pstrip { grid-auto-columns: minmax(0, 14rem); }
  .pchip { padding: 0.35rem 0.6rem; }
  .pchip-name { font-size: 0.9rem; }
  .pchip-total { font-size: 1.15rem; }
  .game .g-chat {
    left: auto;
    right: calc(var(--pad) + var(--safe-r));
    top: calc(var(--pad) + var(--safe-t) + 3.5rem);
    bottom: calc(var(--pad) + var(--safe-b));
    width: var(--chat-w);
    height: auto;
    max-height: none;
    transform: translateX(calc(100% + 3rem + var(--safe-r)));
  }
  .game.chat-open .g-chat { transform: none; }
}

/* ====== Large (desktop up to 4K / ultrawide) ====== */
@media (min-width: 1200px) and (min-height: 600px) {
  .screen.game.has-chat {
    grid-template-columns: minmax(20rem, 1fr) minmax(30rem, 1.45fr) minmax(16rem, 0.75fr);
    grid-template-areas: 'top top top' 'banner banner banner' 'play board chat';
    max-width: 130rem;
  }
  .screen.game:not(.has-chat) { max-width: 100rem; }
  .game.has-chat .g-chat {
    position: static;
    transform: none;
    visibility: visible;
    width: auto;
    transition: none;
  }
  .game.has-chat .chat-toggle, .game.has-chat .chat-close { display: none; }
  /* Fewer players: narrower scorecard, more room for big dice */
  .screen.game.has-chat[data-players='1'], .screen.game.has-chat[data-players='2'] {
    grid-template-columns: minmax(24rem, 1.4fr) minmax(24rem, 1fr) minmax(16rem, 0.7fr);
  }
  .dice { width: min(100%, 44rem); }
  .actions { width: min(100%, 26rem); }
}
/* Ultrawide: keep the composition centered instead of stretching */
@media (min-aspect-ratio: 2/1) and (min-width: 1200px) {
  .screen.game { max-width: min(100%, 230dvh); }
}

/* Very short portrait phones: tighten everything */
@media (orientation: portrait) and (max-height: 600px) {
  .turn-line { font-size: 0.85rem; }
  .hint { display: none; }
  .btn-roll { min-height: 2.9rem; }
  .dice { padding-bottom: 0.5rem; }
}
