:root {
  color-scheme: dark;
  --bg: #101613;
  --panel: #18211d;
  --panel-2: #263229;
  --ink: #f5f1e8;
  --muted: #bac4bd;
  --mint: #8ee6a3;
  --teal: #45c7b0;
  --coral: #ff6b6b;
  --amber: #ffd166;
  --line: rgba(255, 255, 255, 0.16);
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body {
  min-height: 100svh;
  background:
    linear-gradient(180deg, #101613 0%, #111a17 42%, #0d1210 100%),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.04) 0 1px, transparent 1px 72px);
}

button,
a {
  font: inherit;
}

.pr-bar {
  padding: 7px 12px;
  background: #09100d;
  color: #ded7ca;
  font-size: 12px;
  text-align: center;
  border-bottom: 1px solid var(--line);
}

.app {
  width: min(100%, 940px);
  min-height: calc(100svh - 31px);
  margin: 0 auto;
  padding: 18px 16px 22px;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  gap: 14px;
}

.topline,
.scoreboard,
.playfield,
.controls,
.support-strip,
.result {
  border: 1px solid var(--line);
  background: rgba(16, 22, 19, 0.9);
  box-shadow: var(--shadow);
}

.topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-radius: 8px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--amber);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 2.15rem;
  line-height: 1.05;
}

.hub-link,
.support-strip a {
  color: var(--ink);
  text-decoration: none;
}

.hub-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  font-weight: 800;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border-radius: 8px;
}

.scoreboard div {
  min-width: 0;
  padding: 10px;
  background: var(--panel);
}

.scoreboard span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.scoreboard strong {
  display: block;
  margin-top: 3px;
  font-size: 1.4rem;
  line-height: 1;
}

.playfield {
  min-height: 0;
  border-radius: 8px;
  padding: 18px;
  display: grid;
  grid-template-columns: minmax(190px, 0.72fr) minmax(280px, 1.28fr);
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 16px;
  align-items: stretch;
}

.brief,
.board-wrap {
  min-width: 0;
}

.brief {
  display: grid;
  align-content: center;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel-label {
  color: var(--amber);
  font-size: 12px;
  font-weight: 900;
}

.brief strong {
  min-height: 34px;
  font-size: 1.65rem;
  line-height: 1;
}

.brief p {
  min-height: 44px;
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.health {
  color: var(--coral);
  font-size: 1.3rem;
  word-spacing: 7px;
}

.board-wrap {
  display: grid;
  align-items: center;
}

.grid {
  width: min(100%, 480px);
  aspect-ratio: 1;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
}

.cell {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #15211b;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}

.cell::after {
  content: "";
  width: 42%;
  aspect-ratio: 1;
  border-radius: 8px;
  border: 2px solid rgba(245, 241, 232, 0.22);
}

.cell.block {
  background: #2a1719;
}

.cell.block::after {
  border-color: var(--coral);
  background: rgba(255, 107, 107, 0.28);
}

.cell.goal {
  background: #2b2612;
}

.cell.goal::after {
  border-color: var(--amber);
  background: rgba(255, 209, 102, 0.34);
}

.cell.path {
  background: #17302b;
}

.cell.player {
  background: var(--teal);
  box-shadow: 0 0 0 3px rgba(69, 199, 176, 0.22) inset;
}

.cell.player::after {
  border-color: #0c1815;
  background: var(--ink);
  border-radius: 999px;
}

.feedback,
.viewport-state {
  grid-column: 1 / -1;
  margin: 0;
  min-height: 24px;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.viewport-state {
  min-height: 18px;
  color: #8fa39a;
  font-size: 12px;
}

.controls {
  min-height: 74px;
  border-radius: 8px;
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(92px, auto) minmax(176px, 1fr) minmax(92px, auto);
  gap: 12px;
  align-items: center;
}

.controls button,
.result button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
}

.controls button:enabled:hover,
.controls button:enabled:focus-visible,
.result button:enabled:hover,
.result button:enabled:focus-visible,
.hub-link:focus-visible,
.support-strip a:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.controls button:disabled {
  color: #7b867f;
  cursor: default;
  opacity: 0.72;
}

.primary {
  background: var(--mint) !important;
  color: #101613 !important;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(2, 44px);
  gap: 8px;
  justify-content: center;
}

.dpad button {
  padding: 0;
  font-size: 1.35rem;
}

#moveUp {
  grid-column: 2;
}

#moveLeft {
  grid-column: 1;
  grid-row: 2;
}

#moveRight {
  grid-column: 3;
  grid-row: 2;
}

#moveDown {
  grid-column: 2;
  grid-row: 2;
}

.support-strip {
  border-radius: 8px;
  padding: 12px;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.support-strip a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font-weight: 800;
}

.result {
  position: fixed;
  inset: auto 16px 18px;
  max-width: 520px;
  margin: 0 auto;
  border-radius: 8px;
  padding: 18px;
  text-align: center;
}

.result[hidden] {
  display: none;
}

.result-label {
  margin: 0 0 4px;
  color: var(--amber);
  font-size: 12px;
  font-weight: 900;
}

.result strong {
  display: block;
  font-size: 2.6rem;
  line-height: 1;
}

.result p {
  margin: 9px 0;
}

.result button {
  margin: 4px;
  min-width: 128px;
}

@media (max-width: 720px) {
  .app {
    padding: 12px;
    gap: 10px;
  }

  .topline {
    align-items: flex-start;
  }

  h1 {
    font-size: 1.75rem;
  }

  .playfield {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .brief {
    align-content: start;
  }

  .controls {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .scoreboard strong {
    font-size: 1.1rem;
  }

  .scoreboard div {
    padding: 9px 7px;
  }

  .grid {
    gap: 5px;
  }

  .dpad {
    grid-template-columns: repeat(3, 52px);
  }
}
