/* ------------------------------------------------------------------------
   N5 Dōjō — visual system
   Layout: a fixed masthead over a 原稿用紙 (manuscript-grid) band, then a
   single reading column; chapter and reference material sit on washi cards,
   each marked with a vermilion hanko-style badge.
   ---------------------------------------------------------------------- */

:root {
  /* washi paper, sumi ink, ai indigo, shu vermilion, matcha */
  --washi:      #F6F2E9;
  --washi-2:    #FFFDF8;
  --sumi:       #1D2026;
  --sumi-soft:  #5C5E63;
  --ai:         #27477E;
  --ai-soft:    #E5EAF4;
  --shu:        #BF4A35;
  --shu-soft:   #F7E6E1;
  --matcha:     #4C7A52;
  --matcha-soft:#E6EFE4;
  --rule:       rgba(29,32,38,.14);
  --rule-soft:  rgba(29,32,38,.07);
  --card:       #FFFFFF;
  --shadow:     0 1px 2px rgba(29,32,38,.05), 0 8px 24px -16px rgba(29,32,38,.3);

  --display: "Shippori Mincho B1", "Hiragino Mincho ProN", "Yu Mincho", Georgia, serif;
  --body: "Noto Sans JP", "Hiragino Sans", "Yu Gothic", Meiryo, system-ui, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  --col: 56rem;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --washi:      #15171C;
    --washi-2:    #1B1E24;
    --sumi:       #E7E3D9;
    --sumi-soft:  #A0A2A8;
    --ai:         #8FB0E6;
    --ai-soft:    #1E2838;
    --shu:        #E8775F;
    --shu-soft:   #35211D;
    --matcha:     #8CBE93;
    --matcha-soft:#1D2A1F;
    --rule:       rgba(231,227,217,.16);
    --rule-soft:  rgba(231,227,217,.08);
    --card:       #1B1E24;
    --shadow:     0 1px 2px rgba(0,0,0,.4), 0 8px 24px -16px rgba(0,0,0,.8);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --washi:      #15171C;
  --washi-2:    #1B1E24;
  --sumi:       #E7E3D9;
  --sumi-soft:  #A0A2A8;
  --ai:         #8FB0E6;
  --ai-soft:    #1E2838;
  --shu:        #E8775F;
  --shu-soft:   #35211D;
  --matcha:     #8CBE93;
  --matcha-soft:#1D2A1F;
  --rule:       rgba(231,227,217,.16);
  --rule-soft:  rgba(231,227,217,.08);
  --card:       #1B1E24;
  --shadow:     0 1px 2px rgba(0,0,0,.4), 0 8px 24px -16px rgba(0,0,0,.8);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--washi);
  color: var(--sumi);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
}
img { max-width: 100%; }
[hidden] { display: none !important; }

.wrap {
  max-width: var(--col);
  margin-inline: auto;
  padding-left: max(18px, env(safe-area-inset-left, 0px));
  padding-right: max(18px, env(safe-area-inset-right, 0px));
}

/* ---------------------------------------------------------- manuscript -- */
/* 原稿用紙: square cells with a faint centre cross, as in the workbook */
.genko {
  background-color: var(--ai);
  background-image:
    linear-gradient(to right, rgba(255,255,255,.14) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,.14) 1px, transparent 1px),
    linear-gradient(to right, rgba(255,255,255,.07) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,.07) 1px, transparent 1px);
  background-size: 44px 44px, 44px 44px, 22px 22px, 22px 22px;
  background-position: 0 0;
}

/* -------------------------------------------------------------- header -- */
.masthead { color: #fff; }
.masthead .wrap { padding-block: 1.5rem 1.4rem; }
.brandline { display: flex; align-items: center; gap: .85rem; flex-wrap: wrap; }
.hanko {
  flex: none;
  width: 46px; height: 46px;
  display: grid; place-items: center;
  background: var(--shu);
  color: #fff;
  border-radius: 7px;
  font-family: var(--display);
  font-size: 1.45rem; line-height: 1;
  letter-spacing: -.02em;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.22);
}
.brandtext h1 {
  font-family: var(--display);
  font-size: 1.5rem; line-height: 1.15; margin: 0;
  font-weight: 600; letter-spacing: .01em;
  text-wrap: balance;
}
.brandtext p { margin: .15rem 0 0; font-size: .8rem; opacity: .78; }

nav.nav { border-bottom: 1px solid var(--rule); background: var(--washi-2); position: sticky; top: 0; z-index: 20; }
nav.nav .wrap { display: flex; gap: .2rem; overflow-x: auto; padding-block: 0; scrollbar-width: thin; }
nav.nav a {
  flex: none;
  padding: .72rem .8rem;
  font-size: .82rem; font-weight: 500;
  color: var(--sumi-soft); text-decoration: none;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
nav.nav a:hover { color: var(--sumi); }
nav.nav a[aria-current="page"] { color: var(--ai); border-bottom-color: var(--shu); font-weight: 700; }
nav.nav a:focus-visible { outline: 2px solid var(--shu); outline-offset: -2px; border-radius: 3px; }

/* --------------------------------------------------------------- type --- */
main { padding-block: 2rem 4rem; }
h2 {
  font-family: var(--display);
  font-size: 1.5rem; font-weight: 600; line-height: 1.25;
  margin: 2.4rem 0 .9rem; text-wrap: balance;
}
h2:first-child { margin-top: 0; }
h3 {
  font-size: 1.02rem; font-weight: 700; margin: 1.6rem 0 .5rem;
  letter-spacing: .005em;
}
p { margin: 0 0 .9rem; }
.lede { font-size: 1.05rem; color: var(--sumi-soft); max-width: 44rem; }
.eyebrow {
  font-size: .68rem; font-weight: 700; letter-spacing: .13em;
  text-transform: uppercase; color: var(--shu); margin: 0 0 .35rem;
}
.muted { color: var(--sumi-soft); }
.jp { font-family: var(--body); font-feature-settings: "palt"; }
a { color: var(--ai); }

/* --------------------------------------------------------------- cards -- */
.card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow);
}
.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); }
.grid > * { min-width: 0; }

/* chapter tiles */
a.tile {
  display: flex; gap: .9rem; align-items: flex-start;
  background: var(--card); border: 1px solid var(--rule); border-radius: 10px;
  padding: 1rem 1.05rem; text-decoration: none; color: inherit;
  box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}
a.tile:hover { border-color: var(--ai); transform: translateY(-1px); }
a.tile:focus-visible { outline: 2px solid var(--shu); outline-offset: 2px; }
a.tile .num {
  flex: none; width: 34px; height: 34px; border-radius: 6px;
  display: grid; place-items: center;
  background: var(--ai-soft); color: var(--ai);
  font-family: var(--display); font-size: 1.1rem; font-weight: 600;
}
a.tile.done .num { background: var(--shu); color: #fff; }
a.tile h3 { margin: 0; font-size: .98rem; }
a.tile .sub { font-size: .78rem; color: var(--sumi-soft); margin-top: .1rem; }

/* ------------------------------------------------------------- tables --- */
.tablewrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: 9px; background: var(--card); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
caption {
  caption-side: top; text-align: left; padding: .7rem .85rem .55rem;
  font-size: .78rem; font-weight: 700; color: var(--sumi-soft);
  border-bottom: 1px solid var(--rule-soft);
}
th, td { padding: .48rem .85rem; text-align: left; border-bottom: 1px solid var(--rule-soft); vertical-align: top; }
thead th { background: var(--ai-soft); color: var(--ai); font-size: .76rem; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td b { color: var(--shu); }
.num-col { font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- vocab --- */
.vocab { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 0; border: 1px solid var(--rule); border-radius: 9px; overflow: hidden; background: var(--card); }
.vocab div { padding: .55rem .85rem; border-bottom: 1px solid var(--rule-soft); min-width: 0; }
.vocab .r { font-weight: 600; }
.vocab .k { font-size: .92rem; color: var(--ai); margin-left: .4rem; }
.vocab .e { font-size: .84rem; color: var(--sumi-soft); }

/* ------------------------------------------------------------ grammar --- */
.rule-card { border-left: 3px solid var(--shu); background: var(--card); border-radius: 0 9px 9px 0; padding: 1rem 1.15rem; border-top: 1px solid var(--rule); border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.rule-card h3 { margin-top: 0; }
.ex { border-top: 1px dashed var(--rule); padding-top: .6rem; margin-top: .7rem; display: grid; gap: .6rem; }
.ex > div { display: grid; gap: .1rem; }
.ex .r { font-weight: 600; font-size: .94rem; }
.ex .k { color: var(--ai); font-size: .95rem; }
.ex .e { color: var(--sumi-soft); font-size: .85rem; }

/* ------------------------------------------------------------ controls -- */
button, .btn {
  font: inherit; font-size: .88rem; font-weight: 600;
  padding: .5rem .95rem; border-radius: 7px;
  border: 1px solid var(--rule); background: var(--card); color: var(--sumi);
  cursor: pointer; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: var(--ai); }
button:focus-visible, .btn:focus-visible { outline: 2px solid var(--shu); outline-offset: 2px; }
button.primary, .btn.primary { background: var(--ai); border-color: var(--ai); color: #fff; }
button.primary:hover, .btn.primary:hover { filter: brightness(1.1); }
button.accent { background: var(--shu); border-color: var(--shu); color: #fff; }
button[aria-pressed="true"], button.on { background: var(--ai); border-color: var(--ai); color: #fff; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

.chip {
  font-size: .76rem; font-weight: 600; padding: .25rem .6rem; border-radius: 99px;
  background: var(--ai-soft); color: var(--ai); display: inline-block;
}
.chip.shu { background: var(--shu-soft); color: var(--shu); }
.chip.ok  { background: var(--matcha-soft); color: var(--matcha); }

/* ------------------------------------------------------------- answers -- */
.opt {
  display: block; width: 100%; text-align: left; margin-bottom: .4rem;
  border: 1px solid var(--rule); border-radius: 7px; padding: .5rem .8rem;
  background: var(--card); font-weight: 500;
}
.opt.sel { border-color: var(--ai); background: var(--ai-soft); }
.opt.right { border-color: var(--matcha); background: var(--matcha-soft); color: var(--matcha); font-weight: 700; }
.opt.wrong { border-color: var(--shu); background: var(--shu-soft); color: var(--shu); }

/* ---------------------------------------------------------------- misc -- */
.divider { height: 1px; background: var(--rule); border: 0; margin: 2.2rem 0; }
.kana-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
.kana-cell {
  aspect-ratio: 1; display: grid; place-items: center; text-align: center;
  background: var(--card); border: 1px solid var(--rule); border-radius: 6px;
  background-image: linear-gradient(to right, var(--rule-soft) 1px, transparent 1px), linear-gradient(to bottom, var(--rule-soft) 1px, transparent 1px);
  background-size: 50% 50%;
}
.kana-cell.empty { background: transparent; border-color: transparent; background-image: none; }
.kana-cell b { font-size: 1.5rem; font-weight: 500; display: block; line-height: 1.1; }
.kana-cell span { font-size: .66rem; color: var(--sumi-soft); letter-spacing: .04em; }

.meter { height: 7px; border-radius: 99px; background: var(--rule-soft); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--shu); border-radius: 99px; }

footer.site { border-top: 1px solid var(--rule); color: var(--sumi-soft); font-size: .8rem; }
footer.site .wrap { padding-block: 1.6rem 2.4rem; }

@media (max-width: 560px) {
  .brandtext h1 { font-size: 1.25rem; }
  h2 { font-size: 1.3rem; }
  .kana-grid { gap: 3px; }
  .kana-cell b { font-size: 1.2rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
