:root {
  color-scheme: light;
  --ink: #151515;
  --muted: #646464;
  --line: #d9d4ca;
  --paper: #fffdf7;
  --panel: #f4f0e8;
  --accent: #e93f33;
  --accent-dark: #b72a22;
  --blue: #2467c4;
  --green: #188b5f;
  --shadow: 0 18px 50px rgba(41, 35, 24, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(21, 21, 21, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(21, 21, 21, 0.035) 1px, transparent 1px),
    #fbf8ef;
  background-size: 28px 28px;
}

.is-hidden {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  padding: 0 16px;
  color: var(--ink);
  background: #fffaf0;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    background 120ms ease;
}

button:hover {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--ink);
}

button:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--ink);
}

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

.primary {
  color: #fff;
  background: var(--accent);
}

.start-screen {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  background: #fffdf7;
}

.start-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 2px solid var(--ink);
  padding: 18px clamp(18px, 4vw, 54px);
}

.start-nav strong {
  font-size: 20px;
}

.start-nav span {
  color: var(--muted);
  font-weight: 800;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.auth-open-btn {
  min-height: 34px;
  padding: 0 12px;
  background: #fff;
  font-size: 13px;
  font-weight: 900;
}

.user-badge {
  max-width: min(280px, 45vw);
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.start-hero {
  display: grid;
  grid-template-columns: minmax(320px, 0.92fr) minmax(360px, 1.08fr);
  gap: clamp(28px, 5vw, 72px);
  width: min(1320px, calc(100vw - 36px));
  margin: 0 auto;
  padding: clamp(42px, 7vw, 92px) 0 28px;
}

.start-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.start-copy h1 {
  margin: 0 0 18px;
  font-size: clamp(60px, 8vw, 128px);
  line-height: 0.95;
  white-space: nowrap;
}

.start-lede {
  max-width: 620px;
  margin-bottom: 28px;
  color: #363636;
  font-size: clamp(20px, 2.2vw, 30px);
  line-height: 1.35;
}

.start-actions {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.start-actions span {
  color: var(--muted);
  font-weight: 800;
}

.start-draw-btn {
  min-height: 64px;
  padding: 0 34px;
  font-size: 24px;
  font-weight: 900;
}

.start-gallery {
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.gallery-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 2px solid var(--ink);
  background: #ffd139;
  padding: 18px 20px;
}

.gallery-title span {
  color: rgba(21, 21, 21, 0.68);
  font-weight: 900;
}

.gallery-title strong {
  font-size: 26px;
}

.dataset-mosaic {
  padding: 14px;
  background: #fff;
}

.dataset-mosaic canvas {
  display: block;
  width: 100%;
  height: clamp(260px, 36vw, 430px);
  background: #fff;
}

.dataset-note {
  margin: 0;
  border-top: 2px solid var(--ink);
  padding: 16px 20px 18px;
  color: #303030;
  background: #fffdf7;
  font-size: clamp(16px, 1.6vw, 22px);
  font-weight: 900;
  line-height: 1.35;
}

.start-footer {
  display: flex;
  justify-content: flex-end;
  gap: 16px;
  margin-top: auto;
  border-top: 2px solid var(--ink);
  padding: 16px clamp(18px, 4vw, 54px);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 320px);
  gap: 16px;
  width: min(1440px, calc(100vw - 20px));
  margin: 0 auto;
  padding: 12px 0;
}

.stage,
.side-panel {
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.stage {
  display: flex;
  min-height: calc(100dvh - 24px);
  flex-direction: column;
  padding: 16px;
}

.side-panel {
  align-self: start;
  max-height: calc(100dvh - 24px);
  overflow: auto;
  padding: 14px;
}

.topbar {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 24px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--blue);
  font-size: clamp(18px, 1.6vw, 24px);
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 3.7vw, 48px);
  line-height: 1.02;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 12px;
  font-size: 16px;
  line-height: 1.2;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, 72px);
  overflow: hidden;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: #fff;
}

.scoreboard div {
  display: grid;
  min-height: 60px;
  place-items: center;
  border-left: 1px solid var(--ink);
}

.scoreboard div:first-child {
  border-left: 0;
}

.scoreboard span {
  display: block;
  font-size: 23px;
  font-weight: 900;
}

.scoreboard small {
  color: var(--muted);
  font-size: 12px;
}

.prompt-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 14px 0 12px;
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  padding: 10px 0;
}

.prompt-strip span,
.prompt-strip p {
  color: var(--muted);
}

.prompt-strip strong {
  margin-left: 8px;
  font-size: clamp(30px, 4.4vw, 58px);
  line-height: 1;
}

.prompt-strip p {
  max-width: 430px;
  margin-bottom: 0;
  font-size: 14px;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: min(68dvh, 680px);
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #fff;
}

#drawCanvas {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.canvas-grid {
  position: absolute;
  inset: 0;
  z-index: 1;
  background-image:
    linear-gradient(rgba(21, 21, 21, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(21, 21, 21, 0.06) 1px, transparent 1px);
  background-size: 36px 36px;
}

.guess-history {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 3;
  width: min(360px, calc(100% - 28px));
  max-height: 42%;
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 253, 247, 0.94);
  box-shadow: 3px 3px 0 var(--ink);
  pointer-events: none;
}

.guess-history > span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.guess-trail {
  display: flex;
  align-content: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.guess-chip {
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 4px 9px;
  background: #fff;
  font-size: 14px;
  font-weight: 900;
  line-height: 1.15;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.range-control {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  padding: 0 12px;
  background: #fff;
}

.range-control span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.range-control input {
  accent-color: var(--accent);
}

.panel-section {
  padding: 16px 0;
  border-top: 1px solid var(--line);
}

.panel-section:first-child {
  padding-top: 0;
  border-top: 0;
}

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

.model-status {
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.guess-row {
  display: grid;
  grid-template-columns: 88px 1fr 42px;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.guess-meter {
  height: 10px;
  overflow: hidden;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: #fff;
}

.guess-meter span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--green);
  transition: width 180ms ease;
}

.facts {
  display: grid;
  gap: 12px;
  margin: 0;
}

.facts div {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 12px;
}

.facts dt {
  color: var(--muted);
  font-weight: 800;
}

.facts dd {
  margin: 0;
}

.audio-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.audio-board div {
  min-height: 76px;
  border: 1px solid var(--ink);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.audio-board strong,
.audio-board span {
  display: block;
}

.audio-board strong {
  margin-bottom: 8px;
  font-size: 18px;
}

.audio-board span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#sampleCanvas {
  width: 100%;
  height: auto;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: #fff;
}

.sample-json {
  max-height: 180px;
  overflow: auto;
  margin: 12px 0 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  color: #343434;
  background: #fffaf0;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(21, 21, 21, 0.42);
}

.auth-card {
  position: relative;
  width: min(440px, 100%);
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 22px;
  background: var(--paper);
  box-shadow: 6px 6px 0 var(--ink);
}

.records-card {
  position: relative;
  width: min(920px, 100%);
  max-height: min(86dvh, 780px);
  overflow: auto;
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 22px;
  background: var(--paper);
  box-shadow: 6px 6px 0 var(--ink);
}

.auth-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  min-height: 34px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.auth-help {
  margin-bottom: 16px;
  color: var(--muted);
  font-weight: 800;
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.auth-tab {
  min-height: 38px;
  padding: 0 8px;
  background: #fff;
  font-size: 13px;
  font-weight: 900;
}

.auth-tab.is-active {
  color: #fff;
  background: var(--ink);
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-form label,
.auth-form label span,
.auth-form input,
.auth-form select {
  display: block;
}

.auth-form label span {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.auth-form input,
.auth-form select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  padding: 0 12px;
  background: #fff;
}

.auth-message {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--muted);
  font-weight: 800;
}

.records-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding-right: 48px;
}

.records-list {
  display: grid;
  gap: 14px;
}

.record-card {
  overflow: hidden;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: #fff;
}

.record-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 14px;
}

.record-main strong {
  display: block;
  font-size: 24px;
}

.record-main span,
.round-card span,
.record-empty {
  color: var(--muted);
  font-weight: 800;
}

.record-rounds {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  padding: 14px;
}

.round-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fffdf7;
}

.round-card canvas {
  width: 100%;
  height: 110px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background:
    linear-gradient(rgba(21, 21, 21, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(21, 21, 21, 0.05) 1px, transparent 1px),
    #fff;
  background-size: 18px 18px;
}

.round-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 900;
}

.round-status {
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 2px 7px;
  background: #fff;
  font-size: 12px;
  white-space: nowrap;
}

.round-status.is-ok {
  color: #fff;
  background: var(--green);
}

.round-status.is-miss {
  color: #fff;
  background: var(--accent);
}

.round-guesses {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.round-guesses small {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 7px;
  background: #fff;
  font-weight: 800;
}

@media (max-width: 980px) {
  .start-hero {
    grid-template-columns: 1fr;
  }

  .app-shell {
    grid-template-columns: 1fr;
    width: min(100vw - 24px, 1280px);
  }

  .stage {
    min-height: auto;
  }

  .side-panel {
    max-height: none;
  }
}

@media (max-width: 680px) {
  .start-nav,
  .start-footer,
  .start-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .nav-right {
    align-items: flex-start;
    justify-content: flex-start;
  }

  .start-hero {
    width: min(100vw - 20px, 1320px);
    padding-top: 30px;
  }

  .start-copy h1 {
    font-size: clamp(48px, 16vw, 96px);
  }

  .start-lede {
    font-size: 19px;
  }

  .gallery-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-shell {
    width: min(100vw - 20px, 1280px);
    padding: 10px 0;
  }

  .stage,
  .side-panel {
    padding: 14px;
  }

  .topbar,
  .prompt-strip {
    align-items: stretch;
    flex-direction: column;
  }

  .scoreboard {
    grid-template-columns: repeat(3, 1fr);
  }

  .scoreboard div {
    min-height: 58px;
  }

  .prompt-strip strong {
    margin-left: 0;
  }

  .canvas-wrap {
    min-height: min(58dvh, 420px);
  }

  .guess-history {
    top: 10px;
    left: 10px;
    width: min(300px, calc(100% - 20px));
    max-height: 34%;
    padding: 8px 10px;
  }

  .guess-chip {
    font-size: 13px;
    padding: 3px 8px;
  }

  .toolbar button {
    flex: 1;
  }

  .range-control {
    width: 100%;
    justify-content: space-between;
  }

  .audio-board {
    grid-template-columns: 1fr;
  }

  .records-card {
    max-height: 90dvh;
    padding: 18px;
  }

  .records-header,
  .record-main {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 430px) {
  .start-nav {
    gap: 8px;
  }

  .start-nav strong {
    font-size: 18px;
  }

  .start-copy h1 {
    font-size: clamp(38px, 14vw, 62px);
  }

  h1 {
    font-size: 28px;
  }

  .prompt-strip {
    gap: 10px;
    margin: 14px 0 12px;
  }

  .prompt-strip strong {
    font-size: 46px;
  }

  .canvas-wrap {
    min-height: 50dvh;
  }

  .guess-history {
    max-height: 30%;
  }

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

  .toolbar button,
  .range-control {
    width: 100%;
  }

  .range-control {
    grid-column: 1 / -1;
  }
}
