:root {
  --bg: #0c0e12;
  --panel: #161920;
  --ink: #f4f1ea;
  --muted: #9aa3b2;
  --accent: #ff4d18;
  --accent-2: #ffd0b8;
  --good: #3dd68c;
  --line: #2a303c;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #07080a;
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Hiragino Maru Gothic ProN", "Nunito", system-ui, sans-serif;
  user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
  overflow: hidden;
}

body {
  min-height: 100dvh;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
}

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  background: var(--bg);
  overflow: hidden;
}

@media (min-width: 540px) {
  body {
    display: grid;
    place-items: center;
  }
  #app {
    width: min(420px, 100vw);
    height: min(860px, 100dvh);
    border-radius: 24px;
    box-shadow: 0 0 0 1px #22262e, var(--shadow);
  }
}

#hud {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + var(--safe-t)) 12px 8px;
  background: linear-gradient(#161920, #12141a);
  border-bottom: 1px solid #22262e;
  z-index: 2;
  touch-action: manipulation;
}

#hud[hidden] {
  display: none;
}

.hud-mid {
  flex: 1;
  min-width: 0;
  line-height: 1.15;
}

#hud-level {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-2);
}

#hud-name {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#hud-moves {
  min-width: 2.4em;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 18px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: #1d212b;
  color: var(--ink);
  flex: 0 0 auto;
}

.icon-btn:active {
  transform: scale(0.96);
  background: #262b38;
}

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #12151c;
  touch-action: none;
}

#board {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#coach {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(14px + var(--safe-b));
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(12, 14, 18, 0.82);
  border: 1px solid #2a303c;
  color: #e8e4dc;
  font-size: 14px;
  font-weight: 650;
  text-align: center;
  pointer-events: none;
}

#coach[hidden] {
  display: none;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(22px + var(--safe-t)) 22px calc(22px + var(--safe-b));
  background: linear-gradient(
    180deg,
    rgba(8, 10, 14, 0.9) 0%,
    rgba(8, 10, 14, 0.08) 36%,
    rgba(8, 10, 14, 0.08) 60%,
    rgba(8, 10, 14, 0.92) 100%
  );
  touch-action: auto;
}

.overlay.hidden {
  display: none;
}

.title-top h1 {
  margin: 6px 0 8px;
  font-size: clamp(34px, 9vw, 44px);
  line-height: 0.95;
  letter-spacing: -0.04em;
}

.kicker,
.fine,
.sheet-sub,
.win-kicker,
.win-stats,
.tag {
  margin: 0;
  color: var(--muted);
}

.kicker {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-2);
}

.tag {
  font-size: 16px;
  font-weight: 650;
  color: #d9d3c8;
}

.title-bottom {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.btn-play,
.btn-ghost,
.btn-mute {
  min-height: 52px;
  border-radius: 16px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.btn-play {
  background: var(--accent);
  color: #fff7f2;
  font-size: 18px;
  box-shadow: 0 8px 0 #b83310;
  animation: pulse-play 1.8s ease-in-out infinite;
}

@keyframes pulse-play {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.08); }
}

.btn-play:active {
  transform: translateY(2px);
  box-shadow: 0 6px 0 #b83310;
}

.btn-ghost {
  background: #1d212b;
  border: 1px solid #323846;
  color: var(--ink);
  font-size: 15px;
}

.btn-ghost:active,
.btn-mute:active {
  transform: scale(0.98);
}

.btn-mute {
  min-height: 40px;
  font-size: 13px;
  color: var(--muted);
}

.fine {
  text-align: center;
  font-size: 12px;
}

#select {
  background: rgba(8, 10, 14, 0.72);
  justify-content: flex-end;
  padding: 0;
}

.sheet {
  background: #14171e;
  border-radius: 22px 22px 0 0;
  padding: 16px 16px calc(18px + var(--safe-b));
  border-top: 1px solid #2a303c;
  max-height: 86%;
  overflow: auto;
  touch-action: pan-y;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet-head h2 {
  margin: 0;
  font-size: 22px;
}

.sheet-sub {
  margin: 4px 0 14px;
  font-size: 13px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.lvl {
  min-height: 76px;
  border-radius: 14px;
  background: #1d212b;
  border: 1px solid #2c3340;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-weight: 800;
}

.lvl .n {
  font-size: 20px;
}

.lvl .s {
  font-size: 12px;
  color: #ffb020;
  letter-spacing: 0.08em;
}

.lvl.locked {
  opacity: 0.4;
  color: var(--muted);
}

.lvl.current {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.lvl:active:not(.locked) {
  transform: scale(0.97);
}

#win {
  justify-content: center;
  align-items: center;
  background: rgba(8, 10, 14, 0.62);
}

.win-card {
  width: min(340px, 100%);
  background: #161920;
  border: 1px solid #2a303c;
  border-radius: 22px;
  padding: 22px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: center;
  box-shadow: var(--shadow);
}

.win-card h2 {
  margin: 0;
  font-size: 30px;
  letter-spacing: -0.03em;
}

.stars {
  font-size: 22px;
  color: #ffb020;
  letter-spacing: 0.2em;
}

.win-kicker {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--good);
}
