:root {
  color-scheme: light;
  --color-bg: #f7f4f1;
  --color-surface: #ffffff;
  --color-surface-strong: #2b2522;
  --color-text: #2b2522;
  --color-text-muted: rgba(43, 37, 34, 0.68);
  --color-primary: #d6893a;
  --color-primary-soft: rgba(214, 137, 58, 0.14);
  --color-accent: #50b59f;
  --color-error: #d16060;
  --color-border: rgba(43, 37, 34, 0.08);
  --color-shadow: rgba(0, 0, 0, 0.08);
  --font-display: "Playfair Display", serif;
  --font-base: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --transition-base: 180ms ease;
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --radius-pill: 999px;
  --layout-max-width: 1200px;
  --layout-gutter: 24px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --color-bg: #181411;
  --color-surface: #231d1a;
  --color-surface-strong: #f1e0d1;
  --color-text: #f8efe7;
  --color-text-muted: rgba(248, 239, 231, 0.72);
  --color-primary: #f0b15c;
  --color-primary-soft: rgba(240, 177, 92, 0.14);
  --color-accent: #72d2c0;
  --color-error: #ec8c8c;
  --color-border: rgba(248, 239, 231, 0.09);
  --color-shadow: rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top right, rgba(214, 137, 58, 0.08), transparent 40%), var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-base);
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px var(--layout-gutter) 16px;
  max-width: var(--layout-max-width);
  margin: 0 auto;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand-mark {
  font-family: var(--font-display);
  font-size: 28px;
  letter-spacing: 0.08em;
}

.brand-tagline {
  font-size: 14px;
  color: var(--color-text-muted);
}

.header-controls {
  display: flex;
  gap: 12px;
  align-items: center;
}

.key-select label {
  display: block;
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}

.key-select select {
  appearance: none;
  padding: 8px 32px 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface) url('data:image/svg+xml,%3Csvg width="12" height="8" viewBox="0 0 12 8" xmlns="http://www.w3.org/2000/svg"%3E%3Cpath d="M1 1l5 5 5-5" stroke="%236a5e57" stroke-width="1.5" fill="none" stroke-linecap="round"/%3E%3C/svg%3E') no-repeat right 12px center;
  color: var(--color-text);
  font-family: inherit;
}

button {
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
  border: none;
  background: none;
  transition: transform var(--transition-base), box-shadow var(--transition-base), background var(--transition-base), color var(--transition-base);
}

.primary-button {
  background: linear-gradient(135deg, var(--color-primary) 0%, #c16a1f 100%);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-pill);
  font-weight: 600;
  box-shadow: 0 10px 20px rgba(214, 137, 58, 0.24);
}

.primary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 24px rgba(214, 137, 58, 0.28);
}

.ghost-button {
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  color: var(--color-text-muted);
}

.ghost-button:hover {
  border-color: var(--color-border);
  color: var(--color-text);
}

.app-main {
  flex: 1;
  width: 100%;
  max-width: var(--layout-max-width);
  margin: 0 auto;
  padding: 0 var(--layout-gutter) 48px;
}

.mode-panel {
  margin-bottom: 40px;
}

.mode-panel h1 {
  font-family: var(--font-display);
  font-size: 32px;
  margin-bottom: 24px;
}

/* 当有活动练习时，压缩模式面板 */
.mode-panel.compact {
  margin-bottom: 20px;
}

.mode-panel.compact h1 {
  font-size: 24px;
  margin-bottom: 16px;
}

.mode-panel.compact .mode-grid {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.mode-panel.compact .mode-card {
  padding: 18px;
}

.session-summary {
  background: rgba(80, 181, 159, 0.12);
  border: 1px solid rgba(80, 181, 159, 0.32);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 20px;
  color: var(--color-text);
  font-size: 15px;
  box-shadow: 0 18px 30px var(--color-shadow);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}

.mode-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  text-align: left;
  box-shadow: 0 24px 40px var(--color-shadow);
  border: 1px solid var(--color-border);
  position: relative;
  overflow: hidden;
}

.mode-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--color-primary-soft);
  opacity: 0;
  transition: opacity var(--transition-base);
  pointer-events: none;
}

.mode-card:hover {
  transform: translateY(-4px);
}

.mode-card:hover::after {
  opacity: 1;
}

.mode-card.active {
  border-color: var(--color-primary);
  box-shadow: 0 24px 40px var(--color-shadow), 0 0 0 2px rgba(214, 137, 58, 0.2);
}

.mode-card.active::after {
  opacity: 0.3;
}

.mode-card h2 {
  font-size: 22px;
  margin: 12px 0 6px;
}

.mode-card p {
  color: var(--color-text-muted);
  line-height: 1.5;
}

.mode-meta {
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  text-transform: uppercase;
}

.mode-hint {
  display: inline-block;
  margin-top: 16px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: rgba(80, 181, 159, 0.16);
  color: var(--color-accent);
  font-size: 13px;
}

.quiz-workspace {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 32px;
  align-items: start;
}

.workspace-sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
  height: fit-content;
  align-self: start;
}

.session-meta {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 16px 28px var(--color-shadow);
  border: 1px solid var(--color-border);
  display: grid;
  gap: 4px;
}

.session-mode {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-primary);
}

.session-progress,
.session-key {
  color: var(--color-text-muted);
  font-size: 13px;
}

.stats-card,
.mistake-teaser {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 16px 28px var(--color-shadow);
  border: 1px solid var(--color-border);
}

.stats-card h3,
.mistake-teaser h3 {
  margin-top: 0;
  margin-bottom: 12px;
  font-size: 16px;
}

.stats-card dl {
  display: grid;
  gap: 10px;
}

.stats-card dt {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
}

.stats-card dd {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.mistake-teaser ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.mistake-teaser li {
  font-size: 14px;
  color: var(--color-text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.mistake-teaser li .ghost-button {
  flex-shrink: 0;
}

.workspace-main {
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: fit-content;
}

.question-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: 0 28px 45px var(--color-shadow);
  border: 1px solid var(--color-border);
  display: grid;
  gap: 24px;
  height: fit-content;
}

.question-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  color: var(--color-text-muted);
}

.question-prompt {
  font-size: 28px;
  font-weight: 600;
  line-height: 1.4;
}


.answer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.answer-option {
  border-radius: var(--radius-md);
  padding: 16px;
  background: rgba(214, 137, 58, 0.08);
  color: var(--color-surface-strong);
  font-size: 18px;
  font-weight: 600;
  border: 1px solid transparent;
  position: relative;
  transition: transform var(--transition-base), box-shadow var(--transition-base), border-color var(--transition-base), background var(--transition-base);
  cursor: pointer;
}

.answer-option:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(214, 137, 58, 0.18);
}

.answer-option.correct {
  background: rgba(80, 181, 159, 0.18);
  border-color: rgba(80, 181, 159, 0.4);
  color: var(--color-accent);
  box-shadow: 0 10px 24px rgba(80, 181, 159, 0.22);
}

.answer-option.incorrect {
  background: rgba(209, 96, 96, 0.18);
  border-color: rgba(209, 96, 96, 0.4);
  color: #d16060;
  box-shadow: 0 10px 24px rgba(209, 96, 96, 0.18);
}

.answer-option:disabled {
  cursor: not-allowed;
  opacity: 0.8;
}

.answer-feedback {
  min-height: 24px;
  font-size: 15px;
  color: var(--color-text-muted);
}

.fretboard-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 24px 24px 18px;
  box-shadow: 0 24px 40px var(--color-shadow);
  border: 1px solid var(--color-border);
  display: grid;
  gap: 16px;
  height: fit-content;
}

.fretboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
  color: var(--color-text-muted);
}

.fretboard-container {
  overflow-x: auto;
  padding: 10px 0;
}

.fretboard {
  position: relative;
  width: 720px;
  height: 180px;
  margin: 0 auto;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  box-shadow: 0 16px 28px var(--color-shadow);
  overflow: visible;  /* 允许12品标记显示在指板外 */
}


/* 弦 */
.strings {
  position: absolute;
  top: 20px;
  left: 50px;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.string {
  position: relative;
  display: flex;
  align-items: center;
  height: 18px;
}

.string-label {
  position: absolute;
  left: -40px;
  font-size: 10px;
  color: var(--color-text-muted);
  font-weight: 600;
  text-align: right;
  width: 35px;
}

.string-line {
  flex: 1;
  height: 1px;
  background: var(--color-text-muted);
  border-radius: 0.5px;
  opacity: 0.4;
}

.string[data-string="1"] .string-line { height: 0.8px; opacity: 0.35; }
.string[data-string="2"] .string-line { height: 1px; opacity: 0.4; }
.string[data-string="3"] .string-line { height: 1px; opacity: 0.45; }
.string[data-string="4"] .string-line { height: 1.2px; opacity: 0.5; }
.string[data-string="5"] .string-line { height: 1.5px; opacity: 0.55; }
.string[data-string="6"] .string-line { height: 2px; opacity: 0.6; }

/* 品丝 */
.frets {
  position: absolute;
  top: 15px;
  bottom: 15px;
  left: 50px;
  right: 20px;
}

.fret {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--color-border);
  border-radius: 1px;
}

/* 真实吉他品丝位置（基于12平均律） */
.fret[data-fret="0"] { left: 0; width: 3px; background: var(--color-text-muted); opacity: 0.8; }
.fret[data-fret="1"] { left: 11.1%; }
.fret[data-fret="2"] { left: 21.5%; }
.fret[data-fret="3"] { left: 31.2%; }
.fret[data-fret="4"] { left: 40.2%; }
.fret[data-fret="5"] { left: 48.8%; }
.fret[data-fret="6"] { left: 56.9%; }
.fret[data-fret="7"] { left: 64.6%; }
.fret[data-fret="8"] { left: 71.9%; }
.fret[data-fret="9"] { left: 78.9%; }
.fret[data-fret="10"] { left: 85.6%; }
.fret[data-fret="11"] { left: 91.9%; }
.fret[data-fret="12"] { left: 98.2%; }

/* 品位点 */
.fret-dots {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.fret-dot {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-accent);
  border: 2px solid var(--color-surface);
  box-shadow: 0 4px 8px rgba(80, 181, 159, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  top: 50%;
  transform: translate(-50%, -50%);
  animation: fretDotAppear 0.4s ease-out;
  z-index: 10;
  cursor: pointer;
  pointer-events: auto;
}

/* 品位中央位置（品格中间） */
.fret-dot[data-fret="0"] { left: 1%; }  /* 空弦在指板最左边 */
.fret-dot[data-fret="1"] { left: 5.5%; }
.fret-dot[data-fret="2"] { left: 16.3%; }
.fret-dot[data-fret="3"] { left: 26.3%; }
.fret-dot[data-fret="4"] { left: 35.7%; }
.fret-dot[data-fret="5"] { left: 44.5%; }
.fret-dot[data-fret="6"] { left: 52.8%; }
.fret-dot[data-fret="7"] { left: 60.7%; }
.fret-dot[data-fret="8"] { left: 68.2%; }
.fret-dot[data-fret="9"] { left: 75.4%; }
.fret-dot[data-fret="10"] { left: 82.2%; }
.fret-dot[data-fret="11"] { left: 88.7%; }
.fret-dot[data-fret="12"] { left: 95.0%; }

.fret-dot.open-string {
  background: var(--color-primary);
  box-shadow: 0 4px 8px rgba(214, 137, 58, 0.3);
}

@keyframes fretDotAppear {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.3);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* 音符气泡提示 */
.fret-dot-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-surface-strong);
  color: var(--color-surface);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  margin-bottom: 8px;
  transition: opacity 0.2s ease;
}

.fret-dot-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--color-surface-strong);
}

.fret-dot:hover .fret-dot-tooltip {
  opacity: 1;
}

/* 指板装饰标记（品格标记点） */
.fretboard::after {
  content: '';
  position: absolute;
  top: 0;
  left: 50px;
  right: 20px;
  bottom: 0;
  pointer-events: none;
  z-index: 2;
  
  background-image: 
    /* 3品单点 */
    radial-gradient(circle at 26.3% 50%, var(--color-text-muted) 4px, transparent 4px),
    /* 5品单点 */
    radial-gradient(circle at 44.5% 50%, var(--color-text-muted) 4px, transparent 4px),
    /* 7品单点 */
    radial-gradient(circle at 60.7% 50%, var(--color-text-muted) 4px, transparent 4px),
    /* 9品单点 */
    radial-gradient(circle at 75.4% 50%, var(--color-text-muted) 4px, transparent 4px),
    /* 12品双点 */
    radial-gradient(circle at 95.0% 35%, var(--color-text-muted) 4px, transparent 4px),
    radial-gradient(circle at 95.0% 65%, var(--color-text-muted) 4px, transparent 4px);
  opacity: 0.25;
}

.fretboard-note {
  font-size: 14px;
  color: var(--color-text-muted);
  margin-top: 10px;
}

.app-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px var(--layout-gutter) 32px;
  max-width: var(--layout-max-width);
  margin: 0 auto;
  color: var(--color-text-muted);
  gap: 16px;
}

.footer-actions {
  display: flex;
  gap: 12px;
}

.settings-drawer[hidden],
.history-modal[hidden],
.data-manager-modal[hidden],
.app-toast.hidden {
  display: none !important;
}

.settings-drawer,
.history-modal,
.data-manager-modal {
  position: fixed;
  inset: 0;
  background: rgba(16, 12, 10, 0.42);
  backdrop-filter: blur(6px);
  display: flex;
  padding: 24px;
  z-index: 20;
}

.settings-drawer {
  justify-content: flex-end;
}

.history-modal,
.data-manager-modal {
  justify-content: center;
  align-items: center;
}

.settings-content {
  width: min(420px, 100%);
  background: var(--color-surface);
  border-radius: 24px;
  padding: 24px;
  display: grid;
  gap: 24px;
  border: 1px solid var(--color-border);
  box-shadow: 0 18px 38px var(--color-shadow);
}

.settings-header,
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.settings-content fieldset {
  border: none;
  padding: 0;
  display: grid;
  gap: 8px;
}

.settings-content legend {
  font-weight: 600;
  margin-bottom: 6px;
}

.settings-content label {
  font-size: 14px;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-content input[type="number"] {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  font-family: inherit;
}

.history-content {
  width: min(540px, 100%);
  background: var(--color-surface);
  border-radius: 28px;
  padding: 24px 28px;
  display: grid;
  gap: 24px;
  border: 1px solid var(--color-border);
  box-shadow: 0 20px 40px var(--color-shadow);
  max-height: 90vh;
  overflow-y: auto;
}

.history-body {
  display: grid;
  gap: 16px;
}

.history-body ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.history-entry {
  display: grid;
  gap: 4px;
  padding: 16px;
  border-radius: var(--radius-md);
  background: rgba(214, 137, 58, 0.1);
}

.history-entry span {
  font-size: 14px;
}

.data-manager-content {
  width: min(600px, 100%);
  max-height: 85vh;
  background: var(--color-surface);
  border-radius: 28px;
  padding: 24px 28px;
  display: grid;
  gap: 20px;
  border: 1px solid var(--color-border);
  box-shadow: 0 20px 40px var(--color-shadow);
  overflow-y: auto;
}

.data-manager-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.data-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.data-stat-card {
  background: rgba(214, 137, 58, 0.1);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
}

.data-stat-number {
  font-size: 24px;
  font-weight: 600;
  color: var(--color-primary);
}

.data-stat-label {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.data-section {
  border-top: 1px solid var(--color-border);
  padding-top: 16px;
}

.data-section h3 {
  margin: 0 0 12px 0;
  font-size: 16px;
  color: var(--color-text);
}

.data-display {
  background: rgba(43, 37, 34, 0.04);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: monospace;
  font-size: 13px;
  color: var(--color-text-muted);
  max-height: 120px;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  margin-bottom: 12px;
  white-space: pre-wrap;
}

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

.ghost-button.danger {
  color: var(--color-error);
  border-color: transparent;
}

.ghost-button.danger:hover {
  color: #fff;
  background: var(--color-error);
  border-color: var(--color-error);
}

.danger-zone {
  background: rgba(209, 96, 96, 0.08);
  border-radius: var(--radius-md);
  padding: 16px;
  border: 1px solid rgba(209, 96, 96, 0.2);
}

.danger-zone h3 {
  color: var(--color-error);
}

.app-toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(43, 37, 34, 0.92);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-pill);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  font-size: 14px;
  font-weight: 500;
  z-index: 30;
  letter-spacing: 0.02em;
}

.hidden {
  display: none !important;
}

@media (max-width: 1024px) {
  .quiz-workspace {
    grid-template-columns: 1fr;
  }

  .workspace-sidebar {
    order: 2;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    display: grid;
  }

  .workspace-sidebar > * {
    min-height: 100%;
  }
}

@media (max-width: 768px) {
  .app-header,
  .app-main,
  .app-footer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .mode-panel h1 {
    font-size: 26px;
  }

  .question-prompt {
    font-size: 22px;
  }

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

  .fretboard-visual {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

@media (max-width: 560px) {
  .app-header {
    flex-direction: column;
    gap: 18px;
    align-items: flex-start;
  }

  .header-controls {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }

  .key-select select {
    width: 100%;
  }

  .quiz-workspace {
    gap: 20px;
  }

  .workspace-main {
    gap: 18px;
  }

  .fretboard {
    width: 100%;
    min-width: 520px;
    height: 160px;
  }
  
  .fret-marker {
    font-size: 10px;
  }
  
  .string-label {
    font-size: 9px;
    left: -35px;
    width: 30px;
  }
  
  .fret-dot {
    width: 16px;
    height: 16px;
    font-size: 9px;
  }
}
