/* =========================================================
   BrainEtch — tools.css
   Tool workspace shell + each memorization tool.
   ========================================================= */

/* ---------- Workspace shell ---------- */
.workspace-screen {
  flex: 1;
  display: flex;
  min-height: 0;
  background: var(--bg-base);
  overflow: hidden;
}
.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.chunk-nav {
  width: 280px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.chunk-nav .nav-head {
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--border);
}
.chunk-nav .nav-head .back {
  color: var(--text-secondary);
  font-size: 12px;
  display: inline-flex; align-items: center; gap: 4px;
  margin-bottom: 10px;
  cursor: pointer;
  background: transparent; border: 0;
}
.chunk-nav .nav-head .back:hover { color: var(--text-primary); }
.chunk-nav .nav-head .title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.02em;
  margin-bottom: 10px;
  color: var(--text-primary);
  line-height: 1.25;
}
.chunk-nav .nav-list .all-entry {
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.nav-chunk.all {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.nav-chunk.all .num { color: var(--accent); font-size: 12px; }
.nav-chunk.all .preview { font-family: var(--font-body); font-size: 12px; color: var(--text-primary); }
.nav-chunk.all.active .preview { color: var(--accent-bright); }
.chunk-nav .nav-head .mm {
  display: flex; align-items: center; gap: 10px;
  font-size: 11px;
  color: var(--text-secondary);
}
.chunk-nav .nav-head .mm .progress { flex: 1; }
.chunk-nav .nav-list {
  overflow-y: auto;
  padding: 8px 10px 16px;
  flex: 1;
}
.nav-chunk {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  cursor: pointer;
  position: relative;
  background: transparent; border-width: 0; border-left-width: 2px; border-style: solid; border-color: transparent;
}
.nav-chunk:hover { background: var(--bg-raised); }
.nav-chunk.active {
  background: var(--accent-subtle);
  border-left-color: var(--accent);
}
.nav-chunk .num {
  font-size: 11px;
  color: var(--text-placeholder);
  font-variant-numeric: tabular-nums;
  min-width: 20px;
}
.nav-chunk.active .num { color: var(--accent-bright); }
.nav-chunk .preview {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}
.nav-chunk.active .preview { color: var(--text-primary); }
.nav-chunk .dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
  background: var(--bg-raised-2);
  border: 1px solid var(--border-bright);
}
.nav-chunk .dot.g { background: var(--green-bright); border-color: transparent; }
.nav-chunk .dot.a { background: var(--accent); border-color: transparent; }
.nav-chunk .dot.o { background: #e19a5a; border-color: transparent; }
.nav-chunk .due {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--blue-bright);
  position: absolute;
  left: 2px; top: 50%;
  transform: translateY(-50%);
  box-shadow: 0 0 8px rgba(74,138,191,0.7);
}

/* ---------- Tool tab bar ---------- */
.tool-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  padding: 0 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tool-tabs::-webkit-scrollbar { display: none; }
.tool-tab {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 14px 12px;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 11px;
  position: relative;
  white-space: nowrap;
  flex-shrink: 0;
  background: transparent;
  border-left: 0; border-right: 0; border-top: 0;
  font-family: var(--font-body);
}
.tool-tab:hover { color: var(--text-primary); }
.tool-tab .ic { font-size: 17px; line-height: 1; }
.tool-tab.active {
  color: var(--accent-bright);
  border-bottom-color: var(--accent);
}
.tool-tab .pro {
  position: absolute;
  top: 8px; right: 2px;
  font-size: 8px;
  color: var(--accent);
  letter-spacing: 0.1em;
  font-weight: 600;
}

/* ---------- Workspace main area ---------- */
.workspace-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}
.workspace-header-mobile {
  display: none;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  background: var(--bg-surface);
}
.workspace-header-mobile .back {
  color: var(--text-secondary); background: transparent; border: 0;
  padding: 4px 6px; cursor: pointer;
  display: inline-flex; align-items: center;
}
.workspace-header-mobile .title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.workspace-header-mobile .chunk-of {
  font-size: 11px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.tool-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.tool-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.tool-footer .score {
  font-size: 12px;
  color: var(--text-secondary);
}
.tool-footer .score b { color: var(--green-bright); font-weight: 500; }
.tool-footer .score.warn b { color: var(--orange); }
.tool-footer .nav-arrows { margin-left: auto; display: flex; gap: 8px; }
.tool-footer .arrow {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-raised);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
}
.tool-footer .arrow:hover { color: var(--text-primary); border-color: var(--border-bright); }
.tool-footer .arrow:disabled { opacity: 0.4; cursor: not-allowed; }

.chunk-heading-label {
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 22px;
  text-align: center;
}

/* ---------- Read mode ---------- */
.read-body {
  padding: 40px 48px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}
.read-body .text {
  font-family: var(--font-mono);
  font-size: 18px;
  line-height: 2.1;
  color: var(--text-primary);
  letter-spacing: 0.01em;
  text-align: left;
  width: 100%;
  white-space: pre-wrap;
}

/* ---------- First letters ---------- */
.first-letters-body {
  padding: 40px 48px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  gap: 22px;
}
.first-letters-body .hint-text {
  font-family: var(--font-mono);
  font-size: 20px;
  line-height: 2.1;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  text-align: left;
  width: 100%;
  white-space: pre-wrap;
}
.first-letters-body .hint-text .letter { color: var(--text-primary); }
.first-letters-body textarea.input {
  background: var(--bg-surface);
  font-family: var(--font-mono);
  min-height: 160px;
  font-size: 14px;
  line-height: 1.7;
}
.first-letters-body .comparison {
  font-family: var(--font-mono);
  font-size: 16px;
  line-height: 2;
  width: 100%;
  white-space: pre-wrap;
}
.first-letters-body .comparison .w-ok { color: var(--green-bright); }
.first-letters-body .comparison .w-bad { color: var(--red-bright); text-decoration: line-through; }
.first-letters-body .comparison .w-miss { color: var(--text-placeholder); opacity: 0.7; }

/* ---------- Cloze ---------- */
.cloze-body {
  flex: 1;
  overflow-y: auto;
  padding: 36px 48px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.cloze-text {
  font-family: var(--font-mono);
  font-size: 20px;
  line-height: 2.3;
  color: var(--text-primary);
  max-width: 780px;
  text-align: left;
  letter-spacing: 0.01em;
  width: 100%;
}
.cloze-text .word { padding: 0 1px; }
.cloze-text .blank {
  display: inline-block;
  border-bottom: 2px solid var(--border-bright);
  color: transparent;
  min-width: 40px;
  vertical-align: baseline;
  margin: 0 2px;
  cursor: pointer;
  transition: border-color 0.15s;
  position: relative;
}
.cloze-text .blank:hover { border-bottom-color: var(--accent); }
.cloze-text .blank.revealed {
  color: var(--text-primary);
  border-bottom-color: var(--border);
  cursor: default;
}
.cloze-text .blank.correct {
  color: var(--green-bright);
  border-bottom-color: var(--green-bright);
}
.cloze-text .blank.wrong {
  color: var(--red-bright);
  border-bottom-color: var(--red-bright);
  text-decoration: line-through;
}
.cloze-text .blank-input {
  background: transparent;
  border: 0;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: inherit;
  width: 80px;
  padding: 0 2px;
  border-bottom: 2px solid var(--accent);
  outline: none;
  text-align: center;
}

.difficulty-block {
  max-width: 780px;
  width: 100%;
  margin: 36px auto 0;
}
.difficulty-block .label {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 10px;
  display: flex; justify-content: space-between;
}
.difficulty-block .label .val { color: var(--accent-bright); }
.difficulty-block .slider-input {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--bg-raised);
  border-radius: 3px;
  outline: none;
  margin: 16px 0 10px;
}
.difficulty-block .slider-input::-webkit-slider-runnable-track {
  height: 6px;
  background: linear-gradient(to right, var(--accent) 0%, var(--accent) var(--sv,60%), var(--bg-raised) var(--sv,60%), var(--bg-raised) 100%);
  border-radius: 3px;
}
.difficulty-block .slider-input::-moz-range-track {
  height: 6px;
  background: var(--bg-raised);
  border-radius: 3px;
}
.difficulty-block .slider-input::-moz-range-progress {
  height: 6px;
  background: linear-gradient(90deg, var(--accent), var(--accent-bright));
  border-radius: 3px;
}
.difficulty-block .slider-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  background: var(--accent-bright);
  border: 2px solid #1a0f02;
  border-radius: 50%;
  margin-top: -6px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(212,146,42,0.4);
}
.difficulty-block .slider-input::-moz-range-thumb {
  width: 18px; height: 18px;
  background: var(--accent-bright);
  border: 2px solid #1a0f02;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(212,146,42,0.4);
}
.difficulty-block .ticks {
  display: flex; justify-content: space-between;
  font-size: 10px;
  color: var(--text-placeholder);
  letter-spacing: 0.1em;
}

/* ---------- Blank page ---------- */
.blank-page-body {
  padding: 36px 48px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
  gap: 20px;
}
.blank-page-body textarea.input {
  background: var(--bg-surface);
  font-family: var(--font-mono);
  min-height: 260px;
  font-size: 14px;
  line-height: 1.8;
  width: 100%;
}
.blank-page-body .comparison {
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 2;
  width: 100%;
  white-space: pre-wrap;
}
.blank-page-body .comparison .w-ok { color: var(--green-bright); }
.blank-page-body .comparison .w-miss { color: var(--text-placeholder); opacity: 0.55; border-bottom: 1px dashed var(--red); }
.blank-page-body .comparison .w-extra { color: var(--red-bright); text-decoration: line-through; }
.blank-page-body .score-summary {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 28px;
  color: var(--accent-bright);
}
.blank-page-body .score-summary .small {
  font-family: var(--font-body);
  font-style: normal;
  font-size: 12px;
  color: var(--text-secondary);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: 6px;
}

/* ---------- Flashcard ---------- */
.flashcard-area {
  flex: 1; display: flex; flex-direction: column;
  padding: 28px 40px;
  gap: 18px;
  background: radial-gradient(ellipse at top, rgba(212,146,42,0.05), transparent 60%);
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}
.flashcard-area .recall-label {
  text-align: center;
  color: var(--text-secondary);
  font-size: 12px;
  letter-spacing: 0.06em;
}
.flashcard {
  perspective: 1600px;
  min-height: 340px;
  flex: 1;
  cursor: pointer;
}
.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 340px;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(.2,.8,.2,1);
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }

.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: linear-gradient(180deg, var(--bg-raised-2), var(--bg-surface));
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-lg);
  padding: 28px 28px 44px;
  display: flex; flex-direction: column;
  box-shadow: 0 30px 60px -20px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.03);
  overflow: hidden;
}
.flashcard-face.back { transform: rotateY(180deg); }
.flashcard-face .front-label {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-placeholder);
  margin-bottom: 14px;
}
.flashcard-face .chunk-body {
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.8;
  color: var(--text-primary);
  flex: 1;
  white-space: pre-wrap;
}
.flashcard-face .ornament { display: none; }
.flashcard-nav-row {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
}
.flashcard-nav-row .btn {
  flex: 1;
  min-height: 38px;
}

.flip-hint {
  text-align: center;
  color: var(--text-placeholder);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.flip-affordance {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--accent);
  opacity: 0.55;
  pointer-events: none;
  transition: opacity 0.4s;
  animation: flip-pulse 2.4s ease-in-out infinite;
}
.flip-affordance span {
  font-family: var(--font-body);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 500;
}
.flashcard.flipped .flashcard-face.front .flip-affordance { opacity: 0; }
@keyframes flip-pulse {
  0%, 100% { transform: translateX(-50%) translateY(0); opacity: 0.55; }
  50%      { transform: translateX(-50%) translateY(-3px); opacity: 0.85; }
}

.rating-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.rating-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 8px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  display: flex; flex-direction: column;
  align-items: center; gap: 5px;
  cursor: pointer;
  transition: transform 0.12s, background 0.12s;
}
.rating-btn:hover { transform: translateY(-1px); }
.rating-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.rating-btn .emo { font-size: 20px; }
.rating-btn.r { border-color: rgba(139,58,58,0.55); background: rgba(139,58,58,0.15); color: #d8a0a0; }
.rating-btn.o { border-color: rgba(200,122,42,0.5); background: rgba(200,122,42,0.12); color: #e5b381; }
.rating-btn.g { border-color: rgba(58,125,68,0.5); background: rgba(58,125,68,0.15); color: var(--green-bright); }
.rating-btn.b { border-color: rgba(74,138,191,0.5); background: rgba(74,138,191,0.15); color: var(--blue-bright); }
.rating-btn .kbd {
  font-size: 9px;
  color: var(--text-placeholder);
  letter-spacing: 0.1em;
  margin-top: 4px;
  opacity: 0.7;
}

/* ---------- Spaced Rep Queue ---------- */
.sr-queue-empty {
  padding: 60px 40px;
  text-align: center;
  max-width: 520px;
  margin: 0 auto;
}
.sr-queue-empty .ic { font-size: 52px; opacity: 0.5; margin-bottom: 14px; }
.sr-queue-empty h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}
.sr-queue-progress {
  padding: 16px 32px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex; gap: 16px; align-items: center;
  font-size: 12px; color: var(--text-secondary);
}
.sr-queue-progress .progress { flex: 1; }

/* ---------- Listen & Repeat ---------- */
.listen-body {
  padding: 40px 48px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
  gap: 22px;
}
.listen-body .text {
  font-family: var(--font-mono);
  font-size: 18px;
  line-height: 2.1;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
  text-align: left;
  width: 100%;
  white-space: pre-wrap;
}
.listen-body .text .w {
  transition: color 0.12s, background 0.12s;
  padding: 0 1px;
  border-radius: 3px;
}
.listen-body .text .w.current {
  color: var(--accent-bright);
  background: rgba(212,146,42,0.12);
}
.listen-body .text .w.spoken { color: var(--text-primary); }

.listen-controls {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}
.listen-controls .play-btn {
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--accent);
  color: #1a0f02;
  display: flex; align-items: center; justify-content: center;
  border: 0; cursor: pointer;
  font-size: 24px;
  box-shadow: 0 6px 18px rgba(212,146,42,0.35);
  font-weight: 700;
}
.listen-controls .play-btn:hover { background: var(--accent-bright); }
.listen-controls .speed-wrap {
  display: flex; flex-direction: column; gap: 4px;
  min-width: 180px;
}
.listen-controls .speed-wrap label {
  font-size: 10px; letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-secondary);
  display: flex; justify-content: space-between;
}
.listen-controls input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

/* ---------- Scramble ---------- */
.scramble-body {
  padding: 36px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
}
.scramble-target {
  min-height: 80px;
  background: var(--bg-surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex; flex-wrap: wrap; gap: 6px;
  align-content: flex-start;
  transition: border-color .2s, background .2s, box-shadow .2s, min-height .25s;
}
.scramble-target.over {
  border-color: var(--accent);
  background: rgba(212,146,42,0.08);
  box-shadow: 0 0 0 2px rgba(212,146,42,0.18);
}
.scramble-pool {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 10px 0;
  transition: min-height .25s;
}
.scramble-chip.dragging { opacity: 0.35; }
.scramble-chip.flying {
  box-shadow: 0 10px 30px -6px rgba(0,0,0,0.45), 0 0 0 2px rgba(212,146,42,0.3);
  transform-origin: center;
}
.scramble-chip.placed {
  animation: chip-land .28s ease-out both;
}
@keyframes chip-land {
  0%   { transform: scale(1.08); }
  60%  { transform: scale(0.97); }
  100% { transform: scale(1); }
}
.scramble-chip {
  background: var(--bg-raised);
  border: 1px solid var(--border-bright);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 14px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: transform 0.12s, background 0.12s;
}
.scramble-chip:hover { transform: translateY(-1px); background: var(--bg-raised-2); }
.scramble-chip.ok {
  background: rgba(58,125,68,0.2);
  border-color: rgba(76,175,96,0.5);
  color: var(--green-bright);
}
.scramble-chip.bad {
  background: rgba(139,58,58,0.2);
  border-color: rgba(201,74,74,0.5);
  color: #e8a0a0;
  animation: shake 0.3s;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* ---------- Speak It ---------- */
.speak-area {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center;
  padding: 28px 22px;
  gap: 18px;
  background: radial-gradient(ellipse at center, rgba(139,58,58,0.1), transparent 70%);
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}
.speak-area .intro-text {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-placeholder);
  letter-spacing: 0.02em;
  line-height: 1.6;
  max-height: 72px;
  overflow: hidden;
  padding: 0 8px;
  text-align: center;
}
.speak-controls-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.mic-btn {
  width: 150px; height: 150px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #b23a3a, #7a2323 80%);
  display: flex; align-items: center; justify-content: center;
  border: none;
  color: #f7e4e0;
  position: relative;
  box-shadow: 0 20px 50px rgba(139,58,58,0.5), 0 0 0 3px rgba(139,58,58,0.3);
  cursor: pointer;
  transition: transform 0.15s;
}
.mic-btn:hover { transform: scale(1.02); }
.mic-btn.idle {
  background: radial-gradient(circle at 40% 35%, #3d4a5c, #1e2530 80%);
  color: var(--text-primary);
  box-shadow: 0 12px 32px rgba(0,0,0,0.6);
}
.mic-btn .ring {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid rgba(200,80,80,0.6);
  animation: pulse-ring 1.5s ease-out infinite;
}
.mic-btn .ring.r2 { inset: -28px; border-color: rgba(200,80,80,0.35); animation-delay: 0.25s; }
.mic-btn .ring.r3 { inset: -52px; border-color: rgba(200,80,80,0.15); animation-delay: 0.5s; }
.mic-btn.idle .ring { display: none; }
@keyframes pulse-ring {
  0% { transform: scale(0.95); opacity: 1; }
  100% { transform: scale(1.15); opacity: 0; }
}
.speak-area .timer {
  font-family: var(--font-mono);
  font-size: 26px;
  color: var(--text-primary);
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
}
.transcript {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-placeholder);
  line-height: 1.7;
  width: 100%;
  min-height: 96px;
  max-height: 180px;
  overflow-y: auto;
  text-align: left;
}
.transcript .spoken { color: var(--text-primary); }
.transcript .cursor {
  display: inline-block;
  width: 9px; height: 15px;
  background: var(--accent);
  vertical-align: middle;
  margin-left: 2px;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.speak-area .stop-btn {
  background: transparent;
  border: 1px solid var(--border-bright);
  color: var(--text-primary);
  padding: 12px 26px;
  border-radius: 999px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font-body);
}
.speak-area .stop-btn:hover { background: var(--bg-raised); }
.speak-area .note {
  text-align: center;
  font-size: 11px;
  color: var(--text-placeholder);
  line-height: 1.5;
}
.speak-area .note b { color: var(--accent); font-weight: 500; }
.speak-area .result-block {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-md);
  padding: 20px;
}
.speak-area .result-block .score-head {
  display: flex; align-items: baseline; gap: 10px;
  margin-bottom: 12px;
}
.speak-area .result-block .score-head .n {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 32px;
  color: var(--accent-bright);
  letter-spacing: -0.03em;
}
.speak-area .result-block .score-head .l {
  color: var(--text-secondary);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.speak-area .result-block .comparison {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.9;
  white-space: pre-wrap;
}
.speak-area .result-block .comparison .w-ok { color: var(--green-bright); }
.speak-area .result-block .comparison .w-miss { color: var(--text-placeholder); opacity: 0.55; border-bottom: 1px dashed var(--red); }
.speak-area .result-block .comparison .w-extra { color: var(--red-bright); text-decoration: line-through; }

/* ---------- Mnemonic & Quiz ---------- */
.ai-body {
  padding: 36px 48px;
  display: flex; flex-direction: column; gap: 20px;
  max-width: 780px;
  margin: 0 auto;
  width: 100%;
}
.source-chunk {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
  white-space: pre-wrap;
  max-height: 180px;
  overflow-y: auto;
}
.ai-result {
  background: linear-gradient(180deg, rgba(212,146,42,0.06), rgba(212,146,42,0.02));
  border: 1px solid rgba(212,146,42,0.35);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-primary);
  white-space: pre-wrap;
  min-height: 120px;
  position: relative;
}
.ai-result .loading-dots {
  display: inline-flex; gap: 6px;
}
.ai-result .loading-dots span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  animation: dotpulse 1.2s ease-in-out infinite;
}
.ai-result .loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-result .loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotpulse {
  0%, 80%, 100% { transform: scale(0.5); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}
.ai-body .ai-actions { display: flex; gap: 10px; }

.quiz-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-lg);
  padding: 26px 24px;
  display: flex; flex-direction: column; gap: 16px;
}
.quiz-card .q-num {
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-placeholder);
}
.quiz-card .question {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.3;
}
.quiz-card .feedback {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  font-size: 13px;
}
.quiz-card .feedback.ok { color: var(--green-bright); }
.quiz-card .feedback.bad { color: var(--red-bright); }
.quiz-card .feedback .truth {
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
  margin-top: 6px;
  display: block;
}
.quiz-score-summary {
  text-align: center;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 32px;
  letter-spacing: -0.03em;
  color: var(--accent-bright);
  padding: 30px 0 10px;
}

/* ---------- First Letters (redesigned) ---------- */
.fl-hint {
  font-family: var(--font-mono);
  font-size: 18px;
  line-height: 2.2;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
  text-align: left;
  width: 100%;
  white-space: pre-wrap;
  word-spacing: 4px;
}
.fl-hint .fl-word-full {
  color: var(--text-primary);
  font-weight: 500;
}
.fl-hint .fl-letter {
  color: var(--text-primary);
  font-weight: 500;
}
.fl-hint .fl-blank {
  display: inline-block;
  border-bottom: 2px solid var(--border-bright);
  min-width: 8px;
  color: transparent;
  vertical-align: baseline;
  transition: color 0.15s, border-color 0.15s;
}
.fl-hint .fl-blank.revealed {
  color: var(--accent-bright);
  border-bottom-color: var(--accent);
}
.fl-hint .fl-punct {
  color: var(--text-placeholder);
}

/* ---------- Cloze Quiz ---------- */
.cloze-quiz-body {
  flex: 1;
  overflow-y: auto;
  padding: 36px 48px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.cloze-quiz-text {
  font-family: var(--font-mono);
  font-size: 20px;
  line-height: 2.3;
  color: var(--text-primary);
  max-width: 780px;
  text-align: left;
  letter-spacing: 0.01em;
  width: 100%;
  flex: 1;
}
.cloze-quiz-text .blank {
  display: inline-block;
  border-bottom: 2px solid var(--border-bright);
  color: transparent;
  min-width: 60px;
  vertical-align: baseline;
  margin: 0 2px;
  transition: all 0.2s;
}
.cloze-quiz-text .blank.filled {
  color: var(--green-bright);
  border-bottom-color: var(--green-bright);
}
.cloze-quiz-text .blank.active {
  border-bottom-color: var(--accent);
  background: rgba(212,146,42,0.12);
  box-shadow: 0 0 0 2px rgba(212,146,42,0.3);
  border-radius: 4px 4px 0 0;
}
.cloze-choices {
  position: sticky;
  bottom: 0;
  margin-top: 32px;
  width: 100%;
  max-width: 780px;
  display: flex;
  gap: 12px;
  padding: 18px 0;
  background: linear-gradient(180deg, transparent, var(--bg-base) 20%);
  justify-content: center;
  flex-wrap: wrap;
}
.cloze-choice {
  flex: 1 1 180px;
  max-width: 240px;
  min-height: 56px;
  background: var(--bg-surface);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 16px;
  padding: 14px 18px;
  cursor: pointer;
  transition: all 0.14s;
}
.cloze-choice:hover {
  background: var(--bg-raised);
  border-color: var(--accent);
  transform: translateY(-2px);
}
.cloze-choice.correct {
  background: rgba(58,125,68,0.3);
  border-color: var(--green-bright);
  color: var(--green-bright);
}
.cloze-choice.wrong {
  background: rgba(139,58,58,0.25);
  border-color: var(--red-bright);
  color: #e8a0a0;
  animation: shake 0.32s;
}
.cloze-choice.skeleton {
  background: linear-gradient(100deg, var(--bg-surface) 30%, var(--bg-raised) 50%, var(--bg-surface) 70%);
  background-size: 300% 100%;
  animation: cloze-shimmer 1.2s linear infinite;
  color: transparent;
  cursor: default;
  pointer-events: none;
}
@keyframes cloze-shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
.cloze-quiz-meta {
  width: 100%;
  max-width: 780px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 16px;
}
.cloze-quiz-meta .score-frag {
  font-family: var(--font-mono);
  color: var(--accent-bright);
  letter-spacing: -0.01em;
  text-transform: none;
  font-size: 13px;
}

/* ---------- Responsive tweaks for tools ---------- */
@media (max-width: 900px) {
  .chunk-nav { display: none; }
  .workspace-header-mobile { display: flex; }
  .tool-tabs { padding: 0 8px; }
  .tool-tab .lbl { display: none; }
  .cloze-body { padding: 20px 18px; }
  .cloze-text { font-size: 17px; line-height: 2; }
  .read-body { padding: 22px 18px; }
  .read-body .text { font-size: 15px; line-height: 1.9; }
  .first-letters-body { padding: 22px 18px; gap: 14px; }
  .first-letters-body .hint-text { font-size: 16px; }
  .blank-page-body { padding: 22px 18px; }
  .flashcard-area { padding: 18px 16px; }
  .flashcard-face { padding: 20px 18px 36px; }
  .flashcard-face .chunk-body { font-size: 14px; }
  .listen-body { padding: 22px 18px; }
  .listen-body .text { font-size: 15px; line-height: 1.9; }
  .scramble-body { padding: 22px 18px; }
  .ai-body { padding: 22px 18px; }
  .tool-footer { padding: 10px 16px; }
  .rating-btn { font-size: 11px; padding: 10px 4px; }
  .rating-btn .kbd { display: none; }
  .mic-btn { width: 130px; height: 130px; }
  .mic-btn svg { width: 44px !important; height: 44px !important; }
}
