/* Tsumiki design system — ported from doc/design/ to a hand-written stylesheet (no build step).
   Palettes are CSS custom properties selected by [data-theme] on .app. Soft-3D cards use hard
   offset shadows (box-shadow: 0 Npx 0 edge), matching the prototype. */

/* ---- neutrals (shared across themes) ---- */
:root {
  --page:   #d9d6cf;
  --paper:  #FBF8F1;   /* main frame */
  --card:   #ffffff;
  --card-2: #fffdf8;   /* toolbars / rails */
  --border: #efe9dc;
  --border-2:#e7e0d0;
  --track:  #f0ece1;
  --track-2:#ece7d8;
  --ink:    #3d3526;   /* headings */
  --ink-jp: #2c2620;   /* japanese body text */
  --ink-2:  #6f6453;
  --muted:  #7d735e;
  --muted-2:#988e78;
  --muted-3:#a89f8c;
  --muted-4:#b3a98f;
  --radius: 18px;
  --rail-w: 88px;
  --font-ui: 'Zen Maru Gothic','Noto Sans JP',sans-serif;
  --font-jp: 'Noto Sans JP',sans-serif;
  --font-label: 'Hanken Grotesk',sans-serif;
}

/* ---- palettes ---- */
.app[data-theme="0"]{--pri:#5f9244;--pri-edge:#466e30;--pri-soft:#e9f2df;--pri-ink:#3d6326;--sec:#cf6a43;--sec-edge:#a8512f;--sec-soft:#f7e6df;--acc:#e0992e;--acc-soft:#faedd3;--acc-ink:#99620f;}
.app[data-theme="1"]{--pri:#3f4f9e;--pri-edge:#2d3a78;--pri-soft:#e8eaf6;--pri-ink:#2d3a78;--sec:#e8743b;--sec-edge:#bf5628;--sec-soft:#fbe7da;--acc:#e0a52e;--acc-soft:#f9ecd0;--acc-ink:#8c640f;}
.app[data-theme="2"]{--pri:#d7402b;--pri-edge:#ab2f1d;--pri-soft:#fbe6e1;--pri-ink:#a8301d;--sec:#33414f;--sec-edge:#222c37;--sec-soft:#e4e7ea;--acc:#d99a2e;--acc-soft:#f9edd2;--acc-ink:#8f6311;}
.app[data-theme="3"]{--pri:#8a4767;--pri-edge:#6a3550;--pri-soft:#f4e7ee;--pri-ink:#6a3550;--sec:#c79a36;--sec-edge:#9d7826;--sec-soft:#f6eed8;--acc:#cf6a43;--acc-soft:#f9e6dc;--acc-ink:#9a4a2a;}
.app[data-theme="4"]{--pri:#2f7d6b;--pri-edge:#225e50;--pri-soft:#e2f0eb;--pri-ink:#225e50;--sec:#e76f5a;--sec-edge:#c0513e;--sec-soft:#fbe5e0;--acc:#e0a52e;--acc-soft:#f9ecd0;--acc-ink:#8c640f;}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); font-family: var(--font-ui); color: var(--ink); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.18); border-radius: 8px; }
ruby { ruby-position: over; }
a { color: inherit; }

/* ---- app shell ---- */
.app { min-height: 100vh; }
.with-rail { padding-left: var(--rail-w); }

/* nav rail */
.rail {
  position: fixed; left: 0; top: 0; bottom: 0; width: var(--rail-w);
  background: var(--card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; padding: 18px 0; gap: 5px;
  z-index: 55; box-shadow: 2px 0 16px rgba(60,50,20,.06); font-family: var(--font-ui);
}
.rail-home {
  text-decoration: none; width: 52px; height: 52px; border-radius: 15px;
  background: var(--pri); box-shadow: 0 4px 0 var(--pri-edge);
  display: grid; place-items: center; color: #fff; font-weight: 900; font-size: 24px; font-family: var(--font-jp);
}
.rail-sep { width: 34px; height: 1px; background: var(--border); margin: 6px 0; }
.rail a.nav-item {
  text-decoration: none; width: 52px; height: 52px; border-radius: 15px;
  display: grid; place-items: center; font-weight: 700; font-size: 22px;
  font-family: var(--font-jp); color: var(--muted-3); transition: all .14s;
}
.rail a.nav-item:hover { background: var(--track); color: var(--ink); }
.rail a.nav-item.active { background: var(--pri-soft); color: var(--pri-ink); }
.rail .grow { flex: 1; }
.rail .rail-settings {
  text-decoration: none; width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 19px; font-family: var(--font-jp);
  background: var(--sec); color: #fff;
}
.rail .rail-settings.active { box-shadow: 0 0 0 3px var(--sec-soft); }

/* page surface — fills the area next to the rail edge-to-edge (no floating card).
   Inline max-width on individual pages is overridden so every screen fills the background. */
main { min-height: 100vh; }
.frame {
  /* min-height is !important so the per-page inline min-heights (80vh/88vh) can't leave a strip of
     page background showing below short pages — every surface fills at least the viewport. */
  width: 100%; max-width: none !important; margin: 0 !important; min-height: 100vh !important;
  background: var(--paper); border-radius: 0; box-shadow: none;
  font-family: var(--font-ui);
}
/* Pages that want their content readable rather than stretched wrap it in .sheet. */
.sheet { max-width: 1180px; margin: 0 auto; }

/* ---- cards ---- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 4px 0 var(--border); padding: 20px 22px;
}
.card.flat { box-shadow: none; }
.card.tight { padding: 16px 18px; }

/* ---- typography helpers ---- */
.h1 { font-size: 30px; font-weight: 900; color: var(--ink); letter-spacing: .5px; }
.h2 { font-size: 19px; font-weight: 900; color: var(--ink); }
.jp { font-family: var(--font-jp); }
.label {
  font-family: var(--font-label); font-weight: 800; font-size: 11px; letter-spacing: 1.5px;
  color: var(--muted-4); text-transform: uppercase;
}
.muted { color: var(--muted-2); font-weight: 500; }
.subhead { font-size: 14.5px; font-weight: 500; color: var(--muted-2); }

/* ---- buttons ---- */
.btn {
  border: none; cursor: pointer; font-family: var(--font-ui); font-weight: 800; font-size: 14px;
  padding: 12px 22px; border-radius: 13px; display: inline-flex; align-items: center; gap: 8px;
  text-decoration: none; transition: filter .12s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--pri); box-shadow: 0 5px 0 var(--pri-edge); color: #fff; }
.btn-secondary { background: var(--sec); box-shadow: 0 5px 0 var(--sec-edge); color: #fff; }
.btn-ghost { background: var(--card); border: 1px solid var(--border-2); color: var(--muted); }
.btn-soft { background: var(--pri-soft); color: var(--pri-ink); }
.btn:disabled { background: var(--track); color: #c4bca8; box-shadow: none; cursor: default; }

/* segmented control */
.seg { display: inline-flex; background: var(--track); border-radius: 11px; padding: 3px; gap: 0; }
.seg button {
  border: none; cursor: pointer; border-radius: 8px; padding: 6px 11px; font-family: var(--font-label);
  font-weight: 700; font-size: 12px; white-space: nowrap; background: transparent; color: var(--muted-3);
}
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* pills / tags */
.tag { font-size: 11px; font-weight: 800; padding: 4px 9px; border-radius: 8px; }
.tag-pri { color: var(--pri-ink); background: var(--pri-soft); }
.tag-sec { color: var(--sec); background: var(--sec-soft); }
.tag-acc { color: var(--acc-ink); background: var(--acc-soft); }
.tag-muted { color: var(--muted-4); border: 1px solid var(--border-2); }

/* progress bar */
.bar { height: 16px; background: var(--track); border-radius: 9px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--pri); border-radius: 9px; }

/* conic progress ring: set --pct (0-100) on .ring */
.ring { position: relative; border-radius: 50%;
  background: conic-gradient(var(--pri) calc(var(--pct,0)*1%), var(--track-2) 0); }
.ring > .hole { position: absolute; inset: 12px; border-radius: 50%; background: #fff;
  display: grid; place-items: center; text-align: center; }

/* layout utilities */
.row { display: flex; align-items: center; gap: 12px; }
.col { display: flex; flex-direction: column; }
.grow { flex: 1; }
.spread { display: flex; align-items: center; justify-content: space-between; }
.grid { display: grid; gap: 14px; }

/* status dots */
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-known { background: var(--pri); }
.dot-learning { background: var(--acc); }
.dot-unseen { background: var(--sec); }

/* htmx: dim while a request is in flight */
.htmx-request.btn { filter: brightness(.92); }

/* ---- accessibility ---- */
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible,
select:focus-visible, [tabindex]:focus-visible, label:focus-within {
  outline: 3px solid var(--pri, #5f9244);
  outline-offset: 2px;
  border-radius: 6px;
}
.rail a:focus-visible { outline-offset: -3px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .001ms !important; animation-duration: .001ms !important; }
}

/* ---- responsive (narrow screens) ---- */
@media (max-width: 820px) {
  /* nav rail becomes a fixed bottom bar */
  .with-rail { padding-left: 0; padding-bottom: 64px; }
  .rail {
    flex-direction: row; left: 0; right: 0; top: auto; bottom: 0; width: auto; height: 58px;
    padding: 6px 8px; gap: 2px; overflow-x: auto; border-right: none; border-top: 1px solid var(--border);
    box-shadow: 0 -2px 16px rgba(60,50,20,.08);
  }
  .rail-home, .rail a.nav-item { width: 42px; height: 42px; border-radius: 12px; font-size: 19px; }
  .rail-sep { display: none; }
  .rail .grow { flex: 1; }
  .rail .rail-settings { width: 40px; height: 40px; }

  /* frames go edge-to-edge */
  .frame { margin: 0 auto; border-radius: 0; max-width: 100%; box-shadow: none; }
  main { padding: 0; }

  /* stack any multi-column grid inside a frame onto one column */
  .frame [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  /* the reader's 2-column body (reading + rail) stacks too */
  .frame [style*="326px"] { grid-template-columns: 1fr !important; }
}
