:root {
  color-scheme: light;
  --game-aspect: 16 / 9;
  --page-bg: #f7c472;
  --frame-bg: #f5d28a;
  --ink: #2b2419;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  background:
    linear-gradient(180deg, #faad73 0%, #f6cf83 45%, #d99539 100%);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

.page {
  width: 100%;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(10px, 3vw, 40px);
}

.runner-frame {
  width: min(100%, 1120px, calc((100vh - clamp(20px, 6vw, 80px)) * 16 / 9));
  aspect-ratio: var(--game-aspect);
  background: var(--frame-bg);
  border: 1px solid rgba(70, 43, 16, 0.2);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 18px 45px rgba(81, 49, 20, 0.18);
}

.runner-game {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #f8ce82;
  touch-action: manipulation;
  user-select: none;
}

.runner-game canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.runner-age-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  min-width: 38px;
  padding: 5px 8px;
  border: 1px solid rgba(46, 32, 17, 0.24);
  border-radius: 6px;
  background: rgba(255, 238, 194, 0.42);
  color: rgba(46, 32, 17, 0.62);
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  pointer-events: none;
}

.runner-start-panel,
.runner-victory-panel {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  place-items: center;
  padding: clamp(16px, 4vw, 44px);
  background: rgba(70, 43, 16, 0.12);
  pointer-events: none;
}

.runner-start-panel.is-visible,
.runner-victory-panel.is-visible {
  display: grid;
  pointer-events: auto;
}

.runner-start-dialog,
.runner-victory-dialog {
  width: min(360px, 86%);
  padding: 18px 20px 20px;
  border: 1px solid rgba(70, 43, 16, 0.24);
  border-radius: 8px;
  background: rgba(255, 238, 194, 0.9);
  box-shadow: 0 14px 32px rgba(81, 49, 20, 0.2);
  text-align: center;
}

.runner-start-title,
.runner-victory-title {
  color: rgba(46, 32, 17, 0.9);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.runner-start-text,
.runner-victory-distance {
  margin-top: 8px;
  color: rgba(46, 32, 17, 0.72);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.runner-start-text {
  font-size: 14px;
  line-height: 1.35;
  letter-spacing: 0;
}

.runner-start-dialog button,
.runner-victory-actions {
  display: grid;
}

.runner-start-dialog button {
  width: 100%;
  margin-top: 16px;
  place-items: center;
}

.runner-victory-actions {
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.runner-start-dialog button,
.runner-victory-actions button {
  display: inline-grid;
  place-items: center;
  min-height: 38px;
  border: 1px solid rgba(70, 43, 16, 0.26);
  border-radius: 6px;
  background: rgba(255, 219, 135, 0.96);
  color: rgba(46, 32, 17, 0.86);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.05em;
  cursor: pointer;
}

.runner-start-dialog button:focus-visible,
.runner-victory-actions button:focus-visible {
  outline: 2px solid rgba(76, 43, 15, 0.62);
  outline-offset: 2px;
}

.runner-start-dialog button:hover,
.runner-victory-actions button:hover {
  background: rgba(255, 229, 160, 0.98);
}

.runner-final-panel {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  place-items: center;
  padding: clamp(16px, 4vw, 44px);
  background: rgba(70, 43, 16, 0.16);
  pointer-events: none;
}

.runner-final-panel.is-visible {
  display: grid;
  pointer-events: auto;
}

.runner-final-dialog {
  width: min(420px, 88%);
  padding: 18px 20px 20px;
  border: 1px solid rgba(70, 43, 16, 0.24);
  border-radius: 8px;
  background: rgba(255, 238, 194, 0.92);
  box-shadow: 0 14px 32px rgba(81, 49, 20, 0.2);
  text-align: center;
}

.runner-final-title {
  color: rgba(46, 32, 17, 0.9);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.runner-final-distance {
  margin-top: 10px;
  color: rgba(46, 32, 17, 0.86);
  font-size: 18px;
  font-weight: 800;
}

.runner-final-scale {
  margin-top: 8px;
  color: rgba(46, 32, 17, 0.72);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
}

.runner-final-dialog button {
  width: 100%;
  min-height: 38px;
  margin-top: 16px;
  border: 1px solid rgba(70, 43, 16, 0.26);
  border-radius: 6px;
  background: rgba(255, 219, 135, 0.96);
  color: rgba(46, 32, 17, 0.86);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.05em;
  cursor: pointer;
}

.runner-final-dialog button:focus-visible {
  outline: 2px solid rgba(76, 43, 15, 0.62);
  outline-offset: 2px;
}

.runner-final-dialog button:hover {
  background: rgba(255, 229, 160, 0.98);
}

.runner-debug-panel {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  display: grid;
  gap: 6px;
  width: 190px;
  padding: 8px 10px;
  border: 1px solid rgba(56, 39, 18, 0.22);
  border-radius: 6px;
  background: rgba(255, 236, 190, 0.82);
  color: rgba(46, 32, 17, 0.82);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  pointer-events: auto;
}

.runner-debug-state {
  letter-spacing: 0.06em;
}

.runner-debug-row {
  display: grid;
  grid-template-columns: 24px 1fr 34px;
  align-items: center;
  gap: 6px;
}

.runner-debug-row input {
  width: 100%;
  margin: 0;
}

.runner-debug-row output {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.runner-game::before {
  content: "LOADING";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(45, 33, 18, 0.58);
  font-size: clamp(12px, 2.2vw, 18px);
  font-weight: 700;
  letter-spacing: 0.08em;
  pointer-events: none;
}

.runner-game.is-ready::before {
  content: none;
}

.runner-game.has-error::before {
  content: attr(data-error);
  max-width: min(80%, 720px);
  margin: auto;
  text-align: center;
  line-height: 1.35;
}

@media (max-width: 640px) {
  .page {
    padding: 0;
    align-items: start;
    min-height: 100svh;
  }

  .runner-frame {
    width: 100%;
    aspect-ratio: var(--game-aspect);
    border-radius: 0;
    border-inline: 0;
  }
}
