* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f5f5f7;
  color: #222;
}

h1 {
  margin: 0 0 0.25em 0;
  font-weight: 600;
}

.subtitle {
  color: #666;
  margin-top: 0;
  margin-bottom: 1.5em;
}

/* ------- Menu ------- */
.menu-page {
  max-width: 640px;
  margin: 0 auto;
  padding: 40px 24px;
}

.lesson-list {
  list-style: none;
  padding: 0;
  margin: 0 0 24px 0;
  counter-reset: lesson;
}

.lesson-item {
  margin-bottom: 8px;
}

.lesson-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s, border-color 0.15s;
}

.lesson-link:hover {
  background: #f0f6ff;
  border-color: #6aa3ff;
}

.lesson-item.completed .lesson-link {
  border-left: 4px solid #4caf50;
}

.lesson-item.perfect .lesson-link {
  border-left: 4px solid #ffb300;
  background: #fffaf0;
}

.lesson-title {
  font-weight: 600;
  flex: 0 0 auto;
}

.lesson-adds {
  color: #777;
  font-size: 0.92em;
  flex: 1 1 auto;
}

.lesson-badge {
  flex: 0 0 auto;
  background: #eef;
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 0.85em;
  color: #335;
  font-variant-numeric: tabular-nums;
}

.lesson-item.completed .lesson-badge {
  background: #d6f0d8;
  color: #1b5e20;
}

.lesson-item.perfect .lesson-badge {
  background: #ffe9a8;
  color: #6b4f00;
}

.lesson-item.started .lesson-link {
  border-left: 4px solid #bbb;
}

.lesson-item.started .lesson-badge {
  background: #f0f0f0;
  color: #888;
}

.reset-link {
  background: none;
  border: none;
  color: #b00;
  cursor: pointer;
  font-size: 0.9em;
  padding: 4px 0;
}

.reset-link:hover {
  text-decoration: underline;
}

/* ------- Lesson / drill ------- */
.lesson-page {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px;
}

.lesson-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
  gap: 16px;
  flex-wrap: wrap;
}

.lesson-header h1 {
  font-size: 1.4em;
}

.lesson-header .progress,
.lesson-header .score {
  font-variant-numeric: tabular-nums;
  color: #555;
}

.staff-wrap {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 20px;
}

.staff-wrap svg {
  width: 100%;
  height: auto;
  display: block;
}

/* Note coloring driven by group class on the staff renderer's <g> elements. */
.note .note-head {
  fill: #b0b6c0;
  transition: fill 0.15s, transform 0.15s;
}
.note.active .note-head {
  fill: #1f5fff;
}
.note.correct .note-head {
  fill: #2e7d32;
}
.note.wrong .note-head {
  fill: #c62828;
}

.note .correct-label-bg {
  fill: #fff5d6;
  stroke: #c4a01a;
  stroke-width: 1;
}
.note .correct-label {
  fill: #6b4f00;
  font-weight: 600;
}

/* ------- Answer panels ------- */
.answer-panels {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

@media (max-width: 720px) {
  .answer-panels { grid-template-columns: 1fr; }
}

.panel {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 12px;
}

.panel h2 {
  font-size: 0.9em;
  margin: 0 0 10px 0;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.answer-btn {
  flex: 1 1 auto;
  min-width: 44px;
  padding: 10px 12px;
  font-size: 1.05em;
  background: #f7f7fa;
  border: 1px solid #ccc;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}

.answer-btn:hover:not(:disabled) {
  background: #eaf0ff;
  border-color: #6aa3ff;
}

.answer-btn.selected {
  background: #1f5fff;
  border-color: #1f5fff;
  color: #fff;
}

.answer-btn.flash-correct {
  background: #2e7d32 !important;
  border-color: #2e7d32 !important;
  color: #fff !important;
}

.answer-btn.flash-wrong {
  background: #c62828 !important;
  border-color: #c62828 !important;
  color: #fff !important;
}

.answer-btn.flash-hint {
  background: #fff5d6 !important;
  border-color: #c4a01a !important;
  color: #6b4f00 !important;
}

.answer-btn:disabled {
  cursor: default;
  opacity: 0.85;
}

.status-line {
  text-align: center;
  font-size: 1.2em;
  min-height: 1.6em;
  font-weight: 600;
  margin-bottom: 12px;
}

.status-line.correct { color: #2e7d32; }
.status-line.wrong { color: #c62828; }

.back-link {
  display: inline-block;
  color: #555;
  text-decoration: none;
  font-size: 0.92em;
}
.back-link:hover { color: #1f5fff; text-decoration: underline; }

/* ------- Summary modal ------- */
.summary {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  margin-top: 20px;
}
.summary h2 {
  margin-top: 0;
}
.summary .big-score {
  font-size: 2.2em;
  font-weight: 600;
  margin: 8px 0;
}
.summary .record {
  color: #b48400;
  font-weight: 600;
  margin-bottom: 12px;
}
.summary .summary-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.summary button,
.summary a.btn {
  padding: 10px 18px;
  border-radius: 6px;
  border: 1px solid #1f5fff;
  background: #1f5fff;
  color: #fff;
  font-family: inherit;
  font-size: 1em;
  cursor: pointer;
  text-decoration: none;
}
.summary a.btn.secondary {
  background: #fff;
  color: #1f5fff;
}

/* ------- Results page ------- */
.results-page {
  max-width: 960px;
  margin: 0 auto;
  padding: 40px 24px;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.results-subheading {
  margin: 28px 0 10px 0;
  font-size: 1.05em;
  color: #444;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.results-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.results-summary .stat {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 16px;
  text-align: center;
}

.results-summary .stat-num {
  font-size: 1.6em;
  font-weight: 600;
  color: #1f5fff;
  font-variant-numeric: tabular-nums;
}

.results-summary .stat-label {
  font-size: 0.85em;
  color: #666;
  margin-top: 4px;
}

.results-summary .empty {
  grid-column: 1 / -1;
  color: #777;
  text-align: center;
  padding: 24px;
  background: #fff;
  border: 1px dashed #ccc;
  border-radius: 8px;
}

.results-table-wrap {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  overflow-x: auto;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.results-table th,
.results-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid #eee;
  font-size: 0.95em;
}

.results-table th {
  background: #fafafc;
  color: #555;
  font-weight: 600;
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.results-table tbody tr:last-child td {
  border-bottom: none;
}

.results-table tbody tr.row-perfect td {
  background: #fffaf0;
}

/* Grouped history */
#history-list {
  font-size: 0.95em;
}

.history-day {
  margin-bottom: 16px;
}

.history-day-label {
  font-weight: 700;
  font-size: 1em;
  color: #333;
  padding: 6px 0 4px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.history-day-label::before {
  content: '▼ ';
  font-size: 0.75em;
  color: #888;
}

.history-day[open] > .history-day-label::before {
  content: '▼ ';
}

.history-lesson {
  margin: 4px 0 4px 12px;
  border: 1px solid #e8e8e8;
  border-radius: 6px;
  background: #fff;
  overflow: hidden;
}

.history-lesson-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.history-lesson-label::marker,
.history-lesson-label::-webkit-details-marker {
  display: none;
}

.history-lesson-label::before {
  content: '►';
  font-size: 0.65em;
  color: #999;
  flex-shrink: 0;
}

.history-lesson[open] > .history-lesson-label::before {
  content: '▼';
}

.history-lesson-name {
  font-weight: 600;
  color: #222;
}

.history-lesson-count {
  color: #888;
  font-size: 0.85em;
}

.history-lesson-last {
  color: #666;
  font-size: 0.88em;
  font-variant-numeric: tabular-nums;
}

.history-lesson[open] .history-lesson-last {
  display: none;
}

.history-run-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid #eee;
}

.history-run-list li {
  padding: 6px 12px 6px 28px;
  font-size: 0.9em;
  font-variant-numeric: tabular-nums;
  color: #444;
  border-bottom: 1px solid #f0f0f0;
}

.history-run-list li:last-child {
  border-bottom: none;
}

.history-run-list li.run-perfect {
  background: #fffaf0;
  color: #555;
}

.history-run-list li.run-partial {
  color: #aaa;
}

.results-actions {
  margin-top: 20px;
  text-align: right;
}

.menu-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.results-link {
  color: #1f5fff;
  text-decoration: none;
  font-size: 0.95em;
}
.results-link:hover { text-decoration: underline; }

/* ------- Login form ------- */
.login-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 320px;
  margin-top: 8px;
}

.login-form label {
  font-size: 0.9em;
  font-weight: 600;
  color: #444;
  margin-bottom: 2px;
}

.login-form input {
  padding: 9px 12px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 1em;
  font-family: inherit;
  background: #fff;
}

.login-form input:focus {
  outline: none;
  border-color: #1f5fff;
  box-shadow: 0 0 0 2px rgba(31,95,255,0.15);
}

.login-form button {
  margin-top: 4px;
  padding: 10px;
  background: #1f5fff;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 1em;
  font-family: inherit;
  cursor: pointer;
}

.login-form button:hover {
  background: #1448d8;
}

.login-error {
  color: #c62828;
  font-size: 0.9em;
  margin: 0;
}

.username-line {
  font-size: 0.9em;
  color: #666;
  margin-top: 0;
  margin-bottom: 1em;
}

.app-version {
  text-align: center;
  color: #bbb;
  font-size: 0.75em;
  padding: 16px 0 8px;
}
