:root {
  color-scheme: light;
  --ink: #171917;
  --ink-soft: #4e524b;
  --paper: #f8f7f3;
  --bg: #e9e8e2;
  --card: #ffffff;
  --line: #d4d3ca;
  --line-strong: #171917;
  --gold: #f3d24a;
  --gold-deep: #b87a08;
  --gold-soft: #fff6cf;
  --red: #ac3029;
  --red-soft: #fdebe9;
  --green: #1e7346;
  --green-soft: #e6f5ec;
  --used: #a5a8a1;
  --lane-1: #1f4e79;
  --lane-2: #1e6b52;
  --lane-3: #8a4b08;
  --lane-4: #6a2c70;
  --radius: 12px;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  height: 100%;
  font-size: 16px;
  overscroll-behavior: none;
  overflow-x: hidden;
}

.app-shell {
  width: min(100%, 510px);
  margin: 0 auto;
  min-height: 100vh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  box-shadow: 0 0 0 1px rgba(23, 25, 23, 0.08);
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
  position: relative;
  transition: width 0.18s ease;
}

@media (min-width: 760px) {
  .app-shell.wide-6 {
    width: min(100%, 760px);
  }
  .app-shell.wide-8 {
    width: min(100%, 980px);
  }
  .app-shell.wide-6 .fall-piano-keys,
  .app-shell.wide-8 .fall-piano-keys {
    height: 104px;
  }
}

.fall-piano-key.hand-split-right {
  border-left: 2.5px solid #8a8980;
}

.btn-slow-practice {
  width: 100%;
  min-height: 40px;
  padding: 7px 10px;
  font-size: 13px;
  background: var(--green-soft);
  border-color: var(--green);
  color: #134e2e;
  line-height: 1.35;
}

.btn-slow-practice:active {
  background: #d2eedd;
}

@supports (height: 100dvh) {
  .app-shell {
    min-height: 100dvh;
    height: 100dvh;
  }
}

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.view[hidden] {
  display: none !important;
}

.scroll-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 6px;
  padding-bottom: 16px;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 0 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 10px;
}

.brand {
  min-width: 0;
}

.brand h1 {
  font-size: clamp(19px, 5vw, 25px);
  line-height: 1.15;
  margin: 0;
  letter-spacing: 0.02em;
}

.brand p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill-btn {
  border: 1px solid var(--line-strong);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  touch-action: manipulation;
  white-space: nowrap;
}

.pill-btn[aria-pressed="true"] {
  background: var(--ink);
  color: #fff;
}

.pill-btn:active {
  transform: scale(0.97);
}

.pill-btn[hidden] {
  display: none !important;
}

.pause-big-btn {
  min-height: 42px;
  padding: 8px 14px;
  font-size: 15px;
}

.storage-banner {
  background: var(--red-soft);
  border: 1px solid var(--red);
  color: var(--red);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  margin-bottom: 10px;
}

.storage-banner[hidden] {
  display: none;
}

/* Section headers & cards */
.section-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 0.03em;
  margin: 10px 0 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.song-card {
  background: var(--card);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 13px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.song-card.classic-card {
  background: #fcfaf1;
}

.song-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.song-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.song-title {
  margin: 0;
  font-size: 19px;
  line-height: 1.25;
}

.tag {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: #ecebe4;
  color: var(--ink);
}

.tag.classic {
  background: var(--gold);
}

.tag.rhythm {
  background: #e1eef9;
  color: #163d61;
}

.song-sub {
  margin: 3px 0 0;
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.45;
}

.sticker-chip {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f5f4ee;
  color: var(--ink-soft);
  white-space: nowrap;
}

.sticker-chip.earned {
  border-color: var(--gold-deep);
  background: var(--gold-soft);
  color: #6d4600;
}

.song-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--ink-soft);
  background: #f6f5f0;
  border-radius: 8px;
  padding: 7px 10px;
}

.song-progress-hint {
  font-size: 14px;
  font-weight: 700;
  color: #6d4600;
  background: var(--gold-soft);
  border: 1px solid var(--gold-deep);
  border-radius: 8px;
  padding: 6px 10px;
}

.stars-inline {
  letter-spacing: 1px;
  font-size: 15px;
  color: var(--gold-deep);
}

.mono {
  font-family: "IBM Plex Mono", Consolas, ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

.song-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  padding: 11px 14px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  min-height: 46px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--ink);
  color: #fff;
  flex: 1;
}

.btn-secondary {
  background: #fff;
  color: var(--ink);
}

.btn-gold {
  background: var(--gold);
  color: var(--ink);
  flex: 1;
}

.parent-meta {
  border-top: 1px dashed var(--line);
  padding-top: 8px;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.5;
}

.parent-meta a {
  color: #1c4e80;
}

.parent-notice {
  color: var(--red);
  font-weight: 700;
  margin-top: 4px;
}

/* Bottom Sheet: Mode Selector */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(23, 25, 23, 0.56);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 30;
  padding: 12px 10px max(12px, env(safe-area-inset-bottom));
}

.sheet-overlay[hidden] {
  display: none !important;
}

.sheet-card {
  width: min(100%, 490px);
  max-height: 94dvh;
  overflow-y: auto;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 16px;
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 20px;
}

.sheet-sub {
  margin: 1px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.sheet-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.sheet-group[hidden] {
  display: none !important;
}

.sheet-label {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink);
}

.sheet-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.sheet-readout {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--gold-deep);
}

.mode-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mode-option {
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 8px 11px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 2px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.mode-option.selected {
  border-color: var(--ink);
  background: var(--gold-soft);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.mode-option-title {
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.mode-option-desc {
  font-size: 12.5px;
  color: var(--ink-soft);
  line-height: 1.35;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chip-btn {
  border: 1.5px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 5px 10px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  min-height: 36px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.chip-btn.selected {
  background: var(--ink);
  color: #fff;
}

.range-input {
  width: 100%;
  accent-color: var(--ink);
  height: 24px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 11px;
  cursor: pointer;
}

.toggle-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--ink);
}

.sheet-start-btn {
  width: 100%;
  min-height: 48px;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  font-size: 18px;
}

/* Settings */
.settings-card {
  text-align: left;
  max-height: 90dvh;
  overflow-y: auto;
}

.settings-divider {
  border-top: 1px dashed var(--line);
  margin: 4px 0;
}

.settings-hint {
  margin: 0;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-soft);
  line-height: 1.45;
}

.settings-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.song-vis-details {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 6px 10px;
}

.song-vis-details summary {
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink);
  padding: 2px 0;
}

.song-vis-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 4px;
}

.song-vis-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 8px;
  border-radius: 8px;
  background: #f6f5f0;
  cursor: pointer;
}

.song-vis-row.is-hidden-row {
  opacity: 0.65;
  background: #efefef;
}

.song-vis-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  flex: 1;
}

.song-vis-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.song-vis-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--ink);
}

.hidden-songs-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  background: #f3f2ec;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  flex-shrink: 0;
}

.hidden-songs-banner[hidden] {
  display: none !important;
}

.btn-hide-ghost {
  background: #fff;
  color: var(--ink-soft);
  border-color: var(--line);
  flex: 0 0 auto;
  padding: 10px 12px;
  font-size: 13.5px;
  min-height: 46px;
}

.btn-hide-ghost:active {
  background: #ecebe4;
}

.song-card.is-hidden-song {
  opacity: 0.72;
  border-style: dashed;
  background: #f4f4f1;
}

.tag.hidden-tag {
  background: #e5e5e0;
  color: #555;
}

.pill-btn.is-unlocked {
  background: var(--gold-soft);
  border-color: var(--gold-deep);
  color: #5c3a00;
}

.pin-unlock-box {
  background: #fcfaf1;
  border: 1.5px solid var(--gold-deep);
  border-radius: 10px;
  padding: 10px;
}

.pin-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.pin-input-row[hidden],
.pin-unlocked-row[hidden],
.pin-status[hidden] {
  display: none !important;
}

.pin-input {
  flex: 1;
  min-width: 0;
  padding: 9px 11px;
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
  font-size: 16px;
  background: #fff;
  color: var(--ink);
}

.pin-btn {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 8px 16px;
  font-size: 15px;
}

.pin-unlocked-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.pin-unlocked-badge {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--green);
}

.pin-status {
  font-size: 13px;
  font-weight: 700;
  color: var(--green);
}

.pin-status.is-error {
  color: var(--red);
}

.settings-card h2 {
  text-align: center;
  margin-bottom: 12px;
}

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.setting-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 14px;
  font-weight: 700;
}

.num-input {
  padding: 8px 10px;
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
  font-size: 16px;
  width: 120px;
}

.select-input {
  width: 100%;
  padding: 8px 10px;
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  min-height: 40px;
}

.midi-personal-btn {
  background: #e9f4ff;
  border-color: var(--lane-1);
  color: #163d61;
}

.keybind-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.keybind-btn {
  border: 1.5px solid var(--ink);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  min-height: 44px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}

.keybind-btn.listening {
  background: var(--gold);
}

/* Play screen */
.play-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 0 6px;
}

.play-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.play-meta {
  min-width: 0;
}

.play-title {
  margin: 0;
  font-size: clamp(16px, 4.5vw, 20px);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.play-mode-sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.play-hud {
  text-align: right;
  flex-shrink: 0;
}

.hud-clock {
  font: 700 clamp(22px, 6.2vw, 30px)/1 "IBM Plex Mono", Consolas, monospace;
  color: var(--red);
  font-variant-numeric: tabular-nums;
}

.hud-clock-unit {
  font-size: 14px;
  margin-left: 2px;
  color: var(--ink);
}

.hud-score {
  font: 700 clamp(14px, 4vw, 18px)/1.15 "IBM Plex Mono", Consolas, monospace;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  flex-wrap: nowrap;
}

.hud-combo {
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 800;
  line-height: 1.2;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--gold-soft);
  border: 1px solid var(--gold-deep);
  color: #6d4600;
  white-space: nowrap;
}

.hud-wrong {
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 2px;
}

.tolerance-bar {
  background: var(--gold-soft);
  border: 1px solid var(--gold-deep);
  color: #5c3a00;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
}

.tolerance-bar.danger {
  background: var(--red-soft);
  border-color: var(--red);
  color: var(--red);
}

.tolerance-bar[hidden] {
  display: none !important;
}

.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#board {
  position: absolute;
  inset: 0;
  border: 1.5px solid var(--ink);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, minmax(0, 1fr));
  background: #fff;
  overflow: hidden;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

#board[hidden] {
  display: none !important;
}

.tile {
  border: 0;
  border-right: 1px solid #babbb4;
  border-bottom: 1px solid #babbb4;
  background: #fff;
  color: #fff;
  line-height: 1.25;
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
  cursor: pointer;
  border-radius: 0;
  padding: 4px;
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  touch-action: none;
}

.tile:nth-child(4n) {
  border-right: 0;
}

.tile:nth-last-child(-n + 4) {
  border-bottom: 0;
}

.tile.target-row {
  background: #fbfaf5;
}

.tile.black {
  background: var(--ink);
  color: #fff;
}

.tile.black.target-active {
  background: #101210;
  box-shadow: inset 0 0 0 3px var(--gold);
}

.tile.black.guide-pulse {
  box-shadow: inset 0 0 0 5px #ffca28;
}

.tile.edge {
  background: var(--gold);
  color: var(--ink);
}

.tile.used {
  background: var(--used);
  color: #f4f5f1;
}

.tile.wrong {
  background: var(--red) !important;
  color: #fff;
}

.tile-main {
  font-size: clamp(16px, 4.6vw, 20px);
  font-weight: 700;
  pointer-events: none;
}

.tile-sub {
  font-size: 13px;
  font-weight: 600;
  opacity: 0.9;
  pointer-events: none;
}

.tile-hold-badge {
  font-size: 12px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(243, 210, 74, 0.28);
  color: #ffe277;
  pointer-events: none;
}

/* Legacy rhythm stage: Full-height 4-column falling board */
.rhythm-stage {
  position: absolute;
  inset: 0;
  border: 1.5px solid var(--ink);
  background: #ffffff;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.rhythm-stage[hidden] {
  display: none !important;
}

.rhythm-canvas-wrap {
  position: absolute;
  inset: 0;
}

#rhythm-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.rhythm-keys {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: transparent;
  touch-action: none;
}

.rhythm-key {
  border: 0;
  background: transparent;
  color: var(--ink);
  min-height: 88px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  cursor: pointer;
  padding: 6px 4px;
  font-family: inherit;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.rhythm-key.pressed {
  background: rgba(243, 210, 74, 0.12);
}

.rkey-hint {
  font-size: 12px;
  font-weight: 700;
  color: rgba(23, 25, 23, 0.72);
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(23, 25, 23, 0.16);
  pointer-events: none;
  display: none;
}

@media (pointer: fine) {
  .rkey-hint {
    display: inline-block;
  }
}

.tile:focus-visible,
.rhythm-key:focus-visible,
.btn:focus-visible,
.pill-btn:focus-visible,
.chip-btn:focus-visible {
  outline: 3px solid #c88224;
  outline-offset: -3px;
}

.play-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 7px;
  font-size: 14px;
  gap: 8px;
  color: var(--ink-soft);
}

.count {
  font: 700 15px/1.3 "IBM Plex Mono", Consolas, monospace;
  color: var(--ink);
  white-space: nowrap;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(23, 25, 23, 0.56);
  display: grid;
  place-items: center;
  padding: 12px;
  z-index: 20;
}

.overlay[hidden] {
  display: none !important;
}

.modal-card {
  width: min(100%, 380px);
  max-height: 100%;
  overflow-y: auto;
  background: var(--paper);
  padding: 18px 16px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  text-align: center;
}

.modal-card h2 {
  margin: 0 0 6px;
  font-size: 23px;
}

.modal-desc {
  margin: 0 0 12px;
  font-size: 15px;
  color: var(--ink-soft);
  line-height: 1.45;
}

.rehold-hint {
  background: var(--gold-soft);
  border: 1.5px solid var(--gold-deep);
  color: #5c3a00;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 12px;
}

.rehold-hint[hidden] {
  display: none !important;
}

.result-stars {
  font-size: 32px;
  letter-spacing: 4px;
  color: var(--gold-deep);
  margin: 4px 0 10px;
  line-height: 1;
}

.result-stars[hidden] {
  display: none !important;
}

.record-banner {
  background: var(--green-soft);
  border: 1.5px solid var(--green);
  color: var(--green);
  border-radius: 10px;
  padding: 7px 10px;
  margin-bottom: 10px;
  font-size: 15px;
  font-weight: 700;
}

.record-banner[hidden] {
  display: none !important;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.result-grid.three-col {
  grid-template-columns: repeat(3, 1fr);
}

.metric-box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 6px;
}

.metric-label {
  font-size: 13px;
  color: var(--ink-soft);
}

.metric-value {
  font-size: 19px;
  font-weight: 700;
  margin-top: 2px;
}

.compare-box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 10px;
  font-size: 13px;
  text-align: left;
  line-height: 1.55;
}

.compare-box[hidden] {
  display: none !important;
}

.compare-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  text-align: center;
  margin-bottom: 4px;
}

.compare-cell {
  background: #f6f5f0;
  border-radius: 6px;
  padding: 5px 4px;
}

.compare-cell-label {
  font-size: 12px;
  color: var(--ink-soft);
}

.compare-cell-val {
  font-size: 14px;
  font-weight: 700;
}

.sticker-banner {
  background: var(--gold-soft);
  border: 1.5px solid var(--gold-deep);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 15px;
  font-weight: 700;
  color: #5c3a00;
  line-height: 1.4;
}

.sticker-banner-sub {
  font-size: 13px;
  font-weight: 600;
  color: #7a5204;
  margin-top: 2px;
}

.sticker-banner[hidden] {
  display: none !important;
}

.retry-box {
  background: var(--red-soft);
  border: 1.5px solid var(--red);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.retry-box[hidden] {
  display: none !important;
}

.retry-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--red);
}

.retry-btn {
  width: 100%;
  min-height: 48px;
  font-size: 16px;
}

.detail-error-box {
  font-size: 13px;
  color: var(--ink-soft);
  word-break: break-word;
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
}

.detail-error-box[hidden] {
  display: none !important;
}

.result-detail-panel {
  font-size: 13px;
  color: var(--ink-soft);
  background: #f6f5f0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 10px;
  text-align: left;
  line-height: 1.55;
}

.result-detail-panel[hidden] {
  display: none !important;
}

.result-note {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0 0 10px;
  line-height: 1.45;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-actions-row {
  display: flex;
  gap: 8px;
}

.modal-actions-row .btn {
  flex: 1;
}

.result-detail-btn {
  justify-content: center;
}

/* Collection view */
.sticker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.sticker-card {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 10px 6px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.sticker-card.unlocked {
  border-color: var(--gold-deep);
  background: var(--gold-soft);
}

.sticker-card.locked {
  opacity: 0.62;
  filter: grayscale(0.8);
}

.sticker-emoji {
  font-size: 28px;
  line-height: 1.1;
}

.sticker-name {
  font-size: 13px;
  font-weight: 700;
}

.sticker-date {
  font-size: 11px;
  color: var(--ink-soft);
}

.record-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.record-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.record-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  flex-wrap: wrap;
}

.record-bottom {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 13px;
}

.empty-state {
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
}

.license-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-soft);
}

.license-box h3 {
  margin: 0 0 6px;
  font-size: 15px;
  color: var(--ink);
}

.license-box ul {
  margin: 0;
  padding-left: 18px;
}

.license-box li {
  margin-bottom: 6px;
}

.license-box a {
  color: #1c4e80;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

@media (max-height: 520px) {
  .app-shell {
    padding-top: 6px;
    padding-bottom: 6px;
  }
  .play-header {
    padding-bottom: 4px;
  }
  .play-footer {
    padding-top: 4px;
  }
}


/* =========================================================================
 * v4 Fall-Tap UI, Tag Filter, Speed Panel & Floor-Line Playfield
 * ========================================================================= */
.tag-filter-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 4px;
  flex-shrink: 0;
  overflow-x: auto;
}

.filter-chip {
  border: 1.5px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 5px 12px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  min-height: 36px;
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.filter-chip.selected {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.tag.diff-tag {
  background: #e6f5ec;
  color: #165936;
}

.tag.diff-tag.diff-level-1 {
  background: #e6f5ec;
  color: #165936;
}

.tag.diff-tag.diff-level-2 {
  background: #fdf3cc;
  color: #7c5200;
}

.tag.diff-tag.diff-level-3 {
  background: #fdebe9;
  color: #9e2620;
}

.sheet-practice-toggle {
  margin: 2px 0;
}

.result-top-action {
  margin: 2px 0 12px;
}

.result-top-action[hidden] {
  display: none !important;
}

.btn-restart-hero {
  width: 100%;
  min-height: 54px;
  font-size: 19px;
}

.chip-btn:disabled {
  opacity: 0.42;
  background: #e5e4dc;
  color: #7a7d77;
  border-color: #c5c4bb;
  cursor: not-allowed;
}

.speed-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.step-btn {
  border: 1.5px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 13px;
  font-weight: 700;
  min-height: 36px;
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
}

.step-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.speed-warning {
  font-size: 13px;
  font-weight: 700;
  color: var(--red);
  background: var(--red-soft);
  border: 1px solid #e7b5b2;
  border-radius: 8px;
  padding: 6px 10px;
}

.speed-warning[hidden] {
  display: none !important;
}

.other-modes-wrap {
  border-top: 1px solid var(--line);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.other-modes-toggle {
  align-self: center;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px 10px;
}

.other-modes-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.other-modes-panel[hidden] {
  display: none !important;
}

.other-mode-btn {
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 9px;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  min-height: 42px;
  touch-action: manipulation;
}

.other-mode-btn[hidden] {
  display: none !important;
}

/* Top Status Alert Bar (strictly ABOVE falling canvas, never overlaps tiles) */
.fall-status-bar {
  margin: 0 10px 6px;
  min-height: 34px;
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f2f1ea;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  flex-shrink: 0;
}

.fall-status-bar[hidden] {
  display: none !important;
}

.fall-status-bar.alert-red {
  background: #fdecec;
  border-color: #df9a97;
  color: #c62828;
  font-size: 16px;
}

.fall-stage {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  border: 1.5px solid var(--ink);
  background: #ffffff;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.fall-stage[hidden] {
  display: none !important;
}

.fall-canvas-wrap {
  flex: 1 1 auto;
  min-height: 220px;
  position: relative;
}

#fall-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.fall-lane-overlays {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  touch-action: none;
}

.fall-lane-hit {
  border: 0;
  background: transparent;
  width: 100%;
  height: 100%;
  cursor: pointer;
  padding: 0;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.fall-piano-keys {
  flex: 0 0 auto;
  height: 78px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 2px solid var(--ink);
  background: #ffffff;
  touch-action: none;
}

.fall-piano-key {
  border: 0;
  border-right: 1px solid #c7c6bc;
  background: linear-gradient(180deg, #ffffff 0%, #f3f2ec 100%);
  color: var(--ink);
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 10px;
  cursor: pointer;
  font-family: inherit;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.fall-piano-key:last-child {
  border-right: 0;
}

.fall-piano-key.pressed {
  background: linear-gradient(180deg, #dbeeff 0%, #c6e2fc 100%);
}

.fall-piano-key.wrong-flash {
  background: linear-gradient(180deg, #ffd8d6 0%, #f7b5b2 100%);
}

.pkey-hint {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(23, 25, 23, 0.06);
  pointer-events: none;
}

.play-footer[hidden] {
  display: none !important;
}

/* =========================================================================
 * v5 Play Modes, Song Pack Cards & Music Credits Page
 * ========================================================================= */
.pack-song-card {
  background: #fdfcf7;
}

.pack-sub-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 3px;
}

.pack-sub-row .song-sub {
  margin: 0;
}

.credit-link-btn {
  border: 0;
  background: transparent;
  color: #1c4e80;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  text-decoration: underline;
  padding: 2px 4px;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}

.home-credits-footer {
  margin: 14px 0 8px;
  display: flex;
  justify-content: center;
}

.home-credits-footer[hidden] {
  display: none !important;
}

.home-credits-btn {
  width: 100%;
  min-height: 44px;
}

.playmode-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.playmode-option[hidden] {
  display: none !important;
}

.other-modes-wrap[hidden] {
  display: none !important;
}

.credits-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.credit-card {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.credit-card.highlighted {
  border-color: var(--ink);
  background: var(--gold-soft);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.credit-title {
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
  color: var(--ink);
}

.credit-attribution {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
  word-break: break-word;
}

.credit-changes {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-soft);
}

.bests-group-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
  margin: 6px 0 2px;
  padding-left: 2px;
}

.tag.legacy-tag {
  background: #ece7d5;
  color: #6d4600;
}

/* =========================================================================
 * v6 Speed/Frequency/Dual Controls, Custom MIDI Library & Combo HUD
 * ========================================================================= */
.midi-import-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 2px 6px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.midi-import-btn {
  background: var(--gold-soft);
  border-color: var(--gold-deep);
  color: #5c3a00;
  min-height: 36px;
  padding: 5px 11px;
  font-size: 13.5px;
}

.install-app-btn {
  background: var(--green-soft);
  border-color: var(--green);
  color: var(--green);
}

.install-app-btn.is-installed {
  background: #edf5ef;
  border-color: #7ca88b;
  color: #245c39;
}

.install-card {
  width: min(100%, 420px);
  text-align: left;
}

.install-card h2,
.install-card .modal-desc {
  text-align: center;
}

.install-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.install-section[hidden],
.install-callout[hidden],
.install-step-box[hidden] {
  display: none !important;
}

.install-callout {
  background: #f6f4ec;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink);
}

.install-callout.is-success {
  background: var(--green-soft);
  border-color: var(--green);
  color: var(--green);
  font-weight: 700;
}

.install-step-box {
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.install-import-box {
  background: #f7fafd;
  border-color: #b7d2eb;
}

.install-step-title {
  margin: 0;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ink);
}

.install-steps {
  margin: 0;
  padding-left: 20px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink);
}

.install-steps li {
  margin-bottom: 4px;
}

.install-big-btn {
  width: 100%;
  min-height: 46px;
  font-size: 14.5px;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.install-subhint {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--ink-soft);
}

.midi-import-hint {
  font-size: 12.5px;
  color: var(--ink-soft);
  line-height: 1.3;
  flex: 1 1 150px;
  min-width: 0;
}

.midi-import-status {
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 6px;
  flex-shrink: 0;
  background: var(--green-soft);
  border: 1px solid var(--green);
  color: var(--green);
  word-break: break-word;
}

.midi-import-status.is-warn {
  background: var(--gold-soft);
  border-color: var(--gold-deep);
  color: #5c3a00;
}

.midi-import-status.is-error {
  background: var(--red-soft);
  border-color: var(--red);
  color: var(--red);
}

.midi-import-status[hidden] {
  display: none !important;
}

.custom-song-card {
  background: #f7fafd;
  border-color: var(--lane-1);
}

.tag.midi-tag {
  background: #ddebf8;
  color: #163d61;
}

.btn-danger-ghost {
  background: #fff;
  color: var(--red);
  border-color: #d89b97;
  flex: 0 0 auto;
  padding: 10px 14px;
  font-size: 14px;
  min-height: 46px;
}

.btn-danger-ghost:active {
  background: var(--red-soft);
}

.chip-row-compact {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chip-row-compact .chip-btn {
  flex: 1 1 auto;
  padding: 4px 8px;
  font-size: 13px;
  min-height: 34px;
  text-align: center;
  white-space: nowrap;
}

.sheet-compact-toggle {
  padding: 7px 10px;
  font-size: 13.5px;
}

.sheet-compact-toggle span {
  min-width: 0;
  line-height: 1.3;
}

.sheet-compact-toggle input[type="checkbox"] {
  flex-shrink: 0;
}

.compare-extra-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding-top: 6px;
  margin-top: 6px;
  border-top: 1px dashed var(--line);
  font-size: 13px;
  color: var(--ink);
}

.compare-extra-row:first-child {
  border-top: 0;
  margin-top: 0;
  padding-top: 0;
}

@media (max-width: 390px) {
  .tag-filter-bar {
    padding: 4px 2px 4px;
  }
  .chip-row-compact .chip-btn {
    padding: 4px 6px;
    font-size: 12.5px;
  }
}

