/* Reset, typography, focus, buttons, forms, utilities. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + 12px); }
body {
  margin: 0; background: var(--c-bg); color: var(--c-text);
  font-family: var(--font); font-size: var(--fs-base); line-height: var(--lh);
  -webkit-font-smoothing: antialiased; min-height: 100vh; display: flex; flex-direction: column;
  overflow-x: hidden;
}
h1, h2, h3 { line-height: 1.25; font-weight: 700; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
p { margin: 0 0 .75em; }
a { color: var(--c-primary); text-underline-offset: 3px; }
img, svg, video { max-width: 100%; }
code, kbd, pre { font-family: var(--mono); font-size: .92em; }
:not(pre) > code { background: var(--c-surface-2); border: 1px solid var(--c-border); border-radius: 6px; padding: .05em .35em; overflow-wrap: anywhere; }
ul, ol { padding-left: 1.4em; margin: 0 0 .75em; }
li + li { margin-top: .25em; }
strong { font-weight: 700; }
small { font-size: var(--fs-sm); }

:focus-visible { outline: 3px solid var(--c-focus); outline-offset: 2px; border-radius: 4px; }
[tabindex="-1"]:focus { outline: none; }

.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--c-primary); color: var(--c-primary-ink); padding: 10px 16px; border-radius: var(--radius-sm); font-weight: 700; transition: top .15s; }
.skip-link:focus { top: 8px; }
[hidden] { display: none !important; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: 10px; border: 2px solid var(--c-border);
  background: var(--c-surface); color: var(--c-text); font: inherit; font-weight: 600; font-size: 16px;
  text-decoration: none; cursor: pointer; transition: transform .08s, background .15s, border-color .15s, box-shadow .15s;
  -webkit-tap-highlight-color: transparent; white-space: nowrap; user-select: none;
}
.btn:hover { border-color: var(--c-muted); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--c-primary); border-color: var(--c-primary); color: var(--c-primary-ink); box-shadow: 0 2px 0 color-mix(in srgb, var(--c-primary) 60%, #000); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.success { background: var(--c-success-bg); border-color: var(--c-success); color: var(--c-text); }
.btn.danger { border-color: var(--c-danger); color: var(--c-danger); }
.btn.danger.primary, .dialog .btn.danger { background: var(--c-danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--c-surface-2); }
.btn.sm { min-height: 38px; padding: 0 12px; font-size: 15px; }
.btn.lg { min-height: 52px; padding: 0 24px; font-size: 17px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; filter: none; }
.btn.chosen { outline: 3px solid var(--c-primary); outline-offset: 1px; }
.icon-btn { display: inline-grid; place-items: center; min-width: var(--tap); min-height: var(--tap); border: 0; border-radius: 10px; background: transparent; color: var(--c-text); font-size: 18px; cursor: pointer; text-decoration: none; }
.icon-btn:hover { background: var(--c-surface-2); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.link-btn { background: none; border: 0; color: var(--c-primary); font: inherit; font-size: var(--fs-sm); cursor: pointer; padding: 6px 4px; min-height: 32px; text-decoration: underline; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1.5px solid var(--c-border); background: var(--c-surface); color: var(--c-text); font: inherit; font-size: 15px; font-weight: 600; text-decoration: none; cursor: pointer;
}
.chip:hover { border-color: var(--c-primary); }
.chip.active { background: var(--c-primary-soft); border-color: var(--c-primary); color: var(--c-text); }
.chip-time { font-family: var(--mono); font-size: 13px; color: var(--c-muted); }
.tag { display: inline-block; font-size: 13px; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: var(--c-surface-2); color: var(--c-muted); border: 1px solid var(--c-border); }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 4px 12px; border-radius: 999px; background: var(--c-surface-2); font-size: var(--fs-sm); font-weight: 600; }
.pill.good { background: var(--c-success-bg); }
.pill.again { background: var(--c-warn-bg); }

/* Forms */
input, select, textarea { font: inherit; color: inherit; }
.text-input, .search, select, .num-input {
  min-height: var(--tap); padding: 8px 14px; border: 2px solid var(--c-border); border-radius: 10px; background: var(--c-surface); color: var(--c-text); font-size: 16px; max-width: 100%;
}
.text-input:focus, .search:focus, select:focus, .num-input:focus { border-color: var(--c-primary); outline: none; box-shadow: 0 0 0 3px var(--c-primary-soft); }
.search { width: 100%; margin-bottom: 12px; }
[aria-invalid="true"] { border-color: var(--c-danger) !important; }
.form-msg { min-height: 1.5em; font-size: var(--fs-sm); margin-top: 6px; }
.form-msg.error { color: var(--c-danger); font-weight: 600; }
.form-msg.error::before { content: "✕ "; }
.form-msg.success { color: var(--c-success); font-weight: 600; }

/* Callouts (markdown-lite) */
.callout { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm); margin: 0 0 .75em; border-left: 4px solid var(--c-primary); background: var(--c-primary-soft); }
.callout p { margin: 0; }
.callout.warn { border-left-color: var(--c-warn); background: var(--c-warn-bg); }
.callout-icon { flex: none; line-height: 1.6; }

/* Glossary term + popover */
button.term {
  font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: help;
  border-bottom: 2px dotted var(--c-primary); line-height: inherit; min-height: 0;
}
button.term:hover { color: var(--c-primary); }
.term-pop { position: absolute; z-index: 60; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 14px 16px; font-size: 15px; }
.term-pop p { margin: 6px 0 8px; }
.term-en { color: var(--c-muted); font-weight: 400; }
.term-more { font-size: var(--fs-sm); }

/* Toast + dialog */
.toast { position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 80;
  background: var(--c-text); color: var(--c-bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 15px; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.dialog { border: 0; border-radius: var(--radius); padding: 22px; max-width: min(440px, calc(100vw - 32px)); background: var(--c-surface); color: var(--c-text); box-shadow: var(--shadow-lg); }
.dialog::backdrop { background: rgba(10, 14, 20, .5); }
.dialog-msg { font-size: var(--fs-lg); font-weight: 600; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }

.spinner { display: inline-block; width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--c-border); border-top-color: var(--c-primary); animation: spin .8s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Reduced motion: OS preference or user override */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
html.reduce-motion *, html.reduce-motion *::before, html.reduce-motion *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
