:root {
  --bg: #14161a; --bg2: #1e2126; --bg3: #2a2e35; --fg: #e8e8e8; --dim: #9aa0a8;
  --accent: #f2c14e; --accent2: #e05a4e; --ok: #5ec46a;
  --hl: rgba(242,193,78,.28); --hl-border: rgba(242,193,78,.95); --loop: rgba(94,196,106,.16);
  --bar-h: 48px; --sec-h: 40px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); overflow: hidden; -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
#app { position: relative; height: 100%; height: 100dvh; display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
button { font: inherit; color: var(--fg); background: var(--bg3); border: 1px solid #3a3f47; border-radius: 8px; padding: 6px 10px; cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: manipulation; min-height: 36px; }
button:active { transform: translateY(1px); }
button.icon { width: 44px; height: 40px; padding: 0; font-size: 18px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; flex: none; }
button.icon.big { width: 60px; height: 42px; font-size: 22px; background: var(--accent); color: #111; border-color: var(--accent); }
button.icon.small { width: 36px; height: 36px; font-size: 16px; }
button.toggle.on { background: var(--accent); color: #111; border-color: var(--accent); }
button.text { background: none; border-color: transparent; padding: 4px 6px; color: var(--fg); }
#app.counting #playBtn { background: var(--accent2); border-color: var(--accent2); }
select { font: inherit; color: var(--fg); background: var(--bg3); border: 1px solid #3a3f47; border-radius: 8px; padding: 6px 8px; min-height: 36px; }
#top select { flex: 1 1 0; min-width: 0; max-width: none; text-overflow: ellipsis; }
.spacer { flex: 0 0 4px; }
.dim { color: var(--dim); }
.hint { color: var(--dim); font-size: 12px; margin: 6px 0; }
input[type=range] { height: 36px; margin: 0; }
input[type=checkbox] { width: 20px; height: 20px; }

#top { display: flex; gap: 6px; align-items: center; padding: 4px 8px; background: var(--bg2); height: var(--bar-h); flex: none; }
#score { flex: 1; overflow: auto; position: relative; background: #0e0f12; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y; }
#strips { padding: 6px 6px 40vh 6px; width: max-content; min-width: 100%; }
.strip { position: relative; margin: 0 auto 6px auto; background-repeat: no-repeat; background-color: #fff; border-radius: 4px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.strip.current { box-shadow: 0 0 0 2px var(--accent); }
.strip .label { position: absolute; left: 4px; top: 2px; font-size: 10px; color: #777; pointer-events: none; }
.bar { position: absolute; cursor: pointer; border-radius: 3px; touch-action: manipulation; }
@media (hover: hover) { .bar:hover { background: rgba(0,0,0,.05); } }
.bar:active { background: rgba(0,0,0,.08); }
.bar.loop { background: var(--loop); }
.bar.loopA { outline: 2px dashed var(--ok); outline-offset: -2px; }
.bar.on { background: var(--hl); outline: 2px solid var(--hl-border); outline-offset: -2px; }
.bar.on.loop { background: rgba(160,200,90,.32); }
#app.counting .bar.on { animation: pulse .5s ease-in-out infinite alternate; }
@keyframes pulse { from { outline-color: var(--hl-border); } to { outline-color: var(--accent2); } }
#cursor { position: absolute; top: 0; width: 2px; background: var(--accent2); pointer-events: none; display: none; }
#app.playing #cursor { display: block; }
.overlay-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--dim); font-size: 18px; pointer-events: none; text-align: center; padding: 20px; }
.overlay-msg.error { color: #ff9d94; background: rgba(14,15,18,.75); pointer-events: auto; }
.banner { position: sticky; top: 6px; margin: 0 8px; float: right; z-index: 5; background: rgba(94,196,106,.92); color: #0b1a0e; border-radius: 10px; padding: 6px 10px; font-weight: 600; display: flex; gap: 8px; align-items: center; box-shadow: 0 2px 10px rgba(0,0,0,.4); }
.banner button { min-height: 28px; padding: 2px 8px; background: #0b1a0e; color: #fff; border: none; }
#countOverlay { position: sticky; top: 30%; float: right; margin-right: 12%; z-index: 6; font-size: 96px; font-weight: 800; color: var(--accent); text-shadow: 0 2px 12px rgba(0,0,0,.7); pointer-events: none; line-height: 1; }

#sections { display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden; padding: 4px 8px; background: var(--bg2); height: var(--sec-h); flex: none; align-items: center; scrollbar-width: none; overscroll-behavior-x: contain; }
#sections::-webkit-scrollbar { display: none; }
.chip { flex: none; border-radius: 16px; padding: 4px 12px; font-size: 13px; background: var(--bg3); border: 1px solid #3a3f47; min-height: 30px; touch-action: manipulation; -webkit-touch-callout: none; }
.chip.tempo { font-style: italic; }
.chip.current { background: var(--accent); color: #111; border-color: var(--accent); }
.chip.loop { border-color: var(--ok); box-shadow: inset 0 0 0 1px var(--ok); }

#transport { display: flex; gap: 6px; align-items: center; padding: 4px 8px; background: var(--bg2); min-height: calc(var(--bar-h) + 6px); flex: none; flex-wrap: wrap; }
#transport > button { flex: none; }
#pos { display: flex; flex-direction: column; min-width: 90px; line-height: 1.1; flex: 1 1 90px; }
#posMeasure { font-weight: 700; font-size: 15px; }
#posInfo { font-size: 11px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
#tempoBox { display: flex; align-items: center; gap: 4px; }
#tempoRange { width: 120px; }
#tempoLabel { min-width: 52px; text-align: right; font-variant-numeric: tabular-nums; }
#timeBox { font-variant-numeric: tabular-nums; color: var(--dim); font-size: 12px; margin-left: auto; }
#loopBtn { touch-action: none; -webkit-touch-callout: none; }

.panel { position: absolute; right: 8px; top: calc(var(--bar-h) + 8px); width: min(480px, calc(100% - 16px)); max-height: calc(100% - var(--bar-h) - 16px); overflow: auto; overscroll-behavior: contain; background: var(--bg2); border: 1px solid #3a3f47; border-radius: 12px; padding: 10px 12px; z-index: 20; box-shadow: 0 8px 30px rgba(0,0,0,.6); }
.panel.intro { left: 50%; right: auto; top: 50%; transform: translate(-50%, -50%); width: min(520px, calc(100% - 24px)); }
.panel.intro ul { padding-left: 18px; margin: 6px 0 12px; line-height: 1.5; }
.panel-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.panel-head .close { margin-left: auto; }
.panel label { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.panel label.inline { display: inline-flex; margin: 0; }
.panel label > input[type=range] { flex: 1; }
.panel .row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0; }
#anchorList { max-height: 200px; overflow: auto; overscroll-behavior: contain; font-size: 12px; font-variant-numeric: tabular-nums; }
#anchorList table { border-collapse: collapse; width: 100%; }
#anchorList th { text-align: left; color: var(--dim); font-weight: normal; padding: 2px 4px; }
#anchorList td { padding: 2px 4px; border-bottom: 1px solid #2a2e35; }
#anchorList button { padding: 2px 8px; font-size: 12px; min-height: 30px; }
#anchorList tr.cur td { color: var(--accent); }
#syncJson { flex: 1 1 160px; font: 13px monospace; background: var(--bg); color: var(--fg); border: 1px solid #3a3f47; border-radius: 6px; }
#tapArea { text-align: center; margin: 4px 0 10px; }
#tapBtn { width: 100%; height: 84px; font-size: 30px; font-weight: 800; background: var(--accent2); border-color: var(--accent2); touch-action: none; -webkit-touch-callout: none; }
#tapNext { font-size: 16px; margin: 4px 0; }
#toast { position: absolute; left: 50%; bottom: 70px; transform: translateX(-50%); background: #000c; color: #fff; padding: 8px 14px; border-radius: 10px; z-index: 30; pointer-events: none; max-width: 90%; text-align: center; }

@media (pointer: coarse) {
  #syncJson { font-size: 16px; }
  .panel select, .panel input[type=text] { font-size: 16px; }
}
@media (max-height: 460px) {
  :root { --bar-h: 44px; --sec-h: 36px; font-size: 13px; }
  button.icon { height: 40px; width: 42px; }
  button.icon.big { height: 42px; width: 54px; }
  #tempoRange { width: 90px; }
  #posInfo { display: none; }
  #pos { min-width: 56px; flex-basis: 56px; }
  #countOverlay { font-size: 72px; top: 20%; }
  .panel { top: 4px; max-height: calc(100% - 8px); }
  #strips { padding-bottom: 60vh; }
}
@media (max-width: 700px) {
  #timeBox { display: none; }
  #tempoRange { display: none; }
  #top select { font-size: 12px; }
  #pos { min-width: 56px; flex-basis: 56px; }
}
