:root {
  color-scheme: dark;
  --bg: #0d1215;
  --surface: #151b1f;
  --surface-strong: #1b2329;
  --surface-raised: #232d34;
  --board: #11191d;
  --grid: #26343d;
  --border: #33434d;
  --text: #f4f7f8;
  --muted: #9caab3;
  --green: #69e548;
  --green-dark: #2e9f2b;
  --coral: #ff5f61;
  --amber: #ffc349;
  --cyan: #35d8ff;
  --danger: #ff7a72;
  --radius: 8px;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.28);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background: var(--bg);
}

button {
  font: inherit;
}

.app-shell {
  width: min(1240px, calc(100% - 40px));
  margin: 20px auto;
}

.status-strip {
  min-height: 72px;
  display: grid;
  grid-template-columns: minmax(190px, 0.75fr) minmax(420px, 1.5fr) auto;
  align-items: center;
  gap: 24px;
  padding: 12px 16px 12px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 12px;
  height: 32px;
  flex: 0 0 auto;
  border-radius: 3px;
  background: var(--green);
  box-shadow: inset 0 -8px 0 var(--green-dark);
}

.brand-block h1 {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(100px, 1fr));
  margin: 0;
}

.metric {
  min-height: 44px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
  border-left: 1px solid var(--border);
}

.metric dt {
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0;
}

.metric dd {
  min-width: 54px;
  margin: 0;
  color: var(--cyan);
  font-size: 25px;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
  line-height: 1;
  letter-spacing: 0;
}

.toolbar {
  display: flex;
  gap: 10px;
}

.icon-button {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  background: var(--surface-strong);
  cursor: pointer;
  touch-action: manipulation;
  transition:
    border-color 140ms ease,
    background-color 140ms ease,
    color 140ms ease,
    transform 140ms ease;
}

.icon-button svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button:hover {
  border-color: var(--cyan);
  color: var(--cyan);
  background: #1a2930;
}

.icon-button:active {
  transform: translateY(1px);
}

.icon-button:focus-visible,
.direction-button:focus-visible {
  outline: 3px solid rgba(53, 216, 255, 0.32);
  outline-offset: 3px;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 356px;
  align-items: stretch;
  gap: 20px;
  margin-top: 20px;
}

.board-shell {
  position: relative;
  width: min(100%, calc(100svh - 132px));
  max-width: 780px;
  aspect-ratio: 1;
  justify-self: center;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--board);
  box-shadow: var(--shadow);
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.status-overlay {
  position: absolute;
  left: 50%;
  bottom: 4.5%;
  width: min(360px, calc(100% - 32px));
  min-height: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 24px;
  border: 1px solid rgba(95, 119, 132, 0.55);
  border-radius: 7px;
  color: var(--text);
  background: rgba(12, 18, 21, 0.9);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  transform: translateX(-50%);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.status-overlay.is-hidden {
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 8px);
}

.status-overlay strong {
  font-size: 20px;
  line-height: 1.25;
  letter-spacing: 0;
}

.status-overlay span {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0;
}

.mapping-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.mapping-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.section-label {
  margin: 0;
  font-size: 20px;
  font-weight: 750;
  line-height: 1.25;
  letter-spacing: 0;
}

.mapping-note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  letter-spacing: 0;
}

.phase-readout {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--amber);
  white-space: nowrap;
}

.phase-readout strong {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.rotation-icon {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mapping-panel.is-rotating .rotation-icon {
  animation: rotate-quarter 220ms ease-out;
}

@keyframes rotate-quarter {
  from {
    transform: rotate(-90deg);
  }
  to {
    transform: rotate(0);
  }
}

.dpad {
  width: 268px;
  height: 268px;
  display: grid;
  grid-template-columns: repeat(3, 82px);
  grid-template-rows: repeat(3, 82px);
  gap: 11px;
  align-self: center;
  margin: 26px auto 22px;
}

.direction-button {
  position: relative;
  width: 82px;
  height: 82px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 7px;
  border: 1px solid #455864;
  border-radius: 7px;
  color: var(--text);
  background: var(--surface-raised);
  box-shadow:
    inset 0 0 0 3px #182026,
    0 4px 0 #0a0e10;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  transition:
    border-color 120ms ease,
    background-color 120ms ease,
    transform 100ms ease,
    box-shadow 100ms ease;
}

.direction-button:hover {
  border-color: var(--cyan);
  background: #29363e;
}

.direction-button:active,
.direction-button.is-pressed {
  transform: translateY(3px);
  box-shadow:
    inset 0 0 0 3px #182026,
    0 1px 0 #0a0e10;
}

.direction-up {
  grid-column: 2;
  grid-row: 1;
}

.direction-left {
  grid-column: 1;
  grid-row: 2;
}

.direction-right {
  grid-column: 3;
  grid-row: 2;
}

.direction-down {
  grid-column: 2;
  grid-row: 3;
}

.direction-icon {
  --direction-turn: 0deg;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform: rotate(var(--direction-turn));
  transition: transform 180ms ease;
}

.direction-icon[data-direction="up"] {
  --direction-turn: -90deg;
}

.direction-icon[data-direction="right"] {
  --direction-turn: 0deg;
}

.direction-icon[data-direction="down"] {
  --direction-turn: 90deg;
}

.direction-icon[data-direction="left"] {
  --direction-turn: 180deg;
}

.physical-arrow {
  width: 31px;
  height: 31px;
  stroke-width: 2.5;
}

.actual-direction {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--amber);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
}

.mapped-arrow {
  width: 18px;
  height: 18px;
}

.mapping-table {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.mapping-table-title {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.mapping-row {
  min-height: 28px;
  display: grid;
  grid-template-columns: 56px 1fr minmax(82px, auto);
  align-items: center;
  gap: 8px;
  font-size: 13px;
  letter-spacing: 0;
}

.physical-key {
  color: var(--text);
  font-weight: 700;
}

.mapping-separator {
  color: #71818a;
}

.mapped-value {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  color: var(--amber);
  font-weight: 700;
}

.mapped-value .direction-icon {
  width: 16px;
  height: 16px;
}

.keyboard-hint {
  margin: 16px 0 0;
  color: #7f8d95;
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
  letter-spacing: 0;
}

.keyboard-hint span {
  margin: 0 4px;
  color: #52616a;
}

@media (max-width: 980px) {
  .status-strip {
    grid-template-columns: auto 1fr auto;
    gap: 14px;
  }

  .brand-block h1 {
    max-width: 120px;
  }

  .metric {
    gap: 7px;
  }

  .play-layout {
    grid-template-columns: minmax(0, 1fr) 314px;
  }

  .mapping-panel {
    padding: 20px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 24px, 620px);
    margin: 12px auto 24px;
  }

  .status-strip {
    grid-template-columns: 1fr auto;
    gap: 12px;
    padding: 12px;
  }

  .brand-block {
    grid-column: 1;
  }

  .brand-block h1 {
    max-width: none;
    font-size: 16px;
  }

  .brand-mark {
    width: 9px;
    height: 26px;
  }

  .toolbar {
    grid-column: 2;
    grid-row: 1;
  }

  .icon-button {
    width: 40px;
    height: 40px;
  }

  .scoreboard {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .metric {
    min-height: 34px;
  }

  .metric:first-child {
    border-left: 0;
  }

  .metric dt {
    font-size: 12px;
  }

  .metric dd {
    min-width: 42px;
    font-size: 20px;
  }

  .play-layout {
    grid-template-columns: 1fr;
    gap: 14px;
    margin-top: 14px;
  }

  .board-shell {
    width: 100%;
    max-width: none;
  }

  .mapping-panel {
    padding: 18px 16px;
  }

  .dpad {
    margin-top: 20px;
    margin-bottom: 18px;
  }

  .mapping-table {
    margin-top: 0;
  }
}

@media (max-width: 380px) {
  .app-shell {
    width: calc(100% - 16px);
    margin-top: 8px;
  }

  .status-strip {
    padding: 10px;
  }

  .brand-block h1 {
    font-size: 15px;
  }

  .toolbar {
    gap: 7px;
  }

  .dpad {
    width: 238px;
    height: 238px;
    grid-template-columns: repeat(3, 74px);
    grid-template-rows: repeat(3, 74px);
    gap: 8px;
  }

  .direction-button {
    width: 74px;
    height: 74px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
