/* ═══ Reset & Base ═══ */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', 'Noto Sans SC', sans-serif;
  background: #1a1a1a;
  color: #d4d4d4;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 12px;
}

.header { text-align: center; margin-bottom: 10px; }
.header h1 { color: #e2231a; font-weight: 600; font-size: 1.3rem; letter-spacing: 1px; }
.header .sub { color: #666; font-size: 0.78rem; margin-top: 2px; }

/* ═══ Mode Tabs ═══ */
.mode-tabs { display: flex; gap: 6px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
.tab {
  background: #3a3a3a; border: 1px solid #555; color: #d4d4d4;
  padding: 5px 14px; border-radius: 6px; cursor: pointer; font-size: 0.82rem;
  position: relative; transition: background .1s, border-color .1s;
}
.tab:hover { background: #4a4a4a; }
.tab.active { background: #c01e17; border-color: #e2231a; color: #fff; font-weight: 600; }
.history-tab { background: #2a3a3a; border-color: #00adb5; }
.history-tab:hover { background: #2e4848; }
.badge {
  background: #00adb5; color: #fff; font-size: 0.65rem; border-radius: 10px;
  padding: 1px 6px; margin-left: 5px; font-variant-numeric: tabular-nums;
}

/* ═══ Card ═══ */
.card {
  width: 100%; max-width: 920px;
  background: #2a2a2a;
  border-radius: 10px; padding: 16px 20px 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.55);
  border-left: 4px solid #e2231a;
  margin-bottom: 10px;
}

.source-line {
  font-size: 0.82rem; color: #999; margin-bottom: 8px;
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 4px;
}
.source-line b { color: #e2231a; font-style: normal; }
.source-line .passage-info { color: #666; font-size: 0.78rem; }

/* ═══ Text Display (multi-line viewport) ═══ */
.text-area-wrap {
  position: relative;
  background: #1e1e1e;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 8px;
}
.text-area {
  height: 160px;
  overflow: hidden;
  padding: 14px 18px;
  font-family: 'Courier New', 'Consolas', 'Source Code Pro', monospace;
  font-size: 20px;
  line-height: 1.75;
  letter-spacing: .3px;
  user-select: none;
  outline: none;
  cursor: text;
  word-wrap: break-word;
  white-space: pre-wrap;
  position: relative;
}
.text-area:focus { box-shadow: inset 0 0 0 2px #e2231a33; }

.char {
  border-bottom: 2px solid transparent;
  transition: color .06s, background .06s;
  border-radius: 2px;
  position: relative;
}
.char.current {
  background: rgba(0,173,181,.30);
  border-bottom-color: #00adb5;
  box-shadow: 0 0 4px rgba(0,173,181,.3);
  animation: breathe 1.4s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% {
    background: rgba(0,173,181,.22);
    box-shadow: 0 0 4px rgba(0,173,181,.25);
    border-bottom-color: #00adb5;
  }
  50% {
    background: rgba(0,173,181,.55);
    box-shadow: 0 0 14px rgba(0,173,181,.75);
    border-bottom-color: #00e5ee;
  }
}
.char.correct { color: #6bcb6b; }
.char.wrong {
  color: #f05050;
  background: rgba(240,80,80,.22);
  border-bottom-color: #f05050;
}

/* Line marker overlay */
.text-area::before {
  content: '';
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  height: 1.75em;
  background: rgba(0,173,181,.06);
  border-top: 1px solid rgba(0,173,181,.12);
  border-bottom: 1px solid rgba(0,173,181,.12);
  pointer-events: none;
  transform: translateY(-50%);
  z-index: 0;
}

/* ═══ Stats ═══ */
.stats {
  display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 6px 4px 0;
  border-top: 1px solid #3a3a3a; font-size: 0.82rem;
}
.stats .item { display: flex; align-items: baseline; gap: 3px; }
.stats .label { color: #888; }
.stats .value { font-weight: 600; font-variant-numeric: tabular-nums; color: #e0e0e0; }
.stats .value.highlight { color: #00adb5; }
.stats .value.green { color: #6bcb6b; }
.stats .value.yellow { color: #e8c547; }
.stats .value.red { color: #f05050; }

/* ═══ Controls ═══ */
.controls {
  display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; align-items: center;
}
.controls select, .controls button {
  background: #3a3a3a; border: 1px solid #555; color: #d4d4d4;
  padding: 4px 10px; border-radius: 5px; font-size: 0.8rem; cursor: pointer;
}
.controls select:hover, .controls button:hover { background: #4a4a4a; }
.controls button.primary {
  background: #c01e17; border-color: #e2231a; color: #fff; font-weight: 600;
}
.controls button.primary:hover { background: #e2231a; }
.lesson-now { color: #e0e0e0; font-weight: 600; font-size: 0.85rem; }
.section-info { color: #00adb5; font-size: 0.8rem; }

/* ═══ Lesson List ═══ */
.lesson-list-card { border-left-color: #00adb5; }
.lesson-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
}
.lesson-item {
  background: #1e1e1e; border: 1px solid #3a3a3a; border-radius: 8px;
  padding: 10px 12px; cursor: pointer;
  transition: border-color .1s, background .1s, transform .1s;
}
.lesson-item:hover { border-color: #00adb5; background: #222; transform: translateY(-1px); }
.lesson-item.current { border-color: #e2231a; background: #2a2a2a; }
.lesson-item.locked { opacity: .45; cursor: not-allowed; }
.lesson-item.locked:hover { border-color: #3a3a3a; background: #1e1e1e; transform: none; }
.li-title { color: #e0e0e0; font-size: 0.9rem; font-weight: 600; margin-bottom: 3px; }
.li-desc { color: #888; font-size: 0.75rem; margin-bottom: 6px; }
.li-state { color: #00adb5; font-size: 0.72rem; }
.lesson-item.locked .li-state { color: #666; }

/* ═══ Keyboard ═══ */
.keyboard-wrap {
  width: 100%; max-width: 920px;
  background: #222; border-radius: 10px; padding: 10px 12px 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,.55);
  border-bottom: 3px solid #e2231a;
  overflow-x: auto;
}
.kb-row { display: flex; gap: 4px; margin-bottom: 4px; justify-content: center; }
.kb-row:last-child { margin-bottom: 0; }
.kb-key {
  min-width: 40px; height: 40px;
  background: #3a3a3a; border: 1px solid #555;
  border-radius: 4px; border-bottom: 3px solid #444;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: #ccc; font-family: 'Segoe UI', sans-serif;
  cursor: default; user-select: none;
  transition: background .05s, border-color .05s, transform .05s, box-shadow .05s;
  position: relative; flex-shrink: 0;
}
.kb-key .sub { position: absolute; top: 2px; left: 3px; font-size: 9px; color: #666; }
.kb-key.w1p5 { min-width: 56px; }
.kb-key.w2   { min-width: 70px; }
.kb-key.w2p5 { min-width: 84px; }
.kb-key.w3   { min-width: 96px; }
.kb-key.w4   { min-width: 120px; }
.kb-key.w5   { min-width: 150px; }
.kb-key.w6   { min-width: 180px; }
.kb-key.w7   { min-width: 210px; }
.kb-key.pressed {
  background: #00adb5; border-color: #00bcc4; border-bottom-color: #008a91;
  color: #fff; transform: scale(.93);
  box-shadow: 0 0 10px rgba(0,173,181,.5);
}
.kb-key.wrong {
  background: #d32f2f; border-color: #e53935; border-bottom-color: #b71c1c;
  color: #fff; transform: scale(.93);
  box-shadow: 0 0 12px rgba(211,47,47,.6);
}
.kb-key.hint {
  background: rgba(0,173,181,.18);
  border-color: rgba(0,173,181,.6);
  border-bottom-color: rgba(0,173,181,.6);
  box-shadow: 0 0 8px rgba(0,173,181,.35);
  color: #00e5ee;
}
.kb-key.special { font-size: 10px; }

/* ═══ Modal ═══ */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.7); z-index: 100;
  align-items: center; justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
  background: #2a2a2a; border-radius: 12px; padding: 24px 30px;
  max-width: 420px; width: 90%;
  box-shadow: 0 12px 40px rgba(0,0,0,.6);
  border-left: 4px solid #e2231a; text-align: center;
}
.modal h2 { color: #e2231a; margin-bottom: 12px; font-size: 1.2rem; }
.modal .row {
  display: flex; justify-content: space-between;
  padding: 4px 0; border-bottom: 1px solid #3a3a3a; font-size: .9rem;
}
.modal .row:last-child { border-bottom: none; }
.modal .row .val { font-weight: 700; }
.modal .row .val.good { color: #6bcb6b; }
.modal .row .val.meh  { color: #e8c547; }
.modal .row .val.bad  { color: #f05050; }
.modal .close-btn {
  margin-top: 14px; background: #3a3a3a; border: 1px solid #555; color: #d4d4d4;
  padding: 6px 24px; border-radius: 5px; cursor: pointer; font-size: .82rem;
}
.modal .close-btn:hover { background: #4a4a4a; }

/* History modal */
.history-modal { max-width: 640px; text-align: left; }
.best-row { display: flex; gap: 8px; margin-bottom: 12px; }
.best-card {
  flex: 1; background: #1e1e1e; border-radius: 8px; padding: 8px 10px;
  text-align: center; font-size: .78rem; color: #999;
}
.best-card b { display: block; color: #00adb5; font-size: 1.05rem; margin-top: 3px; }
.charts { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.charts > div { flex: 1; min-width: 260px; background: #1e1e1e; border-radius: 8px; padding: 8px; }
.chart-label { color: #888; font-size: .72rem; margin-bottom: 4px; }
.spark { width: 100%; height: 70px; display: block; }
.chart-empty { color: #666; font-size: .75rem; padding: 24px 0; text-align: center; }
.record-list { max-height: 220px; overflow-y: auto; background: #1e1e1e; border-radius: 8px; padding: 4px; }
.rec-row {
  display: grid; grid-template-columns: 72px 24px 1fr 72px 50px;
  gap: 6px; padding: 5px 8px; border-bottom: 1px solid #2a2a2a;
  font-size: .76rem; align-items: center;
}
.rec-row:last-child { border-bottom: none; }
.rec-time { color: #888; font-variant-numeric: tabular-nums; }
.rec-title { color: #ccc; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-wpm { color: #00adb5; font-weight: 600; text-align: right; }
.rec-acc { color: #6bcb6b; text-align: right; }
.empty { color: #666; text-align: center; padding: 30px 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.danger-btn {
  background: #3a1a1a; border: 1px solid #b71c1c; color: #f05050;
  padding: 6px 14px; border-radius: 5px; cursor: pointer; font-size: .82rem;
}
.danger-btn:hover { background: #4a2222; }

/* ═══ Word Mode ═══ */
.word-card { border-left-color: #00adb5; }
.word-display {
  text-align: center; padding: 10px 0 12px;
  min-height: 160px;
  display: flex; flex-direction: column; justify-content: center;
}
.word-phonetic {
  color: #888; font-size: 1rem; font-family: 'Segoe UI', sans-serif;
  min-height: 1.4em; margin-bottom: 6px;
}
.word-input-area {
  font-family: 'Courier New', 'Consolas', monospace;
  font-size: 40px; line-height: 1.4; letter-spacing: 2px;
  min-height: 1.4em; padding: 6px 10px; margin-bottom: 10px;
  outline: none; cursor: text; user-select: none;
  border-radius: 6px; background: #1e1e1e;
}
.word-input-area:focus { box-shadow: inset 0 0 0 2px #00adb555; }
.word-input-area .char.current {
  background: rgba(0,173,181,.30); border-bottom-color: #00adb5;
  border-radius: 3px; animation: breathe 1.4s ease-in-out infinite;
}
.word-input-area .char.correct { color: #6bcb6b; }
.word-input-area .char.wrong {
  color: #f05050; background: rgba(240,80,80,.22); border-radius: 3px;
}
.word-meaning { color: #e0e0e0; font-size: 1.05rem; min-height: 1.4em; }
.word-controls { justify-content: center; }
.word-source { color: #00adb5; font-size: 0.8rem; }

/* ═══ Import Modal ═══ */
.import-modal { max-width: 520px; text-align: left; }
.import-hint { color: #999; font-size: 0.8rem; margin-bottom: 10px; }
.import-hint b { color: #00adb5; }
.import-modal textarea {
  width: 100%; background: #1e1e1e; color: #d4d4d4; border: 1px solid #555;
  border-radius: 6px; padding: 10px; font-family: 'Courier New', monospace;
  font-size: 0.85rem; resize: vertical; outline: none;
}
.import-modal textarea:focus { border-color: #00adb5; }
.primary-btn {
  background: #c01e17; border: 1px solid #e2231a; color: #fff; font-weight: 600;
  padding: 6px 20px; border-radius: 5px; cursor: pointer; font-size: 0.82rem;
}
.primary-btn:hover { background: #e2231a; }

.footer { margin-top: 8px; color: #444; font-size: .7rem; text-align: center; }

/* ═══ Responsive ═══ */
@media (max-width: 700px) {
  .card { padding: 12px 10px; }
  .text-area { height: 120px; font-size: 16px; padding: 10px 12px; line-height: 1.6; }
  .kb-key { min-width: 30px; height: 32px; font-size: 10px; }
  .kb-key.w1p5 { min-width: 42px; }
  .kb-key.w2   { min-width: 52px; }
  .kb-key.w2p5 { min-width: 62px; }
  .kb-key.w3   { min-width: 72px; }
  .kb-key.w4   { min-width: 84px; }
  .kb-key.w5   { min-width: 100px; }
  .kb-key.w6   { min-width: 120px; }
  .kb-key.w7   { min-width: 140px; }
  .kb-row { gap: 3px; margin-bottom: 3px; }
  .keyboard-wrap { padding: 8px; }
  .lesson-list { grid-template-columns: 1fr; }
  .rec-row { grid-template-columns: 60px 20px 1fr 56px 42px; font-size: .72rem; }
}
