:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --side: #ecebe5;
  --card: #ffffff;
  --text: #1b1d1c;
  --muted: #63675f;
  --border: #dedcd3;
  --accent: #1f6f5c;
  --accent-soft: rgba(31, 111, 92, 0.12);
  --accent-text: #ffffff;
  --code-bg: #efeee8;
  --danger: #b3412e;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121413;
    --side: #171a19;
    --card: #1b1e1d;
    --text: #eceee9;
    --muted: #a0a59d;
    --border: #2e3330;
    --accent: #4cb898;
    --accent-soft: rgba(76, 184, 152, 0.16);
    --accent-text: #0d1a16;
    --code-bg: #232826;
    --danger: #ec7a64;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- layout: index left, page right ---------- */
.layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--side);
  border-right: 1px solid var(--border);
  padding: 22px 14px 16px;
  display: flex; flex-direction: column;
}
.brand { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; color: inherit; text-decoration: none; padding: 0 8px; }
.tagline { margin: 0 0 16px; padding: 0 8px; color: var(--muted); font-size: 0.85rem; }

.index { flex: 1; }
.index.sections { flex: none; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.index.skills { flex: none; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.index > summary { list-style: none; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); padding: 0 8px 6px; cursor: default; }
.index > summary::-webkit-details-marker { display: none; }
.days, .pages { list-style: none; margin: 0; padding: 0; }

.day > summary {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; border-radius: 8px; cursor: pointer;
  font-weight: 600; font-size: 0.92rem;
  list-style: none;
}
.day > summary::-webkit-details-marker { display: none; }
.day > summary::before { content: "▸"; color: var(--muted); font-size: 0.75rem; width: 10px; transition: transform 0.15s; }
.day[open] > summary::before { transform: rotate(90deg); }
.day > summary:hover { background: var(--accent-soft); }
.d-date { flex: 1; color: inherit; text-decoration: none; }
.d-date:hover { color: var(--accent); }
.d-date[aria-current="page"] { color: var(--accent); }
.d-count { color: var(--muted); font-weight: 500; font-size: 0.8rem; }
.badge { font-size: 0.68rem; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--accent); color: var(--accent-text); }

.pages { margin: 2px 0 6px 18px; border-left: 1px solid var(--border); }
.pages a {
  display: block; padding: 6px 10px; margin-left: -1px;
  border-left: 2px solid transparent;
  color: inherit; text-decoration: none; font-size: 0.9rem; line-height: 1.35;
}
.pages a:hover { background: var(--accent-soft); }
.pages a[aria-current="page"] { border-left-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.p-title { display: block; }
.p-meta { display: block; font-size: 0.75rem; color: var(--muted); font-weight: 400; margin-top: 2px; }

.side-foot { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 14px 8px 0; margin-top: 12px; border-top: 1px solid var(--border); }
.all-tools { margin-left: auto; font-size: 0.82rem; color: var(--muted); text-decoration: none; }
.all-tools:hover { color: var(--accent); }

main { padding: 40px 48px 64px; max-width: 860px; width: 100%; margin: 0 auto; outline: none; }
/* Wide monitors: keep the page centred beside the index, with a slightly wider column. */
@media (min-width: 1600px) { main { max-width: 960px; } }

/* ---------- page index (right): only where there's room for a third column ---------- */
.toc { display: none; }
@media (min-width: 1280px) {
  .layout.has-toc { grid-template-columns: 280px minmax(0, 1fr) 260px; }
  .toc:not([hidden]) {
    display: block; position: sticky; top: 0; height: 100vh; overflow-y: auto;
    padding: 40px 20px 24px 12px; font-size: 0.85rem; line-height: 1.35;
  }
}
.toc-head { margin: 0 0 8px; padding-left: 12px; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.toc ol { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.toc a { display: block; padding: 5px 10px; margin-left: -1px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; }
.toc a.sub { padding-left: 22px; font-size: 0.8rem; }
.toc a:hover { color: var(--text); }
.toc a[aria-current] { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.toc a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.prose h2, .prose h3 { scroll-margin-top: 16px; }

/* ---------- page ---------- */
.post-head { margin-bottom: 24px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.post-date { margin: 0 0 4px; color: var(--muted); font-size: 0.9rem; }
.post-date a { color: inherit; }
.post-date a:hover { color: var(--accent); }
.post-head h1 { font-size: 2.1rem; line-height: 1.2; margin: 0; letter-spacing: -0.02em; }
.post-summary { margin: 8px 0 0; color: var(--muted); font-size: 1.05rem; }
.post-summary:empty { display: none; }
.pager { display: flex; justify-content: space-between; margin-top: 14px; font-size: 0.85rem; }
.pager-link { color: var(--accent); text-decoration: none; }
.pager-link:hover { text-decoration: underline; }
#older { margin-left: auto; }

.prose { margin-bottom: 32px; }
.prose h2 { font-size: 1.4rem; margin: 2em 0 0.5em; letter-spacing: -0.01em; }
.prose h3 { font-size: 1.15rem; margin: 1.6em 0 0.4em; }
.prose h4, .prose h5 { font-size: 1rem; margin: 1.4em 0 0.4em; }
.prose > :first-child { margin-top: 0; }
.prose p, .prose ul, .prose ol { margin: 0 0 1em; }
.prose li + li { margin-top: 0.25em; }
.prose a { color: var(--accent); }
.prose img { max-width: 100%; border-radius: 8px; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }
.prose blockquote { margin: 0 0 1em; padding: 10px 16px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 8px 8px 0; }
.prose blockquote p:last-child { margin-bottom: 0; }
.prose code { font: 0.88em/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace; background: var(--code-bg); padding: 0.1em 0.35em; border-radius: 5px; overflow-wrap: anywhere; }
.prose pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; overflow-x: auto; margin: 0 0 1em; }
.prose pre code { background: none; padding: 0; font-size: 0.85rem; line-height: 1.45; }
.table-wrap { overflow-x: auto; margin: 0 0 1em; }
.prose table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
.prose th, .prose td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; vertical-align: top; }
.prose th { background: var(--code-bg); font-weight: 600; }
.muted { color: var(--muted); }
.subpages { list-style: none; padding: 0; }
.subpages li { padding: 10px 0; }
.subpages li + li { border-top: 1px solid var(--border); }
.subpages a { font-weight: 600; text-decoration: none; }
.subpages a:hover { text-decoration: underline; }
.subpages .muted { display: block; font-size: 0.92rem; }
.day-link { margin: 0 0 16px; font-size: 0.92rem; }
.day-link a { color: var(--accent); text-decoration: none; }
.day-link a:hover { text-decoration: underline; }

/* ---------- checklist + comments ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px; margin-bottom: 16px; }
.card h2 { font-size: 0.78rem; margin: 0 0 10px; color: var(--muted); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.progress { font-size: 0.85rem; color: var(--muted); }

.checklist, .comments { list-style: none; margin: 0 0 12px; padding: 0; }
.checklist li { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.checklist li + li { border-top: 1px solid var(--border); }
.checklist input[type="checkbox"] { width: 18px; height: 18px; flex: none; accent-color: var(--accent); margin: 0; }
.checklist label { flex: 1; min-width: 0; overflow-wrap: anywhere; cursor: pointer; }
.checklist li.done label { text-decoration: line-through; color: var(--muted); }
.checklist li.empty, .comments:empty { color: var(--muted); }

.comments li { padding: 10px 0; }
.comments li + li { border-top: 1px solid var(--border); }
.c-head { display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; color: var(--muted); }
.c-text { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

input, textarea {
  font: inherit;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.add-row { display: flex; gap: 8px; }
.comment-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 8px; }
.hint { font-size: 0.78rem; color: var(--muted); }

.btn {
  font: inherit; font-weight: 600;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text);
  padding: 9px 16px; border-radius: 10px; cursor: pointer; white-space: nowrap;
}
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); font-weight: 500; }
.btn.small { padding: 5px 10px; font-size: 0.82rem; }
.btn:focus-visible, .pages a:focus-visible, .d-date:focus-visible, .day > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.del { font: inherit; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.del:hover { color: var(--danger); background: var(--accent-soft); }
.file { position: relative; overflow: hidden; }
.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; padding: 0; }

.local-note { font-size: 0.82rem; color: var(--muted); margin: 20px 0 0; }
.warn { color: var(--danger); font-size: 0.85rem; }
[hidden] { display: none !important; }

/* ---------- levels: status window, quests, level map, notices ---------- */
:root { --rank-E: #7a7f78; --rank-D: #2f8a5b; --rank-C: #2f6fb3; --rank-B: #7a4fc0; --rank-A: #c46a16; --rank-S: #c23a3a; }
@media (prefers-color-scheme: dark) {
  :root { --rank-E: #9aa096; --rank-D: #55c18a; --rank-C: #6aa8ec; --rank-B: #a98bf0; --rank-A: #f0a050; --rank-S: #f07a7a; }
}
.rank {
  display: inline-grid; place-items: center; flex: none;
  width: 30px; height: 30px; border-radius: 8px;
  font-weight: 800; font-size: 0.95rem; color: #fff; background: var(--rank-E);
}
.rank-D { background: var(--rank-D); } .rank-C { background: var(--rank-C); } .rank-B { background: var(--rank-B); }
.rank-A { background: var(--rank-A); } .rank-S { background: var(--rank-S); }
.rank-none { background: var(--border); color: var(--muted); }
@media (prefers-color-scheme: dark) { .rank:not(.rank-none) { color: #0d1110; } }

.status {
  border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 14px;
  background: var(--card); padding: 12px 18px 14px; margin-bottom: 24px;
}
.st-head { display: flex; justify-content: space-between; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.st-xp { letter-spacing: 0.02em; font-variant-numeric: tabular-nums; }
.st-main { display: flex; align-items: center; gap: 22px; margin-top: 6px; flex-wrap: wrap; }
.st-level { display: flex; align-items: baseline; gap: 4px; }
.st-lv { font-size: 0.8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.st-level b { font-size: 2.2rem; line-height: 1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.st-rank { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.st-next { flex: 1; min-width: 200px; display: grid; gap: 5px; font-size: 0.9rem; }
.st-next a { color: var(--accent); text-decoration: none; font-weight: 600; }
.st-next a:hover { text-decoration: underline; }
.st-sub { font-size: 0.78rem; color: var(--muted); }
.bar { height: 7px; border-radius: 999px; background: var(--accent-soft); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width 0.3s; }
.stats { list-style: none; margin: 12px 0 0; padding: 10px 0 0; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 8px 22px; }
.stats li { display: flex; align-items: baseline; gap: 6px; }
.stat-code { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; color: var(--muted); }
.stats b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.stat-name { font-size: 0.78rem; color: var(--muted); }
.log .card-head { flex-wrap: wrap; gap: 2px 12px; }
.log-form { display: grid; grid-template-columns: 9.5rem 6.5rem minmax(0, 1fr); gap: 8px 10px; align-items: end; margin-bottom: 12px; }
.log-form label { display: grid; gap: 4px; font-size: 0.78rem; color: var(--muted); min-width: 0; }
.log-form .wide { grid-column: 1 / -1; }
.log-form .btn { grid-column: 1 / -1; justify-self: start; }
select { font: inherit; padding: 9px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); width: 100%; }
select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.log-list { list-style: none; margin: 0; padding: 0; }
.log-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 8px; padding: 8px 0; border-top: 1px solid var(--border); }
.log-list li.empty { display: block; color: var(--muted); }
.log-main { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.log-date { font-weight: 600; min-width: 6.5rem; }
.log-xp { color: var(--accent); font-weight: 600; font-size: 0.85rem; }
.log-note { grid-column: 1; margin: 2px 0 0; font-size: 0.88rem; color: var(--muted); overflow-wrap: anywhere; }
.log-list .del { grid-row: 1; grid-column: 2; }
@media (max-width: 480px) { .log-form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .log-form label:nth-child(3) { grid-column: 1 / -1; } }
.q-xp { font-weight: 500; color: var(--muted); font-size: 0.85em; }
.st-note { margin: 10px 0 0; font-size: 0.85rem; color: var(--muted); }
.st-note b, .toast b { color: var(--accent); font-weight: 700; }

.quests .q-group + .q-group { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.quests h3 { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; margin: 0 0 4px; font-size: 0.95rem; }
.q-state { flex: none; font-size: 0.78rem; font-weight: 500; color: var(--muted); }
.q-group.cleared .q-state { color: var(--accent); font-weight: 700; }
.q-group.locked h3 > span:first-child { color: var(--muted); }
.quests .checklist { margin-bottom: 0; }

.skill-list { list-style: none; margin: 0 0 1.5em; padding: 0; display: grid; gap: 10px; }
.skill-card { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--card); }
.skill-card > div { flex: 1; min-width: 0; display: grid; gap: 4px; }
.skill-card a { font-weight: 600; text-decoration: none; }
.skill-card a:hover { text-decoration: underline; }
.skill-card .st-sub { display: block; }
.skill-lv { flex: none; font-weight: 700; font-variant-numeric: tabular-nums; }
.level-map { list-style: none; margin: 0 0 1em; padding: 0; }
.map-group { margin: 1.4em 0 0.3em; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.map-group:first-child { margin-top: 0; }
.map-row { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-top: 1px solid var(--border); }
.map-row > div { flex: 1; min-width: 0; }
.map-row a { font-weight: 600; text-decoration: none; }
.map-row a:hover { text-decoration: underline; }
.map-row .muted { display: block; font-size: 0.88rem; }
.map-row.exam { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; border-top: 0; margin: 4px 0; }
.map-state { flex: none; font-size: 0.75rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.is-cleared .map-state { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.is-current .map-state { border-color: var(--accent); color: var(--accent); }
.is-locked a { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 10;
  max-width: min(520px, calc(100vw - 32px));
  background: var(--card); color: var(--text); border: 1px solid var(--accent); border-radius: 12px;
  padding: 12px 18px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18); font-size: 0.95rem;
}
.toast.show { animation: toast-in 0.25s ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }
@media (prefers-reduced-motion: reduce) { .toast.show { animation: none; } .bar > span { transition: none; } }

/* ---------- phones / narrow windows: index collapses above the page ---------- */
@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 16px 16px 12px; }
  .brand, .tagline, .index > summary { padding-left: 0; padding-right: 0; }
  .tagline { margin-bottom: 10px; }
  .index > summary {
    cursor: pointer; list-style: none;
    font-size: 0.9rem; text-transform: none; letter-spacing: 0; color: var(--text);
    padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--card);
  }
  .index > summary::after { content: " ▾"; color: var(--muted); }
  .index[open] > summary { margin-bottom: 8px; }
  .side-foot { padding: 12px 0 0; }
  main { padding: 24px 16px 48px; }
  .post-head h1 { font-size: 1.6rem; }
  .card { padding: 14px; }
  .hint { display: none; }
  .status { padding: 10px 14px 12px; margin-bottom: 18px; }
  .st-main { gap: 14px; }
  .st-next { min-width: 100%; }
}
