/* UX V3 · tablet-first / mobile-first practice */

.music-term{
  display:inline;
  padding:0;
  border:0;
  border-bottom:1px dotted currentColor;
  background:transparent;
  color:inherit;
  font:inherit;
  cursor:help;
  text-decoration:none;
  line-height:inherit;
}
.music-term:hover,.music-term:focus{
  color:var(--accent-strong);
  border-bottom-style:solid;
  outline:none;
  background:rgba(37,99,235,.06);
  border-radius:3px;
}

.term-modal{
  position:fixed;
  inset:0;
  z-index:2500;
  display:grid;
  place-items:center;
  padding:20px;
  background:rgba(15,23,42,.55);
  backdrop-filter:blur(5px);
}
.term-modal[hidden]{display:none}
.term-sheet{
  width:min(680px,100%);
  max-height:min(760px,88vh);
  overflow:auto;
  position:relative;
  padding:24px;
  border-radius:22px;
  background:var(--panel);
  border:1px solid var(--border);
  box-shadow:0 28px 80px rgba(15,23,42,.22);
}
.term-sheet h2{text-transform:none;margin-bottom:10px}
.term-definition{font-size:17px;line-height:1.65}
.term-close{
  position:absolute;top:12px;right:12px;
  width:42px;height:42px;border-radius:12px;
  border:1px solid var(--border);background:#fff;font-size:22px;
}
.term-detail-grid{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-top:18px}
.term-detail-grid section{
  padding:13px;border:1px solid var(--border);border-radius:13px;background:var(--panel-soft)
}
.term-detail-grid section>span{
  display:block;text-transform:uppercase;letter-spacing:.08em;font-size:9px;color:var(--muted);font-weight:900
}
.term-detail-grid p{margin:5px 0 0;font-size:13px}
.term-etymology-wrap{grid-column:1/-1}
.term-modal-open{overflow:hidden}

.level-stage-divider{
  padding:12px 10px 4px;
  color:#7f8da0;
  font-size:9px;
  text-transform:uppercase;
  letter-spacing:.13em;
  font-weight:900;
}
.mobile-level-toggle{
  display:none;
  width:100%;
  min-height:46px;
  margin:0 0 10px;
  border:1px solid rgba(255,255,255,.15);
  border-radius:12px;
  background:rgba(255,255,255,.06);
  color:#fff;
  font-weight:800;
}
.stage-badge{
  display:inline-flex;
  margin:0 0 7px;
  padding:4px 7px;
  border-radius:999px;
  font-size:9px;
  font-weight:900;
  text-transform:uppercase;
  letter-spacing:.08em;
  background:rgba(96,165,250,.15);
  color:#b9d6ff;
}

.piano-scroll{
  width:100%;
  overflow-x:auto;
  overflow-y:hidden;
  overscroll-behavior-inline:contain;
  scrollbar-width:thin;
  -webkit-overflow-scrolling:touch;
}
.piano-scroll>.piano{margin-inline:0}
.piano.micro{height:150px;margin-top:10px}
.ear-instruction-v3{margin:10px 0 0}

.v3-score{height:245px!important}
.v3-staff line,.v3-score-event line{stroke:#3c444c;stroke-width:1.2}
.v3-score-event ellipse{fill:#303840}
.v3-score-event text{fill:#303840;font-size:10px}
.v3-score-event.past{opacity:.28}
.v3-score-event.active ellipse{fill:var(--accent)}
.v3-score-event.active line{stroke:var(--accent);stroke-width:2}
.v3-score-event.active .event-label{fill:var(--accent)}
.correct-hit{background:#86efac!important}
.pressed-in-chord{box-shadow:inset 0 0 0 3px #60a5fa!important}
.keep-score-visible.practice-no-help #practiceScore{
  filter:none!important;
  opacity:1!important;
  pointer-events:auto!important;
}
.modal-panel[data-practice-type="ear-match"] #practiceScore,
.modal-panel[data-practice-type="ear-chord"] #practiceScore{
  opacity:.35;
}

.touch-hint{
  display:none;
  font-size:11px;
  color:var(--muted);
  margin:4px 0 0;
}

@media (min-width:1001px){
  .topbar{
    position:sticky;
    top:0;
    z-index:20;
    padding:14px 0 12px;
    background:color-mix(in srgb,var(--bg) 90%,transparent);
    backdrop-filter:blur(12px);
  }
  .tabs{
    position:sticky;
    top:83px;
    z-index:19;
    padding:5px 0 12px;
    background:color-mix(in srgb,var(--bg) 92%,transparent);
    backdrop-filter:blur(12px);
  }
}

@media (max-width:1000px){
  :root{--sidebar:auto}
  .app-shell{display:block}
  .sidebar{
    position:sticky;
    top:0;
    z-index:40;
    height:auto;
    padding:10px 14px;
    background:rgba(17,24,39,.97);
    backdrop-filter:blur(14px);
  }
  .brand{margin-bottom:9px}
  .brand-mark{width:36px;height:36px;border-radius:11px}
  .level-summary{margin-bottom:8px;padding:10px 12px}
  .level-summary strong{display:inline;margin-left:6px}
  .level-summary .progress-track{margin-top:7px}
  .mobile-level-toggle{display:block}
  .level-nav{
    display:none;
    max-height:48vh;
    overflow:auto;
    padding:6px;
    border-radius:13px;
    background:#0d1420;
  }
  .sidebar.levels-open .level-nav{display:grid;grid-template-columns:repeat(2,minmax(0,1fr))}
  .sidebar.levels-open .mobile-level-toggle{background:#1d4ed8}
  .ghost-btn.danger{display:none}
  .main{padding-top:15px}
  .mini-map{display:none}
  .course-layout{grid-template-columns:1fr}
  .lesson-card{box-shadow:none}
  .touch-hint{display:block}
}

@media (max-width:760px){
  body{padding-bottom:calc(72px + env(safe-area-inset-bottom))}
  .main{padding:12px 12px 28px}
  .topbar{margin-bottom:10px}
  .topbar h1{font-size:23px}
  .top-stats{gap:5px}
  .top-stats div{min-width:0;padding:6px}
  .tabs{
    position:fixed;
    left:0;right:0;bottom:0;
    z-index:80;
    margin:0;
    padding:7px 8px calc(7px + env(safe-area-inset-bottom));
    background:rgba(17,24,39,.98);
    border-top:1px solid rgba(255,255,255,.1);
    overflow-x:auto;
    gap:4px;
    scroll-snap-type:x proximity;
    backdrop-filter:blur(16px);
  }
  .tab-btn{
    min-height:48px;
    min-width:max-content;
    border-color:rgba(255,255,255,.08);
    background:transparent;
    color:#aeb7c3;
    padding:9px 12px;
    scroll-snap-align:center;
  }
  .tab-btn.active{background:#2563eb;border-color:#2563eb;color:#fff}
  .lesson-card,.tool-card,.theory-card,.progress-hero,.project-video-card,.project-roadmap-card,
  .project-drills-card,.score-import-card,.project-notes-card,.reference-hero{
    border-radius:15px;
  }
  .lesson-card{padding:16px}
  .lesson-header{gap:9px}
  .lesson-actions{
    display:grid;
    grid-template-columns:1fr 1fr;
  }
  .lesson-actions>*{width:100%}
  .primary-btn,.secondary-btn,.mode-btn,.choice-btn,.icon-btn{min-height:48px}
  .icon-btn{width:48px;min-width:48px;flex:0 0 48px}
  .term-modal{
    align-items:end;
    padding:0;
  }
  .term-sheet{
    width:100%;
    max-height:86vh;
    border-radius:22px 22px 0 0;
    padding:22px 16px calc(20px + env(safe-area-inset-bottom));
  }
  .term-detail-grid{grid-template-columns:1fr}
  .term-etymology-wrap{grid-column:auto}

  .modal{
    padding:0;
    background:#fff;
  }
  .modal-panel,.modal-panel-wide{
    width:100%;
    min-height:100dvh;
    margin:0;
    border:0;
    border-radius:0;
    box-shadow:none;
    padding:12px 12px calc(84px + env(safe-area-inset-bottom));
  }
  .modal-head{
    position:sticky;
    top:0;
    z-index:15;
    margin:-12px -12px 10px;
    padding:12px;
    background:rgba(255,255,255,.96);
    border-bottom:1px solid var(--border);
    backdrop-filter:blur(12px);
  }
  .practice-mode-bar{
    position:sticky;
    top:74px;
    z-index:14;
    margin:0 -4px 8px;
    padding:5px 4px;
    background:rgba(255,255,255,.95);
    grid-template-columns:repeat(3,minmax(0,1fr));
    backdrop-filter:blur(10px);
  }
  .mode-btn{
    justify-content:center;
    padding:8px 5px;
    flex-direction:column;
    gap:3px;
    font-size:10px;
    text-align:center;
  }
  .mode-btn strong{width:24px;height:24px}
  .practice-visual-grid{gap:8px}
  .practice-score{min-height:116px}
  .v3-score{height:210px!important}
  .falling-lane{display:none}
  .practice-hud{
    position:sticky;
    bottom:0;
    z-index:13;
    margin:8px -12px 0;
    padding:7px 12px calc(7px + env(safe-area-inset-bottom));
    background:rgba(255,255,255,.96);
    border-top:1px solid var(--border);
    backdrop-filter:blur(12px);
  }
  .practice-hud span{padding:6px}
  .practice-hud strong{font-size:14px}
  .piano-scroll>.piano:not(.micro){min-width:680px}
  .piano-scroll>.piano.micro{min-width:420px}
  .piano.compact{height:190px}
  .practice-steps{
    flex-wrap:nowrap;
    overflow-x:auto;
    padding-bottom:4px;
    scroll-snap-type:x proximity;
  }
  .practice-step{flex:0 0 auto;scroll-snap-align:center}
  .theory-layout{display:block}
  .theory-nav{
    display:flex;
    overflow-x:auto;
    position:relative;
    padding:6px;
    gap:4px;
    margin-bottom:10px;
  }
  .theory-nav button{white-space:nowrap}
}

@media (max-width:480px){
  .sidebar.levels-open .level-nav{grid-template-columns:1fr}
  .lesson-actions{grid-template-columns:1fr}
  .practice-mode-bar{top:70px}
  .practice-hud{grid-template-columns:repeat(4,minmax(0,1fr))}
  .practice-hud span{font-size:8px;text-align:center}
  .practice-hud strong{font-size:12px}
  .project-meta{display:grid;grid-template-columns:1fr 1fr}
}

@media (orientation:landscape) and (max-height:620px) and (max-width:1000px){
  .sidebar{position:relative}
  .modal-panel,.modal-panel-wide{padding-top:8px}
  .practice-visual-grid{grid-template-columns:1.5fr .5fr}
  .piano.compact{height:145px}
}

.pwa-update-notice{
  position:fixed;
  z-index:200;
  right:24px;
  bottom:24px;
  width:min(520px,calc(100% - 48px));
  max-height:calc(100dvh - 160px);
  overflow:auto;
  padding:16px;
  border:1px solid #111827;
  border-radius:16px;
  box-shadow:0 6px 28px rgba(17,24,39,.16);
  background:#fff;
  color:#111827;
  display:flex;
  flex-direction:column;
  align-items:flex-start;
  gap:12px;
}
.pwa-update-notice[hidden]{display:none}
.pwa-update-notice p{margin:0;max-width:72ch}
.pwa-update-notice .button-row{flex-shrink:0;margin:0}
.pwa-update-notice button{min-width:44px;min-height:44px}
.pwa-update-notice button:focus-visible{outline:3px solid #111827;outline-offset:3px}
@media(max-width:700px){
  .pwa-update-notice{right:12px;bottom:calc(88px + env(safe-area-inset-bottom));width:calc(100% - 24px)}
  .pwa-update-notice .button-row{flex-wrap:wrap}
}
