:root {
  color-scheme: light;
  --ink: #181718;
  --paper: #fff8e7;
  --panel: #ffffff;
  --line: #181718;
  --yellow: #ffcf3f;
  --coral: #ff5c4d;
  --teal: #12b8a6;
  --blue: #2f73ff;
  --mint: #b7f36b;
  --shadow: 0 18px 0 rgba(24, 23, 24, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 8%, rgba(255, 207, 63, 0.42), transparent 28rem),
    radial-gradient(circle at 92% 22%, rgba(18, 184, 166, 0.34), transparent 24rem),
    linear-gradient(135deg, #fff8e7 0%, #f7f2ff 48%, #e9fff8 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 3px solid var(--line);
  background: var(--yellow);
  color: var(--ink);
  min-height: 46px;
  border-radius: 8px;
  padding: 0.7rem 1rem;
  font-weight: 850;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--line);
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 7px 0 var(--line);
}

button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--line);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.primary {
  width: 100%;
  background: var(--coral);
  color: #fff;
}

.secondary {
  background: #fff;
}

.icon-button {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
  background: var(--mint);
  flex: 0 0 auto;
}

.game-promise {
  max-width: 54ch;
  margin: 0.75rem 0 0;
  font-size: 1.08rem;
  line-height: 1.45;
  font-weight: 750;
  color: #38323a;
}

.shell {
  width: min(1460px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(360px, 32vw, 500px);
  gap: 22px;
  align-items: stretch;
}

.stage-panel,
.control-panel {
  border: 4px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  box-shadow: var(--shadow);
}

.stage-panel {
  min-height: calc(100vh - 48px);
  padding: 22px;
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto;
  gap: 14px;
  min-width: 0;
}

.control-panel {
  min-height: calc(100vh - 48px);
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.brand-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 0.78rem;
  font-weight: 900;
  color: #655c68;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
  line-height: 0.96;
}

h1 {
  font-size: clamp(2.55rem, 5.2vw, 4.3rem);
  max-width: 12ch;
}

h2 {
  font-size: clamp(1.65rem, 2.6vw, 2.55rem);
}

.phase-head p:last-child {
  margin: 0.45rem 0 0;
  font-size: 1rem;
  line-height: 1.45;
  color: #4d4650;
}

.how-card,
.play-note,
.setup-status,
.mode-intro,
.online-room {
  border: 3px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.mode-tab {
  min-height: 58px;
  display: grid;
  align-content: center;
  gap: 3px;
  background: #fff;
  text-align: left;
}

.mode-tab.active {
  background: var(--yellow);
  transform: translateY(2px);
  box-shadow: 0 3px 0 var(--line);
}

.mode-tab span {
  font-size: 1rem;
}

.mode-tab small {
  color: #4d4650;
  font-weight: 850;
}

.mode-panel {
  display: none;
}

.mode-panel.active {
  display: block;
}

.how-card {
  padding: 11px 13px;
  margin-top: 12px;
  box-shadow: 6px 6px 0 rgba(24, 23, 24, 0.12);
}

.how-card summary,
.play-note strong {
  display: block;
  font-size: 1.1rem;
  font-weight: 950;
  cursor: pointer;
}

.how-card ol {
  margin: 10px 0 0;
  padding-left: 1.35rem;
}

.how-card li {
  margin: 0.32rem 0;
  line-height: 1.35;
  font-weight: 720;
}

.play-note {
  padding: 13px;
  margin-bottom: 14px;
  background: #fff8d7;
}

.play-note span {
  display: block;
  margin-top: 5px;
  line-height: 1.35;
}

.setup-status {
  display: inline-block;
  margin-bottom: 8px;
  padding: 8px 11px;
  background: var(--mint);
  font-weight: 950;
}

.mode-intro,
.online-room {
  margin-top: 12px;
  padding: 12px;
}

.mode-intro {
  margin-top: 0;
  margin-bottom: 10px;
}

.mode-intro.local {
  background: #fff8d7;
}

.mode-intro.online,
.online-room {
  background: #e9fff8;
}

.mode-intro strong {
  display: block;
  font-size: 1.1rem;
  font-weight: 950;
}

.mode-intro p {
  margin: 0.35rem 0 0;
  line-height: 1.35;
}

.mode-panel input,
.online-room .add-row {
  margin-bottom: 10px;
}

.online-error {
  min-height: 1.3rem;
  margin: 10px 0 0;
  color: #b62020;
  font-weight: 850;
}

.setup-sql-button {
  width: 100%;
  margin-top: 8px;
  background: #fff8d7;
}

.invite-mode #localModeTab,
.invite-mode #createOnline {
  display: none;
}

.invite-mode .mode-tabs {
  grid-template-columns: 1fr;
}

.invite-mode #onlineModeTab {
  background: var(--yellow);
}

.invite-mode #roomCodeInput {
  background: #fff8d7;
  font-weight: 900;
}

.room-code {
  display: inline-block;
  margin: 4px 0 12px;
  border: 3px solid var(--line);
  background: var(--yellow);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 1.8rem;
  font-weight: 950;
  letter-spacing: 0.08em;
}

.room-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.scene-wrap {
  min-height: 360px;
  height: 100%;
  aspect-ratio: 16 / 10;
  position: relative;
  overflow: hidden;
  border: 4px solid var(--line);
  background: #87d7ff;
}

#sceneCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.scene-card {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  max-width: 680px;
  border: 3px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  padding: 14px 16px;
  box-shadow: 7px 7px 0 rgba(24, 23, 24, 0.28);
}

.scene-card span {
  display: inline-block;
  margin-bottom: 0.35rem;
  font-size: 0.8rem;
  font-weight: 900;
  text-transform: uppercase;
}

.scene-card strong {
  display: block;
  font-size: clamp(1.15rem, 2.4vw, 1.75rem);
  line-height: 1.1;
}

.scene-card p {
  margin: 0.45rem 0 0;
  font-size: 1rem;
  line-height: 1.35;
}

.score-strip {
  min-height: 82px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}

.score-pill {
  border: 3px solid var(--line);
  background: #fff;
  padding: 10px;
  min-width: 0;
}

.score-pill strong,
.player-chip strong {
  overflow-wrap: anywhere;
}

.score-pill span {
  display: block;
  margin-top: 4px;
  font-size: 1.35rem;
  font-weight: 950;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 850;
}

.add-row,
.setup-actions,
.result-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

input,
textarea {
  width: 100%;
  border: 3px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 0.8rem;
  min-height: 46px;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 82px;
  line-height: 1.35;
}

input:focus,
textarea:focus {
  box-shadow: 0 0 0 4px rgba(47, 115, 255, 0.22);
}

.player-list,
.caption-inputs,
.vote-cards {
  display: grid;
  gap: 9px;
  margin: 10px 0;
}

.player-chip,
.caption-box,
.vote-card,
.winner-card {
  border: 3px solid var(--line);
  background: #fff;
  border-radius: 8px;
}

.player-chip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
}

.player-chip button {
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-width: 2px;
  border-radius: 50%;
  background: #fff;
  box-shadow: none;
}

.setup-actions {
  grid-template-columns: 1fr 1fr;
  margin: 10px 0;
}

.sticky-action {
  position: sticky;
  bottom: 0;
  z-index: 3;
  padding-top: 8px;
  background: linear-gradient(to top, rgba(255, 255, 255, 0.96) 76%, rgba(255, 255, 255, 0));
}

.caption-box {
  padding: 12px;
}

.caption-box label {
  display: block;
  margin-bottom: 8px;
  font-weight: 900;
}

.caption-box small {
  display: block;
  margin-top: 8px;
  color: #655c68;
  font-weight: 750;
  line-height: 1.3;
}

.timer-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  font-weight: 900;
}

progress {
  width: 100%;
  height: 16px;
  accent-color: var(--teal);
}

.vote-turn {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border: 3px solid var(--line);
  background: var(--mint);
  padding: 12px;
  font-weight: 900;
}

.vote-card {
  width: 100%;
  text-align: left;
  background: #fff;
  box-shadow: 0 5px 0 var(--line);
  min-height: 72px;
}

.vote-card[aria-pressed="true"] {
  background: var(--yellow);
}

.vote-card small {
  display: block;
  margin-top: 8px;
  color: #655c68;
  font-weight: 800;
}

.winner-card {
  padding: 18px;
  background: linear-gradient(135deg, #fff 0%, #fff 45%, #ffe790 45%, #ffe790 100%);
}

.winner-card .caption {
  margin: 0.5rem 0;
  font-size: clamp(1.45rem, 4vw, 2.4rem);
  line-height: 1.05;
  font-weight: 950;
}

.winner-card .meta {
  margin: 0;
  font-weight: 850;
}

.result-actions {
  grid-template-columns: 1fr 1fr;
  margin: 14px 0;
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
    width: min(100% - 22px, 860px);
  }

  .stage-panel,
  .control-panel {
    min-height: auto;
    max-height: none;
  }

  .scene-wrap {
    min-height: 52svh;
  }

  h1 {
    max-width: none;
  }
}

@media (max-height: 820px) and (min-width: 981px) {
  .stage-panel,
  .control-panel {
    padding: 16px;
    gap: 12px;
  }

  h1 {
    font-size: clamp(2.5rem, 4.8vw, 3.7rem);
  }

  .game-promise {
    margin-top: 0.45rem;
  }

  .scene-wrap {
    min-height: 300px;
  }

  .score-strip {
    min-height: 60px;
  }

  .score-pill {
    padding: 7px;
  }
}

@media (max-width: 700px) {
  .shell {
    gap: 12px;
  }

  .brand-row {
    align-items: flex-start;
  }

  h1 {
    font-size: clamp(2.2rem, 12vw, 3.5rem);
  }

  .game-promise {
    font-size: 1rem;
  }

  .score-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .score-pill {
    padding: 8px;
  }

  .score-pill span {
    font-size: 1.1rem;
  }
}

@media (max-width: 560px) {
  .shell {
    width: 100%;
    padding: 0;
  }

  .stage-panel,
  .control-panel {
    border-left: 0;
    border-right: 0;
    box-shadow: none;
    padding: 16px;
  }

  .scene-wrap {
    min-height: 380px;
    aspect-ratio: auto;
  }

  .add-row,
  .setup-actions,
  .room-actions,
  .result-actions,
  .timer-row {
    grid-template-columns: 1fr;
  }

  .mode-tabs {
    grid-template-columns: 1fr;
  }

  .mode-tab {
    min-height: 58px;
  }

  .scene-card {
    left: 10px;
    right: 10px;
    bottom: 10px;
    padding: 11px 12px;
  }

  .scene-card p {
    font-size: 0.92rem;
  }

  .room-code {
    width: 100%;
    text-align: center;
    font-size: 1.55rem;
  }
}

@media (max-width: 390px) {
  .stage-panel,
  .control-panel {
    padding: 12px;
  }

  button {
    padding: 0.65rem 0.8rem;
  }

  .scene-wrap {
    min-height: 340px;
  }

  .how-card ol {
    padding-left: 1.1rem;
  }
}
