/* AniDic — black and white. One black masthead, hard rules, square corners. */
:root {
  --bg: #fff; --fg: #000; --mute: #595959; --line: #000; --soft: #f1f1f1;
  --accent: #000; --on-accent: #fff;
  --font: "Sarabun", "Noto Sans Thai", "Noto Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 17px/1.6 var(--font); padding-bottom: env(safe-area-inset-bottom, 0px); }
body.tpl-inverse { --bg: #000; --fg: #fff; --mute: #bdbdbd; --line: #fff; --soft: #1a1a1a; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
body.tpl-inverse :focus-visible { outline-color: #fff; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h2 { font-size: 1.35rem; } h3 { font-size: 1.1rem; }
p { margin: 0 0 .9rem; }
.boot { padding: 2rem; }
.wrap { max-width: 760px; margin: 0 auto; padding: 0 1rem; }
.mute { color: var(--mute); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* platform bar */
.bar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: calc(.6rem + var(--safe-t)) 1rem .6rem; border-bottom: 2px solid var(--line); }
.bar .mark { font-weight: 800; font-size: 1.2rem; letter-spacing: -.02em; text-decoration: none; }
.bar nav { display: flex; gap: 1rem; align-items: center; font-size: .95rem; }
.btn-link { background: none; border: 0; padding: 0; font: inherit; color: inherit; text-decoration: underline; cursor: pointer; }

/* home masthead */
.mast { background: #000; color: #fff; padding: calc(2.2rem + var(--safe-t)) 1rem 2rem; }
.mast .wrap { padding: 0; }
.mast h1 { font-size: clamp(3.4rem, 17vw, 7rem); font-weight: 800; letter-spacing: -.05em; line-height: .95; margin: 0 0 .6rem; }
.mast p { color: #d9d9d9; max-width: 34ch; }
.mast .field { margin-top: 1.2rem; }
.mast input { background: #fff; color: #000; border-color: #fff; }

/* forms */
label { display: block; font-weight: 700; margin: 1rem 0 .3rem; }
input, select, textarea { width: 100%; font: inherit; font-size: 16px; color: var(--fg); background: var(--bg); border: 2px solid var(--line); border-radius: 0; padding: .7rem .8rem; }
textarea { min-height: 7rem; resize: vertical; }
textarea.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; min-height: 16rem; }
input[type=checkbox], input[type=radio] { width: 1.15rem; height: 1.15rem; accent-color: var(--fg); vertical-align: -.2rem; margin-right: .5rem; }
input[type=color] { padding: .15rem; height: 3rem; }
.check { display: flex; gap: .5rem; align-items: flex-start; font-weight: 400; margin: .8rem 0; }
.check input { flex: none; margin-top: .3rem; }
.hint { font-size: .9rem; color: var(--mute); margin: .25rem 0 0; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.grow { flex: 1 1 12rem; }
.btn { display: inline-block; font: inherit; font-weight: 700; padding: .7rem 1.1rem; border: 2px solid var(--accent); background: var(--accent); color: var(--on-accent); border-radius: 0; cursor: pointer; text-decoration: none; min-height: 2.9rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--fg); border-color: var(--line); }
.btn.sm { padding: .35rem .7rem; min-height: 0; font-size: .9rem; }
.btn.danger { background: transparent; color: var(--fg); border: 2px dashed var(--line); }
.error { border: 2px solid var(--line); background: var(--soft); padding: .7rem .9rem; margin: .8rem 0; font-weight: 700; }
.note { border-left: 6px solid var(--fg); background: var(--soft); padding: .7rem .9rem; margin: 1rem 0; }
.box { border: 2px solid var(--line); padding: 1rem; margin: 1rem 0; }
.terms { max-height: 15rem; overflow: auto; border: 2px solid var(--line); padding: .8rem 1rem; margin: .5rem 0; font-size: .95rem; }
.terms h3 { font-size: 1rem; margin: .8rem 0 .2rem; }
.terms h3:first-child { margin-top: 0; }

/* lists */
.page { padding-top: 1.4rem; padding-bottom: 3rem; }
.dlist { list-style: none; margin: 0; padding: 0; }
.dlist a { display: grid; grid-template-columns: 1fr auto; gap: .1rem 1rem; padding: 1rem 0; border-bottom: 2px solid var(--line); text-decoration: none; }
.dlist a:hover .dname { text-decoration: underline; }
.dname { font-size: 1.25rem; font-weight: 800; }
.dcount { font-weight: 700; text-align: right; white-space: nowrap; }
.dmeta { color: var(--mute); grid-column: 1; }
.ddesc { grid-column: 1 / -1; color: var(--mute); }
.empty { padding: 2rem 0; color: var(--mute); }
.more { margin: 1.2rem 0; }
.foot { border-top: 2px solid var(--line); margin-top: 2rem; padding: 1rem 1rem 2rem; display: flex; flex-wrap: wrap; gap: .5rem 1.4rem; font-size: .92rem; color: var(--mute); }

/* dictionary */
.dhead { padding: calc(1.2rem + var(--safe-t)) 0 1.2rem; border-bottom: 4px solid var(--fg); }
.dhead .up { font-size: .9rem; display: flex; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.dhead h1 { font-size: clamp(1.9rem, 8vw, 3.2rem); font-weight: 800; letter-spacing: -.02em; margin-bottom: .3rem; }
.dhead .tag { color: var(--mute); margin: 0; }
.searchbox { display: flex; gap: .5rem; margin: 1.2rem 0 .6rem; }
.searchbox input { flex: 1; font-size: 18px; }
.kb { display: flex; flex-wrap: wrap; gap: .35rem; margin: .5rem 0; max-height: 11rem; overflow: auto; padding: .1rem; }
.kb button { min-width: 2.7rem; min-height: 2.7rem; padding: .2rem .5rem; border: 2px solid var(--line); background: var(--bg); color: var(--fg); font: inherit; font-size: 1.3rem; cursor: pointer; border-radius: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.kb button small { font-size: .65rem; color: var(--mute); font-family: var(--font); }
.entry-row { display: grid; grid-template-columns: minmax(3.5rem, auto) 1fr; gap: .1rem 1rem; padding: .9rem 0; border-bottom: 1px solid var(--line); text-decoration: none; align-items: baseline; }
.entry-row:hover .hw { text-decoration: underline; }
.hw { font-size: 1.7rem; font-weight: 700; line-height: 1.25; }
.rd { color: var(--mute); }
.pos { font-style: italic; color: var(--mute); }
.df { grid-column: 2; }
.entry-row .meta { grid-column: 2; display: flex; gap: .8rem; flex-wrap: wrap; }
.entry-view .big { font-size: clamp(2.6rem, 14vw, 5rem); line-height: 1.15; font-weight: 700; margin: 1rem 0 .2rem; word-break: break-word; }
.entry-view .def { white-space: pre-wrap; font-size: 1.15rem; margin: 1rem 0; }
.entry-view .ex { border-left: 6px solid var(--accent); padding-left: 1rem; margin: 1.2rem 0; white-space: pre-wrap; }
body.tpl-inverse .entry-view .ex { border-left-color: #fff; }
.tpl-ruled .entry-row { border: 2px solid var(--line); margin: -2px 0 0; padding: .9rem 1rem; }
.tpl-ruled .dhead { border-bottom-width: 8px; }
.frame { width: 100%; border: 0; min-height: 70vh; display: block; background: #fff; }

/* tabs & manage */
.tabs { display: flex; gap: 0; overflow-x: auto; border-bottom: 2px solid var(--line); margin: 1rem 0; scrollbar-width: none; }
.tabs button { flex: none; background: none; border: 0; border-bottom: 5px solid transparent; font: inherit; font-weight: 700; color: var(--mute); padding: .7rem 1rem .5rem; cursor: pointer; margin-bottom: -2px; }
.tabs button[aria-selected=true] { color: var(--fg); border-bottom-color: var(--accent); }
body.tpl-inverse .tabs button[aria-selected=true] { border-bottom-color: #fff; }
.item { display: flex; gap: .6rem; align-items: center; justify-content: space-between; padding: .7rem 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.item .main { flex: 1 1 14rem; min-width: 0; }
.item .acts { display: flex; gap: .4rem; flex-wrap: wrap; }
.pill { display: inline-block; border: 2px solid var(--line); padding: 0 .5rem; font-size: .85rem; font-weight: 700; }
.pill.fill { background: var(--fg); color: var(--bg); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr)); gap: .6rem; }
.stat { border: 2px solid var(--line); padding: .8rem; }
.stat b { display: block; font-size: 2rem; line-height: 1.1; }
.tpl-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.tpl-pick label { margin: 0; border: 2px solid var(--line); padding: .6rem; font-weight: 700; cursor: pointer; text-align: center; }
.tpl-pick input { position: absolute; opacity: 0; }
.tpl-pick label:has(input:checked) { background: var(--fg); color: var(--bg); }
.tpl-pick label:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
progress { width: 100%; height: 1.1rem; accent-color: var(--fg); }
.preview { border: 2px solid var(--line); padding: .8rem 1rem; font-size: 2rem; min-height: 4rem; word-break: break-all; }
pre.snip { background: var(--soft); border: 2px solid var(--line); padding: .8rem; overflow: auto; font-size: 13px; }

#toast { position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%) translateY(150%); background: #000; color: #fff; border: 2px solid #fff; padding: .7rem 1.1rem; max-width: 92vw; font-weight: 700; z-index: 99; transition: transform .2s; visibility: hidden; }
#toast.show { transform: translateX(-50%) translateY(0); visibility: visible; }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
@media (min-width: 700px) { body { font-size: 18px; } .mast { padding-top: 3.5rem; padding-bottom: 3rem; } }
