:root {
  --bg: #f4f1ea;
  --text: #181818;
  --muted: #666666;
  --line: rgba(0, 0, 0, 0.14);
  --card: rgba(255, 255, 255, 0.72);
  --ok: #1f7a3f;
  --warn: #9a6a00;
  --error: #b3261e;
  --selected: #1d4ed8;
  --playhead: #e11d48;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family:
    -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Yu Gothic", "YuGothic",
    "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}

.page {
  width: min(1416px, calc(100% - 32px));
  margin: 0 auto;
  padding: 64px 0 88px;
}

.checker-header {
  padding: 56px 0 48px;
  border-bottom: 1px solid var(--line);
}

.top-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.back-link {
  display: inline-block;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
}

.back-link:hover { color: var(--text); }

.language-control,
.tempo-control,
.timbre-control,
.playback-control,
.exercise-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.65);
  color: var(--muted);
  font-size: 0.86rem;
}

.language-control select,
.tempo-control input,
.timbre-control select,
.playback-control select,
.exercise-control select {
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  outline: none;
}

.tempo-control input { width: 70px; }
.timbre-control select, .playback-control select { min-width: 150px; }
.exercise-control select { min-width: 220px; }

.eyebrow {
  margin: 0 0 12px;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 0;
  font-size: clamp(2.1rem, 6vw, 4.8rem);
  line-height: 1.05;
  letter-spacing: -0.06em;
}

h2 {
  margin: 0 0 16px;
  font-size: 1.2rem;
  line-height: 1.25;
  letter-spacing: -0.03em;
}

.lead {
  max-width: 860px;
  margin: 24px 0 0;
  font-size: 1.05rem;
  color: var(--muted);
}

.checker-panel, .result-section {
  margin-top: 36px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 28px;
}

.hidden-input {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.score-tools, .playback-tools, .exercise-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 8px 0 22px;
  align-items: center;
}

.playback-tools, .exercise-tools {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.5);
}

.playback-hint, .exercise-description {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.exercise-description {
  flex: 1;
  min-width: 220px;
}

.level-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  margin-right: 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.65);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.level-badge.beginner {
  color: #1f7a3f;
  border-color: rgba(31, 122, 63, 0.32);
  background: rgba(31, 122, 63, 0.08);
}

.level-badge.intermediate {
  color: #9a6a00;
  border-color: rgba(154, 106, 0, 0.32);
  background: rgba(154, 106, 0, 0.08);
}

.level-badge.advanced {
  color: #7c2d12;
  border-color: rgba(124, 45, 18, 0.32);
  background: rgba(124, 45, 18, 0.08);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 22px;
  border-radius: 999px;
  border: 1px solid var(--text);
  background: transparent;
  color: var(--text);
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.button:hover { transform: translateY(-1px); }
.button.primary { background: var(--text); color: #ffffff; }
.button.small { min-height: 38px; padding: 0 16px; font-size: 0.86rem; }

.score-box {
  margin: 26px 0 30px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.68);
}

.score-head {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.score-head h2 { margin: 0 0 4px; }
.score-head p { margin: 0; color: var(--muted); font-size: 0.92rem; }

.score-status {
  font-size: 0.86rem;
  color: var(--muted);
  white-space: nowrap;
}

.score-editor {
  width: 100%;
  min-height: 432px;
  display: block;
  border-radius: 18px;
  background: #ffffff;
  cursor: crosshair;
  user-select: none;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.score-editor:focus {
  outline: 2px solid rgba(29, 78, 216, 0.35);
  outline-offset: 4px;
}

.staff-line { stroke: #181818; stroke-width: 1.2; }
.measure-line { stroke: rgba(0, 0, 0, 0.26); stroke-width: 1.15; }
.subdivision-line { stroke: rgba(0, 0, 0, 0.11); stroke-width: 0.8; }
.ledger-line { stroke: #181818; stroke-width: 1.1; }
.slot-marker { fill: rgba(0, 0, 0, 0.12); }
.downbeat-marker { fill: rgba(0, 0, 0, 0.24); }
.voice-label { font-size: 13px; fill: rgba(0, 0, 0, 0.62); font-weight: 600; }

.note-label {
  font-size: 12px;
  fill: rgba(0, 0, 0, 0.64);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.note-label.selected { fill: var(--selected); font-weight: 700; }
.note-label.playing { fill: var(--playhead); font-weight: 700; }

.note-head {
  fill: #181818;
  stroke: #181818;
  stroke-width: 1;
}

.note-head.cantus {
  fill: rgba(0, 0, 0, 0.35);
  stroke: rgba(0, 0, 0, 0.35);
}

.note-head.selected { fill: var(--selected); stroke: var(--selected); }
.note-head.playing { fill: var(--playhead); stroke: var(--playhead); }

.note-stem { stroke: #181818; stroke-width: 1.4; }
.note-stem.cantus { stroke: rgba(0, 0, 0, 0.35); }
.note-stem.selected { stroke: var(--selected); }
.note-stem.playing { stroke: var(--playhead); }

.flag { stroke: #181818; stroke-width: 1.3; fill: none; }
.flag.selected { stroke: var(--selected); }
.flag.playing { stroke: var(--playhead); }

.playhead-line {
  stroke: var(--playhead);
  stroke-width: 3;
  stroke-linecap: round;
  pointer-events: none;
}

.playhead-halo {
  fill: rgba(225, 29, 72, 0.08);
  stroke: rgba(225, 29, 72, 0.22);
  stroke-width: 1;
  pointer-events: none;
}

.accidental {
  font-size: 20px;
  fill: #181818;
  font-family: "Times New Roman", "Hiragino Mincho ProN", "Yu Mincho", serif;
  dominant-baseline: middle;
  pointer-events: none;
}

.accidental.cantus { fill: rgba(0, 0, 0, 0.35); }
.accidental.selected { fill: var(--selected); }
.accidental.playing { fill: var(--playhead); }

.current-notes {
  margin: 0 0 24px;
  padding: 18px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.56);
}

.current-notes h2 { margin-bottom: 10px; }
.current-notes p { margin: 4px 0; color: var(--muted); }
.current-notes strong { color: var(--text); }

.result-section { margin-top: 24px; }

.summary-box {
  margin-bottom: 18px;
  padding: 16px;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.05);
  color: var(--muted);
}

.result-list { display: grid; gap: 10px; }

.result-item {
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.62);
}

.result-item.ok { border-left: 5px solid var(--ok); }
.result-item.warn { border-left: 5px solid var(--warn); }
.result-item.error { border-left: 5px solid var(--error); }

.result-label {
  display: inline-block;
  margin-right: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.result-item.ok .result-label { color: var(--ok); }
.result-item.warn .result-label { color: var(--warn); }
.result-item.error .result-label { color: var(--error); }

@media (max-width: 820px) {
  .page {
    width: min(100% - 24px, 1180px);
    padding-top: 32px;
    padding-bottom: 56px;
  }

  .checker-header { padding-top: 32px; }
  .top-controls, .score-head { display: block; }
  .language-control { margin-top: 12px; }
  .score-status { margin-top: 8px; }
  .score-box { padding: 14px; }
  .score-editor { min-height: 310px; }
}

@media (max-width: 520px) {
  .page { width: min(100% - 18px, 1180px); }

  .checker-panel, .result-section {
    padding: 18px;
    border-radius: 18px;
  }

  .score-box { border-radius: 18px; }
  .button { width: 100%; }

  .score-tools, .playback-tools, .exercise-tools {
    display: grid;
    grid-template-columns: 1fr;
  }

  .language-control, .tempo-control, .timbre-control, .playback-control, .exercise-control {
    width: 100%;
    justify-content: space-between;
  }

  .language-control select, .timbre-control select, .playback-control select, .exercise-control select {
    min-width: 0;
    width: 100%;
  }

  h1 { letter-spacing: -0.045em; }
}


.clef-symbol {
  font-family: "Times New Roman", "Hiragino Mincho ProN", "Yu Mincho", serif;
  fill: rgba(0, 0, 0, 0.72);
  dominant-baseline: middle;
  pointer-events: none;
}

.clef-symbol.treble {
  font-size: 58px;
}

.clef-symbol.bass {
  font-size: 48px;
}


.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  text-decoration: none;
}

.brand-logo {
  display: block;
  width: 42px;
  height: auto;
  object-fit: contain;
}

.brand-text {
  color: var(--muted);
  font-size: 0.92rem;
  letter-spacing: 0.02em;
}

@media (max-width: 520px) {
  .brand-logo {
    width: 38px;
  }
}


.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}


/* Explicit note values for Module 2 / Module 4 */
.note-head.open {
  fill: #ffffff !important;
  stroke: #181818;
  stroke-width: 1.8;
}

.note-head.open.cantus {
  fill: #ffffff !important;
  stroke: rgba(0, 0, 0, 0.46);
  stroke-width: 1.8;
}

.note-head.open.selected {
  fill: #ffffff !important;
  stroke: var(--selected);
  stroke-width: 2.1;
}

.note-head.open.playing {
  fill: #ffffff !important;
  stroke: var(--playhead);
  stroke-width: 2.1;
}

.duration-label {
  font-size: 11px;
  fill: rgba(0, 0, 0, 0.5);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}


/* Module 4 flag kill switch: quarter notes must not show flags. */
.flag {
  display: none !important;
  opacity: 0 !important;
}


/* ACS logo display safeguard */
.brand-logo,
.logo {
  display: block;
  width: 48px;
  max-width: 48px;
  height: auto;
  object-fit: contain;
}


/* Error highlighting */
.note-head.error {
  fill: #b3261e !important;
  stroke: #b3261e !important;
  stroke-width: 2.2 !important;
}

.note-head.open.error {
  fill: #ffffff !important;
  stroke: #b3261e !important;
  stroke-width: 2.4 !important;
}

.note-stem.error {
  stroke: #b3261e !important;
  stroke-width: 2.2 !important;
}

.note-label.error,
.accidental.error {
  fill: #b3261e !important;
  font-weight: 700;
}

.issue-ring {
  fill: none;
  stroke: #b3261e;
  stroke-width: 2;
  opacity: 0.95;
  pointer-events: none;
}

.issue-ring.warn {
  stroke: #c47a00;
}

.note-head.warn {
  stroke: #c47a00 !important;
  stroke-width: 2.1 !important;
}

.note-stem.warn {
  stroke: #c47a00 !important;
  stroke-width: 2 !important;
}

.note-label.warn,
.accidental.warn {
  fill: #c47a00 !important;
  font-weight: 700;
}

/* Module 4 playback icon buttons. */
#playPauseButton,
button[onclick="stopPlayback(true)"] {
  min-width: 2.45rem;
  font-size: 1.05rem;
  line-height: 1;
  letter-spacing: 0;
  text-align: center;
}

/* Module 4 PNG notation and keyboard-input refinement. */
.png-notation {
  pointer-events: none;
  user-select: none;
}

.png-staff {
  opacity: 0.95;
}

.png-staff-fallback-line {
  opacity: 0 !important;
}

.png-clef {
  opacity: 0.96;
}

.png-notehead.selected {
  filter: invert(32%) sepia(62%) saturate(1169%) hue-rotate(192deg) brightness(84%) contrast(93%);
}

.png-notehead.playing {
  filter: invert(19%) sepia(86%) saturate(2042%) hue-rotate(344deg) brightness(92%) contrast(95%);
}

.png-notehead.error,
.png-accidental.error {
  filter: invert(16%) sepia(90%) saturate(2900%) hue-rotate(345deg) brightness(90%) contrast(96%);
}

.png-notehead.warn,
.png-accidental.warn {
  filter: invert(53%) sepia(72%) saturate(850%) hue-rotate(5deg) brightness(92%) contrast(93%);
}

.clef-symbol,
.accidental {
  display: none !important;
}

/* Module 4 pitch alignment and barlines. */
.measure-barline {
  stroke: rgba(23, 23, 23, 0.42);
  stroke-width: 1.25;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.measure-barline.final-thin {
  stroke-width: 1.3;
}

.measure-barline.final-thick {
  stroke-width: 3.1;
}

.note-stem {
  stroke: #171717;
  stroke-width: 1.65;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.note-stem.playing,
.note-stem.selected {
  stroke: currentColor;
}

.png-notehead.quarter-note-head {
  transform-box: fill-box;
  transform-origin: center;
}

/* Module 4 control layout refinement. */
.exercise-tools {
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  flex-wrap: wrap !important;
}

.exercise-load-button,
.example-load-button {
  order: 2;
}

.exercise-description {
  order: 3;
  flex-basis: 100%;
}

.score-tools {
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  flex-wrap: wrap !important;
}

.midi-export-button {
  margin-left: auto !important;
}

@media (max-width: 720px) {
  .midi-export-button {
    margin-left: 0 !important;
  }
}
