:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --ink: #1b2130;
  --muted: #5d6576;
  --line: #d8dbe2;
  --accent: #2a5bd7;
  --accent-ink: #ffffff;
  --warn: #d9480f;
  --good: #2b8a3e;
  --free: #eceef2;
  --free-line: #c3c8d2;
  --head: #e8590c;
  --f-A: #2563eb;
  --f-B: #d97706;
  --f-C: #16a34a;
  --f-D: #c026d3;
  --f-E: #0e7490;
  --shadow: 0 1px 2px rgb(20 25 40 / .06), 0 4px 16px rgb(20 25 40 / .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c;
    --surface: #1b1f29;
    --surface-2: #232836;
    --ink: #e8eaf0;
    --muted: #9aa2b3;
    --line: #2f3545;
    --accent: #6f95ff;
    --accent-ink: #0d1222;
    --warn: #ff8a50;
    --good: #5fd27a;
    --free: #252a37;
    --free-line: #3c4357;
    --head: #ff922b;
    --f-A: #3b7bff;
    --f-B: #e38a12;
    --f-C: #22a85a;
    --f-D: #c540d8;
    --f-E: #1490ad;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top, 0) 0 calc(90px + env(safe-area-inset-bottom, 0));
}
h1, h2, h3, h4 { line-height: 1.2; margin: 0; }
strong { font-weight: 650; }
button, select, textarea { font: inherit; color: inherit; }

/* ---------- header ---------- */
.top {
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px 20px 8px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 { font-size: clamp(1.4rem, 2.6vw, 2rem); letter-spacing: -.01em; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: .95rem; }
.hdd { width: 54px; height: 54px; flex: none; }
.hdd-case { fill: var(--surface-2); stroke: var(--line); stroke-width: 2; }
.hdd-platter { fill: var(--surface); stroke: var(--line); stroke-width: 2; }
.hdd-track { fill: none; stroke: var(--line); stroke-width: 1.5; }
.hdd-mark { stroke: var(--muted); stroke-width: 3; stroke-linecap: round; }
.hdd-spindle { fill: var(--muted); }
.hdd-arm line { stroke: var(--head); stroke-width: 5; stroke-linecap: round; }
.hdd-tip { fill: var(--head); }
.hdd-pivot { fill: var(--muted); }
.hdd-arm { transform-origin: 104px 104px; transition: transform .3s ease; }
.platter { transform-origin: 52px 58px; }
.hdd.spinning .platter { animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.tabs {
  display: flex;
  gap: 6px;
  margin-top: 14px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 4px;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: none;
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 14px 6px 6px;
  cursor: pointer;
  font-size: .92rem;
  color: var(--muted);
}
.tabs button span {
  display: inline-grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--surface-2); font-weight: 700; font-size: .8rem;
}
.tabs button.active { color: var(--ink); border-color: var(--accent); }
.tabs button.active span { background: var(--accent); color: var(--accent-ink); }
.tabs button.done span { background: color-mix(in srgb, var(--accent) 22%, var(--surface-2)); }

/* ---------- layout ---------- */
main { max-width: 1280px; margin: 0 auto; padding: 8px 20px 24px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.lab {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr);
  gap: 16px;
  align-items: start;
}
.side { display: grid; gap: 16px; }
@media (max-width: 920px) {
  .lab { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- disk ---------- */
.disk-top h2 { font-size: 1.3rem; }
.hint { margin: 4px 0 0; color: var(--muted); font-size: .9rem; }
.disk-wrap { position: relative; margin-top: 30px; }
.disk {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: clamp(3px, .7vw, 7px);
}
.cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  display: grid;
  place-items: center;
  align-content: center;
  color: #fff;
  font-weight: 750;
  font-size: clamp(.8rem, 1.9vw, 1.35rem);
  line-height: 1;
  transition: opacity .3s, filter .3s, background-color .25s;
}
.cell::before {
  content: attr(data-addr);
  position: absolute; top: 3px; left: 5px;
  font-size: clamp(.5rem, .9vw, .66rem);
  font-weight: 500;
  opacity: .75;
}
.cell small { font-size: .6em; font-weight: 600; opacity: .9; margin-top: 2px; }
.cell.free {
  background: var(--free);
  border: 1.5px dashed var(--free-line);
  color: var(--muted);
}
.cell.f-A { background: var(--f-A); }
.cell.f-B { background: var(--f-B); }
.cell.f-C { background: var(--f-C); }
.cell.f-D { background: var(--f-D); }
.cell.f-E { background: var(--f-E); }
.cell.dim { opacity: .28; filter: saturate(.4); }
.cell.free.dim { opacity: .5; }
.cell.flash { animation: flash .55s ease-out; }
@keyframes flash {
  0% { transform: scale(.6); box-shadow: 0 0 0 0 var(--head); }
  60% { transform: scale(1.08); box-shadow: 0 0 0 5px color-mix(in srgb, var(--head) 40%, transparent); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 transparent; }
}
.cell.deleting { animation: del .6s ease-in forwards; }
@keyframes del { to { opacity: .15; transform: scale(.82); } }
.cell.lift { transform: translateY(-6px) scale(1.06); box-shadow: 0 8px 18px rgb(0 0 0 / .25); transition: transform .15s; z-index: 2; }
.cell.reading { box-shadow: inset 0 0 0 3px #fff, 0 0 0 3px var(--head); }
.cell.read { box-shadow: inset 0 0 0 3px rgb(255 255 255 / .75); }
.cell.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { filter: brightness(1.25); transform: scale(.94); } }

.head {
  position: absolute; top: 0; left: 0;
  border: 3px solid var(--head);
  border-radius: 10px;
  pointer-events: none;
  transition-property: transform;
  transition-timing-function: cubic-bezier(.45, .05, .3, 1);
  z-index: 3;
  margin: -7px; padding: 4px; box-sizing: content-box;
}
.head span {
  position: absolute; bottom: 100%; left: 50%;
  transform: translate(-50%, -3px);
  background: var(--head); color: #fff;
  font-size: .68rem; font-weight: 700;
  padding: 1px 6px; border-radius: 5px;
  white-space: nowrap;
}
.head.seek span::after { content: " · SEEK"; }
.head.seek { border-style: dashed; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 16px; font-size: .88rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i {
  width: 18px; height: 18px; border-radius: 5px; display: inline-grid; place-items: center;
  color: #fff; font-style: normal; font-weight: 700; font-size: .7rem;
}
.legend i.free { background: var(--free); border: 1.5px dashed var(--free-line); }

.defrag { margin-top: 16px; }
.defrag-row { display: flex; justify-content: space-between; font-weight: 600; font-size: .92rem; margin-bottom: 6px; }

.bar { height: 12px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .3s; }
.bar-fill.warn { background: var(--warn); }
.bar-fill.good { background: var(--good); }

/* ---------- narration ---------- */
.narration { min-height: 220px; }
.step-count { margin: 0 0 4px; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); font-weight: 700; }
.narration h3 { font-size: 1.25rem; margin-bottom: 8px; }
.step-text p { margin: 0 0 8px; }
.tip {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 9%, var(--surface));
  border-radius: 0 8px 8px 0;
  font-size: .93rem;
}

/* ---------- stats ---------- */
.stats h4 { font-size: .95rem; margin-bottom: 8px; }
.stats .mt { margin-top: 18px; }
.fname { font-family: ui-monospace, Menlo, monospace; font-size: .9em; }
.ftable { width: 100%; border-collapse: collapse; font-size: .9rem; }
.ftable th { text-align: left; font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.ftable td { padding: 6px; border-bottom: 1px solid var(--line); }
.ftable td:first-child { display: flex; align-items: center; gap: 8px; }
.ftable .chip { width: 22px; height: 22px; border-radius: 6px; display: inline-grid; place-items: center; color: #fff; font-weight: 700; font-size: .75rem; flex: none; }
.ftable .empty td { color: var(--muted); font-style: italic; }
.badge { display: inline-block; min-width: 26px; text-align: center; padding: 1px 8px; border-radius: 999px; font-weight: 700; font-size: .85rem; background: color-mix(in srgb, var(--good) 18%, var(--surface)); color: var(--good); }
.badge.bad { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); color: var(--warn); }
.small { font-size: .85rem; margin: 8px 0 0; }
.muted { color: var(--muted); }

.compare { display: grid; gap: 8px; }
.cmp-row { display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 10px; font-size: .88rem; }
.cmp-label { font-weight: 600; }
.cmp-val { font-variant-numeric: tabular-nums; min-width: 128px; text-align: right; color: var(--muted); }
.cmp-row.live .cmp-val { color: var(--ink); font-weight: 600; }
.stats.emph .compare { outline: 2px solid var(--accent); outline-offset: 6px; border-radius: 6px; }

/* ---------- pages ---------- */
.page h2 { font-size: 1.6rem; margin: 6px 0 16px; }
.terms { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.term { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); border-top: 4px solid var(--accent); }
.term h3 { font-size: 1.05rem; margin-bottom: 6px; }
.term p { margin: 0; color: var(--muted); font-size: .94rem; }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-top: 16px; }
.two h3 { font-size: 1.15rem; margin-bottom: 8px; }
.two ul { padding-left: 20px; margin: 8px 0; }
.two li { margin-bottom: 6px; }
.ssd { border-top: 4px solid var(--warn); }
.benefits { border-top: 4px solid var(--good); }

.quiz { padding: 0; list-style: none; counter-reset: q; display: grid; gap: 14px; margin: 0 0 16px; }
.quiz > li { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); counter-increment: q; }
.quiz .q { font-weight: 650; margin: 0 0 10px; }
.quiz .q::before { content: counter(q) ". "; color: var(--accent); }
.opts { display: grid; gap: 8px; }
.opt {
  text-align: left; padding: 10px 12px; border-radius: 10px;
  border: 1.5px solid var(--line); background: var(--surface-2); cursor: pointer;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt:disabled { cursor: default; }
.opt.right { border-color: var(--good); background: color-mix(in srgb, var(--good) 15%, var(--surface)); }
.opt.wrong { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 13%, var(--surface)); }
.feedback { margin: 10px 0 0; font-size: .93rem; }
.feedback.ok { color: var(--good); }
.feedback.no { color: var(--warn); }
.feedback span { color: var(--ink); }
.score { font-weight: 700; font-size: 1.05rem; margin: -6px 0 14px; }
.long textarea { width: 100%; border: 1.5px solid var(--line); border-radius: 10px; padding: 10px; background: var(--surface-2); margin: 8px 0 10px; resize: vertical; }
.marks { color: var(--muted); font-weight: 600; }
.scheme { margin: 12px 0 0; padding-left: 20px; }
.scheme li { margin-bottom: 5px; }
.long { margin-bottom: 16px; }
.long h3 { margin-bottom: 6px; }

/* ---------- controls ---------- */
.controls {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom, 0));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  z-index: 10;
}
.btn {
  border: 1.5px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); min-width: 116px; }
.speed { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; color: var(--muted); margin-left: 6px; }
.speed select { border: 1.5px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--surface); }
.progress { position: absolute; top: -1px; left: 0; right: 0; height: 3px; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
@media (max-width: 560px) {
  .btn span { display: none; }
  .btn { padding: 9px 12px; }
  .btn.primary { min-width: 92px; }
  .speed { margin-left: 0; }
  .card { padding: 14px; }
  main, .top { padding-left: 16px; padding-right: 16px; }
  .cmp-row { grid-template-columns: 50px 1fr; }
  .cmp-val { grid-column: 1 / -1; text-align: left; min-width: 0; }
}

button:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .cell, .head, .bar-fill, .hdd-arm { transition: none !important; }
  .cell.flash, .cell.deleting, .cell.pulse, .hdd.spinning .platter { animation: none !important; }
}
