:root {
  --bg: #fbfaf7; --card: #ffffff; --ink: #1c1c22; --muted: #5d5f6b; --line: #e2e0d8;
  --accent: #2f3fb5; --accent-ink: #ffffff; --accent-soft: #e8ebff;
  --good: #1f7a46; --good-soft: #e3f4ea; --warn: #8a5a00; --warn-soft: #fff1d6;
  --radius: 16px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14141a; --card: #1e1e27; --ink: #f1f1f5; --muted: #a5a7b5; --line: #33343f;
    --accent: #8f9bff; --accent-ink: #11122b; --accent-soft: #23264d;
    --good: #6fd49b; --good-soft: #1b3a2a; --warn: #f0c36a; --warn-soft: #3b3017;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 18px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 1.15rem; color: var(--ink); text-decoration: none; letter-spacing: -.01em; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  padding: 8px 11px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: .95rem;
}
.topbar nav a.on { background: var(--accent-soft); color: var(--accent); }
.crumbs { max-width: 720px; margin: 0 auto; padding: 10px 16px 0; font-size: .9rem; color: var(--muted); }
.crumbs a { color: var(--muted); }
.crumbs span.sep { margin: 0 6px; }
main { max-width: 720px; margin: 0 auto; padding: 16px 16px 120px; outline: none; }
h1 { font-size: 1.9rem; line-height: 1.15; margin: .4em 0 .3em; letter-spacing: -.02em; }
h2 { font-size: 1.35rem; margin: 1.4em 0 .4em; }
h3 { font-size: 1.1rem; }
h4 { margin: 1.1em 0 .3em; font-size: 1rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.lede { color: var(--muted); }
.loading { color: var(--muted); }
.foot { max-width: 720px; margin: 0 auto; padding: 8px 16px 32px; color: var(--muted); font-size: .8rem; }

/* tags and chips */
.tag, .chip {
  display: inline-block; padding: 4px 11px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  font-size: .85rem; font-weight: 600; text-decoration: none; margin: 0 6px 6px 0; border: 0; font-family: inherit;
}
button.tag { cursor: pointer; }
.tag.weight { background: var(--warn-soft); color: var(--warn); }
.chip { cursor: pointer; padding: 8px 14px; font-size: .95rem; min-height: 40px; }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.pg { font-size: .75em; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; white-space: nowrap; }
.intro .pg { display: none; }
.count { color: var(--muted); font-weight: 600; font-size: .9rem; margin-left: 8px; }
.linkbtn {
  background: none; border: 0; color: var(--accent); font: inherit; font-size: .95rem; font-weight: 600;
  cursor: pointer; padding: 8px 0; min-height: 40px; text-align: left;
}

/* library */
.search {
  width: 100%; font: inherit; padding: 14px 16px; border: 2px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--ink); margin: 6px 0 10px;
}
.search:focus { outline: none; border-color: var(--accent); }
.searchrow { display: flex; gap: 8px; margin: 6px 0 10px; }
.searchrow .search { margin: 0; flex: 1; min-width: 0; }
.fbtn {
  font: inherit; font-weight: 700; padding: 0 16px; border-radius: var(--radius); border: 2px solid var(--line);
  background: var(--card); color: var(--ink); cursor: pointer; min-height: 52px; white-space: nowrap;
}
.fbtn[aria-expanded="true"], .fbtn.has { border-color: var(--accent); color: var(--accent); }
.fbtn .n {
  display: inline-block; min-width: 1.5em; margin-left: 8px; padding: 0 6px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-size: .8rem; text-align: center;
}
.fpanel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 6px; margin: 0 0 12px; }
.fpanel[hidden] { display: none; }
.fpanel h4 { margin: .2em 0 .5em; }
.pills { margin: 0; }
.pills:not(:empty) { margin-bottom: 10px; }
.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--line);
  padding: 4px; border-radius: 999px; margin: 10px 0;
}
.seg button {
  font: inherit; font-weight: 700; font-size: .95rem; border: 0; background: transparent; color: var(--muted);
  padding: 10px 6px; border-radius: 999px; cursor: pointer; min-height: 44px;
}
.seg button.on { background: var(--card); color: var(--accent); box-shadow: var(--shadow); }
.grouphead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 1.4em 0 .5em; }
.grouphead h2 { margin: 0; }
.cards { display: grid; gap: 14px; }
.gamecard {
  display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  text-decoration: none; color: var(--ink); box-shadow: var(--shadow);
}
.gamecard:active, .gamecard:hover { border-color: var(--accent); }
.gamecard h2 { margin: 0 0 4px; font-size: 1.3rem; }
.facts { color: var(--muted); font-size: .95rem; margin: 0 0 8px; }
.empty { color: var(--muted); padding: 20px 0; }

/* buttons */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 58px; padding: 14px 18px;
  font: inherit; font-weight: 700; border-radius: var(--radius); border: 2px solid var(--accent); text-decoration: none;
  background: var(--card); color: var(--accent); cursor: pointer; text-align: center; margin: 0 0 12px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn small { display: block; font-weight: 500; opacity: .85; font-size: .85rem; }
.btn.stack { flex-direction: column; gap: 0; }
.btn:disabled { opacity: .4; cursor: default; }

/* wizard */
.progress { position: sticky; top: 0; z-index: 10; background: var(--bg); padding: 10px 0 8px; }
.progress .row { display: flex; justify-content: space-between; align-items: baseline; font-weight: 700; }
.progress .row span.of { color: var(--muted); font-weight: 600; font-size: .95rem; }
.bar { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s ease; }
.dots { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 0; }
.dots a { width: 12px; height: 12px; border-radius: 50%; background: var(--line); display: block; }
.dots a.done { background: var(--accent); opacity: .55; }
.dots a.now { background: var(--accent); outline: 3px solid var(--accent-soft); }
.slide { animation: slidein .22s ease; }
.slide.back { animation-name: slideback; }
@keyframes slidein { from { opacity: 0; transform: translateX(28px); } to { opacity: 1; transform: none; } }
@keyframes slideback { from { opacity: 0; transform: translateX(-28px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .slide, .slide.back, .sheet { animation: none; } .bar > i { transition: none; } }
.lesson { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.lesson h1 { margin-top: 0; }
.goal { background: var(--accent-soft); color: var(--accent); border-radius: 12px; padding: 10px 14px; font-weight: 600; margin: 8px 0 16px; }
.block { margin: 14px 0; }
.block .label { font-size: .8rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.block.say .label { color: var(--accent); }
.block.watch { background: var(--warn-soft); border-radius: 12px; padding: 10px 14px; }
.block.watch .label { color: var(--warn); }
.block.check { border: 2px dashed var(--line); border-radius: 12px; padding: 12px 14px; }
.answer { display: none; margin-top: 10px; background: var(--good-soft); color: var(--ink); border-radius: 10px; padding: 10px 12px; }
.answer.show { display: block; }
.answer strong.ok { color: var(--good); }
.reveal { margin-top: 10px; padding: 10px 16px; border-radius: 999px; border: 2px solid var(--accent); background: transparent; color: var(--accent); font: inherit; font-weight: 700; cursor: pointer; min-height: 44px; }
figure { margin: 14px 0; }
figure img { display: block; max-width: 100%; height: auto; border-radius: 12px; border: 1px solid var(--line); background: #fff; }
figure.zoom img { cursor: zoom-in; max-height: 190px; width: auto; max-width: 100%; object-fit: contain; }
figcaption { color: var(--muted); font-size: .9rem; margin-top: 4px; }
.navbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.navbar .inner { max-width: 720px; margin: 0 auto; display: grid; grid-template-columns: 1fr 2fr; gap: 12px; }
.navbar .btn { margin: 0; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.88); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 12px; }
.lightbox img { max-width: 100%; max-height: 100%; background: #fff; border-radius: 8px; }

/* rules text */
.rules section { margin-bottom: 8px; }
.rules ul, .rules ol, .lesson ul { padding-left: 1.3em; }
.rules li { margin: .25em 0; }
.toc { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.tablewrap { overflow-x: auto; margin: 10px 0; }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
blockquote { margin: 12px 0; padding: 10px 14px; border-left: 4px solid var(--line); background: var(--card); border-radius: 0 10px 10px 0; }
blockquote.verbatim { border-left-color: var(--accent); }
.vlabel { font-size: .75rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); margin-bottom: 4px; }
code { background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
details { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin: 12px 0; }
details > summary { cursor: pointer; padding: 14px 16px; font-weight: 700; list-style: none; min-height: 48px; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: "+"; float: right; color: var(--muted); font-size: 1.3rem; line-height: 1; }
details[open] > summary::after { content: "–"; }
details > .body { padding: 0 16px 14px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 14px 0; }

/* types */
details.typecard { margin: 10px 0; scroll-margin-top: 80px; }
details.typecard > summary { position: relative; padding-right: 48px; }
details.typecard > summary::after { position: absolute; right: 16px; top: 12px; float: none; }
.typecard .tname { display: block; font-weight: 700; font-size: 1.05rem; }
.typecard .tgist { display: block; font-weight: 400; color: var(--muted); font-size: .92rem; margin-top: 2px; line-height: 1.4; }
details.typecard > .body p { margin: .4em 0; }
details.typecard.hit { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
details.group { background: transparent; }
details.group > summary { font-size: 1.05rem; }
details.group > .body { padding: 0 0 4px; }
details.group > .body details.typecard { margin: 0 0 10px; }
details.exps > .body .btn:last-child { margin-bottom: 0; }

/* type explainer sheet */
.sheetwrap { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--card); color: var(--ink); width: 100%; max-width: 720px; max-height: 82vh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); position: relative;
  animation: sheetup .2s ease;
}
@keyframes sheetup { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet h2 { margin: 0 44px 8px 0; }
.sheet p { margin: .4em 0; }
.sheet .btn { margin-top: 14px; }
.sheetx {
  position: absolute; top: 10px; right: 10px; width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 1.5rem; line-height: 1; cursor: pointer;
}

/* help */
.helptoc ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.helptoc li { border-top: 1px solid var(--line); }
.helptoc li:first-child { border-top: 0; }
.helptoc .linkbtn { width: 100%; padding: 10px 0; font-size: 1rem; }
.helpsec { scroll-margin-top: 12px; }
.helpsec h2 { margin: 0 0 .3em; font-size: 1.2rem; }
.helpsec .totop { display: block; margin-left: auto; padding: 4px 0 0; min-height: 36px; font-size: .9rem; color: var(--muted); }

.panel p:first-child { margin-top: 0; }
.panel p:last-child { margin-bottom: 0; }
.panel h4:first-child { margin-top: 0; }
