
:root {
  --bg: #fbfbf9;
  --paper: #ffffff;
  --line: #e5e3de;
  --line-soft: #eceae5;
  --line-strong: #d8d6d0;
  --ink: #111111;
  --muted: #8a8880;
  --ghost: #c4c2bb;
  --faint: #b5b3ac;
  --code-bg: #f7f6f3;
  --code-bg-2: #f3f2ee;
  --invert-filter: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121211;
    --paper: #1a1a19;
    --line: #2e2e2c;
    --line-soft: #262624;
    --line-strong: #3c3c3a;
    --ink: #e8e6e1;
    --muted: #8f8d87;
    --ghost: #3e3e3c;
    --faint: #555553;
    --code-bg: #161615;
    --code-bg-2: #1f1f1e;
    --invert-filter: invert(0.88);
  }
}

:root[data-theme="dark"] {
  --bg: #121211;
  --paper: #1a1a19;
  --line: #2e2e2c;
  --line-soft: #262624;
  --line-strong: #3c3c3a;
  --ink: #e8e6e1;
  --muted: #8f8d87;
  --ghost: #3e3e3c;
  --faint: #555553;
  --code-bg: #161615;
  --code-bg-2: #1f1f1e;
  --invert-filter: invert(0.88);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
}

button, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: inherit; text-decoration: none; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 17px;
  font-weight: 700;
}
.logo img { display: block; }

#mode-switch { display: flex; gap: 26px; }

.nav-link {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--muted);
  padding: 4px 0;
  border-bottom: 1px solid transparent;
}
.nav-link:hover { color: var(--ink); }
.nav-link.active { color: var(--ink); border-bottom-color: var(--ink); }

.header-right { display: flex; align-items: center; gap: 14px; }

#lang-switch { display: flex; }

.lang-btn {
  font-size: 12px;
  color: var(--muted);
  padding: 5px 13px;
  border: 1px solid var(--line-strong);
  border-right-width: 0;
}
.lang-btn:last-child { border-right-width: 1px; }
.lang-btn:hover { color: var(--ink); }
.lang-btn.active { background: var(--ink); color: var(--bg); }

#theme-btn {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line-strong);
  padding: 5px 11px;
}
#theme-btn:hover { color: var(--ink); border-color: var(--ink); }

main {
  max-width: 820px;
  margin: 36px auto 72px;
  padding: 0 24px;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 30px 36px;
  margin-bottom: 20px;
}

.task-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 2px;
}

select {
  max-width: 340px;
  padding: 4px 6px;
  border: 1px solid var(--line-strong);
  background: var(--paper);
}

.task-nav { display: flex; align-items: center; gap: 10px; }
.task-nav button {
  font-size: 15px;
  line-height: 1;
  color: var(--muted);
  padding: 2px 5px;
}
.task-nav button:hover:not(:disabled) { color: var(--ink); }
.task-nav button:disabled { color: var(--line-strong); cursor: default; }
.task-pos { font-size: 12px; color: var(--muted); }

.progress { font-size: 12px; color: var(--muted); white-space: nowrap; }

.stage-render {
  padding: 20px 0 0;
  min-height: 52px;
  overflow-x: auto;
  color: var(--ink);
}
.stage-render svg { display: block; }

.stage-render > svg,
.example-preview > svg {
  filter: var(--invert-filter);
}

.fade { opacity: 0; transition: opacity .35s; }
.fade.in { opacity: 1; }

.stage-rule {
  height: 1px;
  background: var(--line-soft);
  margin: 16px 0 20px;
}

.typebox { position: relative; }

.mirror {
  position: absolute;
  inset: 0;
  white-space: pre;
  overflow: hidden;
  pointer-events: none;
  color: var(--ghost);
}
.mirror .ok { color: var(--ink); }
.mirror .bad { background: var(--ink); color: var(--bg); }

.mirror, #input {
  font-size: 14px;
  line-height: 1.6;
  letter-spacing: normal;
  padding: 13px 15px;
}

#input {
  position: relative;
  display: block;
  width: 100%;
  height: 54px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: var(--ink);
  white-space: pre;
  overflow-x: auto;
  resize: none;
  outline: none;
}
.typebox.focus #input { border-color: var(--ink); }
#input:read-only { caret-color: transparent; }

.hint-box {
  display: none;
  margin-top: 14px;
  padding-left: 12px;
  border-left: 1px solid var(--ink);
  color: var(--muted);
}
.hint-box.open { display: block; }
.hint-box code {
  font-size: 13px;
  background: var(--code-bg-2);
  padding: 0 5px;
}

.done-row {
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin-top: 18px;
}
.done-stats { font-size: 13px; color: var(--muted); }
.done-row .btn { margin-left: auto; }

.btn {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .12em;
  padding: 8px 16px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--bg);
}
.btn:hover { background: transparent; color: var(--ink); }

.preview-block {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--line-soft);
}
.code-src {
  font-size: 13px;
  color: var(--faint);
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 12px;
}
.preview-block .stage-render { min-height: 40px; padding: 0; }

.preview-err {
  display: inline-block;
  font-size: 13px;
  color: var(--ink);
  background: var(--code-bg-2);
  border: 1px solid var(--line-strong);
  padding: 6px 10px;
  white-space: pre-wrap;
}
.preview-off { color: var(--muted); font-size: 13px; }
.preview-idle { color: var(--ghost); }

.stage-footer {
  margin-top: 28px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--faint);
}

.learn-head {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--muted);
  margin-bottom: 14px;
}

.learn-tabs {
  display: flex;
  gap: 24px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}
.learn-tab {
  display: flex;
  align-items: baseline;
  gap: 7px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  padding: 6px 0;
  border-bottom: 1px solid transparent;
  white-space: nowrap;
}
.learn-tab:hover { color: var(--ink); }
.learn-tab.active { color: var(--ink); border-bottom-color: var(--ink); }
.tab-done { font-size: 11px; letter-spacing: 0; color: var(--faint); }

.lesson-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line-soft);
}
.lesson-title { display: flex; align-items: baseline; gap: 14px; min-width: 0; }
.lesson-title h2 { font-size: 21px; font-weight: 400; letter-spacing: .01em; }
.ex-no { font-size: 12px; color: var(--faint); }

.lesson-intro { color: var(--muted); margin-bottom: 14px; }

.example { padding: 16px 0; border-top: 1px solid var(--line-soft); }
.lesson-intro + .example { border-top: none; padding-top: 4px; }

.ex-top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 10px;
}
.ex-hint {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-btn {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--ink);
  border-bottom: 1px solid var(--line-strong);
  padding-bottom: 2px;
}
.link-btn:hover { border-bottom-color: var(--ink); }

.ex-body { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.code {
  font-size: 13px;
  background: var(--code-bg);
  border: 1px solid var(--line-soft);
  padding: 12px 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.example-preview {
  border: 1px solid var(--line-soft);
  min-height: 56px;
  padding: 12px 14px;
  overflow-x: auto;
}
.example-preview svg { display: block; }

.gh-link {
  position: fixed;
  right: 16px;
  bottom: 16px;
  color: var(--faint);
  z-index: 10;
}
.gh-link:hover { color: var(--ink); }

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

  header {
    flex-wrap: wrap;
    padding: 10px 14px;
    gap: 10px 14px;
  }
  .logo { order: 1; }
  #mode-switch { order: 2; margin-left: auto; gap: 16px; }
  .header-right { order: 3; width: 100%; justify-content: space-between; }

  main { margin-top: 18px; padding: 0 12px; margin-bottom: 48px; }
  .card { padding: 18px 14px; }

  .task-line { flex-wrap: wrap; }
  select { max-width: 100%; flex: 1; min-width: 140px; }

  .mirror, #input { font-size: 16px; padding: 12px 13px; }
  #input { height: 52px; }

  .done-row { flex-wrap: wrap; }
  .done-row .btn { margin-left: 0; width: 100%; }

  .stage-footer { text-align: center; }

  .ex-body { grid-template-columns: 1fr; }
  .ex-hint { display: none; }
  .learn-tabs { gap: 18px; }

  .gh-link { right: 10px; bottom: 10px; opacity: .7; }
}
