/* Staff Notation Editor */
:root{ --cream:#faf5ec; --paper:#fffdf8; --ink:#221a12; --inksoft:#6f6152; --maroon:#0e386d; --gold:#0b7d74; --golddeep:#0a5f57; --line:#e8ddc9; --radius:16px; --err:#b23c17; }
*{ box-sizing:border-box; margin:0; padding:0; -webkit-tap-highlight-color:transparent; }
[hidden]{ display:none !important; }
html,body{ height:100%; }
body{ font-family:"Hanken Grotesk",system-ui,sans-serif; background:var(--cream); color:var(--ink); line-height:1.5; display:flex; flex-direction:column; min-height:100%; }
header.site{ display:flex; align-items:center; justify-content:space-between; padding:14px 18px; border-bottom:1.5px solid var(--line); background:var(--paper); }
header.site .brand{ font-family:"Fraunces",Georgia,serif; font-weight:900; font-size:20px; letter-spacing:-.02em; color:var(--maroon); text-decoration:none; }
header.site .brand span{ color:var(--gold); }
header.site .back{ font-size:13px; font-weight:700; color:var(--maroon); text-decoration:none; }
main{ width:100%; max-width:1120px; margin:0 auto; padding:22px 16px calc(40px + env(safe-area-inset-bottom)); }
h1.title{ font-family:"Fraunces",Georgia,serif; font-weight:900; font-size:28px; text-align:center; margin:2px 0 2px; }
.sub{ text-align:center; color:var(--inksoft); font-size:15px; margin:0 auto 18px; max-width:760px; }
code{ font-family:ui-monospace,"SF Mono",Menlo,Consolas,monospace; font-size:.92em; background:var(--cream); border:1px solid var(--line); border-radius:5px; padding:0 5px; color:var(--maroon); font-weight:600; }
kbd{ font:600 11px ui-monospace,Menlo,Consolas,monospace; background:#fff; border:1px solid var(--line); border-bottom-width:2px; border-radius:5px; padding:0 5px; color:var(--ink); }
.mus{ font-family:'Noto Music','Segoe UI Symbol',serif; font-weight:400; }

.app{ background:var(--paper); border:1.5px solid var(--line); border-radius:var(--radius); padding:14px; box-shadow:0 8px 24px -18px rgba(34,26,18,.5); }

/* top bar */
.topbar{ display:flex; flex-wrap:wrap; gap:7px; align-items:center; padding-bottom:12px; margin-bottom:12px; border-bottom:1.5px solid var(--line); }
.tb{ font:inherit; font-size:13.5px; font-weight:800; padding:8px 13px; border-radius:10px; border:1.5px solid var(--line); background:#fff; color:var(--maroon); cursor:pointer; list-style:none; white-space:nowrap; }
.tb::-webkit-details-marker{ display:none; }
.tb:hover{ border-color:var(--gold); }
.tb.primary{ background:var(--maroon); border-color:var(--maroon); color:#fff; }
.spacer{ flex:1 1 auto; }
.menu{ position:relative; }
.menu[open] > summary{ border-color:var(--gold); }
.menu-list{ position:absolute; z-index:30; top:calc(100% + 6px); left:0; min-width:250px; background:#fff; border:1.5px solid var(--line); border-radius:12px; box-shadow:0 14px 30px -14px rgba(34,26,18,.45); padding:6px; display:flex; flex-direction:column; }
.menu.right .menu-list{ left:auto; right:0; }
.menu-list button{ font:inherit; text-align:left; border:0; background:none; padding:8px 10px; border-radius:8px; cursor:pointer; display:flex; flex-direction:column; color:var(--ink); }
.menu-list button:hover, .menu-list button:focus-visible{ background:var(--cream); outline:none; }
.menu-list button b{ font-size:14px; color:var(--maroon); }
.menu-list button span{ font-size:12px; color:var(--inksoft); }

/* score details */
.meta{ display:flex; flex-wrap:wrap; gap:10px 12px; margin-bottom:12px; align-items:flex-end; }
.fld{ display:flex; flex-direction:column; gap:4px; }
.fld > label{ font-size:10.5px; font-weight:800; letter-spacing:.1em; text-transform:uppercase; color:var(--golddeep); }
.fld input, .fld select, .tin, .tsel{ font:inherit; font-size:14px; font-weight:600; padding:7px 9px; border:1.5px solid var(--line); border-radius:9px; background:#fff; color:var(--ink); }
.fld input:focus, .fld select:focus, .tin:focus, .tsel:focus, textarea:focus{ outline:none; border-color:var(--gold); box-shadow:0 0 0 3px rgba(11,125,116,.15); }
.fld.grow{ flex:1 1 200px; } .fld.grow input{ width:100%; }
.fld.sm input, .fld.sm select{ width:150px; } .fld.xs input, .fld.xs select{ width:96px; }
details.more{ align-self:flex-end; }
details.more > summary{ cursor:pointer; font-size:13px; font-weight:800; color:var(--maroon); padding:8px 4px; list-style:none; }
details.more > summary::after{ content:' ▾'; }
details.more[open] > summary::after{ content:' ▴'; }
.morebox{ display:flex; flex-wrap:wrap; gap:10px 12px; padding:8px 0 2px; }
details.more[open]{ flex-basis:100%; }

/* tools */
.tools{ border:1.5px solid var(--line); border-radius:12px; background:#fff; margin-bottom:10px; }
.tabs{ display:flex; gap:2px; padding:5px 5px 0; border-bottom:1.5px solid var(--line); overflow-x:auto; scrollbar-width:none; }
.tabs::-webkit-scrollbar{ display:none; }
.tab{ font:inherit; font-size:13px; font-weight:800; padding:8px 13px; border:0; border-radius:9px 9px 0 0; background:none; color:var(--inksoft); cursor:pointer; white-space:nowrap; border-bottom:2.5px solid transparent; margin-bottom:-1.5px; }
.tab:hover{ color:var(--maroon); }
.tab.on{ color:var(--maroon); border-bottom-color:var(--maroon); }
.tab.kbdtoggle{ margin-left:auto; }
.tab.kbdtoggle[aria-pressed="true"]{ color:var(--gold); border-bottom-color:var(--gold); }
.panel-t{ display:none; flex-wrap:wrap; gap:9px 16px; align-items:center; padding:10px 11px; }
.panel-t.on{ display:flex; }
.grp{ display:flex; align-items:center; gap:5px; flex-wrap:nowrap; }
.grp.wrap{ flex-wrap:wrap; }
.lbl{ font-size:10px; font-weight:800; letter-spacing:.1em; text-transform:uppercase; color:var(--golddeep); margin-right:3px; }
.pb{ font:inherit; font-size:15px; font-weight:700; line-height:1; min-width:34px; height:34px; padding:0 9px; border:1.5px solid var(--line); border-radius:9px; background:#fff; color:var(--ink); cursor:pointer; display:inline-flex; align-items:center; justify-content:center; gap:4px; white-space:nowrap; }
.pb.mus{ font-size:19px; }
.pb:hover{ border-color:var(--gold); }
.pb.on, .pb[aria-pressed="true"]{ background:var(--maroon); border-color:var(--maroon); color:#fff; }
.pb.wide{ min-width:auto; font-size:12.5px; font-weight:800; padding:0 11px; }
.pb.note{ font-family:ui-monospace,Menlo,Consolas,monospace; font-weight:800; }
.pb.dyn{ font-family:Georgia,serif; font-style:italic; font-weight:700; font-size:15px; }
.pb:disabled{ opacity:.4; cursor:default; }
.octval{ min-width:22px; text-align:center; font-weight:800; font-size:14px; }
.chk{ display:inline-flex; align-items:center; gap:6px; font-size:12.5px; font-weight:700; color:var(--inksoft); margin-left:4px; cursor:pointer; }
.chk input{ accent-color:var(--gold); width:15px; height:15px; }
.tin{ width:96px; } .tin.wide{ width:180px; } .tin.num{ width:76px; }
.stafflist{ display:flex; flex-direction:column; gap:6px; flex-basis:100%; }
.srow{ display:flex; flex-wrap:wrap; align-items:center; gap:6px 8px; padding:6px 8px; border:1.5px solid var(--line); border-radius:10px; background:var(--paper); }
.srow.act{ border-color:var(--gold); }
.srow .sn{ font-weight:800; font-size:13px; color:var(--maroon); min-width:58px; }
.srow input[type=text]{ width:130px; }

/* keyboard */
.kbd{ border-top:1.5px solid var(--line); background:#fff; padding:8px; border-radius:0 0 12px 12px; }
.kbd-bar{ display:flex; align-items:center; gap:8px; margin-bottom:6px; }
.kbd-hint{ flex:1 1 auto; font-size:12.5px; color:var(--inksoft); text-align:center; }
.keys{ position:relative; height:118px; display:flex; user-select:none; touch-action:manipulation; overflow:hidden; border-radius:0 0 8px 8px; }
.wk{ flex:1 1 0; min-width:0; border:1px solid #cfc4b2; border-top:0; background:linear-gradient(#fff,#f7f2e8); border-radius:0 0 6px 6px; position:relative; cursor:pointer; display:flex; align-items:flex-end; justify-content:center; padding-bottom:5px; font:700 10px "Hanken Grotesk",sans-serif; color:#a49580; }
.wk.c{ color:var(--maroon); }
.bk{ position:absolute; top:0; height:62%; background:linear-gradient(#3b3128,#16110c); border-radius:0 0 5px 5px; cursor:pointer; z-index:2; box-shadow:0 2px 3px rgba(0,0,0,.3); }
.wk.down{ background:#d8efe9; } .bk.down{ background:var(--gold); }

/* transport */
.transport{ display:flex; flex-wrap:wrap; gap:7px 9px; align-items:center; margin:2px 0 6px; }
.btn{ font:inherit; font-size:13.5px; font-weight:800; padding:8px 15px; border-radius:11px; border:1.5px solid var(--maroon); background:var(--maroon); color:#fff; cursor:pointer; }
.btn.stop{ background:#fff; color:var(--inksoft); border-color:var(--line); }
.btn.play.on{ background:var(--gold); border-color:var(--gold); }
.tog{ display:inline-flex; align-items:center; gap:5px; font-size:12.5px; font-weight:800; color:var(--inksoft); cursor:pointer; padding:6px 9px; border:1.5px solid var(--line); border-radius:10px; background:#fff; user-select:none; }
.tog input{ accent-color:var(--gold); width:14px; height:14px; }
.tog:has(input:checked){ border-color:var(--gold); color:var(--golddeep); }
.tog.off{ opacity:.45; }
.zoom{ display:flex; align-items:center; gap:4px; font-size:12.5px; font-weight:800; color:var(--inksoft); }
.zoom span{ min-width:42px; text-align:center; }

.status{ display:flex; flex-wrap:wrap; align-items:center; gap:4px 14px; min-height:26px; margin:0 2px 6px; font-size:12.5px; color:var(--inksoft); }
.status .selname{ font-weight:800; color:var(--gold); }
.status .keys2{ line-height:2; }
.status .warn{ font-weight:700; color:var(--err); cursor:pointer; }
.status .warn:hover{ text-decoration:underline; }

/* the staff */
.sheetwrap{ position:relative; }
.sheet{ background:#fffef9; border:1.5px solid var(--line); border-radius:var(--radius); padding:6px 0; overflow:auto; max-height:78vh; box-shadow:0 8px 24px -18px rgba(34,26,18,.5); outline:none; }
.sheet:focus-visible{ box-shadow:0 0 0 3px rgba(11,125,116,.35), 0 8px 24px -18px rgba(34,26,18,.5); }
.sheet svg{ display:block; width:100%; height:auto; cursor:crosshair; user-select:none; -webkit-user-select:none; }
/* selecting and playing recolour the ink only, so hollow note heads stay hollow */
.nt{ cursor:pointer; touch-action:none; }
.nt:not(.rest).sel{ cursor:ns-resize; }
.nt .hit{ transition:fill .12s; }
.nt:hover .hit{ fill:rgba(11,125,116,.08); }
.nt.sel .hit{ fill:rgba(11,125,116,.16); }
.nt.sel [fill="#221a12"]{ fill:#0b7d74; }
.nt.sel [stroke="#221a12"]{ stroke:#0b7d74; }
.nt.play [fill="#221a12"]{ fill:#c2410c; }
.nt.play [stroke="#221a12"]{ stroke:#c2410c; }
.staff.act ~ .staff, .staff{ }
.ovl{ position:absolute; z-index:20; display:flex; flex-direction:column; align-items:flex-start; gap:2px; transform:translate(-4px,-50%); }
.ovl input{ font:600 15px Georgia,serif; padding:3px 7px; width:120px; border:2px solid var(--gold); border-radius:7px; background:#fff; color:var(--ink); box-shadow:0 6px 16px -8px rgba(0,0,0,.4); outline:none; }
.ovl.chord input{ font:700 15px "Hanken Grotesk",sans-serif; }
.ovl span{ font-size:11px; font-weight:700; color:var(--golddeep); background:rgba(255,253,248,.92); border-radius:5px; padding:0 4px; white-space:nowrap; }
.msg{ font-size:12.5px; font-weight:700; color:#2e7d54; min-height:18px; margin:6px 2px 0; }
.msg.err{ color:var(--err); }

/* text behind the staff */
.editors{ margin-top:10px; }
.stabs{ display:flex; gap:4px; flex-wrap:wrap; margin-bottom:6px; }
.stab{ font:inherit; font-size:12.5px; font-weight:800; padding:5px 11px; border-radius:999px; border:1.5px solid var(--line); background:#fff; color:var(--inksoft); cursor:pointer; }
.stab.on{ background:var(--maroon); border-color:var(--maroon); color:#fff; }
.edrow{ display:grid; grid-template-columns:3fr 2fr; gap:10px; }
.ed{ display:flex; flex-direction:column; gap:5px; min-width:0; }
.ed label{ font-size:10.5px; font-weight:800; letter-spacing:.1em; text-transform:uppercase; color:var(--golddeep); }
.ed label span{ text-transform:none; letter-spacing:0; font-weight:600; color:var(--inksoft); font-size:12px; }
textarea{ font-family:ui-monospace,"SF Mono",Menlo,Consolas,monospace; font-size:14px; line-height:1.65; padding:9px 11px; border:1.5px solid var(--line); border-radius:12px; background:#fff; color:var(--ink); resize:vertical; width:100%; min-height:92px; }
#lyrics{ font-family:Georgia,serif; font-size:15px; }

details.legend{ margin-top:14px; border:1.5px solid var(--line); border-radius:12px; padding:12px 14px; background:#fff; }
details.legend summary{ cursor:pointer; font-weight:800; color:var(--maroon); font-size:14px; }
.legend-cols{ display:grid; grid-template-columns:repeat(auto-fit,minmax(300px,1fr)); gap:4px 22px; margin-top:8px; }
.legend table{ border-collapse:collapse; font-size:13px; width:100%; }
.legend th{ text-align:left; font-size:11px; font-weight:800; letter-spacing:.1em; text-transform:uppercase; color:var(--golddeep); padding:8px 6px 4px; }
.legend td{ padding:4px 6px; border-bottom:1px solid var(--line); vertical-align:top; }
.legend td:first-child{ white-space:nowrap; }

dialog.dlg{ border:1.5px solid var(--line); border-radius:16px; padding:18px 20px; background:var(--paper); color:var(--ink); box-shadow:0 30px 60px -20px rgba(0,0,0,.45); margin:auto; max-width:min(440px, calc(100vw - 32px)); }
dialog.dlg::backdrop{ background:rgba(34,26,18,.35); }
.dlg h3{ font-family:"Fraunces",Georgia,serif; font-size:20px; margin-bottom:12px; }
.dlgrow{ display:flex; flex-wrap:wrap; gap:8px; align-items:center; margin-bottom:10px; }
.dlgrow select{ font:inherit; font-size:14px; font-weight:600; padding:6px 8px; border:1.5px solid var(--line); border-radius:9px; background:#fff; }
.rad{ display:inline-flex; gap:6px; align-items:center; font-weight:800; font-size:14px; min-width:74px; }
.rad input{ accent-color:var(--gold); }
.dlgbtns{ display:flex; justify-content:flex-end; gap:8px; margin-top:14px; }

.panel{ background:var(--paper); border:1.5px solid var(--line); border-radius:var(--radius); padding:18px 20px 20px; margin-top:22px; }
.panel h2{ font-family:"Fraunces",Georgia,serif; font-size:20px; margin:0 0 8px; }
.panel p, .panel li{ color:var(--inksoft); font-size:14.5px; margin-bottom:10px; }
.panel a{ color:var(--maroon); font-weight:700; }
.howto{ padding-left:22px; }
.howto li{ margin-bottom:7px; }
.step-label{ font-size:11px; font-weight:800; letter-spacing:.12em; text-transform:uppercase; color:var(--golddeep); margin-bottom:8px; }
.panel details{ border-top:1.5px solid var(--line); padding:11px 0; }
.panel details summary{ cursor:pointer; font-weight:700; font-size:14.5px; }
.panel details p{ margin:8px 0 0; }
footer{ text-align:center; color:var(--inksoft); font-size:13px; padding:24px 16px 30px; margin-top:auto; }
footer a{ color:var(--maroon); }
#printarea{ display:none; }

@media (max-width:760px){
  .edrow{ grid-template-columns:1fr; }
}
@media (max-width:560px){
  main{ padding:16px 10px calc(40px + env(safe-area-inset-bottom)); }
  /* on a phone the staff comes first and the tools stay at the bottom of the screen */
  .app{ display:flex; flex-direction:column; }
  .topbar{ order:1; gap:6px; } .meta{ order:2; } .transport{ order:3; } .status{ order:4; } .sheetwrap{ order:5; } .msg{ order:6; }
  .tools{ order:7; position:sticky; bottom:0; z-index:25; margin:8px 0 0; box-shadow:0 -12px 26px -16px rgba(34,26,18,.55); }
  .editors{ order:8; } details.legend{ order:9; }
  .tl{ display:none; }
  .panel-t.on{ flex-wrap:nowrap; overflow-x:auto; scrollbar-width:none; padding:8px; gap:14px; }
  .panel-t.on::-webkit-scrollbar{ display:none; }
  .panel-t .grp, .panel-t .grp.wrap{ flex:none; flex-wrap:nowrap; }
  .panel-t.on[data-panel="staves"]{ flex-wrap:wrap; max-height:46vh; overflow-y:auto; }
  .panel-t.on[data-panel="staves"] .grp{ flex-wrap:wrap; }
  .fld.grow{ flex-basis:100%; }
  .fld.xs{ flex:1 1 90px; } .fld.xs input, .fld.xs select{ width:100%; }
  .keys{ height:96px; }
  h1.title{ font-size:22px; }
  .app{ padding:10px; }
  .fld.sm input, .fld.sm select{ width:100%; } .fld.sm{ flex:1 1 140px; }
  .tb{ padding:7px 10px; font-size:13px; }
  .panel-t{ gap:8px 10px; }
  .tab{ padding:8px 10px; }
  .sheet{ max-height:none; }
}
@media print{
  @page{ margin:0; }
  body > *:not(#printarea){ display:none !important; }
  #printarea{ display:block !important; }
  #printarea svg{ display:block; width:100%; height:auto; page-break-after:always; break-after:page; }
  #printarea svg:last-child{ page-break-after:auto; break-after:auto; }
  body{ background:#fff; }
}
