* {
  box-sizing: border-box;
}

:root {
  --bg: #ffffff;
  --text: #111111;
  --muted: #666666;
  --line: #dddddd;
  --soft: #f7f7f7;
  --soft-2: #fafafa;
  --hover: #f0f0f0;
  --correct: #c7f7d4;
  --wrong: #f7c7c7;
  --open: #ececec;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.08);

  --note-c: #e8eef7;
  --note-cs: #efe6ff;
  --note-d: #f8eadf;
  --note-ds: #e8f3df;
  --note-e: #dff4e7;
  --note-f: #e0f2f7;
  --note-fs: #efe9fb;
  --note-g: #ececf8;
  --note-gs: #fde8f2;
  --note-a: #fff0dd;
  --note-as: #f8e3ee;
  --note-b: #e6f6ef;

  --root-ring: #111111;
  --study-dot: rgba(0, 0, 0, 0.14);
  --study-text: #1e1e1e;
}

body {
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 20px;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}

.site-header h1 {
  margin: 0;
  font-size: 2rem;
}

.site-header p {
  margin: 6px 0 0;
  color: var(--muted);
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-left: auto;
}

button,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

button:hover {
  background: #f5f5f5;
}

button:active {
  transform: translateY(1px);
}

.primary-btn,
.ghost-btn {
  padding: 11px 16px;
  border-radius: 10px;
}

.primary-btn {
  background: #111;
  color: #fff;
  border-color: #111;
}

.primary-btn:hover {
  background: #222;
}

.ghost-btn {
  background: #fff;
}

.exit-btn {
  background: #111;
  color: #fff;
  border-color: #111;
  margin-left: auto;
}

.exit-btn:hover {
  background: #222;
}

.mode-banner {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.mode-banner > div {
  background: var(--soft);
  padding: 14px;
  border-radius: 10px;
  border: 1px solid #efefef;
}

.label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.hud {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.hud div {
  background: var(--soft);
  padding: 12px 10px;
  text-align: centre;
  border-radius: 8px;
  border: 1px solid #efefef;
}

.hud-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.hidden {
  display: none !important;
}

/* Study panel */
.study-panel {
  display: grid;
  gap: 14px;
  margin-bottom: 20px;
}

.study-block {
  background: var(--soft);
  border: 1px solid #efefef;
  border-radius: 14px;
  padding: 16px;
}

.study-heading-row {
  display: flex;
  justify-content: space-between;
  align-items: centre;
  gap: 16px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.study-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
}

.study-inline-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mini-btn {
  border-radius: 999px;
  padding: 8px 12px;
  background: #fff;
}

.chip-grid {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.note-chip {
  min-width: 72px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-weight: 700;
  background: #fff;
  position: relative;
}

.note-chip.active {
  border-color: #111;
  box-shadow: inset 0 0 0 1px #111;
}

.note-chip[data-note="C"] {
  background: var(--note-c);
}
.note-chip[data-note="C#"] {
  background: var(--note-cs);
}
.note-chip[data-note="D"] {
  background: var(--note-d);
}
.note-chip[data-note="D#"] {
  background: var(--note-ds);
}
.note-chip[data-note="E"] {
  background: var(--note-e);
}
.note-chip[data-note="F"] {
  background: var(--note-f);
}
.note-chip[data-note="F#"] {
  background: var(--note-fs);
}
.note-chip[data-note="G"] {
  background: var(--note-g);
}
.note-chip[data-note="G#"] {
  background: var(--note-gs);
}
.note-chip[data-note="A"] {
  background: var(--note-a);
}
.note-chip[data-note="A#"] {
  background: var(--note-as);
}
.note-chip[data-note="B"] {
  background: var(--note-b);
}

.note-chip.inactive {
  background: #fff;
  color: var(--muted);
}

.study-scale-controls {
  display: grid;
  grid-template-columns: 150px minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field label {
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
}

.field select {
  height: 46px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 0 12px;
  color: var(--text);
}

.field-action {
  justify-content: end;
}

.study-scale-summary {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid #ececec;
}

.study-scale-summary strong {
  display: block;
  margin-top: 4px;
  font-size: 1.1rem;
}

.scale-notes-summary {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.fretboard-wrapper {
  overflow-x: auto;
}

#fretboard {
  display: grid;
  grid-template-columns: repeat(13, minmax(70px, 1fr));
  gap: 6px;
  min-width: 910px;
}

.cell {
  height: 60px;
  border: 1px solid var(--line);
  display: flex;
  align-items: centre;
  justify-content: centre;
  cursor: pointer;
  background: var(--soft-2);
  position: relative;
  transition: all 0.15s ease;
  border-radius: 6px;
  user-select: none;
  font-weight: 600;
  overflow: hidden;
}

.cell:hover {
  background: var(--hover);
}

.cell.correct {
  background: var(--correct);
  border-color: #9fddae;
}

.cell.wrong {
  background: var(--wrong);
  border-color: #e3a2a2;
}

.cell.found-persistent {
  background: var(--correct);
  border-color: #9fddae;
}

.cell.disabled {
  cursor: default;
}

.open-note {
  background: var(--open);
  font-size: 12px;
}

.open-note::after {
  content: "OPEN";
  position: absolute;
  bottom: 4px;
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.open-note .note-text {
  display: block;
}

.open-note .sub-text {
  display: block;
  font-size: 9px;
  color: var(--muted);
}

.divider {
  border-left: 3px solid #bbbbbb;
}

.fret-numbers {
  display: grid;
  grid-template-columns: repeat(13, minmax(70px, 1fr));
  min-width: 910px;
  margin-top: 8px;
  text-align: centre;
  font-size: 12px;
  color: #888888;
}

/* Study note rendering */
.cell.study-cell {
  background: linear-gradient(180deg, #fafafa 0%, #f7f7f7 100%);
}

.cell.study-cell:hover {
  background: linear-gradient(180deg, #fafafa 0%, #f7f7f7 100%);
}

.study-note-badge {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  display: flex;
  align-items: centre;
  justify-content: centre;
  font-size: 0.64rem;
  text-align: centre;
  line-height: 1.05;
  padding: 4px;
  font-weight: 800;
  border: 1px solid rgba(0, 0, 0, 0.08);
  color: var(--study-text);
  z-index: 1;
}

.study-note-badge.root {
  box-shadow: inset 0 0 0 2px var(--root-ring), 0 0 0 3px rgba(0, 0, 0, 0.05);
}

.study-note-badge.note-c {
  background: var(--note-c);
}
.study-note-badge.note-cs {
  background: var(--note-cs);
}
.study-note-badge.note-d {
  background: var(--note-d);
}
.study-note-badge.note-ds {
  background: var(--note-ds);
}
.study-note-badge.note-e {
  background: var(--note-e);
}
.study-note-badge.note-f {
  background: var(--note-f);
}
.study-note-badge.note-fs {
  background: var(--note-fs);
}
.study-note-badge.note-g {
  background: var(--note-g);
}
.study-note-badge.note-gs {
  background: var(--note-gs);
}
.study-note-badge.note-a {
  background: var(--note-a);
}
.study-note-badge.note-as {
  background: var(--note-as);
}
.study-note-badge.note-b {
  background: var(--note-b);
}

.study-faint-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--study-dot);
  opacity: 0.55;
}

.study-open-label {
  position: absolute;
  bottom: 4px;
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.screen-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.92);
  display: none;
  align-items: centre;
  justify-content: centre;
  padding: 24px;
  z-index: 1000;
  backdrop-filter: blur(6px);
}

.screen-overlay.visible {
  display: flex;
}

.screen-card {
  width: min(920px, 100%);
  background: #fff;
  border: 1px solid #ebebeb;
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 28px;
}

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

.screen-card h2 {
  margin: 0 0 8px;
  font-size: 2rem;
}

.screen-copy {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.5;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.mode-card {
  text-align: left;
  border-radius: 14px;
  padding: 18px;
  min-height: 150px;
  background: #fff;
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mode-card:hover {
  background: #fafafa;
}

.mode-card.selected {
  border-color: #111;
  box-shadow: inset 0 0 0 1px #111;
}

.mode-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.mode-desc {
  font-size: 0.95rem;
  color: var(--muted);
  line-height: 1.45;
}

.message-overlay {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #111;
  color: #fff;
  padding: 18px 30px;
  font-size: 1.4rem;
  border-radius: 12px;
  z-index: 1200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.message-overlay.visible {
  opacity: 1;
  transform: translate(-50%, -50%);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Fix standard CSS spelling where required */
.hud div,
.fret-numbers,
.study-note-badge,
.cell,
.screen-overlay,
.study-heading-row {
  text-align: center;
}

.cell,
.study-note-badge,
.screen-overlay,
.study-heading-row {
  align-items: center;
  justify-content: center;
}

@media (max-width: 900px) {
  .hud {
    grid-template-columns: repeat(3, 1fr);
  }

  .mode-grid {
    grid-template-columns: 1fr;
  }

  .mode-banner {
    grid-template-columns: 1fr;
  }

  .site-header {
    flex-direction: column;
    align-items: stretch;
  }

  .header-actions {
    margin-left: 0;
    justify-content: flex-end;
  }

  .study-scale-controls {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .hud {
    grid-template-columns: repeat(2, 1fr);
  }

  body {
    padding: 14px;
  }

  .screen-card {
    padding: 20px;
  }

  .screen-card h2 {
    font-size: 1.6rem;
  }

  .note-chip {
    min-width: 62px;
    padding: 9px 12px;
    font-size: 0.9rem;
  }

  .study-note-badge {
    width: 38px;
    height: 38px;
    font-size: 0.58rem;
  }
}