/* ālexicon — "clean Japanese restaurant": sumi ink, washi paper, stone; lots of ma.
   Three themes as colour tokens. The theme switch works without JS (radios + :has());
   a few lines of JS only remember the choice. Every token pair was checked against
   WCAG: text ≥ 4.5:1, control edges and focus ≥ 3:1. --rule is decorative only. */

:root {                       /* light — washi */
  --bg: #f4efe4; --card: #fbf8f1; --fg: #1f1b16; --muted: #5c554a;
  --rule: #ddd5c5; --edge: #8f8576; --brand: #bc002d; --accent: #bc002d; --mark: #7a5410; --link: #2c4a6e;
  --accent-fg: #f4efe4; --soft: #ece5d6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:has(#th-auto:checked), :root:not(:has(input[name="theme"])) {
    --bg: #15130f; --card: #1d1a15; --fg: #ebe5d8; --muted: #a8a091;
    --rule: #2e2a23; --edge: #7f7768; --brand: #ff2a2a; --accent: #c9082c; --mark: #d9a066; --link: #9fb7d4;
    --accent-fg: #ebe5d8; --soft: #24201a;
    color-scheme: dark;
  }
}
:root:has(#th-dark:checked) {   /* dark — sumi */
  --bg: #15130f; --card: #1d1a15; --fg: #ebe5d8; --muted: #a8a091;
  --rule: #2e2a23; --edge: #7f7768; --brand: #ff2a2a; --accent: #c9082c; --mark: #d9a066; --link: #9fb7d4;
  --accent-fg: #ebe5d8; --soft: #24201a;
  color-scheme: dark;
}
:root:has(#th-light:checked) {
  --bg: #f4efe4; --card: #fbf8f1; --fg: #1f1b16; --muted: #5c554a;
  --rule: #ddd5c5; --edge: #8f8576; --brand: #bc002d; --accent: #bc002d; --mark: #7a5410; --link: #2c4a6e;
  --accent-fg: #f4efe4; --soft: #ece5d6;
  color-scheme: light;
}
:root:has(#th-neutral:checked) { /* neutral — ishi (stone): less saturation, not less contrast */
  --bg: #d8d6d1; --card: #e3e1dc; --fg: #1d1d1c; --muted: #454543;
  --rule: #c4c1bb; --edge: #7a7874; --brand: #bc002d; --accent: #bc002d; --mark: #6b4c12; --link: #34495a;
  --accent-fg: #e3e1dc; --soft: #cfccc6;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 17px/1.65 system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", "Noto Sans", sans-serif;
}
header, main, footer { max-width: 46rem; margin: 0 auto; padding: 0 16px; }
header { padding-top: 2.2rem; }
h1, h2, h3, .serif {
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", "Noto Serif", Georgia, serif;
  font-weight: 500;
}
h1 { margin: 0; font-size: 2rem; letter-spacing: .06em; }
.tag { margin: .2rem 0 1.4rem; color: var(--muted); font-style: italic; }

/* theme switch: deliberately quiet — small, muted, top-right; still keyboard-reachable, no JS needed */
header { position: relative; }
.theme {
  position: absolute; top: .9rem; right: 16px; border: 0; padding: 0; margin: 0;
  display: flex; gap: .55rem; font-size: .72rem; letter-spacing: .04em;
}
.theme legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.theme label { position: relative; margin: 0; color: var(--muted); }
.theme input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.theme span { cursor: pointer; padding-bottom: 1px; }
.theme input:checked + span { color: var(--fg); border-bottom: 1px solid var(--brand); }
.theme input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }

nav { display: flex; gap: .2rem; border-bottom: 1px solid var(--rule); }
nav button {
  background: none; border: 0; padding: .7rem .9rem; color: var(--muted);
  font: inherit; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
nav button[aria-selected="true"] { color: var(--fg); border-color: var(--brand); }
main { padding-top: 1.4rem; padding-bottom: 3rem; }

input, textarea {
  width: 100%; font: inherit; color: var(--fg); background: var(--card);
  border: 1px solid var(--edge); border-radius: 3px; padding: .65rem .8rem;
}
textarea { line-height: 1.55; }
label { display: block; margin-bottom: .8rem; color: var(--muted); }
label input, label textarea { margin-top: .35rem; }
label.big { color: var(--fg); font-size: 1.05rem; }
button {
  font: inherit; cursor: pointer; border-radius: 3px; padding: .45rem .95rem;
  background: var(--accent); color: var(--accent-fg); border: 1px solid var(--accent);
}
button.ghost, .ghost { background: none; color: var(--link); }
.file { display: inline-block; border: 1px solid var(--edge); border-radius: 3px; padding: .45rem .95rem; cursor: pointer; margin: 0; }
.quiet { color: var(--muted); font-size: .92rem; }
a { color: var(--link); text-underline-offset: .18em; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* chips — like wooden menu tags */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .9rem 0; }
fieldset.chips { border: 0; padding: 0; }
.chip {
  border: 1px solid var(--edge); background: var(--card); color: var(--fg);
  padding: .2rem .7rem; border-radius: 3px; font-size: .88rem;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.chip.add { border-style: dashed; color: var(--muted); }
.facet-group h3, h3.sub {
  margin: 1.8rem 0 .5rem; font-size: .8rem; color: var(--muted);
  letter-spacing: .14em; text-transform: uppercase; font-family: inherit; font-weight: 600;
}

/* results */
.results { list-style: none; padding: 0; margin: 0; }
.card {
  background: var(--card); border: 0; border-top: 1px solid var(--rule);
  padding: 1.1rem 1.1rem 1rem; margin: 0 0 .9rem;
}
.card.layer-autistic { border-left: 3px solid var(--brand); }
.card h2 { margin: 0; font-size: 1.25rem; }
.card .rom { color: var(--muted); font-weight: 400; }
.card .meta { color: var(--muted); font-size: .82rem; letter-spacing: .02em; }
.card .meta .label {
  color: var(--fg); font-size: 1.05rem; letter-spacing: .03em;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", "Noto Serif", Georgia, serif;
}
.card .desc { font-size: 1.06rem; margin: .45rem 0 .55rem; }
.card ol { margin: .4rem 0; padding-left: 1.2rem; }
.card details { margin-top: .4rem; font-size: .92rem; }
.card details summary { color: var(--muted); cursor: pointer; }
.card .etym { white-space: pre-wrap; }
.card .actions { display: flex; gap: .6rem; align-items: center; margin-top: .6rem; flex-wrap: wrap; }
.card .actions a { color: var(--muted); font-size: .82rem; }
.card .placed { font-size: .85rem; color: var(--brand); }
.card .flag { color: var(--mark); font-size: .88rem; }
.card .mismap { font-size: .9rem; border-left: 2px dashed var(--mark); padding-left: .6rem; }
.card .quotes { font-size: .86rem; color: var(--muted); padding-left: 1.1rem; margin: .35rem 0; }
.card .words, .card .linked { font-size: .9rem; margin: .35rem 0; }
.card .w { display: inline-block; margin-right: .4rem; }
.card .w.via-lsa { opacity: .7; font-style: italic; }

/* valence plane (place dialog) */
.plane-wrap { max-width: 22rem; margin: .5rem auto; }
.plane {
  position: relative; aspect-ratio: 1; border: 1px solid var(--edge); border-radius: 3px;
  background: var(--soft); cursor: crosshair; touch-action: none;
}
.plane::before, .plane::after { content: ""; position: absolute; background: var(--rule); }
.plane::before { left: 50%; top: 0; bottom: 0; width: 1px; }
.plane::after { top: 50%; left: 0; right: 0; height: 1px; }
.plane .lbl { position: absolute; font-size: .75rem; color: var(--muted); pointer-events: none; }
.plane .lbl.l { left: .4rem; top: 50%; transform: translateY(-120%); }
.plane .lbl.r { right: .4rem; top: 50%; transform: translateY(-120%); }
.plane .lbl.t { top: .3rem; left: 50%; transform: translateX(.4rem); }
.plane .lbl.b { bottom: .3rem; left: 50%; transform: translateX(.4rem); }
.plane .dot { position: absolute; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%; background: var(--mark); border: 2px solid var(--card); pointer-events: none; }
.plane .ghostdot { position: absolute; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; background: var(--accent); opacity: .55; pointer-events: none; }

dialog {
  border: 1px solid var(--edge); border-radius: 4px; background: var(--bg); color: var(--fg);
  width: min(30rem, calc(100vw - 32px)); padding: 1.2rem 1.3rem;
}
dialog::backdrop { background: rgb(0 0 0 / .5); }
dialog h2 { margin: 0; }
menu { display: flex; justify-content: flex-end; gap: .5rem; padding: 0; margin: 1rem 0 0; }
.io { display: flex; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
footer { padding-bottom: 2.5rem; border-top: 1px solid var(--rule); padding-top: 1rem; }
noscript p { border: 1px solid var(--edge); padding: .8rem 1rem; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }

.a-mark { color: var(--brand); }

.chip.all { background: none; border-style: dotted; color: var(--muted); }
