:root {
  --ink: #102016;
  --paper: #f4f7f2;
  --muted: #4d6156;
  --line: rgba(16, 32, 22, 0.12);
  --field: #146c43;
  --field-deep: #0c4e30;
  --gold: #f0b429;
  --gold-deep: #a56b10;
  --neon: #c6ff3d;
  --card: #fffdf8;
  --bad: #d8453c;
  --shadow: 0 18px 50px rgba(8, 20, 12, 0.18);
  --radius: 22px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  overscroll-behavior: none;
}

body {
  color: var(--ink);
  font-family: "Trebuchet MS", "Avenir Next", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top, #e7f6ea 0, transparent 42%),
    linear-gradient(180deg, #d7ecdf 0%, #b7d7c4 100%);
}

body.night {
  color: #e7f0ea;
  background:
    radial-gradient(circle at top, #1a2740 0, transparent 46%),
    linear-gradient(180deg, #070b12 0%, #101820 100%);
}

body.is-playing {
  overflow: hidden;
  touch-action: none;
}

button, input { font: inherit; }

.app {
  width: min(760px, calc(100% - 24px));
  margin: 0 auto;
  padding: 16px 0 28px;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.kicker {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--field-deep);
}

body.night .kicker { color: var(--gold); }

h1, h2 {
  font-family: "Arial Black", "Arial Narrow", Impact, sans-serif;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  line-height: 0.95;
}

h1 { margin: 2px 0 0; font-size: 1.7rem; }
h2 { margin: 0 0 8px; font-size: clamp(2rem, 5vw, 2.8rem); }

.hud-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  justify-content: center;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.hud-stats b { color: var(--field-deep); }
body.night .hud-stats b { color: var(--neon); }

.stat {
  background: rgba(255, 255, 255, 0.55);
  border-radius: 999px;
  padding: 6px 12px;
  box-shadow: inset 0 0 0 1px var(--line);
}

body.night .stat {
  background: rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.lives { letter-spacing: 0.12em; }

.btn {
  border: 2px solid transparent;
  border-radius: 999px;
  padding: 12px 18px;
  font-weight: 800;
  cursor: pointer;
}

.btn:focus-visible,
.mode:focus-visible,
.char:focus-visible,
.pad-btn:focus-visible,
.sound-btn:focus-visible,
.check input:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.btn-gold { background: var(--gold); color: var(--ink); }
.btn-gold:hover { background: #ffc94a; }
.btn-ghost {
  background: white;
  color: var(--ink);
  border-color: rgba(16, 32, 22, 0.16);
}
body.night .btn-ghost {
  background: transparent;
  color: #e7f0ea;
  border-color: rgba(255, 255, 255, 0.2);
}

.hud-actions,
.sound-toggles {
  display: flex;
  align-items: center;
  gap: 8px;
}

.menu-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.sound-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 16px;
  border: 2px solid rgba(16, 32, 22, 0.16);
  background: white;
  color: var(--ink);
  cursor: pointer;
}

.sound-btn.labeled {
  width: auto;
  height: 52px;
  padding: 0 14px 0 10px;
  gap: 8px;
  font-weight: 800;
  border-color: var(--gold-deep);
  box-shadow: 0 0 0 3px rgba(240, 180, 41, 0.45);
}

.sound-btn svg { display: block; flex: 0 0 auto; }
.sound-btn .cross { display: none; }
.sound-btn.is-muted { color: var(--muted); background: #efe7d4; }
.sound-btn.is-muted .wave { display: none; }
.sound-btn.is-muted .cross { display: block; }

body.night .sound-btn {
  background: rgba(255, 255, 255, 0.06);
  color: #e7f0ea;
  border-color: rgba(255, 255, 255, 0.28);
}
body.night .sound-btn.is-muted { color: #8ea096; }

.play {
  display: flex;
  flex-direction: column;
}

.stage {
  position: relative;
  order: 1;
  border-radius: 28px;
  overflow: hidden;
  touch-action: none;
  box-shadow: var(--shadow), inset 0 0 0 3px rgba(255, 255, 255, 0.35);
  background: #163222;
}

#board {
  display: block;
  width: 100%;
  height: auto;
  background: #163222;
}

.banner {
  position: absolute;
  left: 50%;
  top: 42%;
  translate: -50% -50%;
  margin: 0;
  padding: 8px 18px;
  pointer-events: none;
  text-align: center;
  font-family: "Arial Black", Impact, sans-serif;
  font-size: clamp(42px, 8vw, 76px);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff8ea;
  text-shadow:
    0 3px 0 #0c4e30,
    0 0 24px rgba(240, 180, 41, 0.85);
}

.meters {
  order: 2;
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.meter {
  background: rgba(255, 255, 255, 0.72);
  border-radius: 14px;
  padding: 8px 12px 10px;
  box-shadow: inset 0 0 0 1px var(--line);
}

body.night .meter { background: rgba(255, 255, 255, 0.08); }

.meter p { margin: 0 0 6px; font-size: 0.92rem; font-weight: 800; }

.bar {
  height: 10px;
  border-radius: 999px;
  background: rgba(16, 32, 22, 0.12);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold));
}

.meter.ready .bar span { background: linear-gradient(90deg, #0c4e30, var(--neon)); }

.touch {
  order: 3;
  display: flex;
  justify-content: center;
  margin-top: 14px;
  touch-action: none;
  user-select: none;
}

.power-dock {
  order: 4;
  display: flex;
  justify-content: center;
  margin-top: 10px;
}

.pad-grid {
  display: grid;
  grid-template-columns: 72px 72px 72px;
  grid-template-areas:
    ". up ."
    "left down right";
  gap: 10px;
  justify-content: center;
}

.pad-btn {
  height: 72px;
  border-radius: 18px;
  border: 2px solid rgba(16, 32, 22, 0.12);
  background: white;
  font-size: 1.45rem;
  font-weight: 800;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.pad-btn.up { grid-area: up; }
.pad-btn.left { grid-area: left; }
.pad-btn.down { grid-area: down; }
.pad-btn.right { grid-area: right; }
.pad-btn.power {
  width: calc(72px * 3 + 10px * 2);
  height: 64px;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  background: #e7d7a4;
}
.pad-btn.power.is-ready {
  background: var(--gold);
  box-shadow: 0 0 0 3px rgba(198, 255, 61, 0.55);
}

.pad-btn:active { transform: translateY(1px) scale(0.98); }

.keys {
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
  margin: 10px 0 0;
}

body.night .keys { color: #b7c9be; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(8, 16, 12, 0.62);
  overflow: auto;
}

.overlay[hidden] { display: none !important; }
#banner[hidden] { display: none !important; }

.card {
  width: min(640px, 100%);
  background: var(--card);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 22px 22px 18px;
  box-shadow: var(--shadow);
}

.card .kicker { color: var(--field); }

.lede { margin: 0 0 14px; color: var(--muted); line-height: 1.45; }

.howto-list { margin: 0 0 14px; padding-left: 18px; }
.howto-list li { margin: 0 0 8px; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-weight: 700;
}

.modes { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }

.mode {
  border-radius: 999px;
  border: 2px solid rgba(16, 32, 22, 0.14);
  background: white;
  padding: 8px 14px;
  font-weight: 800;
  cursor: pointer;
}

.mode.is-selected {
  background: var(--field);
  color: white;
  border-color: var(--field);
}

.bests { margin: 0 0 12px; font-weight: 800; color: var(--field-deep); }

.pick-label {
  margin: 8px 0;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

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

.char {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border-radius: 16px;
  border: 2px solid rgba(16, 32, 22, 0.12);
  background: #f7fbf7;
  padding: 6px 4px 8px;
  cursor: pointer;
  text-align: center;
}

.char canvas { width: 72px; height: 72px; }

.char b { font-size: 0.78rem; line-height: 1.15; }
.char small { color: var(--muted); font-size: 0.68rem; line-height: 1.2; }

.char.is-selected {
  border-color: var(--gold-deep);
  box-shadow: inset 0 0 0 2px var(--gold);
  background: #fff8e4;
}

.menu-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

@media (max-width: 720px) {
  .picker { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .hud { align-items: flex-start; flex-wrap: wrap; }
  h1 { font-size: 1.35rem; }
  .char canvas { width: 64px; height: 64px; }
}

body.is-landscape {
  overflow: hidden;
}

body.is-landscape .app {
  width: 100%;
  height: 100dvh;
  max-width: none;
  margin: 0;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

body.is-landscape .play {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    "pad stage power"
    ". meters .";
  align-items: stretch;
  gap: 8px 12px;
}

body.is-landscape .touch {
  grid-area: pad;
  order: 0;
  margin: 0;
  align-self: stretch;
  align-items: center;
}

body.is-landscape .stage {
  grid-area: stage;
  order: 0;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  place-items: center;
  border-radius: 18px;
}

body.is-landscape .meters {
  grid-area: meters;
  order: 0;
  margin-top: 0;
}

body.is-landscape .power-dock {
  grid-area: power;
  order: 0;
  margin: 0;
  align-self: stretch;
  align-items: center;
}

body.is-landscape .pad-btn.power {
  width: 84px;
  height: 148px;
}

@media (max-width: 520px) {
  body:not(.is-landscape) { overflow: hidden; }
  body:not(.is-landscape) .app {
    width: 100%;
    height: 100dvh;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
  }
  body:not(.is-landscape) .play {
    flex: 1 1 auto;
    min-height: 0;
  }
  body:not(.is-landscape) .hud { margin-bottom: 6px; gap: 8px; }
  body:not(.is-landscape) .brand { flex: 1; min-width: 0; }
  body:not(.is-landscape) h1 { font-size: 1.2rem; }
  body:not(.is-landscape) .hud-stats { width: 100%; justify-content: flex-start; gap: 6px; }
  body:not(.is-landscape) .stat { padding: 4px 8px; font-size: 0.82rem; }
  body:not(.is-landscape) #pause-btn { padding: 8px 14px; }
  body:not(.is-landscape) .sound-btn { width: 44px; height: 44px; }
  body:not(.is-landscape) .sound-btn.labeled { width: auto; height: 44px; padding: 0 10px 0 8px; }
  body:not(.is-landscape) .stage {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    place-items: center;
    border-radius: 18px;
  }
  body:not(.is-landscape) .meters { margin-top: 8px; }
  body:not(.is-landscape) .meter { padding: 6px 10px 8px; }
  body:not(.is-landscape) .meter p { font-size: 0.84rem; }
  body:not(.is-landscape) .touch { margin-top: 8px; }
  body:not(.is-landscape) .power-dock { margin-top: 10px; padding-bottom: 12px; }
  body:not(.is-landscape) .pad-grid {
    grid-template-columns: 76px 76px 76px;
    gap: 10px;
  }
  body:not(.is-landscape) .pad-btn { height: 68px; }
  body:not(.is-landscape) .pad-btn.power {
    width: calc(76px * 3 + 10px * 2);
    height: 60px;
  }
  body:not(.is-landscape) .keys { display: none; }
  .card { padding: 16px 14px 14px; }
  .overlay { padding: 10px; }
}

@media (max-height: 520px) {
  body.is-landscape .hud { margin-bottom: 4px; gap: 8px; }
  body.is-landscape h1 { font-size: 1.05rem; }
  body.is-landscape .kicker { font-size: 0.64rem; }
  body.is-landscape .stat { padding: 3px 8px; font-size: 0.78rem; }
  body.is-landscape #pause-btn { padding: 6px 12px; }
  body.is-landscape .sound-btn { width: 40px; height: 40px; border-radius: 12px; }
  body.is-landscape .meters { gap: 4px; }
  body.is-landscape .meter { padding: 4px 8px 5px; }
  body.is-landscape .meter p { margin-bottom: 3px; font-size: 0.75rem; }
  body.is-landscape .pad-grid {
    grid-template-columns: 64px 64px 64px;
    gap: 8px;
  }
  body.is-landscape .pad-btn { height: 64px; border-radius: 16px; }
  body.is-landscape .pad-btn.power { width: 76px; height: 128px; }
  body.is-landscape .keys { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
