/* TypoMem — Editorial calm v3
   ----------------------------------------------------------------
   Adds: Settings drawer, optional metadata fields, theme switcher,
   icon-aligned section heads. Practice input remains untouched.
*/

@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:opsz,wght@8..60,400;8..60,500;8..60,600;8..60,700&family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  /* Paper & ink */
  --paper:        #f5f1ea;
  --paper-2:      #efe9df;
  --paper-3:      #e8e0d2;
  --panel:        #fbf8f2;
  --ink:          #1c1a17;
  --ink-2:        #2e2a25;
  --muted:        #7a7268;
  --muted-2:      #9a9286;
  --rule:         #d9d1bf;
  --rule-2:       #c8bfa9;

  /* States — only as text color, never background fills */
  --ok:           #2f6b3a;
  --soft:         #8a6a18;
  --wrong:        #a82a25;

  /* Functional accent */
  --accent:       #4a3b2a;
  --accent-bg:    #e8dec8;
  --danger:       #a82a25;

  /* Type */
  --serif: "Source Serif 4", "PingFang SC", "Songti SC", "Source Han Serif SC", Georgia, serif;
  --sans:  "IBM Plex Sans", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --mono:  "IBM Plex Mono", "SF Mono", ui-monospace, "JetBrains Mono", "PingFang SC", monospace;

  --reading: "Source Serif 4", Georgia, "Songti SC", "PingFang SC", serif;

  /* Geometry */
  --radius:   3px;
  --radius-2: 6px;
  --gutter:   clamp(20px, 3vw, 36px);
  --maxw:     1280px;
}

:root[data-theme="light"] {
  --paper: #f7f8fa;
  --paper-2: #eef1f5;
  --paper-3: #e2e7ee;
  --panel: #ffffff;
  --ink: #171a1f;
  --ink-2: #292f38;
  --muted: #697382;
  --muted-2: #98a2b3;
  --rule: #d9dee8;
  --rule-2: #c4ccd8;
  --accent-bg: #e8edf5;
}

:root[data-theme="dark"] {
  --paper: #191814;
  --paper-2: #222019;
  --paper-3: #2b2921;
  --panel: #211f19;
  --ink: #ded3c2;
  --ink-2: #cfc3b2;
  --muted: #9b9284;
  --muted-2: #766f66;
  --rule: #3b362d;
  --rule-2: #544d42;
  --ok: #7fbd83;
  --soft: #d5b85a;
  --wrong: #e27972;
  --accent: #ded3c2;
  --accent-bg: #342f25;
  --danger: #e27972;
}

:root[data-theme="cyberpunk2077"] {
  --paper: #272932;
  --paper-2: #20222b;
  --paper-3: #343646;
  --panel: #242631;
  --ink: #e455ae;
  --ink-2: #c1deff;
  --muted: #7b8097;
  --muted-2: #9381ff;
  --rule: #742d8b;
  --rule-2: #9381ff;
  --ok: #40ffe9;
  --soft: #fdf500;
  --wrong: #c71515;
  --accent: #fdf500;
  --accent-bg: #742d8b;
  --danger: #c71515;
}

/* ------------------------------------------------------------- reset */

* { box-sizing: border-box; }
html, body { min-height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.55 var(--sans);
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  background-image:
    radial-gradient(rgba(120, 100, 70, 0.045) 1px, transparent 1px),
    radial-gradient(rgba(120, 100, 70, 0.025) 1px, transparent 1px);
  background-size: 3px 3px, 7px 7px;
  background-position: 0 0, 1px 2px;
}

button, input, textarea, select { font: inherit; color: inherit; }
::selection { background: var(--accent-bg); color: var(--ink); }

/* ------------------------------------------------------------- icons */

.icon {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  color: currentColor;
  vertical-align: -2px;
  display: inline-block;
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
}
.icon-btn-text {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.icon-btn-text .icon { width: 13px; height: 13px; }

/* ------------------------------------------------------------- form atoms */

button {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  padding: 9px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  letter-spacing: 0.02em;
  line-height: 1.2;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease, transform 60ms ease;
}
button:hover { background: var(--ink-2); }
button:active { transform: translateY(0.5px); }
button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

button.secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--rule-2);
}
button.secondary:hover { background: var(--paper-2); border-color: var(--ink); }

button.quiet {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 7px 10px;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
button.quiet:hover { color: var(--ink); background: var(--paper-2); }

button.danger {
  background: transparent;
  color: var(--danger);
  border-color: rgba(168, 42, 37, 0.35);
}
button.danger:hover { background: rgba(168, 42, 37, 0.06); border-color: var(--danger); }

button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

select, input, textarea {
  border: 1px solid var(--rule);
  background: var(--panel);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 9px 11px;
  transition: border-color 120ms ease, background 120ms ease;
}
select:hover, input:hover, textarea:hover { border-color: var(--rule-2); }
select:focus, input:focus, textarea:focus {
  outline: none;
  border-color: var(--ink);
  background: var(--panel);
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'><path d='M2 4l3 3 3-3' fill='none' stroke='%237a7268' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
}

input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  border: 1px solid var(--rule-2);
  border-radius: 2px;
  background: var(--panel);
  cursor: pointer;
  position: relative;
  flex: 0 0 auto;
  padding: 0;
  margin: 0;
  transition: background 120ms, border-color 120ms;
}
input[type="checkbox"]:hover { border-color: var(--ink); }
input[type="checkbox"]:checked {
  background: var(--ink);
  border-color: var(--ink);
}
input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 4px; top: 1px;
  width: 4px; height: 8px;
  border: solid var(--paper);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}

input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border: 1px solid var(--rule-2);
  border-radius: 50%;
  background: var(--panel);
  cursor: pointer;
  position: relative;
  flex: 0 0 auto;
  margin: 0;
  padding: 0;
}
input[type="radio"]:checked { border-color: var(--ink); }
input[type="radio"]:checked::after {
  content: "";
  position: absolute;
  inset: 3px;
  background: var(--ink);
  border-radius: 50%;
}

/* ------------------------------------------------------------- lock */

.lock-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at top, rgba(255,255,255,0.6), transparent 60%),
    var(--paper);
}

.lock-box {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--rule);
  padding: 36px 32px 28px;
  border-radius: var(--radius-2);
  display: grid;
  gap: 14px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.7) inset, 0 24px 48px -24px rgba(28, 26, 23, 0.18);
}

.lock-box .brand {
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-style: italic;
  margin-bottom: 6px;
}

.lock-box input { width: 100%; padding: 12px 13px; }

.lock-error {
  color: var(--wrong);
  font-size: 13px;
  font-family: var(--mono);
}

/* ------------------------------------------------------------- app shell */

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(300px, 360px) 1fr;
  max-width: var(--maxw);
  margin: 0 auto;
}

/* ------------------------------------------------------------- sidebar */

.sidebar {
  border-right: 1px solid var(--rule);
  background:
    linear-gradient(to right, transparent, rgba(0,0,0,0.012)),
    var(--paper);
  padding: var(--gutter);
  display: flex;
  flex-direction: column;
  gap: 26px;
  min-height: 100vh;
  position: sticky;
  top: 0;
  align-self: start;
  max-height: 100vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--rule-2) transparent;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--rule-2); border-radius: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }

.side-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--rule);
}

.app-title {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.015em;
  font-style: italic;
  line-height: 1;
}
.app-subtitle {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
  letter-spacing: 0.02em;
}
.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.pane { min-width: 0; display: block; }

.pane-title {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.pane-title .icon { width: 13px; height: 13px; color: var(--muted); }
.pane-title > span { display: inline-block; }
.pane-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--rule);
  margin-left: 4px;
}

/* Library list */

.material-list {
  display: grid;
  gap: 1px;
  max-height: min(34vh, 320px);
  overflow-y: auto;
  padding: 0;
  margin: 0 -4px;
  scrollbar-width: thin;
  scrollbar-color: var(--rule-2) transparent;
}
.material-list::-webkit-scrollbar { width: 6px; }
.material-list::-webkit-scrollbar-thumb { background: var(--rule-2); border-radius: 3px; }

.material-item {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--ink);
  border: 0;
  border-top: 1px solid var(--rule);
  padding: 11px 4px 11px 14px;
  border-radius: 0;
  cursor: pointer;
  position: relative;
  transition: background 120ms ease;
  font-size: 13px;
}
.material-item:first-child { border-top: 0; }
.material-item:hover { background: var(--paper-2); }
.material-item:focus-visible {
  outline: none;
  background: var(--paper-2);
  box-shadow: inset 2px 0 0 var(--ink);
}
.material-item.active::before {
  content: "";
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 2px;
  background: var(--ink);
}
.material-item.active strong { font-weight: 600; }

.material-item strong {
  display: block;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--serif);
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.material-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-family: var(--mono);
  letter-spacing: 0.02em;
  margin-top: 3px;
}

/* Editor pane */

.editor-pane {
  display: grid !important;
  gap: 10px;
}

.text-input,
.source-input {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
}
.text-input {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 500;
  padding: 11px 12px;
}
.source-input {
  min-height: 160px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  padding: 12px;
}

.seg-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}
.seg-row label {
  font-family: var(--mono);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.seg-row select { flex: 1; padding: 8px 28px 8px 10px; font-size: 13px; }
.mode-controls select { padding: 8px 28px 8px 12px; font-size: 13px; }

.button-row,
.backup-row,
.mode-controls,
.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.button-row { margin-top: 6px; }

/* ------------------------------------------------------------- drawer */

.drawer {
  border-top: 1px solid var(--rule);
  margin: 2px -2px 0;
  padding: 0 2px;
}
.drawer:first-of-type { margin-top: 0; }

.drawer > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 4px;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
  user-select: none;
  outline: none;
}
.drawer > summary::-webkit-details-marker { display: none; }
.drawer > summary:hover { color: var(--ink); }
.drawer > summary:focus-visible {
  background: var(--paper-2);
  border-radius: var(--radius);
}
.drawer > summary > .icon:first-child {
  color: var(--muted);
  width: 14px; height: 14px;
}
.drawer > summary:hover > .icon:first-child { color: var(--ink); }

.drawer-label {
  flex: 0 0 auto;
}
.drawer-hint {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted-2);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 400;
}
.drawer > summary > .chevron {
  margin-left: auto;
  color: var(--muted);
  transition: transform 180ms cubic-bezier(0.4, 0, 0.2, 1);
}
.drawer[open] > summary > .chevron { transform: rotate(180deg); }

.drawer-body {
  padding: 4px 4px 14px;
  display: grid;
  gap: 10px;
}
.drawer-note {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

/* Material details — metadata grid */

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
}
.meta-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.meta-field-full { grid-column: 1 / -1; }
.meta-field > span {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.meta-input {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  font-family: var(--sans);
  font-weight: 400;
}
.meta-notes {
  min-height: 64px;
  resize: vertical;
  font-family: var(--sans);
  line-height: 1.55;
}

/* Settings — option list */

.settings-pane .drawer:first-of-type { border-top: 0; }

.option-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0;
}
.option-list li + li {
  border-top: 1px dashed var(--rule);
}
.option-list label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 4px;
  cursor: pointer;
  user-select: none;
}
.option-list label:hover .opt-title { color: var(--ink); }
.option-list input[type="checkbox"] { margin-top: 2px; }

.opt-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.opt-title {
  font-size: 13px;
  color: var(--ink-2);
  font-weight: 500;
  line-height: 1.3;
}
.opt-help {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}
.opt-help code {
  font-family: var(--mono);
  font-size: 10.5px;
  background: var(--paper-2);
  padding: 1px 4px;
  border-radius: 2px;
  color: var(--ink-2);
}

/* Theme chips */

.theme-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.theme-chip {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 7px;
  padding: 9px 9px 8px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-2);
  cursor: pointer;
  background: var(--panel);
  transition: border-color 120ms, background 120ms;
}
.theme-chip:hover { border-color: var(--rule-2); }
.theme-chip input[type="radio"] {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 12px;
  height: 12px;
}
.theme-chip:has(input:checked) {
  border-color: var(--ink);
  background: color-mix(in srgb, var(--panel) 82%, var(--ink) 8%);
}
.theme-swatch {
  display: block;
  width: 100%;
  height: 32px;
  border-radius: var(--radius);
  border: 1px solid var(--rule);
  position: relative;
  overflow: hidden;
}
.theme-swatch::before,
.theme-swatch::after {
  content: "";
  position: absolute;
  left: 6px;
  height: 2px;
  border-radius: 1px;
}
.theme-swatch::before { top: 9px; right: 14px; }
.theme-swatch::after  { top: 15px; right: 22px; }

.theme-swatch-light { background: #ffffff; border-color: #e5e5e5; }
.theme-swatch-light::before, .theme-swatch-light::after { background: #1c1a17; }

.theme-swatch-paper { background: var(--paper); border-color: var(--rule); }
.theme-swatch-paper::before, .theme-swatch-paper::after { background: var(--ink); }

.theme-swatch-dark { background: #1c1a17; border-color: #1c1a17; }
.theme-swatch-dark::before, .theme-swatch-dark::after { background: #f5f1ea; }

.theme-swatch-cyberpunk2077 {
  background: linear-gradient(135deg, #272932 0 48%, #742d8b 48% 72%, #fdf500 72% 100%);
  border-color: #9381ff;
}
.theme-swatch-cyberpunk2077::before { background: #40ffe9; }
.theme-swatch-cyberpunk2077::after { background: #e455ae; }

.theme-name {
  font-size: 11px;
  color: var(--ink-2);
  font-weight: 500;
  letter-spacing: 0.02em;
  padding-left: 1px;
  overflow-wrap: anywhere;
}

/* Backup row */

.backup-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.backup-row button { padding: 8px 12px; font-size: 12px; }

/* ------------------------------------------------------------- practice */

.practice {
  padding: var(--gutter);
  min-width: 0;
  width: min(100%, 920px);
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  gap: 24px;
  align-content: start;
}

.practice-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--rule);
}
.practice-header > div:first-child { min-width: 0; flex: 1; }

.practice-header h1,
.review-header h2 {
  margin: 6px 0 0;
  font-family: var(--serif);
  font-size: clamp(28px, 3.2vw, 40px);
  font-weight: 500;
  letter-spacing: -0.018em;
  line-height: 1.1;
  font-style: italic;
}

.mode-controls { flex: 0 0 auto; }
.mode-controls select { min-width: 120px; }

/* Stats — typographic, no card chrome */

.stats-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  margin: 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.stats-strip > div {
  background: transparent;
  border: 0;
  border-left: 1px solid var(--rule);
  border-radius: 0;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.stats-strip > div:first-child { border-left: 0; }
.stats-strip span {
  display: block;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.stats-strip strong {
  display: block;
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin-top: 0;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  line-height: 1.1;
}

/* Write area — the hero (UNCHANGED structurally) */

.write-area {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius-2);
  overflow: hidden;
  position: relative;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.8) inset,
    0 1px 2px rgba(28, 26, 23, 0.04),
    0 24px 48px -36px rgba(28, 26, 23, 0.16);
}
.write-area::before {
  content: "";
  position: absolute;
  left: 0; right: 0;
  top: 22px;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--rule-2), transparent);
  pointer-events: none;
  z-index: 1;
}

.input-shell {
  position: relative;
  min-height: 56vh;
  background: transparent;
  isolation: isolate;
}
.input-mirror,
.practice-input {
  width: 100%;
  min-height: 56vh;
  padding: 40px clamp(28px, 4vw, 56px);
  font-family: var(--reading);
  font-size: clamp(19px, 1.4vw, 22px);
  line-height: 1.85;
  letter-spacing: 0.005em;
  white-space: pre-wrap;
  word-break: break-word;
  -webkit-hyphens: auto;
  hyphens: auto;
}
.input-mirror {
  position: absolute;
  inset: 0;
  z-index: 4;
  color: var(--ink);
  overflow: hidden;
  pointer-events: none;
}
.practice-input {
  position: absolute;
  inset: 0;
  z-index: 3;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: color-mix(in srgb, var(--ink) 18%, transparent);
  -webkit-text-fill-color: color-mix(in srgb, var(--ink) 18%, transparent);
  caret-color: var(--ink);
  caret-shape: bar;
}
.practice-input::placeholder { color: var(--muted-2); font-style: italic; }

.token { padding: 0; margin: 0; border-radius: 0; }
.token.exact { color: var(--ok); }
.token.soft {
  color: var(--soft);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-thickness: from-font;
  text-underline-offset: 0.18em;
  text-decoration-color: rgba(138, 106, 24, 0.55);
}
.token.wrong, .token.extra {
  color: var(--wrong);
  text-decoration: underline;
  text-decoration-style: wavy;
  text-decoration-thickness: from-font;
  text-underline-offset: 0.22em;
  text-decoration-color: rgba(168, 42, 37, 0.65);
}
.token.composing {
  color: var(--ink);
  border-bottom: 1px solid var(--ink);
}
.placeholder { color: var(--muted-2); }

.source-input.masked-source {
  color: transparent;
  caret-color: transparent;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 14px rgba(28, 26, 23, 0.32);
  user-select: none;
  filter: blur(0.4px);
}
.practice-input.masked-source,
.input-mirror.masked-source {
  color: var(--ink);
  -webkit-text-fill-color: initial;
  text-shadow: none;
  filter: none;
}

/* Progress hairline */

.progress-line {
  height: 2px;
  background: var(--paper-3);
  position: relative;
  overflow: hidden;
}
.progress-line div {
  height: 100%;
  width: 0;
  background: var(--ink);
  transition: width 0.25s cubic-bezier(0.2, 0.6, 0.2, 1);
}

.controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.controls #startBtn { min-width: 96px; }

/* ------------------------------------------------------------- review */

.review {
  margin-top: 8px;
  padding: 24px clamp(20px, 3vw, 32px) 28px;
  background:
    linear-gradient(to bottom, rgba(255,255,255,0.55), transparent 80px),
    var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius-2);
  position: relative;
}
.review::before {
  content: "";
  position: absolute;
  top: -1px; left: 24px; right: 24px;
  height: 3px;
  background: var(--ink);
  border-radius: 0 0 2px 2px;
}
.review-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--rule);
}
.review-header h2 { font-size: clamp(24px, 2.4vw, 32px); }

.review-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  margin: 18px 0 22px;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.review-grid > div {
  background: transparent;
  border: 0;
  border-left: 1px solid var(--rule);
  border-radius: 0;
  padding: 12px 16px;
}
.review-grid > div:first-child { border-left: 0; }
.review-grid span {
  display: block;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.review-grid strong {
  display: block;
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 500;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.review-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.9fr);
  gap: clamp(20px, 3vw, 36px);
}
.review-body h3 {
  margin: 0 0 12px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
}

.issue-list {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: issue;
  font-size: 14px;
}
.issue-list li {
  counter-increment: issue;
  position: relative;
  padding: 10px 0 10px 32px;
  border-bottom: 1px dashed var(--rule);
  line-height: 1.55;
}
.issue-list li::before {
  content: counter(issue, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 12px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.issue-list li code {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--wrong);
  background: transparent;
  padding: 0;
}
.issue-list li em {
  font-family: var(--serif);
  font-style: italic;
  color: var(--ok);
  font-weight: 500;
}
.issue-meta {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  margin-left: 8px;
  letter-spacing: 0.04em;
}

.source-preview {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 16px 18px;
  max-height: 380px;
  overflow: auto;
  font-family: var(--reading);
  font-size: 14px;
  line-height: 1.75;
  color: var(--ink-2);
  scrollbar-width: thin;
  scrollbar-color: var(--rule-2) transparent;
}
.source-preview::-webkit-scrollbar { width: 6px; }
.source-preview::-webkit-scrollbar-thumb { background: var(--rule-2); border-radius: 3px; }

/* ------------------------------------------------------------- responsive */

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

  .sidebar {
    position: static;
    max-height: none;
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--rule);
    padding: 20px var(--gutter);
    gap: 22px;
  }

  .material-list {
    max-height: 240px;
  }

  .review-body {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  body { font-size: 14px; }

  .practice {
    padding: 18px 16px 28px;
    gap: 18px;
  }

  .sidebar { padding: 18px 16px; gap: 18px; }

  .practice-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding-bottom: 14px;
  }

  .practice-header h1 { font-size: 26px; }

  .mode-controls { width: 100%; }
  .mode-controls select { flex: 1; }

  .stats-strip,
  .review-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .stats-strip > div,
  .review-grid > div {
    border-left: 0;
    border-top: 1px solid var(--rule);
    padding: 11px 14px;
  }
  .stats-strip > div:nth-child(-n+2),
  .review-grid > div:nth-child(-n+2) {
    border-top: 0;
  }
  .stats-strip > div:nth-child(2n),
  .review-grid > div:nth-child(2n) {
    border-left: 1px solid var(--rule);
  }
  .stats-strip strong { font-size: 22px; }

  .input-mirror,
  .practice-input {
    padding: 24px 18px;
    font-size: 17px;
    line-height: 1.8;
    min-height: 50vh;
  }
  .input-shell { min-height: 50vh; }

  .write-area::before { top: 14px; }

  .review { padding: 18px 16px 22px; }

  .controls { gap: 6px; }
  .controls button { flex: 1; min-width: 0; padding: 11px 10px; }
  .controls #clearBtn { flex: 0 0 auto; }

  .meta-grid { grid-template-columns: 1fr; }
  .meta-field { gap: 4px; }

  .theme-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .theme-swatch { height: 28px; }
}

@media (max-width: 420px) {
  .stats-strip { grid-template-columns: 1fr 1fr; }
  .stats-strip strong { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@supports (padding: env(safe-area-inset-bottom)) {
  .practice { padding-bottom: max(var(--gutter), env(safe-area-inset-bottom)); }
}
