:root {
  color-scheme: dark;
  --bg: #101513;
  --panel: #171e1a;
  --inset: #101613;
  --line: #2c382f;
  --text: #f0f4e9;
  --muted: #a2b0a3;
  --lime: #d3f384;
  --lime-hover: #e3ffa6;
  --early: #e8bbff;
  --late: #ffbd83;
  --missed: #ff9292;
  --extra: #e8b7ab;
  --number: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font: 16px/1.55 "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 300px; }
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
button, a, input, select, textarea, summary { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--lime); outline-offset: 4px; }
h1, h2, h3, p, dl, dd { margin: 0; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.quiet { color: var(--muted); font-size: .875rem; }
.shell { width: min(1120px, 100% - 64px); margin-inline: auto; }

.site-header { border-bottom: 1px solid #253027; background: #121815; }
.header-inner {
  min-height: 68px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
}
.brand { display: inline-flex; width: fit-content; gap: 10px; align-items: center; font-weight: 750; white-space: nowrap; }
.brand-extra { color: var(--muted); margin-left: 4px; font-size: .875rem; font-weight: 500; }
.brand-mark { display: inline-flex; gap: 3px; align-items: center; height: 33px; padding: 7px; border-radius: 8px; background: var(--lime); }
.brand-mark i { display: block; width: 3px; height: 8px; border-radius: 2px; background: #172213; }
.brand-mark i:nth-child(2) { height: 17px; }
.brand-mark i:nth-child(3) { height: 12px; }
.brand-mark i:nth-child(4) { height: 6px; }
.main-nav { display: flex; align-items: center; gap: 3px; background: #1c2520; border: 1px solid #2a362c; border-radius: 10px; padding: 3px; white-space: nowrap; }
.main-nav a { padding: 7px 15px; border-radius: 7px; font-size: .875rem; color: var(--muted); text-align: center; }
.main-nav a:hover { color: var(--text); }
.main-nav a[aria-current="page"] { color: var(--lime); background: #2a392a; }
.keyboard-hint { justify-self: end; color: var(--muted); font-size: .875rem; white-space: nowrap; }
kbd { display: inline-block; padding: 0 7px; border: 1px solid #435442; border-radius: 4px; font: inherit; font-size: .8125rem; }

.main { min-height: calc(100svh - 133px); }
.view { padding-block: 36px 48px; }
.page-intro { margin-bottom: 24px; }
.page-intro h1 { font-size: clamp(2rem, 4vw, 3rem); line-height: 1.18; letter-spacing: -.04em; font-weight: 780; }
.page-intro p { margin-top: 9px; color: var(--muted); }
.practice-layout, .import-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(285px, 320px); gap: 18px; align-items: start; }
.panel { min-width: 0; border: 1px solid var(--line); border-radius: 17px; background: var(--panel); }
.panel h2 { font-size: 1.25rem; line-height: 1.3; }
.arena { padding: 26px; background: radial-gradient(ellipse at 35% 0%, #233124 0%, transparent 59%), var(--panel); }
.arena-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 20px; }
.title-block { min-width: 0; }
.small-label { color: var(--lime); font-size: .875rem; }
.arena .arena-header h2 { font-size: clamp(1.45rem, 3vw, 2.05rem); letter-spacing: -.025em; margin-top: 2px; overflow-wrap: anywhere; }
.arena-header p { margin-top: 5px; }
.tempo-display { display: flex; flex-direction: column; align-items: flex-end; color: var(--lime); flex: none; }
.tempo-display strong { font: 700 clamp(2rem, 5vw, 3.15rem)/1 var(--number); letter-spacing: -.09em; }
.tempo-display span { color: var(--muted); font: .8125rem/1.6 var(--number); letter-spacing: .08em; }

.track { border: 1px solid #314038; border-radius: 12px; padding: 13px 14px 12px; background: #111915; }
.track-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: .875rem; margin-bottom: 9px; }
#track-state { color: var(--lime); }
.beat-grid {
  display: grid;
  grid-template-columns: repeat(var(--pulses, 4), minmax(0, 1fr));
  gap: 4px;
  border-radius: 8px;
  overflow: hidden;
}
.beat {
  position: relative;
  min-width: 0;
  height: clamp(65px, 10vw, 95px);
  background: repeating-linear-gradient(90deg, #253229 0 1px, transparent 1px 100%) center / 25% 100%, #19241d;
  border-top: 2px solid transparent;
}
.beat.active { background-color: #2b3b28; border-top-color: var(--lime); }
.beat::before { content: ""; position: absolute; top: 49%; left: 0; width: 100%; height: 1px; background: #3a4c3b; }
.beat-number { position: absolute; bottom: 5px; left: 7px; font: .8125rem/1.3 var(--number); color: var(--muted); }
.beat.active .beat-number { color: var(--lime); }
.hit {
  --hit-color: var(--lime);
  position: absolute;
  top: 49%;
  left: clamp(6px, var(--position), calc(100% - 5px));
  width: clamp(6px, 1.35vw, 13px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--hit-color);
  box-shadow: 0 0 10px color-mix(in srgb, var(--hit-color) 28%, transparent);
}
.hit[data-state="on"] { --hit-color: #a1e2ad; }
.hit[data-state="early"] { --hit-color: var(--early); }
.hit[data-state="late"] { --hit-color: var(--late); }
.hit[data-state="missed"] { --hit-color: var(--missed); opacity: .65; }
.progress-segments { display: flex; gap: 4px; margin-top: 10px; }
.progress-segments i { height: 3px; flex: 1; background: #324036; border-radius: 4px; }
.progress-segments i.done { background: #66906c; }
.progress-segments i.active { background: var(--lime); }
.progress-segments.continuous { overflow: hidden; background: #324036; border-radius: 4px; }
.progress-segments.continuous i { flex: 0 0 var(--completion); background: var(--lime); }

.feedback { color: var(--muted); text-align: center; padding: 17px 0; font-size: .9375rem; }
.feedback[data-tone="on"] { color: var(--lime); }
.feedback[data-tone="early"] { color: var(--early); }
.feedback[data-tone="late"] { color: var(--late); }
.feedback[data-tone="missed"], .feedback[data-tone="extra"] { color: var(--missed); }
.player-controls { display: flex; gap: 9px; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 46px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-weight: 650;
  color: var(--text);
  line-height: 1.3;
  text-align: center;
  touch-action: manipulation;
}
.button.primary { background: var(--lime); color: #172111; }
.button.primary:hover { background: var(--lime-hover); }
.button.secondary { background: #212c23; border-color: #3a4c3d; }
.button.secondary:hover { background: #2b382d; }
.button.small { font-size: .875rem; }
.icon-play { width: 0; height: 0; border-left: 8px solid currentColor; border-top: 5px solid transparent; border-bottom: 5px solid transparent; }
#start { flex: 1; }
.tap-pad {
  flex: 1;
  border: 1px solid #718e51;
  background: #293922;
  color: var(--lime);
  touch-action: none;
  user-select: none;
}
.tap-pad:active, .tap-pad.pressed { background: var(--lime); color: #172111; }
.tap-pad kbd { font-weight: 400; }
.live-stats, .review-stats { display: grid; gap: 0; }
.live-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 19px; padding-top: 14px; border-top: 1px solid var(--line); }
.live-stats div { padding-inline: 10px; }
.live-stats div:first-child { padding-left: 0; }
.live-stats div + div { border-left: 1px solid var(--line); }
.live-stats dt, .review-stats dt { color: var(--muted); font-size: .875rem; }
.live-stats dd, .review-stats dd { font: 600 1.35rem/1.55 var(--number); }
.legend-dot { display: inline-block; width: 7px; height: 7px; margin-right: 6px; vertical-align: .1em; border-radius: 50%; background: var(--lime); }
.legend-dot.early { background: var(--early); }
.legend-dot.late { background: var(--late); }
.legend-dot.missed { background: var(--missed); }
.legend-dot.extra { background: var(--extra); }

.settings { padding: 21px; }
.settings h2 { margin-bottom: 17px; }
.setting + .setting { margin-top: 15px; }
.setting-label { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 6px; font-size: .875rem; color: var(--muted); }
.setting-label output { color: var(--lime); font: .875rem var(--number); }
.tempo-control { display: grid; grid-template-columns: 38px minmax(0, 1fr) 38px; align-items: center; gap: 9px; }
.step-button { display: grid; place-items: center; min-height: 36px; border: 1px solid #3a483e; border-radius: 8px; color: var(--text); background: #222d24; line-height: 1; }
.step-button:hover { border-color: #78935e; }
input[type="range"] { width: 100%; min-height: 30px; margin: 0; accent-color: var(--lime); }
.exercise-options { display: grid; gap: 4px; }
.exercise-option {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 38px;
  padding: 5px 10px;
  text-align: left;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  font-size: .9375rem;
}
.exercise-option:hover { background: #253025; }
.exercise-option[aria-pressed="true"] { color: var(--lime); background: #253426; border-color: #566b47; }
.option-info { font-size: .8125rem; color: var(--muted); white-space: nowrap; }
.compact-settings, .import-range { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.compact-settings label, .import-range label { min-width: 0; font-size: .875rem; color: var(--muted); }
.compact-settings label[hidden] + label { grid-column: 1 / -1; }
select, input[type="number"], input[type="search"], textarea, input[type="file"] {
  color: var(--text);
  background: var(--inset);
  border: 1px solid #3b4b3e;
  border-radius: 7px;
}
select, input[type="number"] { display: block; width: 100%; margin-top: 5px; min-height: 40px; padding: 6px 9px; }
select {
  appearance: none;
  padding-right: 26px;
  background-image: linear-gradient(45deg, transparent 49%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 51%);
  background-position: calc(100% - 13px) 50%, calc(100% - 8px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.latency-settings { margin-top: 14px; color: var(--muted); font-size: .875rem; }
.latency-settings summary { cursor: pointer; }
.latency-settings label { display: flex; justify-content: space-between; align-items: center; margin-block: 8px; }
.input-with-unit { display: inline-flex; gap: 6px; align-items: center; }
.input-with-unit input { width: 75px; margin: 0; }

.import-layout { grid-template-columns: minmax(0, 1fr) minmax(300px, .9fr); }
.import-input, .import-preview, .review-detail { padding: 24px; }
.segmented {
  display: inline-flex;
  gap: 3px;
  border: 1px solid var(--line);
  background: var(--inset);
  padding: 3px;
  border-radius: 9px;
  margin-bottom: 16px;
}
.segmented button { border: 0; border-radius: 6px; background: transparent; padding: 7px 12px; color: var(--muted); font-size: .9375rem; }
.segmented button[aria-pressed="true"] { color: var(--lime); background: #2a392a; }
.score-query { display: flex; gap: 8px; }
.score-query input { flex: 1; min-width: 0; padding: 8px 10px; }
.score-query button { flex: none; }
.search-results { display: grid; gap: 8px; padding: 0; margin: 13px 0 0; list-style: none; }
.search-hit { padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--inset); }
.search-hit:has(.search-hit-choice[aria-pressed="true"]) { border-color: #718850; background: #233023; }
.search-hit-choice[aria-pressed="true"] { color: var(--lime); }
.search-hit-choice[aria-pressed="true"]::before { content: '✓'; }
.search-hit h3 { margin-bottom: 5px; font-size: 1rem; font-weight: 650; overflow-wrap: anywhere; }
.search-hit-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 7px 12px; }
.search-hit-source { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 11px; font-size: .875rem; color: var(--muted); }
.search-hit button { min-height: 36px; padding: 6px 11px; }
.search-hit-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.source-link { display: inline-block; color: var(--lime); font-size: .875rem; text-decoration: underline; text-underline-offset: 3px; overflow-wrap: anywhere; }
.source-link:hover { color: var(--lime-hover); }
#import-source-link { margin-top: 3px; }
.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 160px;
  padding: 13px;
  border: 1px dashed #637556;
  border-radius: 11px;
  background: var(--inset);
  cursor: pointer;
  text-align: center;
}
.dropzone:hover, .dropzone.dragging, .dropzone:focus-within { border-color: var(--lime); background: #1c2b21; }
.dropzone span { color: var(--muted); font-size: .875rem; }
.dropzone input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.file-mark { display: inline-grid; gap: 3px; border: 1px solid #698157; border-radius: 6px; padding: 7px; margin-bottom: 7px; }
.file-mark i { height: 2px; width: 15px; border-radius: 2px; background: var(--lime); }
.file-mark i:last-child { width: 10px; }
.import-input .quiet { margin-block: 12px; }
.ai-label { display: block; margin: 0 0 5px; color: var(--muted); font-size: .875rem; }
#ai-file, #ai-text { width: 100%; padding: 8px; }
#ai-file { margin-bottom: 12px; }
#ai-file::file-selector-button { font: inherit; font-size: .875rem; background: #2d3b2c; color: var(--text); border: 0; border-radius: 5px; padding: 5px 8px; margin-right: 8px; cursor: pointer; }
#ai-text { resize: vertical; }
.message { color: var(--muted); margin-top: 12px; font-size: .875rem; }
.message[data-tone="error"] { color: var(--missed); }
.message[data-tone="ok"] { color: var(--lime); }
.import-preview h2 { margin-bottom: 12px; }
.import-preview h3 { font-size: 1.125rem; overflow-wrap: anywhere; }
.import-progress { display: grid; gap: 8px; margin-top: 14px; }
.import-progress-label { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .875rem; }
.import-progress-label span { color: var(--lime); font-variant-numeric: tabular-nums; white-space: nowrap; }
.score-progress { display: block; width: 100%; height: 8px; accent-color: var(--lime); }
#search-progress { margin-top: 12px; }
.track-setting { margin-top: 12px; }
.empty-preview { display: grid; place-items: center; align-content: center; gap: 12px; min-height: 213px; color: var(--muted); text-align: center; }
.empty-rhythm { display: flex; align-items: end; gap: 5px; height: 34px; }
.empty-rhythm i { background: #435841; width: 7px; border-radius: 3px; height: 60%; }
.empty-rhythm i:nth-child(2) { height: 100%; }
.empty-rhythm i:nth-child(3) { height: 78%; }
.empty-rhythm i:nth-child(4) { height: 43%; }
.import-range, .mini-bars, .import-actions { margin-top: 14px; }
.mini-bars { display: grid; gap: 5px; max-height: 244px; overflow: auto; }
.import-scope { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 14px; }
.import-scope .button { min-height: 34px; padding-block: 5px; }
.import-scope + .import-range { margin-top: 6px; }
.mini-bar { display: flex; align-items: center; justify-content: space-between; min-height: 33px; gap: 8px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); background: var(--inset); font-size: .8125rem; }
.mini-pattern { position: relative; flex: 1; height: 14px; background: linear-gradient(#384a37, #384a37) center / 100% 1px no-repeat; }
.mini-pattern i { position: absolute; inset: 50% auto auto var(--position); width: 5px; height: 5px; border-radius: 50%; background: var(--lime); transform: translate(-50%, -50%); }
.import-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.melody-voice-setting { margin-top: 13px; max-width: 170px; }

.review-empty { display: grid; justify-items: center; align-content: center; min-height: 245px; gap: 16px; }
.score-summary { display: grid; grid-template-columns: minmax(135px, .28fr) 1fr; align-items: center; gap: 22px; padding: 22px; margin-bottom: 15px; }
.accuracy { display: grid; color: var(--lime); padding-right: 15px; border-right: 1px solid var(--line); }
.accuracy span { font-size: .875rem; }
.accuracy strong { font: 700 clamp(2.6rem, 6vw, 4.6rem)/1.12 var(--number); letter-spacing: -.085em; }
.review-stats { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.review-stats div:last-child { grid-column: auto; min-width: 86px; }
.review-heading-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.review-heading-row h2 { margin-bottom: 5px; }
#retry { flex: none; }
.review-bar { margin-top: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--inset); }
.review-bar summary { padding: 9px 11px; cursor: pointer; }
.review-bar summary span { margin-left: 8px; color: var(--muted); font-size: .875rem; }
.review-events { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 10px 10px; margin: 0; list-style: none; }
.review-events li { color: var(--muted); border: 1px solid #334139; border-radius: 5px; padding: 3px 7px; font-size: .875rem; }
.review-events li[data-state="on"] { color: var(--lime); }
.review-events li[data-state="early"] { color: var(--early); }
.review-events li[data-state="late"] { color: var(--late); }
.review-events li[data-state="missed"], .review-events li[data-state="extra"] { color: var(--missed); }
.site-footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 7px 10px; padding-block: 13px max(14px, env(safe-area-inset-bottom)); color: var(--muted); font-size: .8125rem; border-top: 1px solid #253027; }
.site-footer a:hover { color: var(--lime); }

@media (max-width: 880px) {
  .shell { width: calc(100% - 40px); }
  .arena { padding: 20px; }
  .practice-layout { grid-template-columns: minmax(0, 1fr) minmax(235px, 280px); gap: 13px; }
  .review-stats { grid-template-columns: repeat(3, minmax(80px, 1fr)); }
}

@media (max-width: 680px) {
  .shell { width: calc(100% - 28px); }
  .header-inner { min-height: 59px; grid-template-columns: 1fr auto; gap: 4px; }
  .brand { gap: 6px; }
  .brand-extra, .keyboard-hint, .tap-pad kbd { display: none; }
  .brand-mark { height: 29px; padding: 6px; }
  .main-nav a { padding: 6px 9px; }
  .view { padding-block: 21px 28px; }
  .page-intro { margin-bottom: 15px; }
  .page-intro p { font-size: .9375rem; margin-top: 6px; }
  .practice-layout, .import-layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .arena, .settings, .import-input, .import-preview, .review-detail { padding: 16px; }
  .arena-header { margin-bottom: 13px; }
  .track { padding: 9px; }
  .feedback { padding: 12px 0; }
  .live-stats { margin-top: 13px; padding-top: 9px; }
  .live-stats div { padding-inline: 7px; }
  .button { min-height: 48px; }
  .search-hit button { min-height: 44px; }
  .tap-pad { min-height: 68px; }
  .score-summary { grid-template-columns: 1fr; gap: 10px; padding: 16px; }
  .accuracy { border-right: 0; border-bottom: 1px solid var(--line); padding-bottom: 9px; }
  .review-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
}

@media (max-width: 360px) {
  .shell { width: calc(100% - 20px); }
  .main-nav a { padding-inline: 7px; }
  .arena, .settings, .import-input, .import-preview, .review-detail { padding: 13px; }
  .legend-dot { margin-right: 3px; }
  .segmented button { padding-inline: 8px; }
}
