:root {
  color-scheme: dark;
  --bg: #11100f;
  --surface: #1a1917;
  --surface-raised: #22201d;
  --line: #36322d;
  --text: #f6f0e7;
  --muted: #bbb4aa;
  --accent: #e7ff5b;
  --accent-ink: #15170b;
  --danger: #ff765f;
  --wood-a: #5a3726;
  --wood-b: #3f251b;
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 50% -15%, rgba(231, 255, 91, 0.09), transparent 34rem),
    var(--bg);
  color: var(--text);
}

button, input { font: inherit; }
button { color: inherit; }

.app-shell {
  width: min(100%, 460px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 30px 16px 56px;
}

.brand { margin: 0 4px 34px; }
.brand-kicker, .eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 0.67rem;
  font-weight: 800;
  letter-spacing: 0.18em;
}
.brand h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.5rem, 12vw, 3.7rem);
  font-weight: 400;
  letter-spacing: -0.055em;
  line-height: 0.95;
}
.brand-copy-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 13px; }
.brand-copy { margin: 0; color: var(--muted); font-size: 0.7rem; white-space: nowrap; }
.brand-manual-link {
  flex: 0 0 auto;
  padding: 7px 9px;
  border: 1px solid rgba(246, 240, 231, 0.28);
  border-radius: 999px;
  background: rgba(246, 240, 231, 0.035);
  color: var(--muted);
  font-size: 0.6rem;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}
.brand-manual-link:hover { border-color: rgba(246, 240, 231, 0.55); color: var(--text); }

.view, form { width: 100%; min-width: 0; }
.view { animation: reveal 220ms ease-out; }
@keyframes reveal { from { opacity: 0; transform: translateY(5px); } }
#settings-view { animation-name: reveal-opacity; }
@keyframes reveal-opacity { from { opacity: 0; } }

.section-heading, .training-topbar, .target-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.section-heading h2 { margin: 0; font-size: 1.15rem; }

.icon-toggle, .text-button, .secondary-button {
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
}
.icon-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 9px 11px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}
.icon-toggle[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.sound-icon { display: inline-flex; width: 14px; height: 14px; }
.sound-icon svg { width: 100%; height: 100%; fill: currentColor; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

fieldset {
  min-width: 0;
  margin: 10px 0 0;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(26, 25, 23, 0.88);
}
legend { padding: 0 5px; font-size: 0.76rem; font-weight: 800; letter-spacing: 0.06em; }
.legend-icon {
  width: 15px;
  height: 15px;
  margin-right: 5px;
  overflow: visible;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -3px;
}
.legend-icon circle { vector-effect: non-scaling-stroke; }
.legend-note { color: var(--muted); font-size: 0.68rem; font-weight: 500; }

.choice-grid { display: flex; min-width: 0; flex-wrap: wrap; gap: 7px; }
.choice {
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-raised);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 720;
}
.choice:hover { border-color: #5a554e; }
.choice[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}
.key-grid .choice { flex: 1 1 calc(25% - 7px); min-width: 0; padding-inline: 4px; font-size: 0.7rem; }
.key-group-label {
  margin: 4px 2px 8px;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}
.key-grid + .key-group-label { margin-top: 14px; }
.scale-grid .choice { flex: 1 1 0; min-width: 0; padding-inline: 7px; }
.scale-degree-summary {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(231, 255, 91, 0.26);
  border-radius: 10px;
  background: rgba(231, 255, 91, 0.055);
}
.scale-degree-summary p { margin: 0; color: var(--text); font-size: 0.72rem; font-weight: 780; line-height: 1.55; }
.scale-degree-summary .scale-degree-note { margin-top: 3px; color: var(--muted); font-size: 0.64rem; font-weight: 600; }
.compact-grid .choice { padding-inline: 10px; }
.quick-settings { display: grid; gap: 9px; }
.setting-line {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}
.setting-line + .setting-line { padding-top: 9px; border-top: 1px solid var(--line); }
.setting-label { color: var(--muted); font-size: 0.72rem; font-weight: 750; }
.setting-line .choice-grid { flex-wrap: nowrap; }
.setting-line .choice { flex: 1 1 0; padding-inline: 5px; }

.area-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.area-option {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 46px;
  padding: 10px 13px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: var(--surface-raised);
  text-align: left;
  cursor: pointer;
}
.area-option {
  display: flex;
  min-height: 58px;
  padding: 9px 5px;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}
.area-option[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: inset 3px 0 var(--accent);
}
.area-option strong { font-size: 0.78rem; letter-spacing: 0.05em; }
.area-option span { color: var(--muted); font-size: 0.7rem; }
.free-area-card {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  min-width: 0;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 11px;
  background: var(--surface-raised);
}
.free-area-card .area-option { height: 100%; }
.free-area-card.is-selected {
  border: 1px solid var(--accent);
  box-shadow: inset 3px 0 var(--accent);
}
.free-area-card .area-option {
  border: 0;
  border-radius: 10px 0 0 10px;
  box-shadow: none;
}
.free-controls {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-left: 1px solid var(--line);
  font-size: 0.75rem;
}
.free-controls input { width: 100%; accent-color: var(--accent); }
.free-controls output { min-width: 2.5em; color: var(--accent); font-weight: 800; }
.support-settings { display: grid; gap: 9px; }
.support-settings .choice { flex: 1 1 0; }
.field-error { margin: 10px 2px 0; color: var(--danger); font-size: 0.72rem; }

.primary-button, .secondary-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 58px;
  padding: 0 19px;
  border-radius: 15px;
  cursor: pointer;
  font-weight: 850;
  letter-spacing: 0.06em;
}
.primary-button { margin-top: 18px; border: 0; background: var(--accent); color: var(--accent-ink); }
.secondary-button { justify-content: center; margin-top: 9px; color: var(--muted); }

#settings-form > .primary-button {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: calc(14px + env(safe-area-inset-bottom));
  left: 50%;
  width: min(calc(100% - 32px), 428px);
  margin: 0;
  background: #ff9f55;
  color: #211208;
  transform: translateX(-50%);
  box-shadow:
    0 14px 38px rgba(0, 0, 0, 0.58),
    0 0 0 1px rgba(255, 159, 85, 0.32);
}
#settings-view:not([hidden]) ~ .app-footer { margin-bottom: 42px; }

.training-view { margin-top: -10px; }
.training-topbar {
  align-items: flex-start;
  gap: 12px;
  margin: 0 4px 22px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.text-button { padding: 8px 10px; border-radius: 999px; color: var(--muted); font-size: 0.74rem; }
.training-status { display: flex; align-items: center; gap: 8px; }
.training-sound-toggle { flex: 0 0 auto; padding: 7px 8px; font-size: 0.58rem; }
.miss-counter { margin: 0; color: var(--muted); font-size: 0.68rem; letter-spacing: 0.1em; }
.miss-counter strong { color: var(--text); }
.next-note-panel.is-feedback-hidden { visibility: hidden; opacity: 0; }
.target-degree { min-height: 1.55rem; margin: 0; font-size: 1.55rem; line-height: 1; }
.target-degree.is-hidden { min-width: 1px; }
.next-note-panel.is-entering { animation: next-note-in 1000ms ease-out both; }
@keyframes next-note-in { from { opacity: 0; transform: translateY(2px); } }

.fretboard-wrap {
  overflow: hidden;
  border: 1px solid #6d4a36;
  border-radius: 9px;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.35);
}
.fretboard {
  --fret-footer-height: 25px;
  position: relative;
  display: grid;
  grid-template-rows: repeat(6, 48px) var(--fret-footer-height);
  background-image:
    linear-gradient(rgba(12, 8, 6, 0.08), rgba(12, 8, 6, 0.16)),
    url("./assets/rosewood1.jpg");
  background-position: center;
  background-size: cover;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}
.fretboard::before,
.fretboard::after {
  content: "";
  position: absolute;
  z-index: 4;
  right: 0;
  left: 0;
  height: 8px;
  background: linear-gradient(
    to bottom,
    #fffaf0 0 1px,
    #e5dcc9 1px 6px,
    #83735e 6px 8px
  );
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}
.fretboard::before { top: 0; }
.fretboard::after { bottom: var(--fret-footer-height); transform: rotate(180deg); }
.fret-number {
  display: grid;
  place-items: center;
  border-right: 2px solid rgba(222, 211, 193, 0.6);
  background: #191715;
  color: var(--muted);
  font-size: 0.62rem;
}
.fret-cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 0;
  border: 0;
  border-right: 2px solid rgba(222, 211, 193, 0.68);
  background: transparent;
  cursor: pointer;
}
.fret-cell::before {
  content: "";
  position: absolute;
  z-index: 2;
  left: -3px;
  width: calc(100% + 6px);
  height: var(--string-size, 1px);
  background: linear-gradient(to bottom, #fffdf7 0%, #c8c3b8 45%, #777268 100%);
  box-shadow:
    0 1px 0 rgba(0, 0, 0, 0.78),
    0 2px 2px rgba(0, 0, 0, 0.48);
  pointer-events: none;
}
.fret-cell.inlay::after {
  content: "";
  position: absolute;
  z-index: 1;
  bottom: -7px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fffdf4, #c9c5b9 62%, #8b877f);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(255, 255, 255, 0.45);
  pointer-events: none;
}
.fret-cell.inlay-double::after {
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
}
.note-marker {
  position: relative;
  z-index: 6;
  display: grid;
  place-items: center;
  width: 35px;
  height: 35px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1rem;
  font-weight: 900;
  box-shadow: 0 0 0 3px rgba(17,16,15,.28);
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease;
}
.root-guide {
  position: absolute;
  z-index: 5;
  width: 42px;
  height: 42px;
  border: 3px solid #ffd34e;
  border-radius: 50%;
  background: rgba(255, 211, 78, 0.08);
  box-shadow: 0 0 0 2px rgba(17, 16, 15, 0.62), 0 0 12px rgba(255, 211, 78, 0.28);
  pointer-events: none;
}
.note-marker.is-history { opacity: 0.28; transform: scale(0.92); }
.note-marker.is-degree-visible { animation: degree-in 500ms ease-out both; }
@keyframes degree-in { from { color: transparent; transform: scale(0.94); } }
.fret-cell.is-pressed { background: rgba(231, 255, 91, 0.13); }
.note-marker.is-missed,
.note-marker.is-wrong-marker { background: var(--danger); color: #220a06; }
.fret-cell.is-wrong .note-marker { background: var(--danger); color: #220a06; animation: wrong 160ms ease-out; }
@keyframes wrong { from { transform: scale(0.5); } }
.training-form-label {
  margin: 17px 0 13px;
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.15rem;
  text-align: center;
}
.training-navigation {
  display: grid;
  grid-template-columns: max-content max-content max-content;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.form-nav-button,
.training-settings-button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-raised);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 800;
}
.form-nav-button { color: var(--text); font-size: 0.9rem; font-weight: 900; }
.form-nav-button { padding-inline: 6px; }
.form-nav-button:first-child { text-align: left; }
.form-nav-button:last-child { text-align: right; }
.training-settings-button { padding-inline: 6px; }
.training-settings-button.is-solo { grid-column: 2; }
.form-nav-button:hover,
.training-settings-button:hover { border-color: #5a554e; color: var(--text); }
.form-nav-button span { white-space: nowrap; }

.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 42px 4px 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: #999187;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
}
.app-footer a { color: inherit; text-underline-offset: 3px; }
.app-footer a:hover { color: var(--text); }

@media (max-width: 370px) {
  .brand-copy-row { gap: 6px; }
  .brand-copy { max-width: 145px; font-size: 0.68rem; line-height: 1.45; white-space: normal; }
  .brand-manual-link { padding: 6px 7px; font-size: 0.56rem; }
  .setting-line { grid-template-columns: 64px minmax(0, 1fr); gap: 7px; }
  .setting-line .choice { font-size: 0.7rem; }
  .scale-grid .choice { font-size: 0.7rem; }
  .training-status { gap: 5px; }
  .training-sound-toggle { padding-inline: 6px; }
  .fretboard { --fret-footer-height: 23px; grid-template-rows: repeat(6, 44px) var(--fret-footer-height); }
  .note-marker { width: 32px; height: 32px; font-size: 0.8rem; }
  .root-guide { width: 39px; height: 39px; }
  .training-navigation { gap: 2px; }
  .form-nav-button { padding-inline: 4px; font-size: 0.72rem; }
  .training-settings-button { padding-inline: 4px; font-size: 0.62rem; }
}

@media (orientation: landscape) and (max-height: 600px) {
  .app-shell { width: min(100%, 720px); padding-top: 14px; }
  .brand { display: none; }
  .fretboard { --fret-footer-height: 22px; grid-template-rows: repeat(6, 42px) var(--fret-footer-height); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; }
}
