/* Pictionary — THWS-branded styles (Step 7). */

:root {
  /* THWS brand: orange is the only chromatic primary; black + white + greys
     are the companion palette. Inter is the official free fallback for GT Planar. */
  --color-primary: #ff6a00;
  --color-primary-hover: #e05d00;
  --color-primary-shadow: #b34a00;
  --color-primary-glow: rgba(255, 106, 0, 0.25);

  /* Semantic greens — used for "win / correct / available stock" only,
     never as a UI primary. */
  --color-win: #11aa66;
  --color-win-dark: #118855;
  --color-win-glow: rgba(26, 102, 51, 0.18);
}

body.player[data-brand-mode="digitkmu"] {
  --color-primary: #07384a;
  --color-primary-hover: #052b39;
  --color-primary-shadow: #031d27;
  --color-primary-glow: rgba(7, 56, 74, 0.25);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

/* HTML's `hidden` attribute should always win over component display rules
   (e.g. .badge sets display: inline-block which would otherwise unhide it). */
[hidden] { display: none !important; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background: #fafafa;
  color: #1a1a1a;
  padding: 1rem;
  min-height: 100vh;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--color-primary);
}

header h1 {
  font-size: 1.4rem;
  margin: 0;
  font-weight: 600;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}
.brand-logo {
  height: 48px;
  width: auto;
  display: block;
  flex-shrink: 0;
}
body.player[data-brand-mode="digitkmu"] .brand-logo-thws,
body.player[data-brand-mode="thws"] .brand-logo-digitkmu,
body.player .header-brand h1 {
  display: none;
}
body.player[data-brand-mode="digitkmu"] main button:not(.color-btn):not(.judge) {
  border-color: var(--color-primary);
}
body.player[data-brand-mode="digitkmu"] #canvas {
  border-color: var(--color-primary);
}
body.player[data-brand-mode="digitkmu"] .color-btn.active {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--color-primary);
}
body.player[data-brand-mode="digitkmu"] #btn-eraser[aria-pressed="true"] {
  background: var(--color-primary);
  border-color: var(--color-primary);
}
body.admin .brand-logo { height: 36px; }

@media (max-width: 600px) {
  .brand-logo { height: 36px; }
}

#scores {
  font-size: 1.6rem;
  font-weight: bold;
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
}
.score-sep { color: #999; }
body.player header #scores {
  background: rgba(255, 255, 255, 0.94);
  border-radius: 999px;
  padding: 0.2rem 0.9rem;
  align-items: center;
}
.score-correct { color: var(--color-win-dark); }
.score-missed { color: #a33; }

/* Right-side header cluster (scores + fullscreen toggle on player view). */
.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.header-text-btn {
  font: inherit;
  font-size: 0.95rem;
  border-radius: 8px;
  cursor: pointer;
  padding: 0.55rem 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.75);
  background: transparent;
  color: inherit;
  font-weight: 600;
}
.header-text-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.16);
}
.header-text-btn:disabled {
  opacity: 0.45;
}

/* Icon-only button: small, unobtrusive, used for the fullscreen toggle.
   Active state flips to the brand orange so the player can tell at a
   glance whether they're in fullscreen, even via screen-share. */
.icon-btn {
  font-size: 1.4rem;
  padding: 0.3rem 0.65rem;
  border: 1px solid #ccc;
  background: #fff;
  border-radius: 8px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: #f5f5f5; }
.icon-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

/* Step 17: DE | EN segmented toggle. Active side is brand orange so the
   kiosk operator can see the current language at a glance. */
.lang-toggle {
  display: inline-flex;
  border: 1px solid #ccc;
  border-radius: 8px;
  overflow: hidden;
}
.lang-btn {
  font: inherit;
  font-weight: 600;
  font-size: 1.05rem;
  padding: 0.55rem 0.9rem;
  background: #fff;
  border: 0;
  cursor: pointer;
  color: #555;
}
.lang-btn + .lang-btn { border-left: 1px solid #ddd; }
.lang-btn:hover:not([aria-pressed="true"]) { background: #f5f5f5; }
.lang-btn[aria-pressed="true"] {
  background: var(--color-primary);
  color: #fff;
}
/* Player header is filled with the brand colour, so a brand-coloured active
   button would vanish into it. Invert there: active = solid white, inactive
   = see-through on the header. */
body.player header .lang-toggle {
  border-color: rgba(255, 255, 255, 0.75);
}
body.player header .lang-btn {
  background: transparent;
  color: rgba(255, 255, 255, 0.8);
}
body.player header .lang-btn + .lang-btn { border-left-color: rgba(255, 255, 255, 0.75); }
body.player header .lang-btn:hover:not([aria-pressed="true"]) {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}
body.player header .lang-btn[aria-pressed="true"] {
  background: #fff;
  color: var(--color-primary);
}

/* Connection-lost banner: SSE has dropped — every other UI signal is stale,
   so this needs to dominate the page. Full-bleed across the body padding,
   high-contrast red, large text. */
#conn-status {
  background: #cc2222;
  color: #fff;
  border: none;
  padding: 0.9rem 1rem;
  border-radius: 0;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: -1rem -1rem 1.25rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Institutional footer — quiet credit line at the bottom of both surfaces. */
.app-footer {
  margin: 3rem auto 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid #eee;
  text-align: center;
  font-size: 0.85rem;
  color: #888;
}
.app-footer .footer-sep { color: #ccc; margin: 0 0.4rem; }
.app-footer .version-tag {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  color: #aaa;
}

.phase { max-width: 720px; margin: 0 auto; }

/* Buttons */
button {
  font: inherit;
  padding: 0.6rem 1rem;
  border: 1px solid #333;
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.1s;
}
button:hover:not(:disabled) { background: #f0f0f0; }
button:active:not(:disabled) { background: #e0e0e0; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
button.primary:hover:not(:disabled) { background: var(--color-primary-hover); }
button.big {
  font-size: 1.3rem;
  padding: 1rem 2rem;
}

/* Idle phase */
#phase-idle {
  text-align: center;
  padding: 2rem 0;
}
.last-result {
  font-size: 1.3rem;
  margin-bottom: 1.5rem;
  color: #555;
  min-height: 1.5rem;
}

/* Step 16: single "Neue Runde" CTA on the idle screen and post-pull tile. */
.idle-prompt {
  font-size: 1.2rem;
  color: #555;
  margin-bottom: 1rem;
}
.new-round-btn { margin-top: 0.5rem; }

/* Drawing phase */
.word-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.75rem;
  font-size: 1.2rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.word-row .label { color: #666; }
#target-word {
  flex: 1;
  font-weight: 700;
  font-size: 3rem;
  line-height: 1.1;
  color: #000;
}
.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 1.6rem;
}

#canvas {
  display: block;
  width: 100%;
  max-width: 800px;
  aspect-ratio: 4 / 3;
  margin: 0 auto;
  border: 2px solid #333;
  border-radius: 8px;
  background: #fff;
  touch-action: none;
  cursor: crosshair;
}

.drawing-board {
  display: flex;
  flex: 0 1 auto;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  width: 100%;
  min-height: 0;
}
.drawing-tools {
  display: flex;
  flex: 0 0 112px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
}
.controls {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

/* Color palette */
.color-palette {
  display: grid;
  grid-template-columns: repeat(3, 32px);
  gap: 0.25rem;
  justify-content: center;
}
.color-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.16);
  padding: 0;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s, box-shadow 0.15s;
}
.color-btn:hover { transform: scale(1.15); }
.color-btn.active {
  border-color: #333;
  box-shadow: 0 0 0 2px #fff, 0 0 0 3px #333;
}

.brush-palette {
  display: grid;
  grid-template-columns: repeat(2, 36px);
  gap: 0.25rem;
}
.brush-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0.35rem;
  border: 1px solid #bbb;
  border-radius: 7px;
}
.brush-btn[aria-pressed="true"] {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--color-primary-glow);
}
.brush-preview {
  display: block;
  width: 20px;
  height: 4px;
  background: #222;
  border-radius: 3px;
}
.brush-preview-marker {
  height: 7px;
  opacity: 0.55;
  border-radius: 1px;
}
.brush-preview-pencil {
  height: 2px;
  opacity: 0.75;
}
#btn-eraser {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 1.15rem;
}
#btn-eraser[aria-pressed="true"] {
  background: #e65100;
  color: #fff;
  border-color: #bf360c;
}

.brush-controls {
  text-align: center;
  margin-top: 0.5rem;
  color: #555;
}
#brush { vertical-align: middle; }

/* Guessing / judging phase */
#phase-guess h2 {
  margin-top: 0;
  color: #555;
  font-weight: normal;
  font-size: 1.1rem;
}
.ai-guess {
  font-size: 2.4rem;
  font-weight: 600;
  min-height: 3rem;
  padding: 1rem 1.25rem;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 10px;
  margin: 0.5rem 0 1rem;
  line-height: 1.4;
}
.streaming {
  color: #888;
  font-style: italic;
  text-align: center;
  padding: 0.25rem;
}
#phase-guess h3 {
  margin: 1.5rem 0 0.5rem;
  font-size: 1.1rem;
}

.judgment {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
}
.judgment button {
  font-size: 1.3rem;
  padding: 1.25rem;
  border-width: 2px;
}
.judgment .win { border-color: var(--color-win); }
.judgment .lose { border-color: #a33; }
.judgment .skip { border-color: #999; color: #666; }

/* Optional player-info panels (pool + history). Hidden by default; admin
   toggles flip them on. Layout fits inside phase-idle below the new-round
   button without scrolling on a 1080×720 booth touchscreen. */
.player-info-card {
  margin: 1.5rem auto 0;
  max-width: 640px;
  padding: 1rem 1.25rem;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 12px;
  text-align: left;
}
.player-info-card h3 {
  margin: 0 0 0.6rem;
  font-size: 1.1rem;
  color: #333;
}

.prize-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.6rem;
}
.prize-card {
  position: relative;
  background: #fafafa;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 0.7rem 0.5rem;
  text-align: center;
  transition: opacity 0.15s;
}
.prize-card.sold-out { opacity: 0.4; }
.prize-card.sold-out .prize-card-name { text-decoration: line-through; }
.prize-card-emoji { font-size: 2.4rem; line-height: 1; margin-bottom: 0.3rem; }
.prize-card-name { font-size: 0.95rem; font-weight: 600; color: #222; line-height: 1.2; }
.prize-card-stock {
  position: absolute;
  top: 0.3rem;
  right: 0.4rem;
  background: var(--color-win);
  color: #fff;
  font-size: 0.8rem;
  font-weight: bold;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.prize-card.sold-out .prize-card-stock { background: #999; }

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.history-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #f0f8f4;
  border: 1px solid #cfe5d9;
  border-radius: 999px;
  padding: 0.3rem 0.75rem 0.3rem 0.55rem;
  font-size: 0.95rem;
}
.history-emoji { font-size: 1.2rem; line-height: 1; }
.history-name { color: var(--color-win-dark); font-weight: 500; }

/* Prize-pull phase */
#phase-pull {
  text-align: center;
  padding: 1.5rem 0;
}
.pull-headline {
  font-size: 1.8rem;
  margin: 0.5rem 0 1.5rem;
  color: var(--color-win-dark);
}
#btn-pull {
  font-size: 1.6rem;
  padding: 1.4rem 2.6rem;
  margin: 0.5rem 0 1rem;
  box-shadow: 0 4px 0 var(--color-primary-shadow);
}
#btn-pull:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--color-primary-shadow);
}

/* Prize spin animation: 6-color conic gradient ring rotating fast,
   static gift-box circle in the middle. CSS-only; ~2s before reveal. */
.prize-spinner {
  position: relative;
  width: 220px;
  height: 220px;
  margin: 1.5rem auto;
}
.spinner-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(
    #ff595e, #ffca3a, #8ac926, #1982c4, #6a4c93, #ff924c, #ff595e
  );
  animation: prize-spin 0.5s linear infinite;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.2);
}
.spinner-center {
  position: absolute;
  inset: 22%;
  background: #fff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 4rem;
  line-height: 1;
  box-shadow: inset 0 0 0 3px var(--color-primary);
  /* Tiny wobble so the gift looks "shaken", in addition to the ring spinning */
  animation: prize-wobble 0.6s ease-in-out infinite;
}
@keyframes prize-spin {
  to { transform: rotate(360deg); }
}
@keyframes prize-wobble {
  0%, 100% { transform: rotate(-6deg); }
  50%      { transform: rotate(6deg); }
}

.prize-tile {
  background: #fff;
  border: 3px solid var(--color-win);
  border-radius: 16px;
  padding: 2rem 2.5rem;
  margin: 1rem auto;
  max-width: 860px;
  box-shadow: 0 6px 24px var(--color-win-glow);
  animation: prize-reveal 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes prize-reveal {
  from { opacity: 0; transform: scale(0.7); }
  to   { opacity: 1; transform: scale(1); }
}
.prize-emoji {
  font-size: 5.5rem;
  line-height: 1;
  margin-bottom: 0.75rem;
}
.prize-name {
  font-size: 1.6rem;
  font-weight: bold;
  margin: 0.5rem 0 1.5rem;
  color: var(--color-win-dark);
  line-height: 1.3;
}

/* Consolation pull (lose-path with display_consolation_prizes ON):
   muted palette + soft fade-in instead of the celebratory green wheel +
   bounce. JS skips the spinner entirely on this path so the player goes
   straight to the tile reveal. */
#phase-pull.consolation .pull-headline {
  color: #555;
}
#phase-pull.consolation .prize-tile {
  border-color: #c7c7c7;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.08);
  animation: prize-fade-in 0.6s ease-out;
}
#phase-pull.consolation .prize-name {
  color: #444;
}
@keyframes prize-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Narrow viewport (touchscreen portrait, phone) */
@media (max-width: 600px) {
  header { flex-direction: column; align-items: flex-start; }
  body.player .header-actions { flex-wrap: wrap; }
  body.player .lang-btn {
    font-size: 0.95rem;
    padding: 0.5rem 0.7rem;
  }
  body.player .drawing-board { gap: 0.25rem; }
  body.player .drawing-tools { flex-basis: 108px; }
  body.player .color-palette { grid-template-columns: repeat(3, 30px); gap: 0.18rem; }
  body.player .color-btn { width: 30px; height: 30px; }
  body.player .brush-palette { grid-template-columns: repeat(2, 34px); }
  body.player .brush-btn,
  body.player #btn-eraser { width: 34px; height: 34px; }
  header h1 { font-size: 1.1rem; }
  #target-word { font-size: 1.8rem; }
  .ai-guess { font-size: 1.5rem; }
  .judgment { grid-template-columns: 1fr; }
  .pull-headline { font-size: 1.4rem; }
  #btn-pull { font-size: 1.3rem; padding: 1.1rem 1.8rem; }
  .prize-emoji { font-size: 4.5rem; }
  .prize-name { font-size: 1.3rem; }
}

/* ---------- Admin panel ---------- */

body.admin {
  max-width: 1200px;
  margin: 0 auto;
}

body.admin .header-meta {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
  font-size: 1.1rem;
  font-weight: bold;
}

.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.card {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 1rem 1.25rem;
}
.card.full { grid-column: 1 / -1; }
.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  color: #333;
  border-bottom: 1px solid #eee;
  padding-bottom: 0.35rem;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* key-value grid for LIVE STATE */
dl.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 0.75rem;
  row-gap: 0.35rem;
  margin: 0;
}
dl.kv dt { color: #666; }
dl.kv dd { margin: 0; font-weight: 500; }

.badge {
  display: inline-block;
  font-size: 0.8rem;
  padding: 0.1rem 0.4rem;
  background: #fc3;
  color: #000;
  border-radius: 4px;
  margin-left: 0.4rem;
}

/* Control rows */
.ctrl-row {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
  padding: 0.3rem 0;
}
.ctrl-row.danger { border-top: 1px dashed #ddd; margin-top: 0.5rem; padding-top: 0.75rem; }
.ctrl-row.toggle-row label { cursor: pointer; }
.ctrl-row.toggle-row input[type="checkbox"] { width: 1.05rem; height: 1.05rem; cursor: pointer; }
.ctrl-row.toggle-row .sub-toggle { margin-left: 1.6rem; color: #666; font-size: 0.9rem; }
.ctrl-row.toggle-row .sub-toggle input:disabled { cursor: not-allowed; opacity: 0.5; }
.ctrl-row.toggle-row .sub-toggle:has(input:disabled) { opacity: 0.55; cursor: not-allowed; }
/* Step 15 master toggle — boundary marker in the toggle stack. */
.ctrl-row.gacha-toggle-row,
.ctrl-row.stand-toggle-row { border-top: 1px dashed #ddd; margin-top: 0.4rem; padding-top: 0.6rem; }
/* Mask the rest of the gacha-related toggles when the master is off:
   the parent input goes :disabled (via JS), which fades the whole row. */
.ctrl-row.gacha-dependent:has(> label:first-child > input:disabled) { opacity: 0.55; }
.ctrl-row.gacha-dependent input:disabled { cursor: not-allowed; }
.ctrl-row label { color: #555; font-size: 0.95rem; display: inline-flex; gap: 0.3rem; align-items: center; }
.ctrl-row input[type="text"] {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid #bbb;
  border-radius: 6px;
  flex: 1;
  min-width: 10rem;
}
.ctrl-row input[type="number"] {
  font: inherit;
  padding: 0.4rem 0.5rem;
  border: 1px solid #bbb;
  border-radius: 6px;
  width: 4.5rem;
}
.ctrl-row select {
  font: inherit;
  padding: 0.4rem 0.5rem;
  border: 1px solid #bbb;
  border-radius: 6px;
  background: #fff;
}
.ctrl-row button { padding: 0.45rem 0.85rem; font-size: 0.95rem; }
button.small { padding: 0.3rem 0.6rem; font-size: 0.85rem; }
button.destructive {
  background: #a22;
  color: #fff;
  border-color: #a22;
}
button.destructive:hover:not(:disabled) { background: #811; }

.muted { color: #888; }

/* Judgment block */
.judge-row {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}
#judge-thumb {
  width: 180px;
  height: 180px;
  object-fit: contain;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  flex-shrink: 0;
}
.judge-main { flex: 1; min-width: 0; }
.judge-main .ai-guess {
  margin: 0.3rem 0 0.75rem;
  font-size: 1.3rem;
  min-height: 2.5rem;
  padding: 0.75rem;
}
body.admin .judgment:not(.active) { opacity: 0.45; }

/* Rounds + Prize tables share base styling */
table.rounds,
table.prize-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
table.rounds th,
table.rounds td,
table.prize-table th,
table.prize-table td {
  padding: 0.45rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid #eee;
  vertical-align: middle;
}
table.rounds th,
table.prize-table th { color: #666; font-weight: 600; background: #fafafa; }
table.rounds td.word { font-weight: bold; }
table.rounds td.guess { color: #333; max-width: 32rem; }

/* Prize table */
.prize-emoji-cell { font-size: 1.6rem; line-height: 1; width: 2.2rem; text-align: center; }
.prize-name-cell { font-weight: 600; }
.prize-id-cell { font-family: ui-monospace, "Cascadia Code", Menlo, monospace; font-size: 0.85rem; }
.prize-weight-cell { font-variant-numeric: tabular-nums; color: #666; width: 5rem; }
.prize-stock-cell {
  font-variant-numeric: tabular-nums;
  font-weight: bold;
  width: 5rem;
  font-size: 1.05rem;
}
.prize-stock-cell.stock-low {
  color: #b85800;
  background: #fff4e0;
}
.prize-stock-cell.stock-empty {
  color: #999;
  background: #f4f4f4;
  text-decoration: line-through;
}

/* Pity column: counter + ramp/hard threshold + boost badge. */
.prize-pity-cell {
  font-variant-numeric: tabular-nums;
  width: 6.5rem;
  font-size: 0.95rem;
}
.pity-cell {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
}
.pity-cell .pity-meta {
  color: #999;
  margin-left: 0.05rem;
}
.pity-cell.pity-active {
  background: #fff4d6;
  color: #92670d;
  font-weight: 600;
}
.pity-cell.pity-active .pity-meta { color: #b88500; }
.pity-cell.pity-hard {
  background: #ffd6d6;
  color: #a02020;
  font-weight: 700;
}
.pity-cell.pity-hard .pity-meta { color: #a02020; }
.pity-boost {
  font-size: 0.85em;
  margin-left: 0.2rem;
  opacity: 0.85;
}
.pity-icon {
  margin-left: 0.2rem;
}

#pool-total {
  font-weight: normal;
  font-size: 0.9rem;
  margin-left: 0.4rem;
}

.card-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}

/* System-prompt editor textarea: monospace-ish for legibility of multi-line
   instructions, generous min-height, locked appearance when readonly. */
.prompt-textarea {
  width: 100%;
  font: 0.95rem/1.5 ui-monospace, "Cascadia Code", Menlo, monospace;
  padding: 0.7rem 0.85rem;
  border: 1px solid #bbb;
  border-radius: 6px;
  background: #fff;
  color: #1a1a1a;
  resize: vertical;
  min-height: 12rem;
}
.prompt-textarea:focus {
  border-color: var(--color-primary);
  outline: 2px solid var(--color-primary-glow);
  outline-offset: 1px;
}
.prompt-textarea[readonly] {
  background: #f6f6f6;
  color: #444;
  cursor: default;
}
.prompt-hint {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
}

.stock-input {
  font: inherit;
  width: 5rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid #888;
  border-radius: 4px;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.stock-input:focus {
  border-color: var(--color-primary);
  outline: 2px solid var(--color-primary-glow);
  outline-offset: 1px;
}
/* Dictionary table (Step 11) */
table.dict-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
table.dict-table th,
table.dict-table td {
  padding: 0.45rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid #eee;
  vertical-align: middle;
}
table.dict-table th { color: #666; font-weight: 600; background: #fafafa; }

.dict-add-form {
  margin-top: 0.8rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 0;
}
.dict-add-form summary {
  cursor: pointer;
  padding: 0.5rem 0.8rem;
  font-weight: 500;
  color: #555;
}
.dict-add-form summary:hover { color: var(--color-primary); }
.dict-add-fields {
  padding: 0.5rem 0.8rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.dict-add-fields textarea {
  font: 0.95rem/1.5 ui-monospace, "Cascadia Code", Menlo, monospace;
  padding: 0.5rem;
  border: 1px solid #bbb;
  border-radius: 4px;
  resize: vertical;
}
.dict-add-fields textarea:focus {
  border-color: var(--color-primary);
  outline: 2px solid var(--color-primary-glow);
  outline-offset: 1px;
}
.small-btn {
  display: inline-block;
  padding: 0.3rem 0.7rem;
  border: 1px solid #bbb;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}
.small-btn:hover { border-color: var(--color-primary); color: var(--color-primary); }

/* Dictionary editor panel */
.dict-editor {
  margin-top: 0.8rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 0.8rem;
  background: #fafafa;
}
.dict-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}
.dict-editor-lang-toggle {
  display: flex;
  gap: 2px;
}
.dict-editor-lang-toggle .lang-btn {
  padding: 0.2rem 0.6rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}
.dict-editor-lang-toggle .lang-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.dict-editor textarea {
  width: 100%;
  font: 0.95rem/1.5 ui-monospace, "Cascadia Code", Menlo, monospace;
  padding: 0.5rem;
  border: 1px solid #bbb;
  border-radius: 4px;
  resize: vertical;
  min-height: 8rem;
}
.dict-editor textarea:focus {
  border-color: var(--color-primary);
  outline: 2px solid var(--color-primary-glow);
  outline-offset: 1px;
}

/* Previous-round summary on idle screen */
.round-summary {
  display: flex;
  gap: 2rem;
  align-items: center;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 14px;
  padding: 1.5rem 2.5rem;
  margin: 1rem auto 1.5rem;
  max-width: 860px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}
.summary-thumb {
  width: 320px;
  height: 240px;
  object-fit: contain;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  flex-shrink: 0;
}
.summary-details {
  flex: 1;
  min-width: 0;
  font-size: 1.4rem;
  line-height: 1.7;
}
.summary-word { font-size: 1.6rem; }
.summary-guess {
  color: #444;
  font-size: 1.4rem;
}
.summary-verdict {
  font-size: 2rem;
  font-weight: 600;
  margin-top: 0.5rem;
}
.verdict-win { color: var(--color-win); }
.verdict-lose { color: #cc2222; }

/* Pull summary: drawing + details + prize in a row */
.pull-summary-row {
  display: flex;
  gap: 2.5rem;
  align-items: center;
  justify-content: center;
  margin-bottom: 1.5rem;
}
.pull-summary-left {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  flex: 1;
  min-width: 0;
}
.pull-summary-left .summary-thumb {
  width: 200px;
  height: 150px;
}
.pull-summary-left .summary-details {
  font-size: 1.2rem;
  text-align: left;
  flex: 1;
  min-width: 0;
  padding-right: 2.5rem;
}
.pull-summary-left .summary-word,
.pull-summary-left .summary-guess {
  font-size: 1.2rem;
  line-height: 1.6;
}
.pull-summary-left .summary-word span[data-i18n],
.pull-summary-left .summary-guess span[data-i18n] {
  font-weight: 600;
}
.pull-summary-left .summary-verdict { font-size: 1.5rem; margin-top: 0.4rem; }
.pull-summary-prize {
  text-align: center;
  flex-shrink: 0;
  min-width: 120px;
}
.pull-summary-prize .prize-emoji {
  font-size: 5rem;
  line-height: 1.2;
}
.pull-summary-prize .prize-name {
  font-size: 1.4rem;
  font-weight: 600;
  margin-top: 0.4rem;
}

/* Dwell result — shown briefly after judgment before transitioning */
.dwell-result {
  font-size: 1.8rem;
  font-weight: 600;
  text-align: center;
  padding: 1rem;
  animation: dwell-fade-in 0.3s ease-out;
}
@keyframes dwell-fade-in {
  from { opacity: 0; transform: scale(0.9); }
  to   { opacity: 1; transform: scale(1); }
}

/* No-dictionary notification overlay (Step 11) */
.notification-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.notification-card {
  background: #fff;
  border-radius: 12px;
  padding: 2rem 2.5rem;
  max-width: 32rem;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}
.notification-card p {
  font-size: 1.2rem;
  margin: 0 0 1.5rem;
  line-height: 1.5;
}
.notification-actions {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  align-items: center;
}
.notification-actions button {
  min-width: 16rem;
}

img.thumb {
  width: 48px;
  height: 48px;
  object-fit: contain;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  display: block;
}

@media (max-width: 900px) {
  .admin-grid { grid-template-columns: 1fr; }
  .card.full { grid-column: 1; }
  .judge-row { flex-direction: column; }
  #judge-thumb { width: 140px; height: 140px; }
}

/* ==========================================================================
   Step 9 — Kiosk layout for the touch-board (player view only).
   Locks body to 100vh with no scroll/overscroll/touch-pan, so a body
   scrollbar can never compete with the canvas for touches. Optional
   pool/history panels live in a right-side rail in landscape, which
   collapses when both are admin-hidden. Falls back to the original
   scrolling stack at narrow viewports for dev-laptop testing.
   ========================================================================== */

body.player {
  height: 100vh;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  padding: 0;
  display: flex;
  flex-direction: column;
}

body.player header {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding: 0.85rem 1.25rem;
  margin: 0;
  flex-shrink: 0;
  background-color: #07384a;
  color: #fff;
  border-bottom: 0;
}
body.player header::after {
  content: "";
  position: absolute;
  z-index: -1;
  top: -50%;
  bottom: -50%;
  left: -30%;
  width: 22%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.16),
    transparent
  );
  transform: skewX(-22deg);
  animation: player-header-sheen 3.2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes player-header-sheen {
  from { left: -30%; }
  to { left: 115%; }
}
body.player[data-brand-mode="thws"] header {
  background-color: var(--color-primary);
}

body.player[data-brand-mode="thws"] .brand-logo {
  filter: brightness(0) invert(1);
}
body.player main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1rem;
  gap: 0.5rem;
}

/* Body has zero padding now, so the negative-margin full-bleed trick is
   unnecessary — plain box at top of <main> already spans full width. */
body.player #conn-status {
  margin: 0;
}

body.player .player-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
  gap: 1rem;
  align-items: stretch;
}

body.player .canvas-stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Each phase fills the canvas-stage. Idle/guess/pull center their content;
   drawing flows from the top so the canvas can absorb remaining height. */
body.player .canvas-stage .phase {
  flex: 1;
  min-height: 0;
  max-width: none;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
}
body.player .canvas-stage #phase-drawing {
  justify-content: flex-start;
}
body.player .canvas-stage #phase-drawing .drawing-board {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  width: 100%;
}
body.player .canvas-stage #phase-drawing #canvas {
  flex: 0 1 auto;
  min-width: 0;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 4 / 3;
  margin: 0;
}

/* Side rail: collapses when neither pool nor history is visible.
   `:has(> :not([hidden]))` matches if at least one direct child is shown. */
body.player .side-rail {
  flex: 0 0 340px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
}
body.player .side-rail:not(:has(> :not([hidden]))) {
  display: none;
}

/* Rail panels: drop the centered-card margins/max-width so they fill the
   rail width directly. */
body.player .side-rail .player-info-card {
  margin: 0;
  max-width: none;
}

body.player .app-footer {
  margin: 0;
  padding: 0.4rem 1rem;
  border-top: 1px solid #eee;
  flex-shrink: 0;
  font-size: 0.8rem;
}

/* Narrow-viewport fallback: revert to the pre-Step-9 scrolling stack so
   dev-laptop testing in a half-width window still works. The board itself
   runs comfortably above 1000px wide. */
@media (max-width: 1000px) {
  body.player {
    height: auto;
    min-height: 100vh;
    overflow: visible;
    touch-action: auto;
    overscroll-behavior: auto;
    padding: 1rem;
    display: block;
  }
  body.player header {
    padding: 0.85rem 1rem;
    margin: 0 -1rem 1rem;
  }
  body.player main {
    flex: none;
    display: block;
    padding: 0;
    gap: 0;
  }
  body.player #conn-status {
    margin: -1rem -1rem 1.25rem;
  }
  body.player .player-stage {
    display: block;
  }
  body.player .canvas-stage {
    display: block;
  }
  body.player .canvas-stage .phase {
    flex: none;
    display: block;
    max-width: 720px;
    margin: 0 auto;
  }
  body.player .canvas-stage #phase-drawing {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    min-height: 75dvh;
  }
  body.player .canvas-stage #phase-drawing .drawing-board {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    width: 100%;
    justify-content: center;
  }
  body.player .canvas-stage #phase-drawing #canvas {
    flex: 0 1 auto;
    min-width: 0;
    width: auto;
    max-width: calc(100% - 112px - 0.3rem);
    height: auto;
    max-height: 48dvh;
    aspect-ratio: 4 / 3;
    margin: 0;
  }
  body.player .side-rail {
    flex: none;
    display: block;
    overflow: visible;
  }
  body.player .side-rail .player-info-card {
    margin: 1.5rem auto 0;
    max-width: 640px;
  }
  body.player .app-footer {
    margin: 3rem auto 0.5rem;
    padding-top: 1rem;
    font-size: 0.85rem;
  }
}

@media (max-width: 600px) {
  body.player .canvas-stage #phase-drawing {
    min-height: 80dvh;
  }
  body.player .canvas-stage #phase-drawing .drawing-board {
    flex-direction: column;
  }
  body.player .canvas-stage #phase-drawing .drawing-tools {
    flex: 0 0 auto;
    flex-direction: row;
    width: 100%;
    justify-content: space-between;
    gap: 0.25rem;
  }
  body.player .canvas-stage #phase-drawing #canvas {
    width: auto;
    align-self: center;
    max-width: 100%;
    max-height: 32dvh;
  }
  body.player .color-palette {
    grid-template-columns: repeat(6, 30px);
  }
}

@media (max-width: 340px) {
  body.player header {
    padding: 0.4rem 0.5rem;
    margin: 0 -0.5rem 0.5rem;
  }
  body.player .header-actions {
    gap: 0.35rem;
  }
  body.player #scores {
    font-size: 1rem;
    gap: 0.3rem;
  }
  body.player .score-correct,
  body.player .score-missed {
    white-space: nowrap;
  }
  body.player .lang-btn {
    font-size: 0.85rem;
    padding: 0.35rem 0.5rem;
  }
  body.player .header-text-btn {
    font-size: 0.85rem;
    padding: 0.35rem 0.5rem;
  }
  body.player .canvas-stage #phase-drawing #canvas {
    max-height: 30dvh;
  }
}

/* ---------- Poster mode ----------
   Full-screen overlay: DIG:IT poster on the left, a "there's a game here"
   panel on the right with rotating recent drawings. Any tap closes it. */
.poster-screen {
  --poster-bg: #063852;      /* sampled from poster.png */
  --poster-screen-bg: #02202f; /* darker than the poster so it reads as a framed object */
  --poster-divider-w: 40px;
  --poster-accent: #dff45e;
  /* Poster + game panel form one centred group with even side margins.
     The poster takes the largest size that fits beside the panel. */
  --poster-pad-x: max(2rem, 5vw);
  --poster-pad-y: 2rem;
  --poster-gap: 2.5rem;
  --poster-panel-w: clamp(260px, 25vw, 420px);
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--poster-gap);
  padding: var(--poster-pad-y) var(--poster-pad-x);
  background: var(--poster-screen-bg);
  color: #fff;
  cursor: pointer;
  animation: poster-fade 0.6s ease-out;
}
.poster-screen[hidden] { display: none; }
@keyframes poster-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
.poster-art {
  flex: 0 1 auto;
  min-width: 0;
}
.poster-art img {
  display: block;
  /* 1264×848 source: fit the width left beside the panel, or the full
     height, whichever is smaller. */
  width: min(
    calc(100vw - var(--poster-panel-w) - var(--poster-divider-w) - 2 * var(--poster-gap) - 2 * var(--poster-pad-x)),
    calc((100dvh - 2 * var(--poster-pad-y)) * 1264 / 848)
  );
  height: auto;
  border-radius: 12px;
  box-shadow: 0 0 0 1px rgba(223, 244, 94, 0.18);
}
.poster-divider {
  flex: 0 0 var(--poster-divider-w);
  width: var(--poster-divider-w);
  height: min(70dvh, 600px);
  overflow: visible;
}
.poster-divider path,
.poster-divider circle {
  stroke: var(--poster-accent);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.poster-divider circle.filled { fill: var(--poster-accent); }
.poster-game {
  flex: 0 0 var(--poster-panel-w);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  text-align: center;
}
.poster-game-kicker {
  color: var(--poster-accent);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 1rem;
}
.poster-game-title {
  margin: 0;
  font-size: clamp(1.6rem, 2.6vw, 2.6rem);
  line-height: 1.15;
}
.poster-game-sub {
  margin: 0;
  font-size: clamp(1rem, 1.3vw, 1.3rem);
  opacity: 0.9;
}
/* Dark card with a lime hairline: the drawing is the only white surface,
   so it doesn't merge with the poster's white boxes. */
.poster-showcase {
  margin: 0.5rem 0 0;
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  border: 1px solid rgba(223, 244, 94, 0.4);
  border-radius: 12px;
  padding: 0.75rem;
}
.poster-showcase.fade-in { animation: poster-fade 0.6s ease-out; }
.poster-showcase img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: #fff;
  border-radius: 6px;
}
.poster-showcase figcaption {
  margin-top: 0.5rem;
  font-size: 1.05rem;
  text-align: left;
}
.poster-showcase figcaption strong {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.poster-showcase figcaption > div { margin-top: 0.2rem; color: #fff; }
.poster-showcase figcaption span { opacity: 0.7; }
.poster-showcase .verdict-win { color: var(--poster-accent); }
.poster-showcase .verdict-lose { color: #ff9e9e; }
.poster-showcase .summary-verdict {
  font-size: 1.15rem;
  margin-top: 0.35rem;
}
.poster-screen .poster-play {
  background: var(--poster-accent);
  color: var(--poster-bg);
  border-color: var(--poster-accent);
  font-size: clamp(1.3rem, 1.8vw, 1.8rem);
  animation: poster-pulse 1.8s ease-in-out infinite;
}
.poster-screen .poster-play:hover:not(:disabled) {
  background: #eaff8a;
  border-color: #eaff8a;
}
@keyframes poster-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(223, 244, 94, 0.55); }
  50% { transform: scale(1.05); box-shadow: 0 0 0 14px rgba(223, 244, 94, 0); }
}
.poster-hint {
  font-size: 0.95rem;
  opacity: 0.75;
}
@media (prefers-reduced-motion: reduce) {
  .poster-screen .poster-play { animation: none; }
}
/* Portrait / narrow screens: stack poster above the game panel. */
@media (max-aspect-ratio: 1/1) {
  .poster-screen {
    --poster-pad-x: 1rem;
    --poster-pad-y: 1rem;
    --poster-gap: 1rem;
    flex-direction: column;
    justify-content: flex-start;
    overflow-y: auto;
  }
  .poster-art img { width: min(calc(100vw - 2 * var(--poster-pad-x)), calc(50dvh * 1264 / 848)); }
  .poster-divider { display: none; }
  .poster-game { flex: 0 0 auto; width: 100%; }
  .poster-showcase { max-width: 360px; }
}
