:root {
  color-scheme: dark;
  --bg: #111315;
  --panel: #191c1f;
  --panel-soft: #202428;
  --tile: #292e32;
  --tile-edge: #171a1c;
  --ink: #f4f1e8;
  --muted: #878d91;
  --green: #5ddc9d;
  --rows: 3;
}

* { box-sizing: border-box; }

html,
body { width: 100%; min-height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 30%, #24282b 0, #15181a 34%, #0e1011 75%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button,
a { font: inherit; }

button { color: inherit; }

.app {
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  grid-template-rows: 54px minmax(0, 1fr);
}

.topbar {
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 clamp(10px, 3vw, 28px);
  border-bottom: 1px solid rgb(255 255 255 / 7%);
  background: rgb(12 14 15 / 76%);
  backdrop-filter: blur(14px);
}

.back-link,
.brand {
  color: var(--muted);
  text-decoration: none;
  font-size: .7rem;
  font-weight: 850;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.back-link:hover,
.back-link:focus-visible { color: var(--ink); }

.brand {
  color: var(--ink);
  font-size: .84rem;
  letter-spacing: .25em;
}

.brand span { color: var(--green); }

.header-actions {
  justify-self: end;
  display: flex;
  gap: 7px;
}

.icon-button,
.close-button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgb(255 255 255 / 12%);
  border-radius: 50%;
  background: rgb(255 255 255 / 4%);
  cursor: pointer;
}

.icon-button:hover,
.icon-button:focus-visible { background: rgb(255 255 255 / 10%); }

.icon-button svg { width: 17px; }
.speaker { fill: var(--ink); }
.waves,
.slash { fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; }
.slash { display: none; }
.icon-button[aria-pressed="true"] .waves { display: none; }
.icon-button[aria-pressed="true"] .slash { display: block; }

.help-button { font-size: .85rem; font-weight: 900; }

.game-shell {
  width: min(100%, 760px);
  min-height: 0;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) 3px;
  gap: clamp(10px, 2vh, 18px);
  padding: clamp(12px, 2.5vh, 24px) clamp(9px, 2.4vw, 20px) clamp(12px, 2.5vh, 24px);
}

.scorebar {
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  align-items: center;
  gap: 10px;
}

.score-block { display: grid; gap: 0; }
.score-best { text-align: right; }

.score-block span {
  color: var(--muted);
  font-size: .55rem;
  font-weight: 900;
  letter-spacing: .17em;
}

.score-block strong {
  font-size: clamp(1.6rem, 5vw, 2.25rem);
  line-height: 1;
  letter-spacing: -.07em;
  font-variant-numeric: tabular-nums;
}

.status {
  min-width: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  color: #aeb3b5;
  font-size: clamp(.65rem, 2vw, .75rem);
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.status-mark {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #6a7074;
  transition: background 180ms ease, box-shadow 180ms ease;
}

.status.watching .status-mark {
  background: #ffd567;
  box-shadow: 0 0 12px #ffd567;
  animation: status-pulse 800ms ease-in-out infinite alternate;
}

.status.playing .status-mark,
.status.success .status-mark {
  background: var(--green);
  box-shadow: 0 0 12px var(--green);
}

.status.failed .status-mark { background: #ff5f6d; box-shadow: 0 0 12px #ff5f6d; }

.board-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgb(255 255 255 / 8%);
  border-radius: 20px;
  background:
    linear-gradient(90deg, transparent 49.8%, rgb(255 255 255 / 2%) 50%, transparent 50.2%),
    linear-gradient(180deg, #171a1c, #111315);
  box-shadow: 0 28px 70px rgb(0 0 0 / 32%), inset 0 1px rgb(255 255 255 / 4%);
  perspective: 900px;
}

.board-scroller {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(10px, 2vw, 18px);
  scrollbar-color: #4b5155 transparent;
  scrollbar-width: thin;
}

.board-scroller::-webkit-scrollbar { width: 5px; }
.board-scroller::-webkit-scrollbar-track { background: transparent; }
.board-scroller::-webkit-scrollbar-thumb { border-radius: 99px; background: #4b5155; }

.game-board {
  --row-gap: clamp(5px, 1vh, 9px);
  width: 100%;
  height: 100%;
  min-height: 100%;
  display: grid;
  grid-template-rows: none;
  grid-auto-rows: calc((100% - var(--row-gap) - var(--row-gap)) / 3);
  align-content: start;
  gap: var(--row-gap);
  transform: rotateX(2deg);
  transform-origin: center bottom;
}

.tile-row {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(5px, 1.1vw, 9px);
  transition: opacity 220ms ease, transform 220ms ease;
}

.tile {
  --note-color: #fff;
  position: relative;
  min-width: 0;
  min-height: 25px;
  overflow: hidden;
  padding: 0;
  border: 1px solid rgb(255 255 255 / 7%);
  border-bottom-color: var(--tile-edge);
  border-radius: clamp(6px, 1.4vw, 11px);
  background:
    linear-gradient(145deg, rgb(255 255 255 / 4%), transparent 45%),
    var(--tile);
  box-shadow: 0 4px 0 var(--tile-edge), 0 7px 14px rgb(0 0 0 / 18%);
  cursor: default;
  touch-action: manipulation;
  transition: transform 95ms ease, background 140ms ease, box-shadow 140ms ease, border-color 140ms ease, filter 140ms ease;
}

.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--note-color) 85%, white), var(--note-color) 58%, color-mix(in srgb, var(--note-color) 70%, black));
  opacity: 0;
  transition: opacity 130ms ease;
}

.tile-note {
  position: relative;
  z-index: 1;
  color: rgb(255 255 255 / 46%);
  font-size: clamp(.7rem, 2.5vh, 1.2rem);
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
  opacity: 1;
  transition: opacity 120ms ease, color 120ms ease, transform 120ms ease;
}

.tile-note b { color: rgb(255 255 255 / 27%); font-weight: inherit; }

.game-board.input-ready .tile { cursor: pointer; }
.game-board.input-ready .tile:hover { border-color: rgb(255 255 255 / 18%); filter: brightness(1.08); }

.tile.lit {
  transform: translateY(3px) scale(.985);
  border-color: color-mix(in srgb, var(--note-color) 75%, white);
  box-shadow: 0 1px 0 color-mix(in srgb, var(--note-color) 54%, black), 0 0 28px color-mix(in srgb, var(--note-color) 38%, transparent);
}

.tile.lit::after { opacity: 1; }
.tile.lit .tile-note,
.tile.lit .tile-note b { color: rgb(15 18 20 / 64%); opacity: 1; transform: scale(1.08); }

.tile.wrong {
  z-index: 2;
  background: #8d2631;
  border-color: #dc6370;
  box-shadow: 0 2px 0 #56141b, 0 0 24px rgb(255 69 87 / 26%);
}

.start-layer {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(12 14 15 / 26%);
  backdrop-filter: blur(2px);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.start-layer.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.start-layer.result-mode { background: transparent; backdrop-filter: none; }

.start-content {
  display: grid;
  justify-items: center;
  gap: 16px;
}

.result-card {
  min-width: 230px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 15px 13px 13px;
  border: 1px solid rgb(255 255 255 / 15%);
  border-radius: 14px;
  background: rgb(20 23 25 / 94%);
  box-shadow: 0 14px 38px rgb(0 0 0 / 44%);
  text-align: center;
}

.result-stat + .result-stat { border-left: 1px solid rgb(255 255 255 / 10%); }

.result-stat span {
  display: block;
  margin-bottom: 3px;
  color: #9ba0a3;
  font-size: .56rem;
  font-weight: 950;
  letter-spacing: .18em;
}

.result-stat strong {
  display: block;
  font-size: 2.35rem;
  line-height: 1;
  letter-spacing: -.07em;
}

.round-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 9px;
}

.start-button {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 14px 19px 14px 23px;
  border: 1px solid rgb(255 255 255 / 20%);
  border-radius: 999px;
  background: #f1eee4;
  color: #121517;
  box-shadow: 0 10px 30px rgb(0 0 0 / 35%);
  font-size: .72rem;
  font-weight: 950;
  letter-spacing: .16em;
  cursor: pointer;
  transition: transform 150ms ease, background 150ms ease;
}

.start-button:hover,
.start-button:focus-visible { transform: scale(1.04); background: white; }
.start-button:active { transform: scale(.97); }

.start-button i {
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #171a1c;
  color: var(--green);
  font-size: .55rem;
  font-style: normal;
  text-indent: 1px;
}

.retry-button {
  padding: 17px 20px;
  border: 1px solid rgb(255 255 255 / 20%);
  border-radius: 999px;
  background: rgb(25 28 30 / 94%);
  color: var(--ink);
  box-shadow: 0 10px 30px rgb(0 0 0 / 30%);
  font-size: .7rem;
  font-weight: 950;
  letter-spacing: .15em;
  cursor: pointer;
  transition: transform 150ms ease, background 150ms ease;
}

.retry-button:hover,
.retry-button:focus-visible { transform: scale(1.04); background: #303438; }
.retry-button:active { transform: scale(.97); }
.retry-button[hidden] { display: none; }

.progress { overflow: hidden; border-radius: 2px; background: rgb(255 255 255 / 8%); }
.progress span { display: block; width: var(--progress, 0%); height: 100%; background: var(--green); transition: width 160ms ease; box-shadow: 0 0 10px var(--green); }

.instructions {
  width: min(calc(100% - 28px), 430px);
  padding: 30px;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 19px;
  background: #1b1e21;
  color: var(--ink);
  box-shadow: 0 30px 100px rgb(0 0 0 / 65%);
}

.instructions::backdrop { background: rgb(5 6 7 / 76%); backdrop-filter: blur(7px); }

.close-button { position: absolute; top: 15px; right: 15px; color: #a3a8aa; font-size: 1.25rem; }

.eyebrow {
  margin: 0 0 11px;
  color: var(--green);
  font-size: .6rem;
  font-weight: 950;
  letter-spacing: .2em;
}

.instructions h1 { margin: 0 0 24px; font-size: clamp(1.75rem, 8vw, 2.5rem); line-height: 1.04; letter-spacing: -.055em; }

.instructions ol {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: instructions;
}

.instructions li {
  position: relative;
  min-height: 31px;
  margin: 0 0 14px;
  padding-left: 42px;
  color: #c6c9c8;
  font-size: .88rem;
  line-height: 1.5;
  counter-increment: instructions;
}

.instructions li::before {
  content: counter(instructions);
  position: absolute;
  left: 0;
  top: 0;
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #292d30;
  color: var(--ink);
  font-size: .7rem;
  font-weight: 900;
}

.tip { display: flex; gap: 10px; align-items: center; margin: 23px 0; color: var(--muted); font-size: .76rem; }
.tip span { color: #ffd567; font-size: 1.2rem; }

.got-it-button {
  width: 100%;
  padding: 13px;
  border: 0;
  border-radius: 9px;
  background: var(--ink);
  color: #151719;
  font-size: .7rem;
  font-weight: 950;
  letter-spacing: .18em;
  cursor: pointer;
}

@keyframes status-pulse { to { opacity: .4; } }

@media (max-width: 540px) {
  .app { grid-template-rows: 49px minmax(0, 1fr); }
  .topbar { padding-inline: 10px; }
  .back-link { font-size: .62rem; }
  .brand { font-size: .76rem; }
  .icon-button { width: 32px; height: 32px; }
  .game-shell { width: 100%; padding: 10px 5px 8px; gap: 9px; }
  .scorebar { padding-inline: 7px; }
  .board-wrap { border-radius: 14px; }
  .board-scroller { padding: 7px 5px 9px; }
  .game-board { gap: 5px; }
  .tile-row { gap: 4px; }
  .tile { border-radius: 7px; box-shadow: 0 3px 0 var(--tile-edge), 0 5px 9px rgb(0 0 0 / 17%); }
  .instructions { padding: 28px 22px 23px; }
}

@media (max-height: 530px) and (orientation: landscape) {
  .app { grid-template-rows: 42px minmax(0, 1fr); }
  .game-shell { max-width: 900px; grid-template-columns: 108px minmax(0, 1fr) 3px; grid-template-rows: minmax(0, 1fr); gap: 12px; padding-block: 7px; }
  .scorebar { grid-template-columns: 1fr; align-content: center; }
  .score-best { text-align: left; }
  .status { justify-content: flex-start; order: 3; margin-top: 12px; }
  .progress { width: 3px; height: 100%; }
  .progress span { width: 100%; height: var(--progress, 0%); transition-property: height; }
}

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