:root {
  --bg: #0d0d0f;
  --bg-2: #16161a;
  --panel: #1c1c21;
  --panel-2: #232329;
  --line: #33333c;
  --text: #f2ede4;
  --text-dim: #8a8a94;
  --gold: #e2953b;
  --gold-2: #f0b45c;
  --gold-deep: #c47a28;
  --staff: #0f0f12;
  --shadow: 0 10px 40px rgba(0,0,0,0.5);
}

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

html, body {
  height: 100%;
  font-family: 'Bricolage Grotesque', sans-serif;
  background:
    radial-gradient(1000px 500px at 50% -20%, rgba(226,149,59,0.08), transparent),
    linear-gradient(180deg, #0d0d0f 0%, #08080a 100%);
  color: var(--text);
  overflow-y: auto;
}

#app {
  min-height: 100%;
  max-width: 620px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 16px 18px calc(20px + env(safe-area-inset-bottom));
  gap: 14px;
}

/* header */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-clef {
  font-size: 2.1rem;
  color: var(--gold);
  line-height: 1;
  text-shadow: 0 2px 10px rgba(226,149,59,0.4);
}
.brand-name {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: 1.55rem;
  letter-spacing: 0.01em;
  color: var(--text);
}
.best-badge {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 0.78rem;
  background: rgba(226,149,59,0.12);
  color: var(--gold-2);
  padding: 8px 14px;
  border-radius: 999px;
  border: 1.5px solid rgba(226,149,59,0.3);
  white-space: nowrap;
}

/* context chip */
.context-chip {
  align-self: flex-start;
  font-size: 0.82rem;
  font-weight: 400;
  color: var(--text-dim);
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 9px 16px;
  border-radius: 999px;
}

/* stage / staff */
#stage {
  display: flex;
  min-height: 300px;
}
.staff-frame {
  position: relative;
  flex: 1;
  min-height: 300px;
  background: linear-gradient(180deg, #1a1a1e, #131316);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
  padding-bottom: 54px;
}
#canvas { display: block; width: 100%; height: 100%; }

.staff-info {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px 18px;
  pointer-events: none;
}
.staff-note {
  font-family: 'Playfair Display', serif;
  font-weight: 600;
  font-size: 1.7rem;
  color: var(--gold);
  min-width: 1.5em;
}
.staff-meta {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  color: var(--text-dim);
  text-align: right;
}
.staff-meta span { color: var(--text); }

/* overlay (session summary) */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8,8,10,0.82);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.25s ease;
  z-index: 5;
}
.overlay.hidden { display: none; }
.ov-card {
  background: var(--panel);
  border-radius: 22px;
  padding: 28px 30px;
  text-align: center;
  max-width: 90%;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  animation: pop 0.35s cubic-bezier(.2,1.4,.4,1);
}
.ov-emoji { font-size: 3rem; }
.ov-card h2 { font-family: 'Playfair Display', serif; font-weight: 700; font-size: 1.5rem; margin-top: 8px; color: var(--text); }
.ov-fa { font-family: 'Vazirmatn'; direction: rtl; color: var(--text-dim); margin-bottom: 14px; }
.ov-score {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: 3.2rem;
  color: var(--gold);
  line-height: 1;
}
.ov-score span { font-size: 0.85rem; color: var(--text-dim); display: block; margin-top: 6px; font-family: 'Bricolage Grotesque'; }
.ov-best {
  margin: 12px 0;
  font-weight: 600;
  color: var(--gold-2);
  background: rgba(226,149,59,0.14);
  padding: 7px 14px;
  border-radius: 999px;
  display: inline-block;
}
.ov-praise { margin: 14px 0 20px; color: var(--text-dim); font-weight: 400; }

/* controls */
#controls { display: flex; flex-direction: column; gap: 14px; }

.btn-row { display: flex; gap: 12px; }
.big-btn {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 10px;
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 700;
  font-size: 1.02rem;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.big-btn:active { transform: translateY(2px) scale(0.99); }
.big-btn.primary {
  color: #1a1206;
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
  border-color: transparent;
  box-shadow: 0 8px 22px rgba(226,149,59,0.3);
}
.big-btn.primary.paused {
  background: linear-gradient(135deg, #4a4a52, #33333a);
  color: var(--text);
  box-shadow: none;
}
.big-btn.ghost {
  color: var(--text);
  background: var(--panel);
}
.big-btn.ghost:hover { background: var(--panel-2); }

.hint-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
}
.counter {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  color: var(--gold-2);
  font-weight: 700;
}
.space-hint {
  font-size: 0.82rem;
  color: var(--text-dim);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-label {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text);
}
.panel-label.sub { font-size: 0.9rem; color: var(--text-dim); margin-top: 4px; }
.bpm-display {
  font-family: 'Playfair Display', serif;
  font-style: italic;
  font-weight: 700;
  font-size: 1.9rem;
  color: var(--gold);
  letter-spacing: -0.01em;
}

input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--line);
  outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
  border: none;
  box-shadow: 0 2px 10px rgba(226,149,59,0.5);
  cursor: pointer;
}
input[type=range]::-moz-range-thumb {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--gold);
  border: none;
  cursor: pointer;
}

.toggle-row { display: flex; gap: 10px; }
.toggle {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text-dim);
  border-radius: 12px;
  padding: 13px;
  font-family: 'Bricolage Grotesque', sans-serif;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.toggle.on {
  background: rgba(226,149,59,0.14);
  border-color: rgba(226,149,59,0.5);
  color: var(--gold-2);
}
.toggle:active { transform: scale(0.97); }

/* footer */
#footer {
  text-align: center;
  padding: 6px 0 2px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.fa-sub {
  font-family: 'Vazirmatn', sans-serif;
  direction: rtl;
  font-size: 0.8rem;
  color: var(--text-dim);
}
#footer a {
  color: var(--gold-deep);
  font-size: 0.75rem;
  text-decoration: none;
  border-bottom: 1px dotted var(--gold-deep);
  align-self: center;
}
#footer a:hover { color: var(--gold); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }