* {
  box-sizing: border-box;
}

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

body {
  display: grid;
  place-items: center;
  color: var(--game-text);
  background: var(--game-surface);
  font-family: var(--game-font);
}

button,
output {
  color: inherit;
  font: inherit;
}

button {
  touch-action: manipulation;
}

button:focus-visible {
  outline: 3px solid var(--game-accent);
  outline-offset: 2px;
}

.game {
  width: min(100%, 420px);
  min-height: 100svh;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 12px;
  overflow: hidden;
  background: var(--game-bg);
}

html:not([data-embed='true']) .game {
  box-shadow: var(--game-shadow);
}

.game-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 10px;
}

.eyebrow,
h1,
.training-spec,
.status,
.decision-panel p {
  margin: 0;
}

.eyebrow {
  color: var(--game-accent);
  font-family: var(--game-mono);
  font-size: 0.62rem;
  font-weight: 750;
  letter-spacing: 0.08em;
}

h1 {
  margin-top: 2px;
  font-size: clamp(1.35rem, 6vw, 1.75rem);
  line-height: 1.05;
  letter-spacing: -0.035em;
}

.training-spec {
  flex: 0 0 auto;
  color: var(--game-muted);
  font-family: var(--game-mono);
  font-size: 0.58rem;
  line-height: 1.45;
  text-align: right;
}

.training-spec span {
  display: block;
}

.board-section {
  display: grid;
  place-items: center;
}

.board {
  width: min(100%, 240px);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--game-divider);
  border-radius: var(--game-radius);
  background: var(--game-surface-strong);
}

.cell {
  position: relative;
  min-width: 0;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 0;
  border: 1px solid var(--game-divider);
  border-radius: 3px;
  background: var(--game-bg);
}

button.cell {
  cursor: pointer;
}

.cell.wall {
  border-color: transparent;
  background:
    repeating-linear-gradient(
      135deg,
      transparent 0 5px,
      color-mix(in srgb, var(--game-muted) 30%, transparent) 5px 8px
    ),
    var(--game-surface-strong);
}

.cell.risk::before {
  position: absolute;
  bottom: 4px;
  left: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--game-warning);
  content: '';
  opacity: 0.65;
}

.cell.target {
  min-width: 44px;
  min-height: 44px;
  border-color: var(--game-accent);
  color: var(--game-accent-strong);
  font-family: var(--game-mono);
  font-weight: 800;
}

.cell.target[aria-pressed='true'] {
  color: var(--game-on-accent);
  background: var(--game-accent);
}

.cell.target > span:first-child {
  position: absolute;
  top: 2px;
  left: 4px;
  z-index: 1;
  font-size: 0.65rem;
}

.cell.is-path {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--game-accent) 38%, transparent);
}

.cell.is-crash {
  border-color: var(--game-danger);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--game-danger) 54%, transparent);
}

.cell.is-crash::after {
  position: absolute;
  z-index: 3;
  color: var(--game-danger);
  content: '×';
  font-family: var(--game-mono);
  font-size: 1.35rem;
  font-weight: 900;
  line-height: 1;
}

.policy {
  position: absolute;
  right: 3px;
  bottom: 1px;
  color: var(--game-accent);
  font-family: var(--game-mono);
  font-size: 0.65rem;
  font-weight: 800;
  opacity: 0.8;
}

.start-marker {
  position: absolute;
  top: 2px;
  left: 3px;
  color: var(--game-muted);
  font-family: var(--game-mono);
  font-size: 0.5rem;
  font-weight: 800;
}

.agent {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  width: 19px;
  height: 19px;
  border: 3px solid var(--game-bg);
  border-radius: 50%;
  background: var(--game-accent);
  box-shadow: 0 0 0 2px var(--game-accent);
  transform: translate(-50%, -50%);
}

.agent[data-controller='agent'] {
  border-radius: 4px;
  background: var(--game-warning);
  box-shadow: 0 0 0 2px var(--game-warning);
}

.agent.is-crashed {
  background: var(--game-danger);
  box-shadow: 0 0 0 2px var(--game-danger);
  opacity: 0.72;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--game-divider);
  border-radius: var(--game-radius);
}

.metrics div {
  min-width: 0;
  padding: 6px 3px;
  text-align: center;
}

.metrics div + div {
  border-left: 1px solid var(--game-divider);
}

.metrics dt {
  overflow: hidden;
  color: var(--game-muted);
  font-size: 0.55rem;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metrics dd {
  margin: 2px 0 0;
  font-family: var(--game-mono);
  font-size: 0.78rem;
  font-weight: 800;
}

.move-pad {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 5px;
}

.move-pad button,
.move-pad span {
  min-height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--game-divider);
  border-radius: var(--game-radius);
  background: var(--game-surface);
  font-family: var(--game-mono);
  font-weight: 800;
}

.move-pad button {
  cursor: pointer;
}

.move-pad button:disabled {
  cursor: default;
  opacity: 0.42;
}

.move-pad span {
  color: var(--game-muted);
  font-size: 0.72rem;
}

.decision-panel {
  padding: 8px;
  border: 1px solid var(--game-divider);
  border-left: 4px solid var(--game-accent);
  border-radius: var(--game-radius);
  background: var(--game-surface);
}

.decision-panel[hidden] {
  display: none;
}

.decision-panel p {
  min-height: 1.25em;
  color: var(--game-muted);
  font-size: 0.66rem;
  line-height: 1.25;
}

.decision-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
  margin-top: 6px;
}

.decision-actions button {
  min-height: 44px;
  padding: 5px 7px;
  border: 1px solid var(--game-divider);
  border-radius: var(--game-radius);
  background: var(--game-bg);
  cursor: pointer;
  font-size: 0.68rem;
  font-weight: 750;
}

.decision-actions .primary {
  border-color: var(--game-accent);
  color: var(--game-on-accent);
  background: var(--game-accent);
}

.decision-actions .quiet {
  min-height: 44px;
  color: var(--game-muted);
}

.decision-actions button:disabled {
  cursor: default;
  opacity: 0.5;
}

.status {
  min-height: 2.6em;
  color: var(--game-muted);
  font-size: 0.7rem;
  line-height: 1.3;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 320px), (max-height: 580px) {
  .game {
    gap: 6px;
    padding: 9px;
  }

  .decision-panel {
    padding: 6px;
  }

  .decision-actions {
    margin-top: 4px;
  }

  .status {
    font-size: 0.65rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
