:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --line: #dfe3e8;
  --text: #18202a;
  --muted: #667085;
  --primary: #2767d8;
  --primary-soft: #edf4ff;
  --danger: #b42318;
  --shadow: 0 12px 35px rgba(24, 32, 42, .10);
}
* { box-sizing: border-box; }
html { background: var(--bg); color: var(--text); font-family: Arial, "Noto Sans KR", sans-serif; }
body { margin: 0; min-width: 320px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
.app-shell { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  min-height: 74px; padding: 13px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.brand h1 { margin: 0; font-size: 21px; letter-spacing: -.03em; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.top-actions, .button-row { display: flex; gap: 7px; flex-wrap: wrap; }
.button {
  min-height: 36px; padding: 8px 12px; border: 1px solid #cfd5dd; border-radius: 8px;
  background: #fff; color: #1f2937; font-weight: 700; font-size: 13px;
}
.button:hover:not(:disabled) { background: #f8fafc; }
.button.primary { color: #fff; border-color: var(--primary); background: var(--primary); }
.button.primary:hover:not(:disabled) { background: #1f58bb; }
.button.ghost { background: #fff; }
.button.danger { color: var(--danger); }
.button.wide { width: 100%; }
.button.grow { flex: 1; }
.workspace { display: grid; grid-template-columns: 324px minmax(0, 1fr); min-height: calc(100vh - 74px); }
.panel {
  position: sticky; top: 74px; align-self: start; max-height: calc(100vh - 74px); overflow-y: auto;
  background: var(--panel); border-right: 1px solid var(--line); padding: 13px 15px 28px;
}
.tool-section { padding: 13px 0 15px; border-bottom: 1px solid #eceff3; }
.tool-section:last-child { border-bottom: 0; }
.tool-section h2 { margin: 0 0 11px; font-size: 14px; letter-spacing: -.02em; }
.tool-section label { display: block; margin: 9px 0 0; color: #404958; font-size: 12px; font-weight: 700; }
.tool-section input[type="text"], .tool-section select {
  width: 100%; height: 36px; margin-top: 5px; padding: 0 9px; border: 1px solid #d7dce3; border-radius: 7px; background: #fff; color: #1d2733;
}
.tool-section input[type="range"] { width: 100%; margin: 8px 0 0; accent-color: var(--primary); }
.tool-section.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 9px; }
.tool-section.two-col h2 { grid-column: 1 / -1; }
.two-col.compact { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.help { margin: 9px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.upload-box {
  display: block !important; margin: 0 !important; padding: 14px 12px; border: 1.5px dashed #aeb7c5; border-radius: 10px;
  text-align: center; background: #fafcff; cursor: pointer;
}
.upload-box:hover { border-color: var(--primary); background: var(--primary-soft); }
.upload-box strong { display: block; color: #273444; font-size: 13px; }
.upload-box span { display: block; margin-top: 5px; color: var(--muted); font-size: 10.5px; line-height: 1.45; }
.file-name { margin: 8px 0 9px; color: #475467; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.source-preview {
  position: relative; min-height: 120px; max-height: 235px; overflow: hidden; border: 1px solid #e0e5eb; border-radius: 9px; background: #f8fafc;
  display: flex; align-items: center; justify-content: center;
}
.source-preview img { display: block; width: 100%; max-height: 235px; object-fit: contain; background: #fff; }
.source-preview .source-empty { padding: 20px; text-align: center; color: #89919d; font-size: 11px; line-height: 1.5; }
.source-preview:not(.empty) .source-empty { display: none; }
.source-preview.empty img { display: none; }
.image-actions { margin-top: 10px; }
.analysis-status { margin-top: 10px; padding: 9px 10px; border-radius: 8px; background: #f2f4f7; color: #475467; font-size: 11px; line-height: 1.5; }
.analysis-status.working { background: #fff7e6; color: #8a4b00; }
.analysis-status.success { background: #ecfdf3; color: #027a48; }
.analysis-status.error { background: #fef3f2; color: #b42318; }
.duration-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.duration-grid button {
  position: relative; min-height: 58px; padding: 7px 2px 4px; border: 1px solid #d8dde5; border-radius: 8px; background: #fff;
}
.duration-grid button.active { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }
.duration-grid small { display: block; margin-top: 4px; font-size: 9px; color: #5d6675; }
.note-icon { position: relative; display: inline-block; width: 18px; height: 23px; }
.note-icon::before { content: ""; position: absolute; left: 3px; bottom: 2px; width: 10px; height: 7px; border: 2px solid #111; border-radius: 50%; transform: rotate(-15deg); }
.note-icon.filled::before { background: #111; }
.note-icon.stem::after { content: ""; position: absolute; width: 2px; height: 18px; background: #111; left: 12px; top: 0; }
.note-icon.flag { background-image: linear-gradient(135deg, transparent 51%, #111 52%, #111 58%, transparent 59%); background-size: 10px 10px; background-repeat: no-repeat; background-position: 11px 1px; }
.inline-controls { display: flex; gap: 12px; margin-top: 9px; }
.check { display: inline-flex !important; align-items: center; gap: 5px; margin: 9px 0 0 !important; font-weight: 600 !important; }
.check input { accent-color: var(--primary); }
.editor-area { min-width: 0; padding: 15px 18px 42px; }
.editor-status {
  position: sticky; top: 86px; z-index: 20; display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  width: fit-content; max-width: 100%; margin: 0 auto 12px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 999px;
  background: rgba(255,255,255,.94); box-shadow: 0 5px 18px rgba(0,0,0,.06); color: #445064; font-size: 11px;
}
.keyboard-hint { color: #7c8593; }
.score-pages { display: flex; flex-direction: column; align-items: center; gap: 22px; }
.score-page {
  position: relative; width: min(100%, 900px); aspect-ratio: 210 / 297; background: white; box-shadow: var(--shadow); overflow: hidden;
}
.score-page svg { display: block; width: 100%; height: 100%; }
.score-page .clickable-measure { cursor: crosshair; }
.score-page .note-hit { cursor: pointer; }
.score-page .measure-selected { fill: rgba(39, 103, 216, .035); stroke: rgba(39, 103, 216, .55); stroke-width: 1.5; stroke-dasharray: 5 4; }
.score-page .note-selected { stroke: #2767d8 !important; fill: #2767d8 !important; }
.analysis-canvas { display: none; }
.toast {
  position: fixed; left: 50%; bottom: 26px; z-index: 100; transform: translateX(-50%) translateY(12px);
  padding: 10px 14px; border-radius: 9px; background: #111827; color: #fff; font-size: 13px; opacity: 0; pointer-events: none;
  transition: .18s ease; box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.saved-dialog { width: min(650px, calc(100vw - 28px)); border: 0; border-radius: 14px; padding: 0; box-shadow: 0 24px 70px rgba(0,0,0,.28); }
.saved-dialog::backdrop { background: rgba(15, 23, 42, .55); }
.dialog-head { display: flex; justify-content: space-between; gap: 15px; padding: 18px 18px 13px; border-bottom: 1px solid #e4e7ec; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.icon-button { border: 0; background: transparent; font-size: 25px; color: #687180; }
.saved-list { padding: 10px 14px 16px; max-height: 58vh; overflow-y: auto; }
.saved-item { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 11px 5px; border-bottom: 1px solid #eceef2; }
.saved-title { font-weight: 750; }
.saved-meta { margin-top: 3px; color: var(--muted); font-size: 11px; }
.saved-actions { display: flex; gap: 5px; align-items: center; }
.empty-state { padding: 25px 10px; text-align: center; color: var(--muted); font-size: 13px; }

@media (max-width: 980px) {
  .topbar { position: static; align-items: flex-start; }
  .workspace { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
  .image-section { grid-row: span 2; }
  .editor-status { top: 8px; }
}
@media (max-width: 640px) {
  .topbar { display: block; padding: 12px; }
  .top-actions { margin-top: 10px; }
  .workspace { display: block; }
  .panel { display: block; padding: 12px; }
  .editor-area { padding: 12px 6px 28px; }
  .score-pages { gap: 12px; }
  .score-page { width: 100%; }
  .keyboard-hint { display: none; }
}

@page { size: A4 portrait; margin: 0; }
@media print {
  html, body { width: 210mm; background: #fff !important; }
  .no-print { display: none !important; }
  .workspace, .editor-area, .score-pages { display: block; padding: 0; margin: 0; }
  .score-page { width: 210mm; height: 297mm; aspect-ratio: auto; box-shadow: none; margin: 0; page-break-after: always; break-after: page; }
  .score-page:last-child { page-break-after: auto; break-after: auto; }
  .score-page .measure-selected { fill: transparent; stroke: transparent; }
  .score-page .note-selected { stroke: #111 !important; fill: #111 !important; }
}
