:root {
  --bg: #111318;
  --panel: #1b1e26;
  --text: #e8eaf0;
  --muted: #9aa0ad;
  --line: #2a2e3a;
  --white-row: #262a35;
  --black-row: #171a21;
  --on: #3b82f6;
  --correct: #22c55e;
  --wrong: #ef4444;
  --missing: #facc15;
  --primary: #3b82f6;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
[hidden] { display: none !important; } /* display:grid/flex 규칙이 hidden 속성을 이기지 못하게 */
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

.screen { display: none; }
.screen.active { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.bar { padding: 10px 16px; background: var(--panel); flex: none; }
.bar h1 { font-size: 20px; margin: 0; }
.quiz-head { display: flex; align-items: center; gap: 12px; }
.question-box { flex: 1; min-width: 0; }
#question { font-size: 26px; font-weight: 700; line-height: 1.2; }
#answer-text { font-size: 16px; color: var(--muted); min-height: 20px; }

.content { flex: 1; overflow-y: auto; padding: 8px 16px 16px; }
.content h2 { font-size: 15px; color: var(--muted); margin: 16px 0 8px; font-weight: 600; }
.row { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.row label { display: flex; align-items: center; gap: 6px; padding: 6px 0; }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); user-select: none;
}
.chips label:has(input:checked) { border-color: var(--primary); background: #1e3a8a; }

.warn { color: var(--missing); margin: 8px 0 0; }
.summary { color: var(--text); line-height: 1.6; }
.summary .muted { color: var(--muted); }

.actions { display: flex; gap: 10px; justify-content: flex-end; }
button {
  font: inherit; font-size: 17px; padding: 12px 18px; border-radius: 10px; border: 0;
  color: var(--text); background: var(--line); touch-action: manipulation; cursor: pointer;
}
button.primary { background: var(--primary); color: #fff; flex: 1; }
button.secondary { background: var(--line); }
button.danger { background: #7f1d1d; }
button.small { padding: 8px 12px; font-size: 15px; }
button:disabled { opacity: 0.4; cursor: default; }

/* 세로 건반: 흰건반 14행 그리드, 검은건반은 absolute로 경계 위에 겹침 */
#roll {
  flex: 1; min-height: 0;
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: repeat(var(--white-count, 14), minmax(0, 1fr));
  border-top: 1px solid var(--line);
  background: #0c0e12;
}
.cell {
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  min-height: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: flex-end;
  line-height: 1;
}
.cell.white {
  background: #f3f4f6; color: #4b5563;
  border-bottom: 1px solid #aeb3bf;
  padding-right: 12px;
  font-size: clamp(11px, 2.2vh, 15px);
}
.cell.black {
  position: absolute; left: 0; width: 58%;
  height: calc(100% / var(--white-count, 14) * 0.6);
  background: #1f2330; color: #9aa0ad;
  border-radius: 0 5px 5px 0;
  box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5);
  padding-right: 8px;
  font-size: clamp(10px, 1.8vh, 13px);
  z-index: 2;
}
#roll .cell.on { background: var(--on); color: #fff; }
#roll .cell.correct { background: var(--correct); color: #fff; }
#roll .cell.wrong { background: var(--wrong); color: #fff; }
#roll .cell.missing { box-shadow: inset 0 0 0 3px var(--missing); }

#stats-table { width: 100%; border-collapse: collapse; }
#stats-table th, #stats-table td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: right; }
#stats-table th:first-child, #stats-table td:first-child { text-align: left; }
#weak-list { padding-left: 24px; line-height: 1.8; }

/* 연습 모드 선택 */
.modes { display: flex; flex-direction: column; gap: 6px; }
.modes label {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
}
.modes label:has(input:checked) { border-color: var(--primary); background: #1e3a8a; }
.modes label:has(input:disabled) { opacity: 0.45; }
.modes .mode-text { display: flex; flex-direction: column; line-height: 1.25; }
.modes .mode-hint { font-size: 13px; color: var(--muted); }
.modes .mode-soon { font-size: 12px; color: var(--missing); margin-left: auto; }
.setting-off { opacity: 0.4; pointer-events: none; }

/* 역방향 보기 버튼 */
.choices {
  flex: none; display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  padding: 8px 16px; background: var(--panel);
}
.choice { min-height: 48px; font-size: 18px; font-weight: 600; }
.choice.correct { background: var(--correct); color: #fff; }
.choice.wrong { background: var(--wrong); color: #fff; }
.choice:disabled { opacity: 1; }
.choice:disabled:not(.correct):not(.wrong) { opacity: 0.5; }

/* 공부 순서 */
.guide-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.guide-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.guide-card.done { opacity: 0.6; }
.guide-card.done .guide-title { text-decoration: line-through; }
.guide-head { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; }
.guide-body { margin: 8px 0 4px; line-height: 1.5; color: var(--text); }
.guide-goal { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.guide-start { width: 100%; }
.guide-soon { font-size: 13px; color: var(--missing); }
.guide-tips { padding-left: 20px; line-height: 1.6; color: var(--text); }
.guide-tips li { margin-bottom: 8px; }
.content > .muted { color: var(--muted); margin: 8px 0 12px; }

/* 귀 훈련 */
#roll-ear { flex: 1; min-height: 0; position: relative; display: grid; grid-template-columns: 1fr;
  grid-template-rows: repeat(var(--white-count, 14), minmax(0, 1fr)); border-top: 1px solid var(--line); background: #0c0e12; }
#roll-ear .cell.on { background: var(--on); color: #fff; }
#roll-ear .cell.correct { background: var(--correct); color: #fff; }
#roll-ear .cell.wrong { background: var(--wrong); color: #fff; }
#roll-ear .cell.missing { box-shadow: inset 0 0 0 3px var(--missing); }
#ear-question { font-size: 22px; font-weight: 700; line-height: 1.2; }
.answer-line { font-size: 16px; color: var(--muted); min-height: 20px; }
#ear-choices { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); }
#ear-choices .choice { font-size: 16px; min-height: 44px; padding: 8px 4px; }

/* 모드별 통계 */
.stats-section { margin-bottom: 20px; }
.stats-section h2 { margin-top: 12px; }
.stats-line { margin: 0 0 8px; font-weight: 600; }
.stats-table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.stats-table th, .stats-table td { padding: 6px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }
.weak-list { padding-left: 24px; line-height: 1.7; margin: 0 0 10px; }
.stats-section > button { width: 100%; }

/* 코드 진행 */
.prog-content { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.prog-top { align-items: center; }
.prog-top select { font: inherit; font-size: 16px; padding: 6px 8px; border-radius: 8px; background: var(--panel); color: var(--text); border: 1px solid var(--line); }
.prog-presets { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 8px 0; }
.prog-slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 8px 0; }
.slot { min-height: 52px; font-size: 14px; line-height: 1.2; padding: 6px 4px; white-space: pre-line; background: var(--panel); border: 1px solid var(--line); }
.slot.empty { color: var(--muted); font-size: 20px; }
.slot.active { border-color: var(--primary); }
.slot.playing { background: var(--on); color: #fff; border-color: var(--on); }
.prog-slot-actions { justify-content: flex-end; }
.picker { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-top: 8px; }
.picker-tabs { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.picker-tabs .active { background: var(--primary); color: #fff; }
.picker-spacer { flex: 1; }
.picker-grid { display: grid; gap: 6px; }
#picker-degrees { grid-template-columns: repeat(4, 1fr); }
#picker-roots { grid-template-columns: repeat(6, 1fr); margin-bottom: 8px; }
#picker-types { grid-template-columns: repeat(3, 1fr); }
.picker-grid button.active { background: var(--primary); color: #fff; }
#roll-prog { flex: 0 0 34vh; min-height: 160px; position: relative; display: grid; grid-template-columns: 1fr;
  grid-template-rows: repeat(var(--white-count, 14), minmax(0, 1fr)); border-top: 1px solid var(--line); background: #0c0e12; }
#roll-prog .cell.white { font-size: clamp(9px, 1.6vh, 13px); }
#roll-prog .cell.black { font-size: clamp(8px, 1.3vh, 11px); }
#roll-prog .cell.on { background: var(--on); color: #fff; }
