/* ── Jengo Dictionary — scoped under #dict-overlay ──────────────────
   The screen is a full-viewport overlay launched from the Config tab.
   All rules live under #dict-overlay so generic class names (.card,
   .zone, .app-header…) won't collide with the rest of the app.
   Uses existing CSS vars from style.css; adds dictionary-only tint
   stops locally. */

#dict-overlay {
  position: fixed;
  inset: 0;
  z-index: 1001;
  background: #fff;
  display: none;
  overscroll-behavior: none;
  /* Local-only tint stops — derived from --brand so they auto-track theme */
  --brand-tint-strong: color-mix(in oklab, var(--brand) 18%, white);
  --brand-tint-faint: color-mix(in oklab, var(--brand) 4%, white);
  --orange-tint: #fdf4e6;
  --jp-font: var(--paragraph-font-family);
  --ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  --dict-header-h: 50px;
  color: var(--color-text-primary);
  font-family: var(--ui-font);
}
#dict-overlay.open {
  display: block;
}

/* Word-detail styles are shared with the reader, which mounts DetailContent into
   a .wd-scope container outside #dict-overlay. Replicate the local var stops the
   detail subtree consumes so it renders identically there. */
.wd-scope {
  --brand-tint-strong: color-mix(in oklab, var(--brand) 18%, white);
  --brand-tint-faint: color-mix(in oklab, var(--brand) 4%, white);
  --orange-tint: #fdf4e6;
  --jp-font: var(--paragraph-font-family);
  --ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--color-text-primary);
  font-family: var(--ui-font);
}

/* Reset global button margins/padding that bleed into the overlay */
:is(#dict-overlay, .wd-scope) button { margin: 0; }

/* Root react mount fills the overlay */
:is(#dict-overlay, .wd-scope) #dict-mount {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

/* App shell inside the overlay */
:is(#dict-overlay, .wd-scope) .dict-app {
  position: relative;
  width: 100%;
  /* Fill the whole overlay (full screen). The soft keyboard simply overlays the
     bottom of this white surface — so there's never a white gap between content
     and keyboard. The results list is padded by --dict-kbd (set in JS) so its
     last rows still scroll clear of the keyboard. */
  height: 100%;
  background: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Top brand header */
:is(#dict-overlay, .wd-scope) .dict-header {
  height: calc(var(--dict-header-h) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  padding-left: 1rem;
  padding-right: 1rem;
  gap: 0.75rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
  overflow: hidden;
  transition: height 0.22s ease, padding 0.22s ease;
}
/* Reclaim the header while the search field is focused on mobile — it's pure
   chrome there (Back is restored on blur; the input's own clear-X resets). */
@media (max-width: 767px) {
  :is(#dict-overlay, .wd-scope) .dict-app.kbd-open .dict-header {
    height: 0;
    padding-top: 0;
    box-shadow: none;
  }
}
:is(#dict-overlay, .wd-scope) .dict-header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  flex: 1;
}
:is(#dict-overlay, .wd-scope) .dict-header .icon-btn {
  background: none;
  border: none;
  color: #fff;
  padding: 0.3rem;
  margin: 0;
  cursor: pointer;
  opacity: 0.95;
  display: inline-flex;
  align-items: center;
}
:is(#dict-overlay, .wd-scope) .dict-header .icon-btn svg { width: 20px; height: 20px; }

/* Scrollable content body */
:is(#dict-overlay, .wd-scope) .dict-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}
:is(#dict-overlay, .wd-scope) .dict-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  /* Contain overscroll so the page underneath the fixed overlay doesn't
     rubberband on iOS/macOS when the user scrolls past either edge. */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
/* While the keyboard is up, reserve its height at the bottom of the list so the
   last results can scroll above it (the app shell itself stays full-height, so
   no white gap shows between content and keyboard). --dict-kbd is set in JS. */
:is(#dict-overlay, .wd-scope) .dict-app.kbd-open .dict-scroll {
  padding-bottom: var(--dict-kbd, 0px);
}

/* Desktop two-column layout */
:is(#dict-overlay, .wd-scope) .dict-layout {
  display: flex;
  align-items: flex-start;
  gap: 1.25rem;
  max-width: 1180px;
  margin: 0 auto;
  width: 100%;
}
:is(#dict-overlay, .wd-scope) .dict-layout-main { flex: 1; min-width: 0; }
:is(#dict-overlay, .wd-scope) .dict-layout-side {
  width: 380px;
  flex-shrink: 0;
  position: sticky;
  top: 0.75rem;
  padding-right: 1rem;
  padding-top: 0.75rem;
}
@media (max-width: 900px) {
  :is(#dict-overlay, .wd-scope) .dict-layout-side { display: none; }
}

/* ── Search region ──
   Sits above .dict-scroll as a flex-shrink-0 sibling so it is never inside
   the scrollable container. This prevents iOS rubber-band bounce from pulling
   the bar down when the user overscrolls past the top. */
:is(#dict-overlay, .wd-scope) .search-region {
  flex-shrink: 0;
  /* Brand green so the bar's backdrop flows out of the header above it — the
     input itself stays white. The green→white edge is its own divider, so no
     bottom border is needed. */
  background: var(--brand);
  padding: 0.75rem 1rem;
  /* Match the header's collapse/expand timing. On blur the header animates its
     height back in (0.22s) while this bar hands back the safe-area inset it
     borrowed while the header was collapsed; transitioning padding over the
     same curve keeps the two in lockstep so the bar slides down smoothly
     instead of snapping up first. */
  transition: padding-top 0.22s ease;
}
@media (max-width: 767px) {
  /* Tighter on phones — the keyboard already eats the screen, so don't spend
     pixels on padding around the field. */
  :is(#dict-overlay, .wd-scope) .search-region { padding: 0.5rem 0.75rem; }
  /* When the field is focused the brand header (which carried the notch inset)
     collapses to 0, so the search bar inherits the safe-area top itself. */
  :is(#dict-overlay, .wd-scope) .dict-app.kbd-open .search-region {
    padding-top: calc(0.5rem + env(safe-area-inset-top, 0px));
  }
}
:is(#dict-overlay, .wd-scope) .search-shell { max-width: 760px; margin: 0 auto; }
:is(#dict-overlay, .wd-scope) .search-input-wrap { position: relative; display: flex; align-items: center; }
:is(#dict-overlay, .wd-scope) .search-input-wrap .lead {
  position: absolute; left: 0.7rem; width: 18px; height: 18px;
  color: var(--color-text-muted); pointer-events: none;
}
:is(#dict-overlay, .wd-scope) .search-input-wrap .clear {
  position: absolute; right: 1px;
  top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px;
  border: none; background: transparent;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
  color: #888;
}
:is(#dict-overlay, .wd-scope) .search-input-wrap .clear::after {
  content: '';
  position: absolute;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #ebebeb;
  transition: background 0.12s, transform 0.1s;
}
:is(#dict-overlay, .wd-scope) .search-input-wrap .clear:hover::after {
  background: #ddd;
}
:is(#dict-overlay, .wd-scope) .search-input-wrap .clear:active::after {
  transform: scale(0.84);
  background: color-mix(in oklab, var(--brand) 18%, #ddd);
}
:is(#dict-overlay, .wd-scope) .search-input-wrap:focus-within .clear::after {
  background: color-mix(in oklab, var(--brand) 10%, #ebebeb);
}
:is(#dict-overlay, .wd-scope) .search-input-wrap:focus-within .clear:hover::after {
  background: color-mix(in oklab, var(--brand) 20%, #ddd);
}
:is(#dict-overlay, .wd-scope) .search-input-wrap .clear svg {
  width: 13px; height: 13px;
  position: relative; z-index: 1;
  transition: transform 0.15s, color 0.12s;
}
:is(#dict-overlay, .wd-scope) .search-input-wrap .clear:hover svg {
  transform: rotate(90deg);
  color: #555;
}

/* Paste & search — occupies the same right-edge slot as .clear, but only
   renders when the field is empty, so the two never coexist. */
:is(#dict-overlay, .wd-scope) .search-input-wrap .paste-search {
  position: absolute; right: 1px;
  top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px;
  border: none; background: transparent;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
  color: #888;
}
:is(#dict-overlay, .wd-scope) .search-input-wrap .paste-search::after {
  content: '';
  position: absolute;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #ebebeb;
  transition: background 0.12s, transform 0.1s;
}
:is(#dict-overlay, .wd-scope) .search-input-wrap .paste-search:hover::after { background: #ddd; }
:is(#dict-overlay, .wd-scope) .search-input-wrap .paste-search:active::after {
  transform: scale(0.84);
  background: color-mix(in oklab, var(--brand) 18%, #ddd);
}
:is(#dict-overlay, .wd-scope) .search-input-wrap:focus-within .paste-search::after {
  background: color-mix(in oklab, var(--brand) 10%, #ebebeb);
}
:is(#dict-overlay, .wd-scope) .search-input-wrap .paste-search svg {
  width: 16px; height: 16px;
  position: relative; z-index: 1;
  transition: transform 0.12s, color 0.12s;
}
:is(#dict-overlay, .wd-scope) .search-input-wrap .paste-search:hover svg { color: var(--brand); }
:is(#dict-overlay, .wd-scope) .search-input-wrap .paste-search:active svg { transform: scale(0.9); }
:is(#dict-overlay, .wd-scope) .search-input {
  width: 100%;
  border: 1px solid #d6d6d6;
  border-radius: 10px;
  padding: 0.7rem 3rem 0.7rem 2.4rem;
  font-size: 1.05rem;
  font-family: var(--jp-font);
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
:is(#dict-overlay, .wd-scope) .search-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--brand) 16%, transparent);
}

/* Loading spinner that sits in the clear-button slot inside the input.
   Same dimensions as the .clear button so the input never reflows. */
:is(#dict-overlay, .wd-scope) .search-spinner {
  position: absolute; right: 15px;
  width: 16px; height: 16px;
  border: 2px solid var(--color-border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: dict-spin 0.7s linear infinite;
}
@keyframes dict-spin { to { transform: rotate(360deg); } }
/* Inline error notice — only rendered when present, so it costs no space otherwise. */
:is(#dict-overlay, .wd-scope) .search-error {
  margin: 0 0 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: color-mix(in oklab, var(--color-danger) 8%, white);
  border: 1px solid color-mix(in oklab, var(--color-danger) 25%, var(--color-border));
  color: var(--color-danger);
  font-size: 0.82rem;
}

/* ── Results region ── */
:is(#dict-overlay, .wd-scope) .results-region { padding: 0.85rem 1rem 6rem; }
@media (max-width: 767px) {
  :is(#dict-overlay, .wd-scope) .results-region { padding: 0.5rem 0.75rem 4rem; }
}
:is(#dict-overlay, .wd-scope) .results-shell { max-width: 760px; margin: 0 auto; }

:is(#dict-overlay, .wd-scope) .zone {
  border-radius: 12px;
  overflow: hidden;
  margin: 0 0 0.4rem;
  border: 1px solid transparent;
  background: #fff;
}
:is(#dict-overlay, .wd-scope) .zone:first-child { margin-top: 0.25rem; }

:is(#dict-overlay, .wd-scope) .zone-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.45rem 0.85rem;
  border-bottom: 1px solid transparent;
}
:is(#dict-overlay, .wd-scope) .zone-header .zone-label {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
}
:is(#dict-overlay, .wd-scope) .zone-header .zone-count {
  font-size: 0.7rem; font-weight: 600; font-variant-numeric: tabular-nums; opacity: 0.65;
}
:is(#dict-overlay, .wd-scope) .zone-header-right {
  display: flex; align-items: center; gap: 0.5rem;
}
:is(#dict-overlay, .wd-scope) .zone-select-toggle {
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.04em;
  color: var(--brand); background: none; border: none;
  cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 2px;
  font-family: inherit;
}

:is(#dict-overlay, .wd-scope) .zone.zone-neutral { border-color: #d4d4d4; }
:is(#dict-overlay, .wd-scope) .zone-header.zone-neutral {
  background: #ececec; color: #555; border-bottom-color: #d4d4d4;
}
:is(#dict-overlay, .wd-scope) .zone.zone-brand { border-color: color-mix(in oklab, var(--brand) 30%, #d8d8d8); }
:is(#dict-overlay, .wd-scope) .zone-header.zone-brand {
  background: color-mix(in oklab, var(--brand) 14%, white);
  color: var(--brand);
  border-bottom-color: color-mix(in oklab, var(--brand) 30%, #d8d8d8);
}
:is(#dict-overlay, .wd-scope) .zone.zone-warn { border-color: color-mix(in oklab, var(--orange) 32%, #d8d8d8); }
:is(#dict-overlay, .wd-scope) .zone-header.zone-warn {
  background: color-mix(in oklab, var(--orange) 16%, white);
  color: var(--orange);
  border-bottom-color: color-mix(in oklab, var(--orange) 32%, #d8d8d8);
}

:is(#dict-overlay, .wd-scope) .zone-body { display: flex; flex-direction: column; }
:is(#dict-overlay, .wd-scope) .zone-body .card {
  border-radius: 0;
  border: none;
  border-top: 1px solid color-mix(in srgb, currentColor 8%, transparent);
  margin: 0;
  background: #fff;
  transform: none !important;
  box-shadow: none !important;
}
:is(#dict-overlay, .wd-scope) .zone-body .card:first-child { border-top: none; }
:is(#dict-overlay, .wd-scope) .zone-body .card:hover {
  background: color-mix(in oklab, var(--brand) 4%, #fafafa);
}
/* Selected card: inset shadow so it can't be clipped by .zone's overflow. */
:is(#dict-overlay, .wd-scope) .zone-body .card.is-active {
  box-shadow: inset 0 0 0 2px var(--brand);
  position: relative;
  z-index: 1;
}

/* Tinted dictionary cards by tier */
:is(#dict-overlay, .wd-scope) .zone-brand .zone-body .card.result.tier-exact {
  background: color-mix(in oklab, var(--brand) 16%, white);
  border-top-color: color-mix(in oklab, var(--brand) 25%, white);
}
:is(#dict-overlay, .wd-scope) .zone-brand .zone-body .card.result.tier-exact + .card {
  border-top-color: color-mix(in oklab, var(--brand) 18%, white);
}
:is(#dict-overlay, .wd-scope) .zone-brand .zone-body .card.result.tier-strong {
  background: color-mix(in oklab, var(--brand) 8%, white);
}
:is(#dict-overlay, .wd-scope) .zone-brand .zone-body .card.result.tier-weak {
  background: color-mix(in oklab, var(--brand) 3%, white);
}
:is(#dict-overlay, .wd-scope) .zone-warn .zone-body .card.didyou {
  background: color-mix(in oklab, var(--orange) 10%, white);
  border-top-color: color-mix(in oklab, var(--orange) 20%, white);
}

/* Neutral zone — suggest grid attaches under header. Transparent container
   background; tiles use border-top as row dividers (matches prototype). */
:is(#dict-overlay, .wd-scope) .zone-neutral .suggest-grid {
  border: none; border-radius: 0;
  background: transparent;
  gap: 0;
  max-height: 9rem;
}
:is(#dict-overlay, .wd-scope) .zone-neutral .suggest-tile {
  background: #ececec;
  border-top: 1px solid #d4d4d4;
}
:is(#dict-overlay, .wd-scope) .zone-neutral .suggest-tile:hover { background: #dfe6e1; }

/* Splice word cards — div container with inner nav + check buttons */
:is(#dict-overlay, .wd-scope) .splice-word-card { gap: 0; padding: 0; }
:is(#dict-overlay, .wd-scope) .splice-word-card.is-unselected { opacity: 0.45; }
:is(#dict-overlay, .wd-scope) .card-nav {
  flex: 1; min-width: 0;
  display: flex; align-items: stretch; gap: 0.85rem;
  padding: 0.75rem 0.9rem;
  background: none; border: none;
  text-align: left; font: inherit; color: inherit;
  cursor: pointer;
}
:is(#dict-overlay, .wd-scope) .card-check {
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; width: 3rem;
  background: none; border: none; cursor: pointer;
  color: var(--brand);
  border-left: 1px solid color-mix(in srgb, currentColor 8%, transparent);
}
:is(#dict-overlay, .wd-scope) .card-check:hover { background: color-mix(in oklab, var(--brand) 5%, transparent); }

/* Generic card shape */
:is(#dict-overlay, .wd-scope) .card {
  display: flex;
  align-items: stretch;
  gap: 0.85rem;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--color-border);
  background: #fafafa;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  width: 100%;
  transition: background 0.12s;
}
:is(#dict-overlay, .wd-scope) .card-body {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 0.1rem;
}
:is(#dict-overlay, .wd-scope) .card-reading {
  font-family: var(--jp-font);
  font-size: 0.78rem;
  color: var(--color-text-secondary);
  letter-spacing: 0.02em;
  line-height: 1.2;
}
:is(#dict-overlay, .wd-scope) .card-headword {
  font-family: var(--jp-font);
  font-size: 1.45rem;
  font-weight: 700;
  color: #111;
  line-height: 1.2;
  letter-spacing: 0.005em;
}
:is(#dict-overlay, .wd-scope) .card-altform {
  font-size: 0.74rem;
  color: var(--color-text-secondary);
  margin-top: 0.12rem;
}
:is(#dict-overlay, .wd-scope) .card-altform-canon {
  font-family: var(--jp-font); font-weight: 700; color: var(--color-text-primary);
}
:is(#dict-overlay, .wd-scope) .card-def {
  font-size: 0.86rem;
  color: var(--color-text-secondary);
  line-height: 1.4;
  margin-top: 0.18rem;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}
:is(#dict-overlay, .wd-scope) .card-meta {
  display: flex; align-items: center; gap: 0.35rem;
  margin-top: 0.3rem; flex-wrap: wrap;
}
:is(#dict-overlay, .wd-scope) .pos-chip {
  font-size: 0.66rem; color: #666;
  text-transform: uppercase; letter-spacing: 0.05em;
  background: #efefef; border-radius: 3px;
  padding: 1px 5px; font-weight: 600;
}
:is(#dict-overlay, .wd-scope) .tag-common {
  font-size: 0.66rem; font-weight: 700;
  color: #2e7d32; background: #e8f5e9;
  border: 1px solid #c8e6c9; border-radius: 3px;
  padding: 1px 5px; letter-spacing: 0.04em;
}
:is(#dict-overlay, .wd-scope) .tag-jlpt {
  font-size: 0.66rem; font-weight: 700;
  color: #fff; background: #555;
  border-radius: 3px; padding: 1px 5px;
  letter-spacing: 0.04em;
}
:is(#dict-overlay, .wd-scope) .exact-tag {
  display: inline-flex; align-items: center; gap: 0.2rem;
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.08em;
  color: var(--brand); text-transform: uppercase;
  background: #fff;
  border: 1px solid color-mix(in oklab, var(--brand) 45%, white);
  border-radius: 3px; padding: 1px 5px;
}
:is(#dict-overlay, .wd-scope) .card-trail {
  display: flex; align-items: center; flex-shrink: 0;
  color: var(--color-text-muted);
}
:is(#dict-overlay, .wd-scope) .card-trail svg { width: 16px; height: 16px; }

/* Suggest grid — flexbox with grow so the partial last row stretches its
   items to fill the full container width. The 1px gaps reveal the gray
   container background as clean dividers. */
:is(#dict-overlay, .wd-scope) .suggest-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  background: #d4d4d4;
  border: 1px solid #d4d4d4;
  border-radius: 10px;
  overflow: hidden;
  max-height: 9rem;
}
:is(#dict-overlay, .wd-scope) .suggest-tile {
  flex: 1 1 6rem;          /* grow and shrink, basis 6rem */
  min-width: 6rem;
  display: flex; flex-direction: column; align-items: center; gap: 0.1rem;
  padding: 0.45rem 0.7rem 0.55rem;
  background: #ececec; border: none;
  cursor: pointer; text-align: center;
  font: inherit; color: inherit;
  transition: background 0.12s;
}
:is(#dict-overlay, .wd-scope) .suggest-tile:hover { background: #dfe6e1; }
:is(#dict-overlay, .wd-scope) .suggest-reading {
  font-family: var(--jp-font); font-size: 0.72rem; color: #666;
  letter-spacing: 0.01em; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 100%;
}
:is(#dict-overlay, .wd-scope) .suggest-headword {
  font-family: var(--jp-font); font-size: 1.2rem; font-weight: 700;
  color: #1a1a1a; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 100%;
}
:is(#dict-overlay, .wd-scope) .suggest-gloss {
  font-size: 0.72rem; color: #555; line-height: 1.3;
  margin-top: 0.1rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 100%;
}

/* Match highlight inside headwords */
:is(#dict-overlay, .wd-scope) .match-hl {
  background: color-mix(in oklab, var(--brand) 20%, transparent);
  border-radius: 3px; padding: 0 1px;
  box-shadow: 0 1px 0 color-mix(in oklab, var(--brand) 30%, transparent) inset;
}
:is(#dict-overlay, .wd-scope) .card.didyou .match-hl {
  background: color-mix(in oklab, var(--orange) 20%, transparent);
}
:is(#dict-overlay, .wd-scope) .suggest-tile .match-hl {
  background: rgba(0, 0, 0, 0.08); color: #1a1a1a; box-shadow: none;
}

/* Did-you-mean "from → to" lead-in */
:is(#dict-overlay, .wd-scope) .card.didyou .corrected {
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.05em;
  color: var(--orange); text-transform: uppercase;
  margin-bottom: 0.15rem;
}

/* Custom word add buttons */
:is(#dict-overlay, .wd-scope) .custom-word-actions {
  margin-top: 1.4rem;
  display: flex; flex-direction: row; gap: 0.5rem;
}
:is(#dict-overlay, .wd-scope) .custom-word-actions .action-btn.custom-word-btn { flex: 1; }
:is(#dict-overlay, .wd-scope) .action-btn.custom-word-btn {
  width: 100%;
  background: #fff;
  border: 1.5px dashed color-mix(in oklab, var(--brand) 35%, #d0d0d0);
  color: var(--brand);
  border-radius: 12px;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.6rem 0.5rem;
}
:is(#dict-overlay, .wd-scope) .custom-btn-text {
  display: flex; flex-direction: column; align-items: center; gap: 0.05rem;
  min-width: 0; overflow: hidden;
}
:is(#dict-overlay, .wd-scope) .custom-btn-word {
  font-size: 0.95rem; font-weight: 700;
  font-family: var(--jp-font);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 100%;
}
:is(#dict-overlay, .wd-scope) .custom-btn-dest {
  font-size: 0.68rem; font-weight: 600; opacity: 0.8;
  white-space: nowrap;
}
:is(#dict-overlay, .wd-scope) .action-btn.custom-word-btn:hover {
  background: var(--brand-tint);
  border-style: solid;
  border-color: var(--brand);
}
:is(#dict-overlay, .wd-scope) .action-btn.custom-word-btn.is-added {
  background: var(--brand);
  border-style: solid;
  border-color: var(--brand);
  color: #fff;
}

/* Empty state */
:is(#dict-overlay, .wd-scope) .empty {
  padding: 4rem 1rem 5rem;
  text-align: center;
  color: var(--color-text-muted);
}
:is(#dict-overlay, .wd-scope) .empty .empty-icon {
  width: 44px; height: 44px;
  margin: 0 auto 0.85rem;
  color: #cfcfcf;
}
:is(#dict-overlay, .wd-scope) .empty h3 { margin: 0 0 0.3rem; font-size: 1rem; color: #555; font-weight: 600; }
:is(#dict-overlay, .wd-scope) .empty p { margin: 0; font-size: 0.88rem; max-width: 22rem; margin-inline: auto; }
/* Renamed from .hint-row/.hint to dict-* to avoid clashing with the
   global .hint pill used for tooltips in the rest of the app. */
:is(#dict-overlay, .wd-scope) .empty .dict-hint-row {
  margin-top: 1.4rem;
  display: flex; flex-direction: column; gap: 0.55rem;
  align-items: stretch;
  max-width: 22rem;
  margin-inline: auto;
  text-align: left;
}
:is(#dict-overlay, .wd-scope) .empty .dict-hint {
  display: flex; align-items: center; gap: 0.6rem;
  width: auto; height: auto;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border-light);
  border-radius: 8px;
  background: #fafafa;
  font-size: 0.82rem; color: #555;
  font-weight: 400;
  cursor: default;
}
:is(#dict-overlay, .wd-scope) .empty .dict-hint kbd {
  display: inline-flex; align-items: center;
  font-family: var(--jp-font); font-size: 0.85rem;
  padding: 0.05rem 0.45rem;
  background: #fff; border: 1px solid var(--color-border);
  border-radius: 5px; color: #333;
  flex-shrink: 0;
}
:is(#dict-overlay, .wd-scope) .empty .dict-hint kbd.dict-hint-icon {
  padding: 0.2rem; color: var(--brand);
}
:is(#dict-overlay, .wd-scope) .empty .dict-hint kbd.dict-hint-icon svg { width: 15px; height: 15px; }
@media (max-width: 767px) {
  /* Less top air on phones so recents/hints sit nearer the field. */
  :is(#dict-overlay, .wd-scope) .empty { padding: 1.75rem 1rem 4rem; }
}

/* Recent lookups — shown instead of the static hints once history exists. */
:is(#dict-overlay, .wd-scope) .empty .dict-recents {
  margin-top: 1.4rem;
  max-width: 24rem; margin-inline: auto;
  text-align: left;
}
:is(#dict-overlay, .wd-scope) .empty .dict-recents-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.5rem; padding: 0 0.15rem;
}
:is(#dict-overlay, .wd-scope) .empty .dict-recents-label {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--color-text-muted);
}
:is(#dict-overlay, .wd-scope) .empty .dict-recents-clear {
  font-size: 0.72rem; font-weight: 600; color: var(--brand);
  background: none; border: none; cursor: pointer;
  padding: 0.2rem 0.3rem; font-family: inherit;
}
:is(#dict-overlay, .wd-scope) .empty .dict-recents-list {
  display: flex; flex-direction: column; gap: 0.4rem;
}
:is(#dict-overlay, .wd-scope) .empty .dict-recent-chip {
  display: flex; align-items: baseline; gap: 0.5rem;
  width: 100%; text-align: left;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--color-border-light);
  border-radius: 8px; background: #fff;
  cursor: pointer; font-family: var(--ui-font);
  transition: background 0.12s, border-color 0.12s;
}
:is(#dict-overlay, .wd-scope) .empty .dict-recent-chip:hover {
  background: var(--brand-tint-faint);
  border-color: color-mix(in oklab, var(--brand) 25%, var(--color-border-light));
}
:is(#dict-overlay, .wd-scope) .empty .dict-recent-chip:active {
  transform: scale(0.99);
}
:is(#dict-overlay, .wd-scope) .empty .dict-recent-word {
  font-family: var(--jp-font); font-size: 0.95rem; font-weight: 600;
  color: var(--color-text-primary); flex-shrink: 0;
}
:is(#dict-overlay, .wd-scope) .empty .dict-recent-reading {
  font-family: var(--jp-font); font-size: 0.78rem;
  color: var(--color-text-muted); flex-shrink: 0;
}
:is(#dict-overlay, .wd-scope) .empty .dict-recent-def {
  font-size: 0.78rem; color: var(--color-text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
/* Sentence recents: full-width, one-line clamp, subtle left brand accent so they
   read as a distinct kind without splitting the list into separate groups. */
:is(#dict-overlay, .wd-scope) .empty .dict-recent-chip.is-sentence {
  border-left: 3px solid color-mix(in oklab, var(--brand) 45%, var(--color-border-light));
}
:is(#dict-overlay, .wd-scope) .empty .dict-recent-sentence {
  font-family: var(--jp-font); font-size: 0.9rem;
  color: var(--color-text-primary); min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ── Splice view (paste a sentence) ── */
:is(#dict-overlay, .wd-scope) .splice-banner {
  display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 0.4rem 0.75rem;
  background: var(--brand-tint);
  border: 1px solid color-mix(in oklab, var(--brand) 28%, white);
  border-radius: 999px;
  font-size: 0.8rem; color: var(--brand);
  margin-bottom: 0.75rem;
}
:is(#dict-overlay, .wd-scope) .splice-banner svg { width: 14px; height: 14px; }
:is(#dict-overlay, .wd-scope) .splice-sentence {
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 1rem 1.1rem 0.9rem;
  margin-bottom: 1.1rem;
}
:is(#dict-overlay, .wd-scope) .splice-jp {
  display: flex; flex-wrap: wrap; gap: 0.15rem 0.25rem;
  font-family: var(--jp-font);
  font-size: 1.45rem; line-height: 2.2;
  letter-spacing: 0.005em;
}
:is(#dict-overlay, .wd-scope) .splice-token {
  background: none; border: none;
  padding: 0.05rem 0.2rem; margin: 0;
  border-radius: 5px;
  cursor: pointer; font: inherit; color: #111;
  position: relative;
  transition: background 0.12s, color 0.12s;
}
:is(#dict-overlay, .wd-scope) .splice-token ruby rt {
  font-size: 0.5em; color: #888;
  font-weight: 400; line-height: 1;
  padding-bottom: 2px;
}
:is(#dict-overlay, .wd-scope) .splice-token:not(.is-particle):hover {
  background: color-mix(in oklab, var(--brand) 16%, white);
  color: var(--brand);
}
:is(#dict-overlay, .wd-scope) .splice-token:not(.is-particle):not(:disabled)::after {
  content: ""; position: absolute;
  left: 0.2rem; right: 0.2rem; bottom: 2px;
  height: 1.5px;
  background: color-mix(in oklab, var(--brand) 45%, white);
  border-radius: 1px; opacity: 0.5;
  transition: opacity 0.12s;
}
:is(#dict-overlay, .wd-scope) .splice-token:not(.is-particle):not(:disabled):hover::after { opacity: 1; }
:is(#dict-overlay, .wd-scope) .splice-token.is-particle { color: #bbb; cursor: default; }
:is(#dict-overlay, .wd-scope) .splice-token.is-particle ruby rt { color: transparent; }
:is(#dict-overlay, .wd-scope) .splice-token.is-active {
  background: var(--brand-tint); color: var(--brand);
}
:is(#dict-overlay, .wd-scope) .splice-translation {
  margin-top: 0.6rem;
  font-size: 0.88rem;
  color: var(--color-text-secondary);
  font-style: italic;
  line-height: 1.5;
  border-top: 1px solid var(--color-border-light);
  padding-top: 0.6rem;
}
:is(#dict-overlay, .wd-scope) .splice-bulk-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 0.85rem;
}
@media (max-width: 460px) {
  :is(#dict-overlay, .wd-scope) .splice-bulk-actions { grid-template-columns: 1fr; }
}
:is(#dict-overlay, .wd-scope) .splice-bulk-btn {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.7rem 0.85rem;
  width: 100%; border-radius: 10px;
  text-align: left;
}
:is(#dict-overlay, .wd-scope) .splice-bulk-text {
  display: flex; flex-direction: column; min-width: 0; flex: 1;
}
:is(#dict-overlay, .wd-scope) .splice-bulk-title { font-size: 0.9rem; font-weight: 700; }
:is(#dict-overlay, .wd-scope) .splice-bulk-sub {
  font-size: 0.72rem; opacity: 0.78;
  font-weight: 400; letter-spacing: 0;
  text-transform: none;
}
:is(#dict-overlay, .wd-scope) .conjugated-chip {
  font-family: var(--jp-font);
  font-size: 0.7rem;
  color: var(--color-text-secondary);
  background: rgba(0, 0, 0, 0.05);
  border-radius: 3px; padding: 1px 6px;
  font-weight: 500; letter-spacing: 0.02em;
}

/* ── Bottom sheet (mobile) / right panel (desktop) detail ── */
:is(#dict-overlay, .wd-scope) .detail-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.32);
  opacity: 0; pointer-events: none;
  transition: opacity 0.22s ease;
  z-index: 80;
}
:is(#dict-overlay, .wd-scope) .detail-backdrop.open { opacity: 1; pointer-events: auto; }
:is(#dict-overlay, .wd-scope) .detail-sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: #fff;
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.16);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  height: 76%;
  max-height: 86%;
  display: flex; flex-direction: column;
  z-index: 90;
}
:is(#dict-overlay, .wd-scope) .detail-sheet.open { transform: translateY(0); }
:is(#dict-overlay, .wd-scope) .detail-grabber {
  width: 36px; height: 4px;
  background: #d6d6d6;
  border-radius: 2px;
  margin: 0.55rem auto 0;
}

:is(#dict-overlay, .wd-scope) .detail-panel {
  position: relative; /* containing block for the uk-choice tap-away backdrop + add note */
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  overflow: hidden;
  display: flex; flex-direction: column;
  height: calc(100vh - var(--dict-header-h) - 5rem);
}
/* Wraps DetailContent so it can stay mounted (state preserved) but hide when
   the sentence explorer takes over. Mimics the panel/sheet flex column so the
   scroll region fills and the action bar pins exactly as before. */
:is(#dict-overlay, .wd-scope) .detail-host {
  display: flex; flex-direction: column; flex: 1; min-height: 0;
}
:is(#dict-overlay, .wd-scope) .detail-host[hidden] { display: none; }
:is(#dict-overlay, .wd-scope) .detail-panel-empty {
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.88rem;
}
:is(#dict-overlay, .wd-scope) .detail-panel-empty .empty-icon {
  width: 36px; height: 36px;
  margin: 0 auto 0.7rem; color: #d0d0d0;
}

:is(#dict-overlay, .wd-scope) .detail-scroll {
  overflow-y: auto;
  padding: 0.85rem 1.15rem 0;
  flex: 1;
}
:is(#dict-overlay, .wd-scope) .detail-panel .detail-scroll {
  padding: 1.1rem 1.2rem 0;
}

:is(#dict-overlay, .wd-scope) .detail-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 0.5rem;
}
:is(#dict-overlay, .wd-scope) .detail-head-text { flex: 1; min-width: 0; }
:is(#dict-overlay, .wd-scope) .detail-reading {
  font-family: var(--jp-font);
  font-size: 0.95rem;
  color: var(--color-text-secondary);
  margin-bottom: 0.1rem;
}
/* Pitch accent contour — drawn through the reading kana (no extra row).
   High morae carry a top line, low morae a bottom line, and a vertical connector
   bridges every pitch change, so the full low→high→low flow reads across the
   word. Muted blue (reference info — not amber=AI, not green=action). Multiple
   accents render as separated copies. */
:is(#dict-overlay, .wd-scope) {
  --pa-line: color-mix(in oklab, var(--color-accent-new) 50%, var(--color-text-muted));
}
:is(#dict-overlay, .wd-scope) .pa-reading { display: inline-block; margin-right: 0.7rem; }
:is(#dict-overlay, .wd-scope) .pa-reading:last-child { margin-right: 0; }
:is(#dict-overlay, .wd-scope) .pa-mora {
  display: inline-block;
  padding: 2px 0;
  border-top: 1.5px solid transparent;
  border-bottom: 1.5px solid transparent;
  box-sizing: border-box;
}
:is(#dict-overlay, .wd-scope) .pa-h { border-top-color: var(--pa-line); }
:is(#dict-overlay, .wd-scope) .pa-l { border-bottom-color: var(--pa-line); }
:is(#dict-overlay, .wd-scope) .pa-step { border-right: 1.5px solid var(--pa-line); }
/* Soften the elbows where the contour turns, so corners read as bends not pixels. */
:is(#dict-overlay, .wd-scope) .pa-rad-tr { border-top-right-radius: 2.5px; }
:is(#dict-overlay, .wd-scope) .pa-rad-br { border-bottom-right-radius: 2.5px; }
:is(#dict-overlay, .wd-scope) .pa-rad-tl { border-top-left-radius: 2.5px; }
:is(#dict-overlay, .wd-scope) .pa-rad-bl { border-bottom-left-radius: 2.5px; }
:is(#dict-overlay, .wd-scope) .detail-headword-row {
  display: flex; align-items: center; gap: 0.55rem; flex-wrap: wrap;
}
:is(#dict-overlay, .wd-scope) .detail-headword {
  font-family: var(--jp-font);
  font-size: 2.1rem; font-weight: 700;
  color: #111; line-height: 1.15;
  letter-spacing: 0.005em;
}
:is(#dict-overlay, .wd-scope) .audio-btn-inline {
  flex-shrink: 0; width: 2rem; height: 2rem;
  padding: 0; margin: 0; border-radius: 50%;
  background: var(--brand-tint);
  border: 1px solid color-mix(in oklab, var(--brand) 25%, white);
  color: var(--brand);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s, transform 0.15s, border-color 0.15s;
}
:is(#dict-overlay, .wd-scope) .audio-btn-inline:hover {
  background: color-mix(in oklab, var(--brand) 22%, white);
}
:is(#dict-overlay, .wd-scope) .audio-btn-inline:active { transform: scale(0.93); }
:is(#dict-overlay, .wd-scope) .audio-btn-inline svg { width: 0.95rem; height: 0.95rem; }
:is(#dict-overlay, .wd-scope) .audio-btn-inline.is-playing {
  background: var(--brand); color: #fff; border-color: var(--brand);
  animation: audio-pulse 0.9s ease-in-out infinite;
}
@keyframes audio-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--brand) 35%, transparent); }
  50%       { box-shadow: 0 0 0 6px color-mix(in oklab, var(--brand) 0%, transparent); }
}

:is(#dict-overlay, .wd-scope) .detail-kebab {
  background: none; border: none;
  color: #aaa; cursor: pointer;
  padding: 0.35rem; font-size: 1.2rem;
  border-radius: 6px;
  flex: none;
  line-height: 0;
}
:is(#dict-overlay, .wd-scope) .detail-kebab svg { width: 20px; height: 20px; display: block; }
:is(#dict-overlay, .wd-scope) .detail-kebab:hover { background: #f2f2f2; color: #555; }

:is(#dict-overlay, .wd-scope) .detail-tags {
  display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.55rem;
}
:is(#dict-overlay, .wd-scope) .detail-senses {
  list-style: decimal;
  margin: 0.85rem 0 1.1rem;
  padding-left: 1.2rem;
  font-size: 0.95rem;
  line-height: 1.65;
  color: #1f1f1f;
}
:is(#dict-overlay, .wd-scope) .detail-senses li { margin-bottom: 0.45rem; }
:is(#dict-overlay, .wd-scope) .sense-text { color: #1f1f1f; }

/* The definition itself is the generate trigger — tap a sense for AI examples.
   Kept visually identical to plain text so it never reads as a button heap;
   the affordance is a hover tint (desktop) + a sparkle that surfaces on
   hover/active. Discoverability on touch is taught in the empty-search hints. */
:is(#dict-overlay, .wd-scope) .sense-tap {
  display: block; width: 100%;
  margin: -0.1rem -0.4rem;
  padding: 0.1rem 0.4rem;
  background: none; border: none; border-radius: 8px;
  font: inherit; line-height: inherit; color: inherit;
  text-align: left; cursor: pointer;
  transition: background 0.12s;
}
:is(#dict-overlay, .wd-scope) .sense-tap:hover { background: var(--color-ai-tint); }
:is(#dict-overlay, .wd-scope) .sense-tap.is-active {
  background: color-mix(in oklab, var(--color-ai) 10%, white);
}
:is(#dict-overlay, .wd-scope) .sense-spark {
  display: inline-flex; vertical-align: -1px;
  margin-left: 0.3rem;
  color: var(--color-ai);
  opacity: 0; transition: opacity 0.12s;
}
:is(#dict-overlay, .wd-scope) .sense-spark svg { width: 12px; height: 12px; }
:is(#dict-overlay, .wd-scope) .sense-tap:hover .sense-spark,
:is(#dict-overlay, .wd-scope) .sense-tap.is-active .sense-spark { opacity: 1; }
@media (hover: none) {
  /* No hover on touch — keep the sparkle hidden until the sense is opened. */
  :is(#dict-overlay, .wd-scope) .sense-tap:hover { background: none; }
}
:is(#dict-overlay, .wd-scope) .sense-ex-loading {
  display: flex; align-items: center; gap: 0.35rem;
  padding: 0.4rem 0.1rem 0.2rem;
}
:is(#dict-overlay, .wd-scope) .sense-ex-list {
  display: flex; flex-direction: column; gap: 0.4rem;
  margin: 0.45rem 0 0.1rem;
}
:is(#dict-overlay, .wd-scope) .sense-ex-more {
  font-size: 0.72rem;
  color: var(--color-ai);
  opacity: 0.8;
  padding: 0.05rem 0.1rem;
}
:is(#dict-overlay, .wd-scope) .sense-ex-error {
  font-size: 0.78rem;
  color: var(--color-danger);
  padding: 0.4rem 0.1rem 0.2rem;
}
:is(#dict-overlay, .wd-scope) .sense-context {
  display: inline-flex; flex-wrap: wrap; gap: 0.25rem;
  margin-left: 0.45rem; vertical-align: 1px;
}
:is(#dict-overlay, .wd-scope) .sense-context-chip {
  display: inline-block;
  font-size: 0.66rem; font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: lowercase;
  font-style: italic;
  color: var(--color-text-secondary);
  background: #f0f0f0;
  border-radius: 3px; padding: 1px 6px;
  font-family: var(--ui-font);
}

/* See also xref row */
:is(#dict-overlay, .wd-scope) .detail-xrefs {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 0.35rem; margin-bottom: 1.1rem;
}
:is(#dict-overlay, .wd-scope) .detail-xrefs-label {
  font-size: 0.72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--color-text-secondary);
  margin-right: 0.1rem;
}
:is(#dict-overlay, .wd-scope) .xref-chip {
  font-size: 0.85rem;
  color: var(--brand);
  background: none;
  border: 1px solid var(--brand);
  border-radius: 4px;
  padding: 1px 8px;
  cursor: pointer;
  transition: background 0.1s;
}
:is(#dict-overlay, .wd-scope) .xref-chip:hover { background: color-mix(in srgb, var(--brand) 8%, transparent); }

/* Alternate kanji forms — tappable chips that swap the headword in place.
   The active form (canonical or chosen) reads as filled; the rest are quiet. */
:is(#dict-overlay, .wd-scope) .detail-forms {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 0.35rem; margin-bottom: 1.1rem;
}
:is(#dict-overlay, .wd-scope) .detail-forms-label {
  font-size: 0.72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--color-text-secondary);
  margin-right: 0.1rem;
}
:is(#dict-overlay, .wd-scope) .form-chip {
  display: inline-flex; align-items: baseline; gap: 0.3rem;
  font-family: var(--jp-font); font-size: 0.9rem;
  color: var(--color-text-secondary);
  background: none;
  border: 1px solid var(--color-border-light);
  border-radius: 4px;
  padding: 1px 8px;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}
:is(#dict-overlay, .wd-scope) .form-chip:hover {
  border-color: color-mix(in oklab, var(--brand) 35%, var(--color-border-light));
}
:is(#dict-overlay, .wd-scope) .form-chip.is-active {
  color: var(--brand); border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 8%, transparent);
}
:is(#dict-overlay, .wd-scope) .form-chip-tag {
  font-family: var(--ui-font); font-size: 0.65rem;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--color-text-muted);
}

/* Action row at bottom of detail */
:is(#dict-overlay, .wd-scope) .detail-actions {
  padding: 0.75rem 1.15rem calc(0.85rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--color-border-light);
  background: #fff;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
:is(#dict-overlay, .wd-scope) .detail-actions .full { grid-column: 1 / -1; }
:is(#dict-overlay, .wd-scope) .action-btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.4rem; padding: 0.7rem 0.85rem;
  border-radius: 10px;
  font-size: 0.9rem; font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
:is(#dict-overlay, .wd-scope) .action-btn svg { width: 16px; height: 16px; }
:is(#dict-overlay, .wd-scope) .action-btn.ghost {
  background: #fff; border: 1px solid #d6d6d6; color: #555;
}
:is(#dict-overlay, .wd-scope) .action-btn.ghost:hover { border-color: #999; color: #222; }
:is(#dict-overlay, .wd-scope) .action-btn.enc-add.is-added {
  background: var(--brand-tint);
  border-color: color-mix(in oklab, var(--brand) 30%, white);
  color: var(--brand);
  cursor: default;
}
:is(#dict-overlay, .wd-scope) .action-btn.toggle-add {
  background: var(--brand-tint);
  border: 1px solid color-mix(in oklab, var(--brand) 25%, white);
  color: var(--brand);
}
:is(#dict-overlay, .wd-scope) .action-btn.toggle-add:hover {
  background: color-mix(in oklab, var(--brand) 16%, white);
}
:is(#dict-overlay, .wd-scope) .action-btn.toggle-add.is-added {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
:is(#dict-overlay, .wd-scope) .action-btn.toggle-add.is-added:active { transform: scale(0.97); }
:is(#dict-overlay, .wd-scope) .action-btn.primary {
  background: var(--brand); border: 1px solid var(--brand); color: #fff;
}
:is(#dict-overlay, .wd-scope) .action-btn.primary:hover { opacity: 0.9; }

/* ── Reader variant: mark / flashcards / overflow row ─────────────── */
:is(#dict-overlay, .wd-scope) .reader-actions {
  grid-template-columns: 1fr auto;
}
/* Encounter variant: forgot-flag + flashcards, with a consequence caption. */
:is(#dict-overlay, .wd-scope) .enc-actions { grid-template-columns: 1fr 1fr; }
:is(#dict-overlay, .wd-scope) .enc-actions .reader-flash { grid-column: 1 / -1; }
:is(#dict-overlay, .wd-scope) .enc-action-note {
  margin: 0.15rem 0 0;
  font-size: 0.76rem;
  line-height: 1.45;
  color: var(--color-text-muted);
  text-align: center;
}
:is(#dict-overlay, .wd-scope) .reader-actions .reader-mark { grid-column: 1 / -1; }
:is(#dict-overlay, .wd-scope) .reader-actions .reader-flash { grid-column: 1; }
:is(#dict-overlay, .wd-scope) .action-btn.reader-mark.is-locked {
  opacity: 0.55;
  cursor: default;
}
:is(#dict-overlay, .wd-scope) .reader-more-wrap {
  grid-column: 2;
  position: relative;
  display: flex;
}
:is(#dict-overlay, .wd-scope) .reader-more-btn {
  padding: 0.7rem;
  aspect-ratio: 1;
}
:is(#dict-overlay, .wd-scope) .reader-more-btn.is-active {
  border-color: var(--brand);
  color: var(--brand);
}
:is(#dict-overlay, .wd-scope) .reader-more-menu {
  position: absolute;
  bottom: calc(100% + 0.4rem);
  right: 0;
  min-width: 13rem;
  background: #fff;
  border: 1px solid var(--color-border-light);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.14);
  padding: 0.3rem;
  z-index: 5;
  animation: readerMoreIn 0.14s ease both;
}
@keyframes readerMoreIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
:is(#dict-overlay, .wd-scope) .reader-more-item {
  display: flex; align-items: center; gap: 0.6rem;
  width: 100%;
  padding: 0.62rem 0.7rem;
  border: 0; background: transparent;
  border-radius: 8px;
  font-family: inherit; font-size: 0.88rem; font-weight: 600;
  color: var(--color-text-primary);
  cursor: pointer;
  text-align: left;
}
:is(#dict-overlay, .wd-scope) .reader-more-item svg { width: 17px; height: 17px; flex: none; color: var(--color-text-muted, #888); }
:is(#dict-overlay, .wd-scope) .reader-more-item:hover { background: var(--brand-tint-faint, #f4f4f4); }
:is(#dict-overlay, .wd-scope) .reader-more-item:disabled { opacity: 0.5; cursor: default; }
:is(#dict-overlay, .wd-scope) .reader-more-item.danger { color: #c0392b; }
:is(#dict-overlay, .wd-scope) .reader-more-item.danger svg { color: #c0392b; }
:is(#dict-overlay, .wd-scope) .reader-more-item.danger:hover { background: #fdecea; }
:is(#dict-overlay, .wd-scope) .reader-more-done {
  grid-column: 1 / -1;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.6rem;
  font-size: 0.85rem; font-weight: 600;
  color: var(--brand);
}
:is(#dict-overlay, .wd-scope) .reader-more-done svg { width: 16px; height: 16px; }

/* ── Crash fallback (error boundary) ───────────────────── */
:is(#dict-overlay, .wd-scope) .dict-crash {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.75rem; text-align: center;
  min-height: 60vh; padding: 2rem 1.5rem calc(2rem + env(safe-area-inset-bottom, 0px));
}
:is(#dict-overlay, .wd-scope) .dict-crash-title {
  font-size: 1.05rem; font-weight: 700; color: var(--color-text-primary);
}
:is(#dict-overlay, .wd-scope) .dict-crash-msg {
  font-size: 0.72rem; color: var(--color-text-secondary);
  max-width: 100%; max-height: 40vh; overflow: auto;
  line-height: 1.4; word-break: break-word; white-space: pre-wrap;
  text-align: left; margin: 0; padding: 0.6rem 0.75rem;
  background: var(--color-bg-subtle, #f5f5f5); border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
:is(#dict-overlay, .wd-scope) .dict-crash .action-btn { margin-top: 0.5rem; padding-inline: 1.5rem; }

/* ── Add-to-Flashcards deck picker ─────────────────────── */
:is(#dict-overlay, .wd-scope) .flash-picker {
  border-top: 1px solid var(--color-border-light);
  background: var(--brand-tint-faint, #fafafa);
  padding: 0.6rem 1.15rem 0.7rem;
  max-height: 40vh;
  overflow-y: auto;
  animation: flashPickerIn 0.18s ease both;
}
@keyframes flashPickerIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
:is(#dict-overlay, .wd-scope) .flash-picker-head {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--color-text-muted, #999);
  padding: 0.2rem 0 0.5rem;
}
:is(#dict-overlay, .wd-scope) .flash-picker-msg {
  font-size: 0.85rem;
  color: var(--color-text-muted, #999);
  padding: 0.5rem 0;
}
:is(#dict-overlay, .wd-scope) .flash-deck-list { display: flex; flex-direction: column; gap: 0.4rem; }
:is(#dict-overlay, .wd-scope) .flash-deck-opt {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--color-border, #e0e0e0);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--color-text-primary, #2c2c2c);
  text-align: left;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}
:is(#dict-overlay, .wd-scope) .flash-deck-opt:hover { background: var(--color-surface, #f5f5f5); }
:is(#dict-overlay, .wd-scope) .flash-deck-opt:disabled { opacity: 0.5; cursor: default; }
:is(#dict-overlay, .wd-scope) .flash-deck-opt.is-on {
  border-color: color-mix(in oklab, var(--brand) 45%, white);
  background: var(--brand-tint);
}
:is(#dict-overlay, .wd-scope) .flash-deck-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
:is(#dict-overlay, .wd-scope) .flash-dir {
  flex-shrink: 0;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--color-surface, #f5f5f5);
  color: var(--color-text-secondary, #6a6a6a);
  border: 1px solid var(--color-border, #e0e0e0);
}
:is(#dict-overlay, .wd-scope) .flash-dir.flash-dir-comprehension { color: #1f6a3e; background: #eaf5ee; border-color: #d2e6da; }
:is(#dict-overlay, .wd-scope) .flash-dir.flash-dir-production { color: #8e5400; background: #fbf3e3; border-color: #ecdfc1; }
:is(#dict-overlay, .wd-scope) .flash-deck-check {
  flex-shrink: 0;
  display: inline-flex;
  color: var(--brand);
}
:is(#dict-overlay, .wd-scope) .flash-deck-check svg { width: 18px; height: 18px; }
:is(#dict-overlay, .wd-scope) .flash-deck-status {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--brand);
  font-variant-numeric: tabular-nums;
}

/* ── Detail subsections (Examples, Kanji breakdown, AI tools) ── */
:is(#dict-overlay, .wd-scope) .detail-section {
  margin-top: 1.25rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--color-border-light);
}
:is(#dict-overlay, .wd-scope) .detail-section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.55rem;
}
:is(#dict-overlay, .wd-scope) .detail-section-label {
  font-size: 0.7rem; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--color-text-secondary);
}
:is(#dict-overlay, .wd-scope) .detail-section-count {
  font-size: 0.7rem; color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

/* .detail-kanji* rules live in the "Kanji breakdown" section further down —
   a duplicate copy of the whole block used to sit here and silently lose the
   cascade to it. */

/* AI tools section.
   No flex gap here — children that "merge" (button + its panel, pill + its
   examples list) need to touch flush. Spacing between independent items
   is handled by explicit margins below. */
:is(#dict-overlay, .wd-scope) .detail-section.ai-tools {
  display: flex; flex-direction: column; gap: 0.5rem;
}
:is(#dict-overlay, .wd-scope) .ai-tools-label {
  display: inline-flex; align-items: center; gap: 0.3rem;
  color: var(--color-ai);
  font-size: 0.7rem; font-weight: 700;
  letter-spacing: 0.1em; text-transform: uppercase;
}
:is(#dict-overlay, .wd-scope) .ai-tools-label svg { width: 12px; height: 12px; }

/* Segmented AI-tools row (design 1C — DIC-WORDCOMP): equal-width vertical
   icon+label buttons. Explain · Compare, plus In-context in reader/book. */
:is(#dict-overlay, .wd-scope) .ai-seg-row {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0.55rem;
}
:is(#dict-overlay, .wd-scope) .ai-seg-btn {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 0.4rem;
  padding: 0.8rem 0.5rem;
  background: var(--color-ai-tint);
  border: 1px solid color-mix(in oklab, var(--color-ai) 25%, white);
  border-radius: 13px;
  color: var(--color-ai);
  font: inherit; cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
:is(#dict-overlay, .wd-scope) .ai-seg-btn:hover {
  background: color-mix(in oklab, var(--color-ai) 14%, white);
  border-color: color-mix(in oklab, var(--color-ai) 45%, white);
}
:is(#dict-overlay, .wd-scope) .ai-seg-btn.is-active {
  background: var(--color-ai); color: #fff; border-color: var(--color-ai);
}
:is(#dict-overlay, .wd-scope) .ai-seg-btn svg { width: 19px; height: 19px; flex-shrink: 0; }
:is(#dict-overlay, .wd-scope) .ai-seg-label { font-size: 0.78rem; font-weight: 700; }
:is(#dict-overlay, .wd-scope) .ai-seg-compare {
  background: color-mix(in oklab, var(--color-ai) 12%, white);
  border-width: 1.5px;
  border-color: color-mix(in oklab, var(--color-ai) 45%, white);
}
:is(#dict-overlay, .wd-scope) .ai-seg-new {
  position: absolute; top: -6px; right: -4px;
  font-size: 8px; font-weight: 800; letter-spacing: 0.05em;
  color: #fff; background: var(--color-ai);
  padding: 1px 6px; border-radius: 20px;
}

/* AI explanation card overlay — floats over the entry like Compare's window
   instead of growing the definition inline. */
/* Full-screen overlay (mirrors Compare). Portalled to <body> under .wd-scope,
   so it's fixed to the viewport — never clipped by the detail sheet's transform.
   z 2100/2101: above every host that embeds DetailContent — #dict-overlay (1000),
   reader/book/flashcard (~1000), and the kanji-detail overlay (2000), whose entry
   screen also has an Explain button. The z-index lives on these fixed elements
   directly (the .wd-scope portal root is the same node, so it can't carry it). */
:is(#dict-overlay, .wd-scope) .ai-overlay-backdrop {
  position: fixed; inset: 0; z-index: 2100;
  background: rgba(0, 0, 0, 0.28);
  animation: dict-fade-in 0.2s ease both;
}
:is(#dict-overlay, .wd-scope) .ai-overlay-card {
  position: fixed; inset: 0; z-index: 2101;
  display: flex; flex-direction: column;
  background: var(--color-ai-tint);
  overflow: hidden;
  animation: dict-fade-in 0.18s ease both;
  padding-top: env(safe-area-inset-top, 0px);
}
:is(#dict-overlay, .wd-scope) .ai-overlay-head {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.7rem 0.6rem 0.65rem 1rem;
  border-bottom: 1px solid color-mix(in oklab, var(--color-ai) 14%, white);
  flex-shrink: 0;
}
:is(#dict-overlay, .wd-scope) .ai-overlay-word {
  font-family: var(--jp-font); font-weight: 700; flex: 1;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
:is(#dict-overlay, .wd-scope) .ai-overlay-body {
  flex: 1; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 0.9rem 1rem calc(1.2rem + env(safe-area-inset-bottom, 0px));
  font-size: 0.9rem; line-height: 1.6;
  color: #1f1f1f;
  /* Full-bleed surface, readable measure on wide screens. */
  width: 100%; max-width: 720px; margin: 0 auto;
}
:is(#dict-overlay, .wd-scope) .ai-explain-para { margin: 0 0 0.55rem; }
:is(#dict-overlay, .wd-scope) .ai-explain-para:last-child { margin-bottom: 0; }

/* Structured explanation: fixed-order labeled cards. Quiet white surfaces on the
   amber panel tint — the label carries the structure, not color or icons. */
:is(#dict-overlay, .wd-scope) .ai-card {
  background: var(--color-bg);
  border: 1px solid color-mix(in oklab, var(--color-ai) 14%, white);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  margin-bottom: 0.45rem;
}
:is(#dict-overlay, .wd-scope) .ai-card:last-child { margin-bottom: 0; }
:is(#dict-overlay, .wd-scope) .ai-card-label {
  display: flex; align-items: center; gap: 0.32rem;
  font-size: 0.66rem; font-weight: 700;
  letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--color-ai);
  margin-bottom: 0.25rem;
}
:is(#dict-overlay, .wd-scope) .ai-card-icon { display: inline-flex; color: var(--color-ai); }
:is(#dict-overlay, .wd-scope) .ai-card-icon svg { width: 13px; height: 13px; }
:is(#dict-overlay, .wd-scope) .ai-card-body { margin: 0; }
/* Pitfall is a caution, not a category — the icon carries the warning so the
   label stays in the uniform amber set. */
:is(#dict-overlay, .wd-scope) .ai-card-pitfall .ai-card-icon { color: var(--color-danger); }
:is(#dict-overlay, .wd-scope) .ai-related {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 0.3rem;
}
:is(#dict-overlay, .wd-scope) .ai-related-word {
  font-weight: 600; margin-right: 0.4rem;
}
:is(#dict-overlay, .wd-scope) .ai-related-diff { color: var(--color-text-secondary); }
/* Neutral surface so the example reads as a distinct quoted sentence — the
   amber tint here blended into the panel and looked like a rendering bug. */
:is(#dict-overlay, .wd-scope) .ai-card-example {
  background: var(--color-surface);
  border-color: var(--color-border-light);
}
:is(#dict-overlay, .wd-scope) .ai-example-jp {
  margin: 0; font-size: 1rem; line-height: 1.6; color: var(--color-text-primary);
}
:is(#dict-overlay, .wd-scope) .ai-example-en {
  margin: 0.15rem 0 0; color: var(--color-text-secondary);
}
:is(#dict-overlay, .wd-scope) .ai-loading {
  display: flex; align-items: center; gap: 0.35rem;
  padding: 0.45rem 0.7rem 0.7rem;
}
:is(#dict-overlay, .wd-scope) .ai-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: color-mix(in oklab, var(--orange) 60%, white);
  animation: ai-bounce 0.9s ease-in-out infinite;
}
:is(#dict-overlay, .wd-scope) .ai-dot:nth-child(2) { animation-delay: 0.12s; }
:is(#dict-overlay, .wd-scope) .ai-dot:nth-child(3) { animation-delay: 0.24s; }
:is(#dict-overlay, .wd-scope) .ai-loading-text {
  margin-left: 0.25rem;
  font-size: 0.78rem; color: var(--color-text-secondary);
  font-style: italic;
}
@keyframes ai-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%           { transform: translateY(-3px); opacity: 1; }
}

/* ── Example sentences (Tatoeba) ──────────────────────────────── */
:is(#dict-overlay, .wd-scope) .detail-section {
  margin-top: 1.25rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--color-border-light);
}
:is(#dict-overlay, .wd-scope) .detail-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.55rem;
}
:is(#dict-overlay, .wd-scope) .detail-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
}
:is(#dict-overlay, .wd-scope) .detail-section-count {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}
:is(#dict-overlay, .wd-scope) .detail-examples {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
:is(#dict-overlay, .wd-scope) .detail-example {
  background: #fafafa;
  border: 1px solid var(--color-border-light);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  transition: background 0.12s, border-color 0.12s;
  width: 100%;
}
:is(#dict-overlay, .wd-scope) .detail-example:hover {
  background: var(--brand-tint-faint, color-mix(in oklab, var(--brand) 6%, white));
  border-color: color-mix(in oklab, var(--brand) 25%, var(--color-border));
}
/* Loading placeholder: same box as a real example so examples don't pop in. */
:is(#dict-overlay, .wd-scope) .detail-example.is-skeleton {
  cursor: default;
  pointer-events: none;
  gap: 0.4rem;
}
:is(#dict-overlay, .wd-scope) .detail-example.is-skeleton:hover {
  background: #fafafa;
  border-color: var(--color-border-light);
}
:is(#dict-overlay, .wd-scope) .sk-line {
  height: 0.95rem;
  border-radius: 5px;
  background: color-mix(in oklab, var(--color-text-secondary) 16%, transparent);
  animation: dict-sk-pulse 1.2s ease-in-out infinite;
}
:is(#dict-overlay, .wd-scope) .sk-line.short { width: 55%; height: 0.78rem; }
@keyframes dict-sk-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.85; }
}
@media (prefers-reduced-motion: reduce) {
  :is(#dict-overlay, .wd-scope) .sk-line { animation: none; opacity: 0.55; }
}
:is(#dict-overlay, .wd-scope) .detail-example-jp {
  font-family: var(--jp-font);
  font-size: 1rem;
  color: #111;
  line-height: 1.5;
}
:is(#dict-overlay, .wd-scope) .detail-example-en {
  font-size: 0.82rem;
  color: var(--color-text-secondary);
  line-height: 1.4;
}
:is(#dict-overlay, .wd-scope) .detail-see-more {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  width: 100%;
  margin-top: 0.55rem;
  padding: 0.45rem;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--brand);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
}
:is(#dict-overlay, .wd-scope) .detail-see-more:hover { background: var(--brand-tint); }
:is(#dict-overlay, .wd-scope) .detail-see-more svg { width: 14px; height: 14px; transform: rotate(90deg); }

/* ── Sentence Explorer ─────────────────────────────────────────── */
:is(#dict-overlay, .wd-scope) .explorer-scroll {
  overflow-y: auto;
  padding: 0.65rem 1.15rem 0;
  flex: 1;
  min-height: 0;
}
:is(#dict-overlay, .wd-scope) .explorer-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0 0.7rem;
  border-bottom: 1px solid var(--color-border-light);
  margin-bottom: 0.85rem;
}
:is(#dict-overlay, .wd-scope) .explorer-back {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: none;
  border: none;
  padding: 0.25rem 0.4rem 0.25rem 0.2rem;
  font-size: 0.85rem;
  color: var(--brand);
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
}
:is(#dict-overlay, .wd-scope) .explorer-back:hover { background: var(--brand-tint); }
:is(#dict-overlay, .wd-scope) .explorer-back svg { width: 16px; height: 16px; }
:is(#dict-overlay, .wd-scope) .explorer-title {
  flex: 1;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  text-align: center;
}
:is(#dict-overlay, .wd-scope) .explorer-close {
  background: none;
  border: none;
  color: #aaa;
  cursor: pointer;
  padding: 0.35rem;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
:is(#dict-overlay, .wd-scope) .explorer-close:hover { color: #555; background: rgba(0,0,0,.05); }
:is(#dict-overlay, .wd-scope) .explorer-close svg { width: 16px; height: 16px; }
:is(#dict-overlay, .wd-scope) .explorer-sentence {
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 0.95rem 1rem 0.85rem;
  margin-bottom: 0.85rem;
}
:is(#dict-overlay, .wd-scope) .explorer-jp {
  font-size: 1.35rem;
  line-height: 2.1;
}
:is(#dict-overlay, .wd-scope) .explorer-loading {
  font-size: 0.88rem;
  color: var(--color-text-muted);
  padding: 0.5rem 0;
}
:is(#dict-overlay, .wd-scope) .explorer-hint {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.6rem 0.8rem;
  background: var(--brand-tint);
  border: 1px dashed color-mix(in oklab, var(--brand) 30%, white);
  border-radius: 10px;
  color: var(--brand);
  font-size: 0.82rem;
  line-height: 1.4;
  margin-bottom: 0.95rem;
}
:is(#dict-overlay, .wd-scope) .explorer-hint svg { flex-shrink: 0; width: 16px; height: 16px; }
:is(#dict-overlay, .wd-scope) .explorer-active-word {
  background: var(--brand-tint);
  border: 1px solid color-mix(in oklab, var(--brand) 28%, white);
  border-radius: 12px;
  padding: 0.85rem 1rem 0.9rem;
  margin-bottom: 0.95rem;
}
:is(#dict-overlay, .wd-scope) .explorer-active-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}
:is(#dict-overlay, .wd-scope) .explorer-active-text { flex: 1; min-width: 0; }
:is(#dict-overlay, .wd-scope) .explorer-active-headword {
  font-family: var(--jp-font);
  font-size: 1.55rem;
  font-weight: 700;
  color: #111;
  line-height: 1.2;
}
:is(#dict-overlay, .wd-scope) .explorer-active-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.45rem;
}
:is(#dict-overlay, .wd-scope) .explorer-active-senses {
  list-style: none;
  margin: 0.4rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
:is(#dict-overlay, .wd-scope) .explorer-active-senses li {
  font-size: 0.9rem;
  color: #1f1f1f;
  line-height: 1.5;
  counter-increment: sense;
  padding-left: 1.2rem;
  position: relative;
}
:is(#dict-overlay, .wd-scope) .explorer-active-senses li::before {
  content: counter(sense) ".";
  position: absolute; left: 0;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-weight: 600;
  top: 0.15rem;
}
:is(#dict-overlay, .wd-scope) .explorer-active-senses {
  counter-reset: sense;
}
:is(#dict-overlay, .wd-scope) .detail-back-sentence {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.4rem;
}
:is(#dict-overlay, .wd-scope) .detail-back-sentence svg { width: 15px; height: 15px; }
:is(#dict-overlay, .wd-scope) .explorer-active-form {
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  border-top: 1px solid color-mix(in oklab, var(--brand) 15%, white);
  font-size: 0.8rem;
  color: var(--color-text-secondary);
}
:is(#dict-overlay, .wd-scope) .explorer-active-form-jp {
  font-family: var(--jp-font);
  font-weight: 600;
  color: #333;
}
:is(#dict-overlay, .wd-scope) .explorer-add-word {
  margin-top: 0.65rem;
  width: 100%;
  display: inline-flex;
  align-items: center;
}
:is(#dict-overlay, .wd-scope) .explorer-add-word svg:last-child { margin-left: auto; opacity: 0.85; }
:is(#dict-overlay, .wd-scope) .explorer-back-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}
:is(#dict-overlay, .wd-scope) .explorer-back-action svg { width: 16px; height: 16px; }

/* ── Kanji breakdown ───────────────────────────────────────────── */
:is(#dict-overlay, .wd-scope) .detail-kanji-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
:is(#dict-overlay, .wd-scope) .detail-kanji {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  background: #fafafa;
  border: 1px solid var(--color-border-light);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  transition: background 0.12s, border-color 0.12s;
  width: 100%;
}
:is(#dict-overlay, .wd-scope) .detail-kanji:hover {
  background: var(--brand-tint-faint, color-mix(in oklab, var(--brand) 6%, white));
  border-color: color-mix(in oklab, var(--brand) 25%, var(--color-border));
}
:is(#dict-overlay, .wd-scope) .detail-kanji-char {
  font-family: var(--jp-font);
  font-size: 2.4rem;
  line-height: 1;
  font-weight: 500;
  color: #111;
  flex-shrink: 0;
  width: 2.5rem;
  text-align: center;
}
:is(#dict-overlay, .wd-scope) .detail-kanji-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
:is(#dict-overlay, .wd-scope) .detail-kanji-meanings {
  font-size: 0.9rem;
  font-weight: 600;
  color: #1a1a1a;
}
:is(#dict-overlay, .wd-scope) .detail-kanji-readings {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  font-size: 0.78rem;
  color: #444;
  font-family: var(--jp-font);
}
:is(#dict-overlay, .wd-scope) .detail-kanji-reading-row {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
}
/* Same colored 訓/音 chips as the kanji-detail modal (kd-kun/kd-on) so the
   reading labels read identically in both surfaces. */
:is(#dict-overlay, .wd-scope) .detail-kanji-reading-label {
  font-size: 0.6rem;
  font-weight: 700;
  white-space: nowrap;
  border-radius: 3px;
  padding: 1px 5px;
  line-height: 1.4;
  flex-shrink: 0;
}
:is(#dict-overlay, .wd-scope) .krl-kun { color: var(--reading-kun); border: 1px solid color-mix(in oklab, var(--reading-kun) 22%, transparent); }
:is(#dict-overlay, .wd-scope) .krl-on  { color: var(--reading-on); border: 1px solid color-mix(in oklab, var(--reading-on) 22%, transparent); }
:is(#dict-overlay, .wd-scope) .detail-kanji-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.2rem;
  font-size: 0.72rem;
  color: var(--color-text-secondary);
}
:is(#dict-overlay, .wd-scope) .detail-kanji svg {
  width: 16px;
  height: 16px;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

/* ── UK (usually written with kana) notice + add-time choice ──── */
:is(#dict-overlay, .wd-scope) .uk-notice {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.28rem 0.65rem;
  margin: 0.85rem 0 0.25rem;
  background: color-mix(in oklab, var(--orange) 8%, white);
  border: 1px solid color-mix(in oklab, var(--orange) 22%, white);
  border-radius: 6px;
  font-size: 0.75rem; font-weight: 600;
  color: var(--orange);
  letter-spacing: 0.01em;
}
/* Transparent tap-away layer behind the kanji/kana prompt. Covers the whole
   panel; the prompt itself paints above it (higher z-index) and stays tappable. */
:is(#dict-overlay, .wd-scope) .uk-choice-backdrop {
  position: absolute; inset: 0; z-index: 5; background: transparent;
}
:is(#dict-overlay, .wd-scope) .uk-choice {
  position: relative; z-index: 6;
  padding: 0.65rem 1.15rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid color-mix(in oklab, var(--orange) 20%, var(--color-border-light));
  background: color-mix(in oklab, var(--orange) 5%, white);
  animation: flashPickerIn 0.18s ease both;
}
:is(#dict-overlay, .wd-scope) .uk-choice-cancel {
  display: block; width: 100%; margin-top: 0.5rem;
  padding: 0.5rem; border: none; background: none;
  font-family: inherit; font-size: 0.8rem; font-weight: 600;
  color: var(--color-text-secondary); cursor: pointer;
}
:is(#dict-overlay, .wd-scope) .uk-choice-head {
  font-size: 0.82rem; font-weight: 600;
  color: var(--color-text-primary); margin-bottom: 0.18rem;
}
:is(#dict-overlay, .wd-scope) .uk-choice-sub {
  font-size: 0.72rem; color: var(--orange);
  font-weight: 600; margin-bottom: 0.6rem;
}
:is(#dict-overlay, .wd-scope) .uk-choice-btns {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem;
}
:is(#dict-overlay, .wd-scope) .uk-choice-btn {
  flex-direction: column; gap: 0.1rem;
}
:is(#dict-overlay, .wd-scope) .uk-choice-jp {
  font-family: var(--jp-font); font-size: 1rem; font-weight: 700;
}
:is(#dict-overlay, .wd-scope) .uk-choice-label {
  font-size: 0.65rem; font-family: var(--ui-font); opacity: 0.75; font-weight: 500;
}

/* "Added 淋しい to Deck" confirmation — floats at the top of the panel so it
   never covers the add button / deck picker the user is still interacting with. */
:is(#dict-overlay, .wd-scope) .dict-added-note {
  position: absolute; left: 0.75rem; right: 0.75rem; top: 0.75rem; z-index: 7;
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.55rem 0.8rem;
  border-radius: 10px;
  background: color-mix(in oklab, var(--brand) 12%, white);
  border: 1px solid color-mix(in oklab, var(--brand) 28%, transparent);
  color: var(--brand);
  font-size: 0.82rem; font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
  animation: flashPickerIn 0.18s ease both;
  pointer-events: none;
}
:is(#dict-overlay, .wd-scope) .dict-added-note svg { width: 15px; height: 15px; flex-shrink: 0; }
:is(#dict-overlay, .wd-scope) .dict-added-jp { font-family: var(--jp-font); font-weight: 700; }

/* ── Dictionary settings panel ───────────────────────────────── */
:is(#dict-overlay, .wd-scope) .dict-settings-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.28);
  z-index: 95;
  animation: dict-fade-in 0.2s ease both;
}
@keyframes dict-fade-in { from { opacity: 0; } to { opacity: 1; } }
:is(#dict-overlay, .wd-scope) .dict-settings-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: min(300px, 100%);
  background: #fff;
  border-left: 1px solid var(--color-border);
  display: flex; flex-direction: column;
  z-index: 96;
  transform: translateX(100%);
  transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.08);
}
:is(#dict-overlay, .wd-scope) .dict-settings-panel.open { transform: translateX(0); }
@media (max-width: 767px) {
  :is(#dict-overlay, .wd-scope) .dict-settings-panel {
    top: auto; left: 0; width: 100%;
    border-left: none;
    border-radius: 18px 18px 0 0;
    border-top: 1px solid var(--color-border);
    transform: translateY(100%);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.14);
    max-height: 60vh;
  }
  :is(#dict-overlay, .wd-scope) .dict-settings-panel.open { transform: translateY(0); }
}
:is(#dict-overlay, .wd-scope) .dict-settings-grabber {
  display: none;
  width: 36px; height: 4px;
  background: #d6d6d6; border-radius: 2px;
  margin: 0.55rem auto 0; flex-shrink: 0;
}
@media (max-width: 767px) {
  :is(#dict-overlay, .wd-scope) .dict-settings-grabber { display: block; }
}
:is(#dict-overlay, .wd-scope) .dict-settings-head {
  display: flex; align-items: center;
  padding: 0.8rem 0.85rem 0.8rem 1.15rem;
  border-bottom: 1px solid var(--color-border-light);
  flex-shrink: 0; gap: 0.5rem;
}
:is(#dict-overlay, .wd-scope) .dict-settings-title {
  flex: 1; font-size: 0.9rem; font-weight: 700;
  color: var(--color-text-primary); letter-spacing: 0.01em;
}
:is(#dict-overlay, .wd-scope) .dict-settings-body { flex: 1; overflow-y: auto; padding: 0.25rem 0 1rem; }
:is(#dict-overlay, .wd-scope) .dict-settings-group-label {
  font-size: 0.66rem; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--color-text-muted);
  padding: 0.95rem 1.15rem 0.35rem;
}
:is(#dict-overlay, .wd-scope) .dict-settings-group-label:first-child { padding-top: 0.55rem; }
:is(#dict-overlay, .wd-scope) .dict-settings-row-select { cursor: default; }
:is(#dict-overlay, .wd-scope) .dict-settings-select {
  flex-shrink: 0; max-width: 9.5rem;
  font-family: var(--ui-font); font-size: 0.82rem;
  color: var(--color-text-primary);
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 8px; padding: 0.4rem 0.5rem;
  cursor: pointer;
}
:is(#dict-overlay, .wd-scope) .dict-settings-select:focus { outline: none; border-color: var(--brand); }
:is(#dict-overlay, .wd-scope) .dict-settings-select:disabled { opacity: 0.6; cursor: not-allowed; }
:is(#dict-overlay, .wd-scope) .dict-settings-row {
  display: flex; align-items: center; gap: 0.85rem;
  padding: 0.9rem 1.15rem;
  cursor: pointer; transition: background 0.12s;
  border-bottom: 1px solid var(--color-border-light);
}
:is(#dict-overlay, .wd-scope) .dict-settings-row:last-child { border-bottom: none; }
:is(#dict-overlay, .wd-scope) .dict-settings-row:hover { background: var(--color-surface); }
:is(#dict-overlay, .wd-scope) .dict-settings-label {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 0.18rem;
}
:is(#dict-overlay, .wd-scope) .dict-settings-label-main {
  font-size: 0.9rem; font-weight: 600;
  color: var(--color-text-primary); line-height: 1.3;
}
:is(#dict-overlay, .wd-scope) .dict-settings-label-sub {
  font-size: 0.76rem; color: var(--color-text-muted); line-height: 1.35;
}
/* Scoped toggle switch */
:is(#dict-overlay, .wd-scope) .dict-toggle { position: relative; flex-shrink: 0; }
:is(#dict-overlay, .wd-scope) .dict-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
:is(#dict-overlay, .wd-scope) .dict-toggle-track {
  width: 34px; height: 20px; background: #ccc;
  border-radius: 10px; position: relative;
  transition: background 0.2s; cursor: pointer; display: block;
}
:is(#dict-overlay, .wd-scope) .dict-toggle input:checked + .dict-toggle-track { background: var(--brand); }
:is(#dict-overlay, .wd-scope) .dict-toggle-thumb {
  position: absolute; top: 3px; left: 3px;
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
:is(#dict-overlay, .wd-scope) .dict-toggle input:checked + .dict-toggle-track .dict-toggle-thumb {
  transform: translateX(14px);
}

/* ── Handwriting input dock ───────────────────────────────────────────
   Mobile-only ink panel docked above the soft keyboard. Bar-only while the
   keyboard is up; expands to a canvas + candidate strip when drawing.
   Colors via tokens; radii are literal to match the rest of this file. */
#dict-overlay .hw-dock {
  position: fixed;
  left: 0; right: 0;
  bottom: var(--dict-kbd, 0px);
  z-index: 20;
  /* Bar-only state (typing): a barely-there translucent strip (~8% surface) so
     it reads as a toolbar without covering the results behind it. Opaque only
     when the drawing canvas is open (.open) below. */
  background: color-mix(in oklab, var(--color-surface) 8%, transparent);
}
#dict-overlay .hw-dock.open {
  bottom: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
}

/* Candidate strip — top of the panel, under the thumb. Horizontal control row;
   scrollbar fully hidden (never visible on mobile). */
#dict-overlay .hw-candidates {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 54px;
  padding: 0.45rem 0.6rem;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border-light);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
#dict-overlay .hw-candidates::-webkit-scrollbar { display: none; }
#dict-overlay .hw-cand {
  flex: 0 0 auto;
  min-width: 46px; height: 46px;
  padding: 0 0.45rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-bg);
  color: var(--color-text-primary);
  font-family: var(--jp-font);
  font-size: 1.55rem;
  line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
#dict-overlay .hw-cand:active {
  background: var(--brand-tint-strong);
  border-color: var(--brand);
  transform: scale(0.94);
}
#dict-overlay .hw-cand-hint {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  padding-left: 0.2rem;
}

/* One-time ML Kit model download offer (native only) — slim strip between the
   candidate row and the canvas; KanjiVG keeps working while it's visible. */
#dict-overlay .hw-dl {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.6rem;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border-light);
}
#dict-overlay .hw-dl-btn {
  flex: 1 1 auto;
  height: 34px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--brand);
  font-family: var(--ui-font);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, transform 0.08s;
}
#dict-overlay .hw-dl-btn:active {
  background: var(--brand-tint-strong);
  transform: scale(0.98);
}
#dict-overlay .hw-dl-status {
  flex: 1 1 auto;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  padding-left: 0.2rem;
}
#dict-overlay .hw-dl .hw-tool { flex: 0 0 auto; }
#dict-overlay .hw-dl .hw-tool svg { width: 13px; height: 13px; }

/* Ink slate */
#dict-overlay .hw-canvas-wrap {
  position: relative;
  height: var(--hw-canvas-h, 260px);
}
#dict-overlay .hw-canvas {
  display: block;
  width: 100%; height: 100%;
  background: var(--color-bg);
  touch-action: none;
  /* A horizontal drag while drawing must not trigger iOS text selection. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
/* Undo pinned left, Clear pinned right; the strip between them stays
   pointer-transparent so it doesn't block drawing along the top of the canvas. */
#dict-overlay .hw-canvas-tools {
  position: absolute;
  top: 0.35rem; left: 0.45rem; right: 0.45rem;
  display: flex; justify-content: space-between;
  pointer-events: none;
}
/* Mirrors the search-box clear button: transparent hit target + a soft grey
   circle behind a small glyph. */
#dict-overlay .hw-tool {
  pointer-events: auto;
  position: relative;
  width: 40px; height: 40px;
  border: none; background: transparent;
  color: #888;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0; cursor: pointer;
}
#dict-overlay .hw-tool::after {
  content: '';
  position: absolute;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: #ebebeb;
  transition: background 0.12s, transform 0.1s;
}
#dict-overlay .hw-tool:hover::after { background: #ddd; }
#dict-overlay .hw-tool:active::after {
  transform: scale(0.84);
  background: color-mix(in oklab, var(--brand) 18%, #ddd);
}
#dict-overlay .hw-tool svg {
  width: 16px; height: 16px;
  position: relative; z-index: 1;
  transition: transform 0.15s, color 0.12s;
}
#dict-overlay .hw-clear svg { width: 13px; height: 13px; }
#dict-overlay .hw-clear:hover svg { transform: rotate(90deg); color: #555; }

/* Toolbar — input accessory above the keyboard / bottom of the panel */
#dict-overlay .hw-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 44px;
  padding: 0.25rem 0.6rem;
}
/* Caret nudge — grey pill split into ◁ | ▷, docked left of the bar. */
#dict-overlay .hw-caret-group {
  display: inline-flex;
  margin-right: auto;
  border-radius: 999px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}
#dict-overlay .hw-caret {
  width: 48px; height: 40px;
  border: none; padding: 0;
  background: #ebebeb;
  color: color-mix(in oklab, var(--brand) 60%, #666);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 0.12s;
}
#dict-overlay .hw-caret + .hw-caret { border-left: 1px solid #ddd; }
#dict-overlay .hw-caret:active { background: #ddd; }
#dict-overlay .hw-caret svg { width: 18px; height: 18px; }

#dict-overlay .hw-draw-toggle {
  display: inline-flex; align-items: center; gap: 0.4rem;
  height: 40px; padding: 0 0.95rem;
  border: 1.5px solid var(--brand);
  border-radius: 999px;
  background: var(--brand-tint-strong);
  color: var(--brand);
  font-family: var(--ui-font);
  font-size: 0.9rem; font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  transition: background 0.14s, transform 0.08s, color 0.14s;
}
#dict-overlay .hw-draw-toggle:active { transform: scale(0.96); }
#dict-overlay .hw-draw-toggle .hw-draw-kanji {
  font-family: var(--jp-font);
  font-size: 1.2rem; line-height: 1; font-weight: 600;
}
#dict-overlay .hw-draw-toggle .hw-draw-label { letter-spacing: 0.01em; }
/* In draw mode the button means "go back to the keyboard" — invert to a solid
   fill so its state reads as active. */
#dict-overlay .hw-draw-toggle.active {
  background: var(--brand);
  color: var(--color-bg);
}
#dict-overlay .hw-draw-toggle.active svg { width: 20px; height: 20px; }
