:root {
  --ink: #182033;
  --paper: #fff9ed;
  --line: #243047;
  --mint: #35d7a8;
  --lemon: #ffd85a;
  --berry: #e95b88;
  --sky: #69c8ff;
  --moon: #fff4a8;
  --shadow: 5px 5px 0 rgba(24, 32, 51, 0.9);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(90deg, rgba(36, 48, 71, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(36, 48, 71, 0.06) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
canvas:focus-visible {
  outline: 3px solid var(--lemon);
  outline-offset: 3px;
}

.game-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.game-board {
  min-width: 0;
  width: min(1080px, 100%);
  max-width: calc(100vw - 20px);
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.game-header {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  border-bottom: 2px solid var(--line);
  padding: 14px;
  background: linear-gradient(90deg, #24315f, #6dd7cf);
}

.game-header > div {
  min-width: 0;
}

.game-header h1,
.game-header .kicker {
  color: #ffffff;
}

.back-link,
.icon-button,
.primary-button,
.secondary-button {
  border: 2px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  font-weight: 900;
  text-decoration: none;
  box-shadow: 3px 3px 0 var(--line);
}

.back-link {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  padding: 7px 11px;
  background: var(--mint);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.icon-button {
  width: 42px;
  height: 42px;
  cursor: pointer;
  font-size: 1.3rem;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  cursor: pointer;
  padding: 9px 14px;
}

.primary-button {
  background: var(--lemon);
}

.secondary-button {
  background: var(--sky);
}

.kicker {
  margin: 0 0 3px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.45rem, 5vw, 2.65rem);
  line-height: 1;
  letter-spacing: 0;
  word-break: keep-all;
}

.hud-grid {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 2px solid var(--line);
  background: #fffdf8;
}

.hud-grid div {
  min-width: 0;
  border: 2px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #ffffff;
}

.hud-grid span {
  display: block;
  color: #526078;
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.hud-grid strong {
  display: block;
  margin-top: 2px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: clamp(1.1rem, 4vw, 1.65rem);
  line-height: 1;
}

.canvas-wrap {
  position: relative;
  min-width: 0;
  width: min(800px, calc(100vw - 44px));
  margin: 14px auto;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #24315f;
  overflow: hidden;
}

canvas {
  width: 100%;
  height: auto;
  display: block;
  image-rendering: pixelated;
  touch-action: manipulation;
}

.result-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  padding: 24px;
  background: rgba(255, 249, 237, 0.96);
  text-align: center;
}

.result-overlay[hidden] {
  display: none;
}

.result-kicker {
  margin: 0;
  color: #526078;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-weight: 900;
  text-transform: uppercase;
}

.result-overlay h2 {
  margin: 0;
  font-size: clamp(1.6rem, 8vw, 3rem);
}

.result-overlay p {
  max-width: 430px;
  margin: 0;
  line-height: 1.7;
  overflow-wrap: anywhere;
  word-break: keep-all;
}

.game-footer {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 2px solid var(--line);
  padding: 12px 14px;
  background: #fffdf8;
}

.game-footer p {
  margin: 0;
  color: #44506a;
  line-height: 1.55;
  overflow-wrap: anywhere;
  word-break: keep-all;
}

.action-row {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.secondary-button.is-active {
  background: var(--mint);
}

@media (max-width: 680px) {
  .game-shell {
    display: block;
    width: 100vw;
    max-width: 100vw;
    padding: 10px;
    overflow: hidden;
  }

  .game-board {
    width: min(300px, calc(100vw - 20px));
    max-width: min(300px, calc(100vw - 20px));
    margin: 0;
  }

  .game-header {
    position: relative;
    grid-template-columns: minmax(0, 1fr);
    padding-right: 14px;
  }

  h1 {
    font-size: clamp(1.25rem, 6vw, 1.7rem);
    line-height: 1.08;
  }

  .icon-button {
    position: absolute;
    top: 14px;
    left: 122px;
    width: 38px;
    height: 38px;
  }

  .back-link {
    justify-self: start;
  }

  .hud-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 10px 12px;
  }

  .hud-grid div {
    padding: 7px 8px;
  }

  .hud-grid strong {
    font-size: clamp(1rem, 5vw, 1.35rem);
  }

  .canvas-wrap {
    width: calc(100% - 24px);
    max-width: calc(100% - 24px);
  }

  .game-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .action-row {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
  }

  .action-row .primary-button,
  .action-row .secondary-button {
    min-width: 0;
    padding-inline: 7px;
    font-size: 0.9rem;
    white-space: nowrap;
  }
}
