/* DARS — calm study look: paper, deep teal ink, copper (the wire) accent. M3-style tokens, light + dark. */
:root {
  color-scheme: light;
  --bg: #F6F4EE;          /* paper */
  --surface: #FFFFFF;
  --surface-2: #EFECE4;
  --on-surface: #1A1C1B;  /* 16:1 on --bg */
  --on-v: #4A4F4D;        /* 7.9:1 on --bg (AAA body) */
  --outline: #C9C5BA;
  --primary: #0B5F63;     /* 7.4:1 on white */
  --on-primary: #FFFFFF;
  --primary-c: #CDEBEA;
  --on-primary-c: #002022;
  --copper: #9A4E12;      /* 6.1:1 on white */
  --copper-c: #FFDCC4;
  --on-copper-c: #331200;
  --success: #2C6B2F;
  --error: #B3261E;
  --error-c: #F9DEDC;
  --on-error-c: #410E0B;
  --shadow: 0 1px 2px rgba(20, 24, 22, .08), 0 4px 14px rgba(20, 24, 22, .06);
  --r-sm: 10px; --r-md: 16px; --r-lg: 24px;
  --ease: cubic-bezier(.2, 0, 0, 1);
  --font: "Vazirmatn", "Inter", system-ui, sans-serif;
  --font-book: "Inter", system-ui, sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0F1416;
  --surface: #172024;
  --surface-2: #1F2A2E;
  --on-surface: #E1E6E4;  /* 13:1 */
  --on-v: #B8C2BF;        /* 8.6:1 */
  --outline: #3A4A4E;
  --primary: #7DD3D6;     /* 9.9:1 on --surface */
  --on-primary: #003638;
  --primary-c: #134B4E;
  --on-primary-c: #C9F1F1;
  --copper: #F2A66B;
  --copper-c: #5A2C0A;
  --on-copper-c: #FFDCC4;
  --success: #8CD58E;
  --error: #FFB4AB;
  --error-c: #5C1712;
  --on-error-c: #FFDAD6;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .3);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0F1416; --surface: #172024; --surface-2: #1F2A2E; --on-surface: #E1E6E4; --on-v: #B8C2BF;
    --outline: #3A4A4E; --primary: #7DD3D6; --on-primary: #003638; --primary-c: #134B4E; --on-primary-c: #C9F1F1;
    --copper: #F2A66B; --copper-c: #5A2C0A; --on-copper-c: #FFDCC4; --success: #8CD58E;
    --error: #FFB4AB; --error-c: #5C1712; --on-error-c: #FFDAD6;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--on-surface); font: 16px/1.75 var(--font); }
a { color: var(--primary); }
.ms { font-family: "Material Symbols Rounded"; font-weight: normal; font-style: normal; font-size: 22px; line-height: 1;
      display: inline-block; vertical-align: middle; font-variation-settings: "FILL" 0, "wght" 450; user-select: none; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.wrap { max-width: 920px; margin: 0 auto; padding: 0 16px 96px; }
.muted { color: var(--on-v); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--copper); outline-offset: 2px; border-radius: 6px; }

/* top bar */
.bar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px; padding: 10px 12px;
       background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
       border-bottom: 1px solid color-mix(in srgb, var(--outline) 50%, transparent); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--on-surface); font-weight: 800;
         font-size: 18px; margin-inline-end: auto; min-width: 0; }
.brand .logo { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; flex: none;
               background: var(--primary); color: var(--on-primary); }
.brand .logo .ms { font-size: 20px; font-variation-settings: "FILL" 1; }
.brand small { display: block; font-size: 12px; font-weight: 500; color: var(--on-v); line-height: 1.3; white-space: nowrap;
               overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: transparent; color: var(--on-surface);
            display: grid; place-items: center; cursor: pointer; text-decoration: none; font: inherit; flex: none;
            transition: background .2s var(--ease), transform .2s var(--ease); }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(.92); }
.chip-btn { height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--outline); background: transparent;
            color: var(--on-surface); font: 600 13px var(--font); cursor: pointer; text-decoration: none;
            display: inline-flex; align-items: center; gap: 6px; transition: background .2s var(--ease); }
.chip-btn:hover { background: var(--surface-2); }

/* cards */
.card { background: var(--surface); border-radius: var(--r-lg); padding: 20px; box-shadow: var(--shadow); margin-top: 16px; }
.card h2 { margin: 0 0 8px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.card h2 .ms { color: var(--copper); }
.hero { background: linear-gradient(135deg, var(--primary) 0%, color-mix(in srgb, var(--primary) 70%, var(--copper)) 140%);
        color: var(--on-primary); position: relative; overflow: hidden; }
.hero::after { /* a faint wire running across */
  content: ""; position: absolute; inset: auto -10% -40px -10%; height: 90px; border-top: 3px solid color-mix(in srgb, var(--copper-c) 55%, transparent);
  border-radius: 50%; opacity: .55; pointer-events: none; }
.hero .k { font-size: 13px; opacity: .9; }
.hero .big { font-size: 44px; font-weight: 800; line-height: 1.1; margin: 4px 0; }
.hero .facts { font-size: 13px; opacity: .92; }

.btn { min-height: 48px; padding: 0 22px; border-radius: 24px; border: 0; background: var(--primary); color: var(--on-primary);
       font: 700 15px var(--font); display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
       text-decoration: none; transition: transform .15s var(--ease), box-shadow .2s var(--ease), filter .2s var(--ease); }
.btn:hover { box-shadow: var(--shadow); filter: brightness(1.06); }
.btn:active { transform: scale(.97); }
.btn.tonal { background: var(--primary-c); color: var(--on-primary-c); }
.btn.wide { width: 100%; }

.continue { display: flex; gap: 14px; align-items: center; text-decoration: none; color: inherit; }
.continue .pg { width: 64px; height: 80px; flex: none; border-radius: 10px; background: var(--copper-c); color: var(--on-copper-c);
                display: grid; place-items: center; font-weight: 800; font-size: 20px; box-shadow: inset 0 -4px 0 rgba(0,0,0,.08); }
.continue .meta { min-width: 0; flex: 1; }
.continue .meta b { display: block; }
.continue .meta span { font-size: 13px; color: var(--on-v); display: block; overflow-wrap: anywhere; }

/* go / search */
.go { display: flex; gap: 8px; margin-top: 16px; }
.go input { flex: 1; min-width: 0; height: 52px; border-radius: 26px; border: 1px solid var(--outline); background: var(--surface);
            color: var(--on-surface); padding: 0 20px; font: 15px var(--font); transition: border-color .2s var(--ease), box-shadow .2s var(--ease); }
.go input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent); }
.go .btn { min-height: 52px; }

/* roadmap */
.steps { list-style: none; margin: 0; padding: 0; }
.steps li { display: flex; gap: 12px; align-items: center; padding: 8px 0; }
.steps .dot { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 13px; font-weight: 800;
              background: var(--surface-2); color: var(--on-v); }
.steps .done .dot { background: var(--primary); color: var(--on-primary); }
.steps .next .dot { background: var(--copper-c); color: var(--on-copper-c); }
.steps .tag { margin-inline-start: auto; font-size: 12px; font-weight: 700; color: var(--on-v); white-space: nowrap; }
.steps .done .tag { color: var(--success); }

/* contents */
.toc { list-style: none; margin: 0; padding: 0; }
.toc > li { border-bottom: 1px solid color-mix(in srgb, var(--outline) 45%, transparent); }
.toc > li:last-child { border-bottom: 0; }
.toc details > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 12px 4px; cursor: pointer;
                         border-radius: var(--r-sm); transition: background .2s var(--ease); }
.toc details > summary::-webkit-details-marker { display: none; }
.toc summary:hover { background: var(--surface-2); }
.toc .no { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none; font: 800 14px var(--font-book);
           background: var(--primary-c); color: var(--on-primary-c); }
.toc .ttl { flex: 1; min-width: 0; font: 600 15px/1.45 var(--font-book); direction: ltr; text-align: left; }
.toc .pp { font-size: 12px; color: var(--on-v); white-space: nowrap; }
.toc .chev { transition: transform .25s var(--ease); color: var(--on-v); }
.toc details[open] .chev { transform: rotate(180deg); }
.sub { list-style: none; margin: 0 0 10px; padding: 0 8px; direction: ltr; }
.sub a { display: flex; justify-content: space-between; gap: 12px; padding: 7px 10px; border-radius: 8px; text-decoration: none;
         color: var(--on-surface); font: 14px/1.5 var(--font-book); transition: background .2s var(--ease); }
.sub a:hover { background: var(--surface-2); }
.sub a span:last-child { color: var(--on-v); white-space: nowrap; }
.sub.grid { display: flex; flex-wrap: wrap; gap: 6px; }
.sub.grid a { background: var(--surface-2); padding: 6px 12px; }

/* reader */
.rhead { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 14px; }
.where { flex: 1; min-width: 200px; }
.where .chap { font: 600 14px/1.4 var(--font-book); direction: ltr; text-align: start; overflow-wrap: anywhere; }
.pagebadge { display: inline-flex; align-items: center; gap: 8px; border-radius: 14px; padding: 6px 14px; background: var(--copper-c);
             color: var(--on-copper-c); font-weight: 800; font-size: 15px; }
.pagebadge small { font-weight: 500; opacity: .85; font-size: 12px; }
.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px; margin-top: 12px; border-radius: 22px;
         background: var(--surface-2); }
.modes a { min-height: 40px; border-radius: 18px; display: flex; align-items: center; justify-content: center; text-align: center;
           text-decoration: none; color: var(--on-v); font-size: 13px; font-weight: 700; line-height: 1.2; padding: 4px 6px;
           transition: background .2s var(--ease), color .2s var(--ease); }
.modes a:hover { color: var(--on-surface); }
.modes a.on { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
.modes a .soon { display: block; font-size: 10px; font-weight: 500; opacity: .8; }
.note { margin-top: 12px; padding: 12px 14px; border-radius: var(--r-md); background: var(--copper-c); color: var(--on-copper-c);
        font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.paper { margin-top: 14px; background: #fff; border-radius: 6px; box-shadow: var(--shadow); overflow: hidden; position: relative; }
.paper img { display: block; width: 100%; height: auto; transition: filter .3s var(--ease); }
.paper.night img { filter: invert(.9) hue-rotate(180deg); }
.paper .ph { aspect-ratio: 612 / 792; }
.tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.tools .chip-btn[aria-pressed="true"] { background: var(--primary-c); color: var(--on-primary-c); border-color: transparent; }
.rawtext { margin-top: 12px; background: var(--surface); border-radius: var(--r-md); padding: 16px; box-shadow: var(--shadow);
           direction: ltr; text-align: left; white-space: pre-wrap; overflow-wrap: anywhere; font: 14px/1.6 var(--font-book); }
.rules { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; direction: ltr; }
.rules span { background: var(--surface-2); border-radius: 8px; padding: 4px 10px; font: 13px/1.4 var(--font-book); }
.rules b { color: var(--primary); }

.pager { direction: ltr; position: fixed; inset: auto 0 0 0; z-index: 10; display: flex; align-items: center; justify-content: center; gap: 10px;
         padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--bg) 92%, transparent);
         backdrop-filter: blur(10px); border-top: 1px solid color-mix(in srgb, var(--outline) 50%, transparent); }
.pager form { display: flex; align-items: center; gap: 6px; }
.pager input { width: 76px; height: 44px; border-radius: 22px; border: 1px solid var(--outline); background: var(--surface);
               color: var(--on-surface); text-align: center; font: 700 15px var(--font); }
.pager .icon-btn { background: var(--primary-c); color: var(--on-primary-c); }
.pager .icon-btn[aria-disabled="true"] { opacity: .35; pointer-events: none; }

/* search results */
.hits { list-style: none; margin: 0; padding: 0; }
.hits a { display: block; padding: 12px; border-radius: var(--r-md); text-decoration: none; color: var(--on-surface);
          transition: background .2s var(--ease); }
.hits a:hover { background: var(--surface-2); }
.hits .snip { direction: ltr; text-align: left; font: 14px/1.6 var(--font-book); color: var(--on-v); display: block; }
.hits mark { background: var(--copper-c); color: var(--on-copper-c); border-radius: 3px; padding: 0 2px; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login .card { width: 100%; max-width: 400px; padding: 28px; }
.login .logo { width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center; background: var(--primary);
               color: var(--on-primary); margin-bottom: 12px; }
.login .logo .ms { font-size: 30px; font-variation-settings: "FILL" 1; }
.login h1 { margin: 0; font-size: 26px; }
.field { display: block; margin-top: 14px; }
.field span { display: block; font-size: 13px; font-weight: 600; color: var(--on-v); margin-bottom: 4px; }
.field input { width: 100%; height: 52px; border-radius: 14px; border: 1px solid var(--outline); background: var(--surface);
               color: var(--on-surface); padding: 0 16px; font: 16px var(--font); direction: ltr;
               transition: border-color .2s var(--ease), box-shadow .2s var(--ease); }
.field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent); }
.err { margin-top: 14px; padding: 10px 14px; border-radius: 12px; background: var(--error-c); color: var(--on-error-c); font-size: 14px; }

.fade-in { animation: fade .35s var(--ease) both; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (min-width: 720px) {
  .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .grid2 > .card { margin-top: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
