:root {
  --ink: #070b12;
  --panel: #121c2e;
  --panel-2: #1b2942;
  --yellow: #ffe14a;
  --yellow-deep: #f5b942;
  --paper: #f6f7fb;
  --red: #ff3b55;
  --green: #1ed98a;
  --line: rgba(255, 225, 74, 0.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(900px 420px at 50% -10%, rgba(255, 225, 74, 0.18), transparent 60%),
    var(--ink);
  color: var(--paper);
  font-family: Inter, "Segoe UI", "Liberation Sans", "Nimbus Sans", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

button,
canvas,
img { -webkit-user-select: none; user-select: none; }

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding:
    calc(8px + env(safe-area-inset-top))
    calc(10px + env(safe-area-inset-right))
    calc(8px + env(safe-area-inset-bottom))
    calc(10px + env(safe-area-inset-left));
}

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  overflow: hidden;
}

canvas {
  display: block;
  touch-action: none;
  background: #071018;
  max-width: 100%;
  max-height: 100%;
  border-radius: 16px;
  box-shadow:
    0 0 0 3px var(--yellow),
    0 0 0 8px rgba(255, 225, 74, 0.12),
    0 18px 40px rgba(0, 0, 0, 0.45);
}

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  pointer-events: none;
}

#overlay[hidden] { display: none; }

.card {
  pointer-events: auto;
  width: min(100%, 420px);
  max-height: 100%;
  overflow: auto;
  text-align: center;
  background: rgba(8, 14, 26, 0.9);
  border: 2px solid var(--yellow);
  border-radius: 18px;
  padding: 16px 16px 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
}

.mode-banner {
  margin: 0;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #d5dced;
}

.card h1,
.card h2 {
  margin: 0;
  color: var(--yellow);
  letter-spacing: 0;
  line-height: 1.15;
  font-size: clamp(22px, 5.4vw, 34px);
}

.card h2 { font-size: clamp(28px, 7vw, 42px); }

.sub {
  margin: 6px 0 0;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--paper);
}

.hero {
  width: 104px;
  height: auto;
  margin: 8px auto 2px;
  display: block;
  filter: drop-shadow(0 10px 0 rgba(0, 0, 0, 0.35));
}

.card ol {
  margin: 10px auto 12px;
  padding-left: 1.15em;
  text-align: left;
  max-width: 36em;
  font-size: 15px;
  line-height: 1.35;
}

.card p { margin: 6px 0; }

.keys {
  color: #c9d2e3;
  font-size: 13px;
  font-weight: 700;
}

.scoreline {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.name-label {
  display: block;
  margin: 8px 0 4px;
  font-size: 13px;
  font-weight: 800;
}

input[type="text"],
#player-name {
  width: 100%;
  min-height: 48px;
  box-sizing: border-box;
  font: inherit;
  font-weight: 800;
  text-align: center;
  color: var(--paper);
  background: #0c1422;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  touch-action: manipulation;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
}

.card-actions button { min-height: 48px; }

#board-list {
  list-style: none;
  margin: 8px 0;
  padding: 0;
  text-align: left;
}

#board-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 225, 74, 0.2);
  font-weight: 800;
  font-size: 14px;
}

#board-list li span:last-child {
  color: #d5dced;
  font-weight: 700;
  text-align: right;
}

.card, .card-actions, input, button { touch-action: manipulation; }
.card { touch-action: pan-y; }

#toast {
  position: absolute;
  top: 16%;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(6, 10, 18, 0.88);
  border: 2px solid var(--yellow);
  color: var(--yellow);
  font-weight: 800;
  letter-spacing: 0.12em;
  font-size: 14px;
  pointer-events: none;
  white-space: nowrap;
}

#toast[hidden] { display: none; }
#toast.bad { border-color: var(--red); color: #fff; }

.controls {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.dpad {
  display: grid;
  width: max-content;
  grid-template-columns: 68px 68px 68px;
  grid-template-areas:
    ". up ."
    "left down right";
  gap: 6px;
}

.dpad [data-dir="up"] { grid-area: up; }
.dpad [data-dir="down"] { grid-area: down; }
.dpad [data-dir="left"] { grid-area: left; }
.dpad [data-dir="right"] { grid-area: right; }

button {
  font: inherit;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--yellow);
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 14px;
  min-height: 60px;
  min-width: 64px;
  padding: 8px 12px;
  cursor: pointer;
  touch-action: manipulation;
}

.dpad button { font-size: 22px; padding: 0; }

button:active { transform: translateY(1px) scale(0.98); background: var(--panel-2); }
button:focus-visible { outline: 3px solid var(--paper); outline-offset: 2px; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.primary {
  background: var(--yellow);
  color: #1a1204;
  border-color: #fff4b0;
}

.keyhints {
  grid-column: 1 / -1;
  margin: 0;
  text-align: center;
  color: #9eabc2;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.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: 420px) {
  .dpad { grid-template-columns: 64px 64px 64px; gap: 6px; }
  button, .dpad button { min-height: 52px; min-width: 52px; }
  .card ol { font-size: 14.5px; }
  .hero { width: 72px; }
  .actions { flex-direction: column; align-items: stretch; }
  .actions button { min-width: 0; }
  #app { gap: 6px; }
}

@media (max-height: 700px) {
  .hero { display: none; }
  .card { padding: 10px; }
  .card ol { margin: 6px auto 8px; }
  .keyhints { display: none; }
}

@media (max-height: 640px) and (orientation: portrait) {
  .mode-banner { font-size: 11px; }
  .dpad { grid-template-columns: 56px 56px 56px; }
}

#stage, .mode-banner, .controls { min-width: 0; }

@media (orientation: landscape) and (max-height: 520px) {
  #app { flex-direction: row; align-items: stretch; position: relative; }
  .mode-banner {
    position: absolute;
    top: 4px;
    left: 8px;
    right: 230px;
    z-index: 3;
    text-align: left;
    pointer-events: none;
  }
  #stage { flex: 1; }
  .controls {
    width: min(220px, 38vw);
    grid-template-columns: 1fr;
    align-content: center;
  }
  .actions { flex-direction: column; justify-content: center; }
  .keyhints { display: none; }
  .hero { display: none; }
  .card { width: min(92%, 340px); }
  .card h1 { font-size: 18px; }
  .card ol { font-size: 12px; }
}

@media (min-width: 860px) {
  .controls {
    width: max-content;
    margin: 0 auto;
    grid-template-columns: auto auto;
  }
  .actions { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  .hero { filter: none; }
}

.ownership-notice{margin:0;text-align:center;font-size:10px;line-height:1.3;color:#ffe14a;flex-shrink:0;padding:2px 8px;}
.install-tip{margin:5px 0 0;font-size:11px;line-height:1.35;color:#c6d0e0;}
