/* Core styles: the shell, the bottom sheet, toasts, marks, characters. Colors come only from the tokens
   that the text pack's app.css defines (--paper, --paper-2, --ink, --ink-2, --ink-3, --rule, --seal, --seal-ink, --wash, --shadow). */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html:has(.sheet.in), html:has(.sheet.in) body { overscroll-behavior-y: contain; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 1.125rem/1.6 var(--serif); min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent; overflow-wrap: break-word;
}
[lang|="zh"] { font-family: var(--han); }
a { color: inherit; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--seal); outline-offset: 2px; border-radius: 3px; }
#view:focus, #view:focus-visible { outline: none; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 1rem; top: 1rem; background: var(--paper); padding: .5rem 1rem; z-index: 10; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.noscript { padding: 2rem; }
.muted { color: var(--ink-3); }
.small { font-size: .9rem; }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.scroll-x { overflow-x: auto; overscroll-behavior-x: contain; }

/* Shell */
.bar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: .4rem;
  padding: .35rem .75rem; /* body already pads the side insets */
  background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.bar nav { display: flex; gap: .1rem; flex: 1; justify-content: center; }
.bar nav a { text-decoration: none; padding: 0 .6rem; min-height: var(--tap); display: inline-flex; align-items: center; color: var(--ink-2); border-radius: 999px; font-size: 1rem; }
.bar nav a[aria-current="page"] { color: var(--seal); text-decoration: underline; text-underline-offset: .35em; text-decoration-thickness: 1.5px; }
.brand { text-decoration: none; display: inline-grid; min-width: var(--tap); min-height: var(--tap); place-items: center; }
.seal { display: inline-grid; place-items: center; width: 2.1rem; height: 2.1rem; background: var(--seal); color: var(--seal-ink); font: 600 1.3rem/1 var(--brush); border-radius: 4px; }
.theme-btn { appearance: none; border: 0; background: none; color: var(--ink-2); min-width: var(--tap); min-height: var(--tap); border-radius: 50%; cursor: pointer; }
main { max-width: var(--measure); margin: 0 auto; padding: 1.25rem 1.1rem 3rem; }
.site-foot { text-align: center; font-size: .85rem; color: var(--ink-3); padding: 1rem 1rem calc(1.5rem + env(safe-area-inset-bottom)); }

/* Buttons */
.btn { appearance: none; border: 1px solid var(--seal); background: transparent; color: var(--seal); min-height: var(--tap); padding: 0 1.3rem; border-radius: 999px; cursor: pointer; font-size: 1.05rem; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.btn.primary { background: var(--seal); color: var(--seal-ink); }
.btn.quiet { border-color: var(--rule); color: var(--ink-2); }
.btn.small { min-height: 36px; font-size: .92rem; padding: 0 .9rem; }
.btn:active { transform: translateY(1px); }
.link-btn { appearance: none; border: 0; background: none; color: var(--ink-3); text-decoration: underline; cursor: pointer; padding: .3rem; min-height: 36px; }

/* Marks and characters */
.mark {
  appearance: none; background: none; border: 0; padding: 0; margin: 0; font: inherit; color: inherit; cursor: pointer; text-align: inherit;
  text-decoration-line: underline; text-decoration-style: dotted; text-decoration-color: var(--seal);
  text-decoration-thickness: 1.5px; text-underline-offset: .22em;
}
.mark:active { background: var(--wash); }
/* A button is one box: a long phrase wraps inside it, never past the screen edge. */
.mark { max-width: 100%; white-space: normal; vertical-align: baseline; }
.glue:has(.mark) { white-space: normal; }
.glue .mark + * { white-space: nowrap; }
.glue { white-space: nowrap; }
.han {
  appearance: none; background: none; border: 0; padding: .06em 0; margin: 0; font: inherit; color: inherit; cursor: pointer; border-radius: 3px; min-width: 1.1em;
  --han-rule: color-mix(in srgb, var(--ink-3) 60%, transparent);
  text-decoration-line: underline; text-decoration-color: var(--han-rule); text-decoration-thickness: 1px; text-underline-offset: .3em; text-decoration-skip-ink: none;
}
span.han { cursor: inherit; }
.han.glossed { color: var(--seal); --han-rule: color-mix(in srgb, var(--seal) 60%, transparent); }
.han:active { background-color: var(--wash); }
.mark .han { text-decoration-style: dotted; text-decoration-color: var(--seal); text-decoration-thickness: 1.5px; }

/* Sheet */
.scrim { position: fixed; inset: 0; background: rgba(10, 14, 20, .4); z-index: 20; opacity: 0; transition: opacity .2s ease; cursor: pointer; touch-action: none; }
.scrim.in { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 82dvh; display: flex; flex-direction: column;
  background: var(--paper); color: var(--ink); border-radius: 14px 14px 0 0; box-shadow: var(--shadow);
  transform: translateY(100%); transition: transform .28s cubic-bezier(.2,.8,.2,1);
  max-width: 40rem; margin: 0 auto; padding-bottom: env(safe-area-inset-bottom);
}
.sheet.in { transform: none; }
.sheet.dragging { transition: none; }
.sheet .grab, .sheet header { touch-action: none; }
.sheet .grab { width: 2.6rem; height: 5px; border-radius: 5px; background: var(--rule); margin: .55rem auto .25rem; cursor: grab; }
.sheet header { display: flex; align-items: center; gap: .5rem; padding: .2rem .9rem .5rem; border-bottom: 1px solid var(--rule); }
.sheet header .ttl { flex: 1; min-width: 0; }
.sheet header h2 { margin: 0; font-size: 1.15rem; font-weight: 500; border-radius: 4px; }
.sheet .kind { font-size: .75rem; letter-spacing: .16em; text-transform: uppercase; color: var(--seal); display: block; margin-bottom: .1rem; }
.sheet .crumbs { display: flex; align-items: center; gap: .1rem; overflow-x: auto; touch-action: pan-x; scrollbar-width: none; padding: 0 .6rem; border-bottom: 1px solid var(--rule); background: var(--wash); white-space: nowrap; flex: none; }
.sheet .crumbs::-webkit-scrollbar { display: none; }
.sheet .crumb { appearance: none; border: 0; background: none; font-size: .88rem; min-height: var(--tap); padding: 0 .45rem; max-width: 11em; flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: var(--tap); color: var(--ink-2); cursor: pointer; }
button.crumb { text-decoration: underline dotted var(--ink-3); text-underline-offset: .25em; }
.sheet .crumb.here { color: var(--ink); font-weight: 600; max-width: 13em; }
.sheet .crumbs .sep { color: var(--ink-3); flex: none; }
.icon-btn { appearance: none; border: 0; background: none; min-width: var(--tap); min-height: var(--tap); border-radius: 50%; cursor: pointer; font-size: 1.3rem; color: var(--ink-2); }
.sheet .body { overflow-y: auto; padding: 1rem 1.1rem 1.5rem; overscroll-behavior: contain; font-size: 1.07rem; }
.sheet .body p { margin: 0 0 .8rem; }
.sheet .big-han { font: 400 4.2rem/1.1 var(--brush); float: right; margin: 0 0 .4rem 1rem; }
.sheet dl { margin: .6rem 0; }
.sheet dt { font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); margin-top: .9rem; }
.sheet dd { margin: .15rem 0 0; }
.sheet .zh-quote { font-family: var(--han); font-size: 1.15rem; }
.sheet .links { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; clear: both; }
.sheet .links a { font-size: .9rem; color: var(--ink-2); border: 1px solid var(--rule); border-radius: 999px; padding: .35rem .8rem; text-decoration: none; }
.sheet .src { font-size: .85rem; color: var(--ink-3); }
/* The thing tapped is already the open sheet: blink the title and say so. */
.sheet .here-hint { margin: .4rem 1rem 0; font-size: .9rem; color: var(--seal); }
.sheet h2.pulse { animation: here-pulse .9s ease 2; }
@keyframes here-pulse { 50% { color: var(--seal); background: var(--wash); } }

/* Toast and update banner */
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 30; background: var(--ink); color: var(--paper); padding: .7rem 1.1rem; border-radius: 999px; font-size: .95rem; box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: calc(100vw - 2rem); }
#toast button { background: none; border: 0; color: var(--seal); font-weight: 600; margin-left: .6rem; min-height: 36px; cursor: pointer; }
#toast.warn { background: var(--seal); color: var(--seal-ink); }
#update { position: fixed; top: calc(.6rem + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 31; background: var(--ink); color: var(--paper); padding: .5rem .6rem .5rem 1rem; border-radius: 999px; font-size: .95rem; }
#update button { background: var(--seal); color: var(--seal-ink); border: 0; border-radius: 999px; padding: .3rem .8rem; margin-left: .4rem; cursor: pointer; }
.pending { padding: 1rem; background: var(--paper-2); border-radius: 6px; color: var(--ink-2); font-size: 1rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
