:root {
  --go-black: #171717;
  --go-white: #fffdf8;
  --go-paper: #f4f1e9;
  --go-paper-strong: #ebe5d8;
  --go-line: #c8bda8;
  --go-muted: #6f6a5f;
  --go-board: #d9a441;
  --go-board-dark: #a97724;
  --go-accent: #2f7d55;
  --go-danger: #a33d3d;
  --shadow: rgba(23, 23, 23, 0.16);
}

body {
  background:
    linear-gradient(90deg, rgba(23, 23, 23, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(23, 23, 23, 0.035) 1px, transparent 1px),
    var(--go-paper);
  background-size: 44px 44px;
  color: var(--go-black);
}

.train-shell {
  display: grid;
  min-height: 100vh;
  padding: 20px;
}

.train-play {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 14px;
  width: min(1420px, 100%);
  margin: 0 auto;
  min-width: 0;
}

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

.topbar h1,
.start-panel h2,
.finish-panel h2,
.end-leaderboard h3 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(28px, 3vw, 42px);
  line-height: 1;
}

.topbar p,
.start-panel p,
.finish-panel p,
.status {
  margin: 5px 0 0;
  color: var(--go-muted);
}

.topbar-stats {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.language-toggle {
  display: inline-flex;
  padding: 3px;
  border: 2px solid var(--go-black);
  border-radius: 999px;
  background: var(--go-white);
  box-shadow: 0 5px 0 #000;
}

.language-toggle button {
  min-height: 32px;
  border: 0;
  border-radius: 999px;
  padding: 0 10px;
  background: transparent;
  color: var(--go-muted);
  font-weight: 900;
  cursor: pointer;
}

.language-toggle button.active {
  background: var(--go-black);
  color: var(--go-white);
}

.score-pill,
.timer-pill {
  min-width: 116px;
  padding: 10px 14px;
  border: 2px solid var(--go-black);
  border-bottom-width: 6px;
  border-radius: 8px;
  background: var(--go-white);
  text-align: center;
  box-shadow: 0 8px 18px var(--shadow);
}

.timer-pill {
  background: var(--go-black);
  color: var(--go-white);
}

.timer-pill.urgent {
  border-color: var(--go-danger);
  color: #fff4f4;
}

.score-pill span,
.timer-pill span,
.final-score span {
  display: block;
  font-size: 30px;
  font-weight: 900;
  line-height: 1;
}

.score-pill small,
.timer-pill small,
.final-score small {
  color: inherit;
  opacity: 0.72;
}

.progress-track {
  height: 18px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--go-paper-strong);
  border: 2px solid var(--go-black);
}

#progressFill {
  width: 0;
  height: 100%;
  background: repeating-linear-gradient(
    135deg,
    var(--go-black) 0,
    var(--go-black) 12px,
    #363636 12px,
    #363636 24px
  );
  transition: width 200ms ease;
}

.start-panel,
.finish-panel {
  align-self: center;
  justify-self: center;
  width: min(560px, 100%);
  padding: 30px;
  border: 2px solid var(--go-black);
  border-bottom-width: 8px;
  border-radius: 8px;
  background: var(--go-white);
  text-align: center;
  box-shadow: 0 16px 30px var(--shadow);
}

.finish-panel {
  align-self: start;
  margin-top: 16px;
}

.badge-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 18px;
}

.badge-row span {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-block;
  background: radial-gradient(circle at 34% 30%, #555, #050505 72%);
  border: 2px solid #050505;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.22);
}

.badge-row span:nth-child(2) {
  background: radial-gradient(circle at 34% 30%, #fff, #d8d8d8 74%);
  border-color: #b8b8b8;
}

.badge-row span:nth-child(3) {
  background: var(--go-board);
  border-color: var(--go-board-dark);
}

.badge-row.big span {
  width: 46px;
  height: 46px;
}

.start-panel label {
  display: grid;
  gap: 8px;
  margin: 22px 0 14px;
  text-align: left;
  color: var(--go-muted);
}

.start-panel input {
  height: 48px;
  border: 2px solid var(--go-black);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--go-white);
  color: var(--go-black);
}

.primary,
.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 8px;
  padding: 0 18px;
  font-weight: 900;
  cursor: pointer;
}

.primary {
  border: 0;
  background: var(--go-black);
  color: var(--go-white);
  box-shadow: 0 6px 0 #000;
}

.primary:active,
.secondary:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #000;
}

.primary:disabled,
.secondary:disabled {
  cursor: wait;
  opacity: 0.68;
  transform: none;
}

.secondary {
  background: var(--go-white);
  color: var(--go-black);
  border: 2px solid var(--go-black);
  box-shadow: 0 6px 0 #000;
}

.game-panel {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) minmax(360px, 430px);
  gap: 18px;
  min-height: 0;
}

.board-wrap {
  display: grid;
  min-width: 0;
}

#trainBoard {
  width: min(100%, calc(100vh - 124px));
  height: auto;
  max-height: calc(100vh - 124px);
  justify-self: center;
  align-self: center;
  background: var(--go-board);
  border: 2px solid var(--go-black);
  border-radius: 8px;
  box-shadow: 0 12px 0 var(--go-black), 0 22px 34px var(--shadow);
}

.guess-panel {
  align-self: center;
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 2px solid var(--go-black);
  border-bottom-width: 8px;
  border-radius: 8px;
  background: var(--go-white);
  box-shadow: 0 14px 26px var(--shadow);
}

.question-strip {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--go-black);
  font-weight: 900;
}

.question-strip span:last-child {
  color: var(--go-muted);
  text-align: right;
}

.mobile-meta-line {
  display: none;
}

.round-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.round-meta-grid div {
  min-width: 0;
  padding: 9px 10px;
  border-radius: 8px;
  background: var(--go-paper);
  border: 1px solid var(--go-line);
}

.round-meta-grid dt {
  color: var(--go-muted);
  font-size: 12px;
  font-weight: 800;
}

.round-meta-grid dd {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
  font-weight: 800;
}

.meter-card {
  padding: 16px;
  border-radius: 8px;
  background: var(--go-paper);
  border: 2px solid var(--go-black);
}

.meter-readout {
  text-align: center;
  margin-bottom: 12px;
}

.meter-readout span {
  display: block;
  font-size: 42px;
  font-weight: 900;
  color: var(--go-black);
}

.meter-readout small,
.slider-labels,
.reveal-panel small {
  color: var(--go-muted);
}

#guessSlider {
  width: 100%;
  accent-color: var(--go-black);
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}

.reveal-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.reveal-panel div {
  padding: 10px;
  border-radius: 8px;
  background: var(--go-paper);
  border: 1px solid var(--go-line);
}

.reveal-panel span {
  display: block;
  font-weight: 900;
  font-size: 20px;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.final-score {
  width: 190px;
  margin: 18px auto;
  padding: 16px;
  border-radius: 8px;
  background: var(--go-paper);
  border: 2px solid var(--go-black);
}

.end-leaderboard {
  margin: 22px 0 18px;
  padding-top: 18px;
  border-top: 2px solid var(--go-black);
  text-align: left;
}

.end-leaderboard h3 {
  text-align: center;
}

#leaderboard {
  margin: 12px 0 0;
  padding-left: 24px;
}

#leaderboard li {
  margin: 9px 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--go-paper);
  border: 1px solid var(--go-line);
}

#leaderboard strong {
  display: block;
}

#leaderboard span {
  color: var(--go-muted);
  font-size: 13px;
}

.status {
  min-height: 22px;
  font-size: 14px;
}

.hidden {
  display: none !important;
}

@media (max-width: 1080px) {
  .game-panel {
    grid-template-columns: 1fr;
  }

  #trainBoard {
    width: min(100%, 92vw);
    max-height: none;
  }

  .guess-panel {
    align-self: stretch;
  }
}

@media (max-width: 680px) {
  body {
    overflow-x: hidden;
  }

  .train-shell {
    min-height: 100svh;
    padding: 8px 10px 10px;
  }

  .train-play {
    gap: 8px;
    min-height: calc(100svh - 18px);
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "title lang"
      "stats stats";
    align-items: end;
    gap: 6px 10px;
  }

  .topbar h1 {
    font-size: 23px;
  }

  .topbar p {
    font-size: 12px;
    margin-top: 2px;
  }

  .title-group {
    grid-area: title;
    min-width: 0;
  }

  .topbar-actions {
    display: contents;
  }

  .topbar-stats {
    grid-area: stats;
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
    gap: 8px;
  }

  .score-pill,
  .timer-pill {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 7px;
    min-width: 0;
    min-height: 38px;
    padding: 5px 10px;
    border-width: 2px;
    border-bottom-width: 4px;
    box-shadow: none;
  }

  .score-pill span,
  .timer-pill span {
    font-size: 22px;
  }

  .score-pill small,
  .timer-pill small {
    font-size: 12px;
  }

  .language-toggle {
    grid-area: lang;
    justify-self: end;
    box-shadow: none;
  }

  .language-toggle button {
    min-height: 26px;
    padding: 0 8px;
    font-size: 12px;
  }

  .progress-track {
    height: 12px;
  }

  .game-panel {
    gap: 8px;
  }

  #trainBoard {
    width: min(100%, calc(100svh - 282px), 94vw);
    border-radius: 6px;
    box-shadow: 0 7px 0 var(--go-black), 0 12px 18px var(--shadow);
  }

  .guess-panel {
    gap: 8px;
    padding: 10px;
    border-bottom-width: 5px;
    box-shadow: 0 8px 16px var(--shadow);
  }

  .question-strip {
    font-size: 14px;
  }

  .mobile-meta-line {
    display: block;
    color: var(--go-muted);
    font-size: 12px;
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .round-meta-grid {
    display: none;
  }

  .meter-card {
    padding: 10px;
  }

  .game-panel.answered .meter-card {
    display: none;
  }

  .meter-readout {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 8px;
    margin-bottom: 6px;
  }

  .meter-readout span {
    font-size: 32px;
  }

  .meter-readout small {
    font-size: 12px;
  }

  .slider-labels {
    font-size: 11px;
  }

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

  .reveal-panel div {
    padding: 8px;
  }

  .reveal-panel span {
    font-size: 16px;
  }

  .primary,
  .secondary {
    min-height: 52px;
    padding: 0 12px;
    text-align: center;
  }

  .start-panel .primary,
  .finish-panel > .primary {
    width: min(100%, 220px);
    margin-inline: auto;
  }

  .status {
    min-height: 16px;
    font-size: 12px;
    margin-top: 0;
  }

  .game-panel:not(.hidden) ~ .status {
    display: none;
  }

  .action-row {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 8px;
  }

  .action-row .primary,
  .action-row .secondary {
    width: min(100%, 260px);
  }
}

@media (max-width: 390px) {
  .topbar h1 {
    font-size: 20px;
  }

  .score-pill,
  .timer-pill {
    padding-inline: 8px;
  }

  #trainBoard {
    width: min(100%, calc(100svh - 278px), 92vw);
  }
}

@media (max-width: 680px) and (max-height: 700px) {
  .train-shell {
    padding-block: 6px;
  }

  .train-play {
    gap: 6px;
    min-height: calc(100svh - 12px);
  }

  .topbar {
    gap: 4px 8px;
  }

  .topbar h1 {
    font-size: 19px;
  }

  .topbar p {
    font-size: 11px;
  }

  .language-toggle {
    padding: 2px;
  }

  .language-toggle button {
    min-height: 24px;
    padding-inline: 7px;
    font-size: 11px;
  }

  .score-pill,
  .timer-pill {
    min-height: 34px;
    padding-block: 3px;
  }

  .score-pill span,
  .timer-pill span {
    font-size: 20px;
  }

  .progress-track {
    height: 10px;
  }

  #trainBoard {
    width: min(100%, calc(100svh - 370px), 88vw);
  }

  .guess-panel {
    gap: 6px;
    padding: 8px;
  }

  .question-strip {
    font-size: 13px;
  }

  .meter-card {
    padding: 8px;
  }

  .meter-readout span {
    font-size: 28px;
  }

  .primary,
  .secondary {
    min-height: 50px;
  }
}
