:root {
  color-scheme: light;
  font-family: "Arial Black", Impact, Haettenschweiler, "Segoe UI", sans-serif;
  --paper: #fffaf0;
  --ink: #07142e;
  --muted: #4a5870;
  --pink: #ff2f73;
  --green: #00df72;
  --yellow: #ffe100;
  --cyan: #10c9ee;
  --blue-soft: #dfe7f2;
  --cream: #fff9ed;
  --panel: rgba(255, 250, 240, 0.96);
  --shadow: 6px 6px 0 var(--ink);
}

body.dark-theme {
  --paper: #111827;
  --ink: #f8fafc;
  --muted: #cbd5e1;
  --blue-soft: #263244;
  --cream: #172033;
  --panel: rgba(17, 24, 39, 0.96);
  --shadow: 6px 6px 0 #020617;
  background: radial-gradient(#334155 1px, transparent 1px), var(--paper);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: radial-gradient(#ece5d7 1px, transparent 1px), var(--paper);
  background-size: 12px 12px;
  color: var(--ink);
}

body::before,
body::after {
  content: "";
  position: fixed;
  left: 0;
  z-index: 20;
  width: 100%;
  height: 10px;
  background: repeating-linear-gradient(45deg, var(--yellow) 0 12px, var(--yellow) 12px 20px, #07142e 20px 28px, #07142e 28px 36px);
  border-block: 2px solid #07142e;
  pointer-events: none;
}

body::before { top: 0; }
body::after { bottom: 0; }

button,
input,
select { font: inherit; }

button,
select { cursor: pointer; }

button {
  border: 0;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 760px) 330px;
  gap: 18px;
  width: min(1120px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 34px 0;
  align-items: start;
}

.game-stage,
.side-panel,
.round-board,
.answer-form,
.setup-panel,
.status-card,
.leader-card,
.history-card,
.turn-card,
.modal-card {
  border: 4px solid var(--ink);
  border-radius: 0;
  box-shadow: var(--shadow);
}

.game-stage {
  display: grid;
  gap: 16px;
  align-content: start;
  padding: 24px;
  background: var(--panel);
}

.topbar {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) auto;
  align-items: start;
  gap: 18px;
}

.brand-logo {
  width: 104px;
  aspect-ratio: 1;
  object-fit: contain;
  border: 4px solid var(--ink);
  background: white;
  box-shadow: 6px 6px 0 var(--ink);
}

.title-block { min-width: 0; }

.badge-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 9px;
}

.eyebrow,
.tagline,
.hud-item span,
.letter-card span,
.timer-card span,
.answer-field span,
.status-card span,
.section-head span,
.turn-card span,
.setup-field span,
.toggle-row span,
.modal-head span,
.winner-card span {
  margin: 0;
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 950;
  letter-spacing: 0;
  line-height: 1;
  text-transform: uppercase;
}

.eyebrow,
.tagline {
  display: inline-flex;
  align-items: center;
  min-height: 29px;
  padding: 7px 10px 6px;
  border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
}

.eyebrow { background: var(--pink); color: white; }
.tagline { background: white; color: #07142e; }

h1 {
  display: grid;
  gap: 0;
  margin: 0;
  font-size: clamp(3.15rem, 7vw, 4.15rem);
  font-weight: 950;
  line-height: 0.64;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 span { display: block; width: max-content; text-shadow: 4px 4px 0 var(--yellow); }
h1 span:nth-child(2) { background: var(--yellow); color: #07142e; padding-inline: 5px; text-shadow: none; }
h1 span:nth-child(3) { color: var(--pink); text-shadow: none; }
h1 span:nth-child(4) { color: var(--green); text-shadow: none; }

.hud {
  display: grid;
  grid-template-columns: repeat(2, 112px);
  gap: 14px;
}

.hud-item,
.letter-card,
.timer-card {
  border: 3px solid var(--ink);
  background: var(--cream);
  box-shadow: 5px 5px 0 var(--ink);
  padding: 16px;
}

.hud-item:nth-child(2),
.timer-card { background: var(--blue-soft); }

.hud-item { min-height: 94px; }
.hud-item strong,
.letter-card strong,
.timer-card strong,
.turn-card strong {
  display: block;
  margin-top: 8px;
  font-size: 1.85rem;
  line-height: 1;
}

.setup-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  background: var(--cyan);
}

.setup-panel.is-hidden { display: none; }

.setup-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.setup-field,
.toggle-row {
  display: grid;
  gap: 7px;
  border: 3px solid var(--ink);
  background: white;
  color: #07142e;
  padding: 10px;
  box-shadow: 4px 4px 0 var(--ink);
}

.setup-field.wide { grid-column: span 2; }

.setup-field select,
.name-row input,
.answer-field input {
  width: 100%;
  min-height: 48px;
  border: 3px solid var(--ink);
  border-radius: 0;
  outline: 0;
  background: white;
  color: #07142e;
  padding: 9px 10px;
  font-family: Arial, "Segoe UI", sans-serif;
  font-size: 1rem;
  font-weight: 900;
  box-shadow: 3px 3px 0 var(--ink);
}

.toggle-row {
  align-content: center;
  grid-template-columns: auto 1fr;
  align-items: center;
}

.toggle-row input { width: 22px; height: 22px; }

.name-list {
  display: grid;
  gap: 10px;
}

.name-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.color-chip {
  width: 34px;
  aspect-ratio: 1;
  border: 3px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
}

.setup-actions {
  display: grid;
  grid-template-columns: 120px 150px minmax(0, 1fr);
  gap: 12px;
}

.round-board {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 18px;
  padding: 17px;
  background: var(--cyan);
}

.letter-card {
  display: grid;
  place-items: center;
  min-height: 218px;
  background: var(--yellow);
  color: #07142e;
  transform: rotate(-1.2deg);
}

.letter-card.spin strong { animation: spinLetter 520ms steps(6, end); }

.letter-card strong {
  margin: 2px 0 0;
  font-size: clamp(6.6rem, 14vw, 8rem);
  line-height: 0.82;
}

.timer-card {
  display: grid;
  align-content: center;
  gap: 10px;
  min-height: 218px;
  padding: 28px 18px;
  transform: rotate(0.8deg);
}

.timer-card strong { font-size: clamp(4.2rem, 9vw, 5.35rem); }
.timer-card.warning { animation: warningPulse 700ms infinite; }

.timer-track {
  width: 100%;
  height: 20px;
  overflow: hidden;
  border: 3px solid var(--ink);
  background: white;
}

.timer-track i {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--green);
  transition: width 220ms linear, background 220ms ease;
}

.turn-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--yellow);
  color: #07142e;
}

.turn-card strong { margin: 0; font-size: 1.4rem; text-transform: uppercase; }

.answer-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 14px;
  padding: 14px 18px 18px;
  background: var(--blue-soft);
}

.answer-field { display: grid; gap: 7px; }
.answer-field input { min-height: 67px; font-size: 1.22rem; }
.answer-field input:focus { background: #fff7bd; }
.answer-field input.valid { background: #d8ffe9; }
.answer-field input.invalid { background: #ffe1eb; }

.actions {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: 74px minmax(0, 1fr) 74px;
  gap: 14px;
  padding-top: 8px;
}

.primary-button,
.secondary-button,
.icon-button {
  min-height: 64px;
  border: 3px solid var(--ink);
  border-radius: 0;
  font-weight: 950;
  text-transform: uppercase;
  box-shadow: 5px 5px 0 var(--ink);
  transition: transform 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
}

.primary-button:hover,
.secondary-button:hover,
.icon-button:hover { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }
.primary-button { background: var(--green); color: #07142e; }
.secondary-button { background: var(--green); color: #07142e; }
.secondary-button.alt,
.icon-button { background: var(--yellow); color: #07142e; }
.icon-button { width: 74px; font-size: 1.6rem; }
.icon-button.danger { background: var(--pink); color: white; }
button:disabled { cursor: not-allowed; opacity: 0.55; transform: none; }

.side-panel {
  display: grid;
  gap: 16px;
  position: sticky;
  top: 34px;
  padding: 18px;
  background: #f2f6fb;
}

body.dark-theme .side-panel { background: #0f172a; }

.status-card,
.leader-card,
.history-card {
  background: var(--cream);
  padding: 16px;
}

.status-card { background: var(--yellow); color: #07142e; }
.status-card strong { display: block; margin-top: 6px; font-size: 2rem; line-height: 1; text-transform: uppercase; }
.status-card p { margin: 10px 0 0; font-family: Arial, "Segoe UI", sans-serif; font-size: 0.95rem; font-weight: 900; line-height: 1.35; }

.leader-card,
.history-card { display: grid; gap: 12px; }
.section-head { display: flex; align-items: center; justify-content: space-between; }
.section-head strong { display: grid; place-items: center; width: 36px; aspect-ratio: 1; border: 3px solid var(--ink); background: var(--yellow); color: #07142e; box-shadow: 3px 3px 0 var(--ink); }
#historyList,
#leaderboardList { display: grid; gap: 9px; margin: 0; padding: 0; list-style: none; max-height: 320px; overflow: auto; }
#historyList li,
#leaderboardList li { border: 3px solid var(--ink); background: white; color: #07142e; padding: 10px; box-shadow: 4px 4px 0 var(--ink); font-family: Arial, "Segoe UI", sans-serif; font-size: 0.9rem; font-weight: 900; }
#leaderboardList li { display: flex; justify-content: space-between; gap: 8px; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(7, 20, 46, 0.78);
}

.modal[hidden] { display: none; }

.modal-card {
  width: min(560px, 100%);
  max-height: min(720px, calc(100vh - 44px));
  overflow: auto;
  padding: 18px;
  background: var(--paper);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-head strong { font-size: 1.55rem; text-transform: uppercase; }
.judge-list { display: grid; gap: 10px; margin-bottom: 14px; }
.judge-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; border: 3px solid var(--ink); background: white; color: #07142e; padding: 12px; box-shadow: 4px 4px 0 var(--ink); font-family: Arial, "Segoe UI", sans-serif; font-weight: 900; }
.judge-row button { min-width: 90px; min-height: 42px; border: 3px solid var(--ink); background: var(--pink); color: white; font-weight: 950; box-shadow: 3px 3px 0 var(--ink); }
.judge-row button.is-valid { background: var(--green); color: #07142e; }

.winner-card { position: relative; display: grid; gap: 12px; text-align: center; overflow: hidden; }
.winner-card strong { font-size: clamp(2.4rem, 9vw, 4.6rem); line-height: 0.9; color: var(--pink); text-transform: uppercase; }
.winner-card p { margin: 0; font-family: Arial, "Segoe UI", sans-serif; font-weight: 900; }
.confetti { position: absolute; inset: 0; pointer-events: none; background: repeating-linear-gradient(90deg, transparent 0 28px, rgba(255, 225, 0, 0.45) 28px 34px, transparent 34px 58px, rgba(255, 47, 115, 0.35) 58px 64px, transparent 64px 86px, rgba(0, 223, 114, 0.35) 86px 92px); opacity: 0.22; animation: confettiSlide 1s linear infinite; }

@keyframes spinLetter {
  0% { transform: rotateX(0) scale(1); }
  50% { transform: rotateX(90deg) scale(1.08); }
  100% { transform: rotateX(0) scale(1); }
}

@keyframes warningPulse {
  0%, 100% { background: var(--blue-soft); }
  50% { background: #ffe1eb; }
}

@keyframes confettiSlide {
  from { background-position: 0 0; }
  to { background-position: 120px 0; }
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; width: min(760px, calc(100% - 24px)); }
  .side-panel { position: static; }
}

@media (max-width: 720px) {
  .app-shell { width: min(100% - 18px, 520px); padding: 28px 0; }
  .game-stage,
  .side-panel { padding: 12px; border-width: 3px; box-shadow: 5px 5px 0 var(--ink); }
  .topbar { grid-template-columns: 68px minmax(0, 1fr); }
  .brand-logo { width: 60px; border-width: 3px; box-shadow: 4px 4px 0 var(--ink); }
  .hud { grid-column: 1 / -1; grid-template-columns: 1fr 1fr; }
  h1 { font-size: clamp(2.35rem, 13vw, 3.45rem); }
  .setup-grid,
  .round-board,
  .answer-form,
  .setup-actions { grid-template-columns: 1fr; }
  .setup-field.wide { grid-column: auto; }
  .round-board { gap: 12px; padding: 12px; }
  .letter-card,
  .timer-card { min-height: 132px; }
  .letter-card strong { font-size: clamp(5.1rem, 28vw, 7.5rem); }
  .timer-card strong { font-size: clamp(2.7rem, 16vw, 4rem); }
  .actions { grid-template-columns: 56px minmax(0, 1fr) 56px; }
  .icon-button { width: 56px; }
}
.scenery-card {
  width: min(720px, 100%);
}

.scenery-stage {
  position: relative;
  min-height: 360px;
  overflow: hidden;
  border: 4px solid var(--ink);
  background: linear-gradient(#8ed8ff 0 48%, #7ae071 48% 100%);
  box-shadow: 5px 5px 0 var(--ink);
}

.scenery-stage.sunrise { background: linear-gradient(#ffcf75 0 45%, #ffd6e6 45% 58%, #7ae071 58% 100%); }
.scenery-stage.neon { background: linear-gradient(#101827 0 48%, #123b54 48% 62%, #00df72 62% 100%); }
.scenery-stage.forest { background: linear-gradient(#9ee7ff 0 42%, #1f9d55 42% 62%, #7ae071 62% 100%); }
.scenery-stage.ocean { background: linear-gradient(#9ee7ff 0 45%, #10c9ee 45% 64%, #ffe100 64% 100%); }
.scenery-stage.festival { background: linear-gradient(#f9a8d4 0 44%, #ffe100 44% 58%, #00df72 58% 100%); }
.scenery-stage.ai-generated { background: #07142e; }

.scene-ai-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 500ms ease;
  z-index: 1;
}

.scene-ai-img.loaded {
  opacity: 1;
}

.image-loader {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-family: Arial, "Segoe UI", sans-serif;
  color: white;
  z-index: 0;
  text-align: center;
}

.loader-text {
  font-size: 1.4rem;
  font-weight: 900;
  animation: pulseOpacity 1s infinite alternate;
}

.loader-sub {
  font-size: 0.95rem;
  font-weight: bold;
  opacity: 0.7;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulseOpacity {
  from { opacity: 0.5; }
  to { opacity: 1; }
}

.scenery-stage.loading .scene-elements {
  opacity: 0;
  pointer-events: none;
}
.scene-elements {
  transition: opacity 300ms ease;
}

.scene-sun {
  position: absolute;
  top: 22px;
  right: 34px;
  width: 76px;
  aspect-ratio: 1;
  border: 4px solid var(--ink);
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 5px 5px 0 var(--ink);
}

.scene-cloud {
  position: absolute;
  width: 118px;
  height: 42px;
  border: 4px solid var(--ink);
  background: white;
  box-shadow: 4px 4px 0 var(--ink);
}

.cloud-one { top: 42px; left: 34px; }
.cloud-two { top: 88px; right: 170px; transform: rotate(2deg); }

.scene-hills {
  position: absolute;
  left: -8%;
  right: -8%;
  bottom: 92px;
  height: 128px;
  background: linear-gradient(135deg, #27a8b9 0 50%, #168394 50% 100%);
  clip-path: polygon(0 100%, 18% 34%, 34% 100%, 52% 24%, 72% 100%, 88% 40%, 100% 100%);
  border-bottom: 4px solid var(--ink);
}

.scene-ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 112px;
  background: repeating-linear-gradient(90deg, #00df72 0 28px, #13c96e 28px 56px);
  border-top: 4px solid var(--ink);
}

.scene-sign,
.scene-badge,
.scene-letter {
  position: absolute;
  border: 4px solid var(--ink);
  box-shadow: 5px 5px 0 var(--ink);
  font-family: Arial, "Segoe UI", sans-serif;
  font-weight: 950;
  z-index: 2;
}

.scene-sign span,
.scene-badge span {
  display: block;
  margin-bottom: 5px;
  font-size: 0.68rem;
  text-transform: uppercase;
}

.scene-sign strong,
.scene-badge strong {
  display: block;
  word-break: break-word;
}

.place-sign {
  left: 28px;
  bottom: 28px;
  width: min(285px, calc(100% - 56px));
  padding: 14px;
  background: var(--yellow);
  color: #07142e;
  transform: rotate(-1deg);
}

.name-badge {
  left: 44px;
  top: 116px;
  max-width: 210px;
  padding: 12px;
  background: white;
  color: #07142e;
}

.animal-badge {
  right: 30px;
  top: 132px;
  max-width: 220px;
  padding: 12px;
  background: var(--pink);
  color: white;
  transform: rotate(2deg);
}

.thing-badge {
  right: 74px;
  bottom: 36px;
  max-width: 230px;
  padding: 12px;
  background: var(--cyan);
  color: #07142e;
}

.scene-letter {
  display: grid;
  place-items: center;
  left: 50%;
  top: 52%;
  width: 96px;
  aspect-ratio: 1;
  background: white;
  color: #07142e;
  font-family: "Arial Black", Impact, sans-serif;
  font-size: 4rem;
  transform: translate(-50%, -50%) rotate(-5deg);
}

.scenery-caption {
  margin: 14px 0;
  font-family: Arial, "Segoe UI", sans-serif;
  font-weight: 900;
  line-height: 1.35;
}

@media (max-width: 560px) {
  .scenery-stage { min-height: 430px; }
  .cloud-two { right: 22px; }
  .name-badge,
  .animal-badge,
  .thing-badge {
    left: 22px;
    right: 22px;
    max-width: none;
  }
  .name-badge { top: 106px; }
  .animal-badge { top: 180px; }
  .thing-badge { bottom: 112px; }
  .scene-letter { top: 50%; width: 78px; font-size: 3.2rem; }
}
.judge-row small {
  display: block;
  margin-top: 5px;
  color: #4a5870;
  font-size: 0.78rem;
  font-weight: 900;
}