:root {
  --ink: #202124;
  --paper: #fffdf7;
  --panel: #ffffff;
  --line: #ded9cb;
  --mint: #77c9b3;
  --coral: #f26f63;
  --gold: #f2b84b;
  --blue: #5d7ce6;
  --shadow: 0 18px 55px rgba(37, 32, 22, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 18% 8%, rgba(119, 201, 179, 0.25), transparent 28%),
    radial-gradient(circle at 82% 18%, rgba(242, 184, 75, 0.24), transparent 24%),
    linear-gradient(135deg, #f8fbf7 0%, #fff7ec 48%, #f3f7ff 100%);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1540px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #666254;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 4.1rem);
  line-height: 0.98;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(105px, 1fr));
  gap: 10px;
}

.stats div,
.side-panel,
.challenge-card,
.tool-row {
  background: rgba(255, 255, 255, 0.84);
  border: 1px solid rgba(222, 217, 203, 0.9);
  box-shadow: var(--shadow);
}

.stats div {
  min-height: 72px;
  border-radius: 8px;
  padding: 12px 14px;
}

.stats span,
.vote-card span,
.notebook-card span,
.brush-control span {
  display: block;
  color: #6d675b;
  font-size: 0.78rem;
  font-weight: 750;
}

.stats strong {
  display: block;
  margin-top: 5px;
  font-size: 1.15rem;
}

.game-grid {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 310px;
  gap: 16px;
  align-items: start;
}

.side-panel {
  border-radius: 8px;
  padding: 16px;
}

.field + .field {
  margin-top: 18px;
}

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

.stepper,
.segmented,
.tool-row,
.tournament-header,
.challenge-card,
.badges {
  display: flex;
  align-items: center;
}

.stepper {
  gap: 8px;
}

.stepper input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  text-align: center;
  font-weight: 850;
}

.stepper button,
.segmented button,
.tool-row button,
.tournament-header button,
.vote-card button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fffaf0;
  font-weight: 850;
}

.stepper button {
  width: 42px;
  flex: 0 0 42px;
}

.segmented {
  gap: 6px;
}

.segmented button {
  flex: 1;
  padding: 0 9px;
  font-size: 0.84rem;
}

.segmented button.active,
.mode-list button.active,
.primary-action {
  color: #111;
  background: var(--gold);
  border-color: #d79524;
}

.mode-list {
  display: grid;
  gap: 8px;
}

.mode-list button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  text-align: left;
  background: #fff;
}

.mode-list span {
  display: block;
  font-weight: 900;
}

.mode-list small {
  color: #6d675b;
  font-weight: 700;
}

.compact {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.compact input {
  grid-column: 1 / -1;
  width: 100%;
}

.primary-action,
.secondary-action {
  width: 100%;
  min-height: 44px;
  margin-top: 14px;
  border-radius: 8px;
  font-weight: 950;
}

.primary-action {
  border: 0;
}

.secondary-action {
  border: 1px solid #bbc7f5;
  background: #eef2ff;
}

.secondary-action + .secondary-action {
  margin-top: 8px;
}

.play-area {
  min-width: 0;
}

.challenge-card {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  border-radius: 8px;
  padding: 15px;
}

.challenge-card p {
  margin-bottom: 5px;
  color: #686151;
  font-weight: 900;
}

.challenge-card h2 {
  margin-bottom: 0;
  font-size: 1.35rem;
}

.badges {
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
}

.badges span {
  border-radius: 999px;
  padding: 8px 10px;
  background: #e8f6f1;
  font-size: 0.78rem;
  font-weight: 900;
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 900 / 620;
  border: 2px solid #252525;
  border-radius: 8px;
  background:
    linear-gradient(rgba(0, 0, 0, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  box-shadow: var(--shadow);
  touch-action: none;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#drawCanvas {
  z-index: 2;
}

.blink-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  color: #fff;
  background: rgba(29, 30, 35, 0.78);
  font-size: clamp(1.8rem, 6vw, 4rem);
  font-weight: 950;
}

.hidden {
  display: none;
}

.tool-row {
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
  border-radius: 8px;
  padding: 12px;
}

.swatches {
  display: flex;
  gap: 8px;
}

/* Outranks the generic .tool-row button skin, which would paint the
   swatches paper-white and square. */
.tool-row button.swatch {
  width: 36px;
  height: 36px;
  min-height: 36px;
  border: 3px solid transparent;
  border-radius: 50%;
  background: var(--swatch);
}

.tool-row button.swatch.active {
  border-color: #111;
}

.brush-control {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 180px;
}

.brush-control input {
  width: 140px;
}

.tool-row button {
  padding: 0 14px;
}

.tool-row .done-tool {
  border-color: #d79524;
  background: var(--gold);
}

.vote-panel {
  max-height: calc(100vh - 138px);
  overflow: auto;
}

.tournament-header {
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.tournament-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.tournament-header button {
  padding: 0 14px;
}

.vote-board {
  display: grid;
  gap: 10px;
}

.vote-card,
.notebook-card {
  display: grid;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fffdf8;
}

.vote-card {
  grid-template-columns: 84px 1fr auto;
}

.vote-card img {
  width: 84px;
  height: 58px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.vote-card strong {
  display: block;
  font-size: 0.88rem;
}

.vote-card button {
  padding: 0 10px;
  background: #e8f6f1;
}

.notebook-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  margin-bottom: 10px;
}

.notebook-header p {
  margin: 0;
}

.notebook-header button,
.result-actions button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
  font-weight: 850;
}

.notebook-board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.notebook-card {
  grid-template-columns: 1fr;
  padding: 8px;
}

.notebook-card img {
  width: 100%;
  aspect-ratio: 1.35;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.empty-note {
  grid-column: 1 / -1;
  margin: 0;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: #6d675b;
  font-weight: 750;
}

.result-dialog {
  width: min(880px, calc(100% - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  background: #fffdf8;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

.result-dialog::backdrop {
  background: rgba(20, 18, 15, 0.48);
}

.result-layout {
  display: grid;
  grid-template-columns: minmax(260px, 1.15fr) 1fr;
  gap: 18px;
  padding: 18px;
}

.result-layout img {
  width: 100%;
  aspect-ratio: 900 / 620;
  object-fit: cover;
  border: 2px solid #252525;
  border-radius: 8px;
  background: var(--paper);
}

.result-layout h2 {
  margin-bottom: 8px;
  font-size: 1.8rem;
}

.result-layout p:not(.eyebrow) {
  color: #5e594f;
  font-weight: 700;
  line-height: 1.45;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 16px 0;
}

.result-stats span {
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: #f8fbf7;
  font-weight: 950;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.result-actions button {
  padding: 0 14px;
}

.result-actions button:nth-child(2) {
  border-color: #d79524;
  background: var(--gold);
}

@media (max-width: 1120px) {
  .game-grid {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .vote-panel {
    grid-column: 1 / -1;
    max-height: none;
  }

  .vote-board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Fullscreen drawing: the play area takes the whole screen (native fullscreen
   where supported, fixed overlay on iPhone). Rotating to landscape gives the
   canvas the most room — the wrap keeps its aspect and maximizes. */
.play-area.board-full {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 10px;
  background:
    linear-gradient(135deg, #f8fbf7 0%, #fff7ec 48%, #f3f7ff 100%);
  overflow: hidden;
}

.play-area.board-full .challenge-card {
  display: none;
}

.play-area.board-full .canvas-wrap {
  /* as big as the screen allows while keeping the drawing aspect */
  width: min(100%, calc((100dvh - 92px) * 900 / 620));
  margin: 0 auto;
}

.play-area.board-full .tool-row {
  flex-wrap: wrap;
}

@media (max-width: 760px) {
  .app-shell {
    padding: 12px;
  }

  /* The board is the game — on a phone it comes first, controls after. */
  .play-area {
    order: -1;
  }

  /* App-like on a phone: the topbar collapses to one compact strip and stays
     stuck to the top, so level, points, timer and streak never scroll away. */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin: -12px -12px 12px;
    padding: 10px 12px 8px;
    background: rgba(255, 253, 247, 0.94);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
  }

  h1 {
    display: none;
  }

  .eyebrow {
    margin: 0;
  }

  .stats {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .stats div {
    min-height: 0;
    padding: 6px 10px;
  }

  .challenge-card {
    align-items: stretch;
    flex-direction: column;
  }

  .game-grid,
  .vote-board,
  .notebook-board,
  .result-layout {
    grid-template-columns: 1fr;
  }

  .badges {
    justify-content: start;
  }
}
