/* Dictionary owns only its presentation. No shared typography/layout overrides. */
[data-lookup-hint] {
  text-decoration: underline dotted var(--accent);
  text-underline-offset: .2em;
}
#dictionary-lookup-hint {
  position: fixed; z-index: 25; display: flex; align-items: center;
  box-sizing: border-box; width: max-content; max-width: min(21rem,calc(100vw - 16px));
  padding: 8px 13px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--muted); pointer-events: none;
  font: 400 13px/1.55 var(--ui-font,sans-serif); text-wrap: balance;
  opacity: 1; transform: translateY(0);
  transition: opacity 550ms ease-out, transform 550ms ease-out;
}
#dictionary-lookup-hint strong {
  color: var(--ink); font-weight: 650;
}
#dictionary-lookup-hint.is-fading {
  opacity: 0; transform: translateY(-4px);
}
#dictionary-lookup-hint::after {
  content: ''; position: absolute; left: var(--hint-tip); width: 7px; height: 7px;
  background: var(--surface); border: solid var(--line); border-width: 0 1px 1px 0;
}
#dictionary-lookup-hint[data-side="above"]::after { bottom: -5px; transform: translateX(-50%) rotate(45deg); }
#dictionary-lookup-hint[data-side="below"]::after { top: -5px; transform: translateX(-50%) rotate(225deg); }
@media (prefers-reduced-motion: reduce) {
  #dictionary-lookup-hint { transition: opacity 200ms linear; }
  #dictionary-lookup-hint.is-fading { transform: none; }
}
/* One quiet action for both hovered words and explicit selections. */
html #dictionary-hover, html #dictionary-selection {
  position:fixed; z-index:26; box-sizing:border-box; width:auto; min-width:0;
  min-height:28px; padding:4px 10px; margin:0; border:1px solid var(--line);
  border-radius:6px; background:var(--surface); color:var(--ink);
  box-shadow:0 2px 8px #00000012; font:500 13px/18px var(--ui-font,sans-serif);
  cursor:pointer; white-space:nowrap; transform:none; transition:none;
}
html #dictionary-hover[hidden], html #dictionary-selection[hidden] { display:none; }
html #dictionary-hover:hover, html #dictionary-selection:hover { background:var(--surface-muted); color:var(--ink); }
html #dictionary-hover:focus-visible, html #dictionary-selection:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }
@media (pointer:coarse) { html #dictionary-selection { min-height:44px; padding:8px 12px; } }
#dictionary-toggle, #dictionary-selection, #dictionary-panel { box-sizing: border-box; }
#dictionary-toggle {
  position: fixed; z-index: 24; right: 0; top: 42%; min-height: 70px;
  padding: 14px 8px; border: 1px solid var(--line); border-right: 0;
  border-radius: 8px 0 0 8px; background: var(--surface); color: var(--accent);
  font: 600 14px/1.5 var(--ui-font); writing-mode: vertical-rl;
  box-shadow: -2px 2px 10px #263a6010;
}
#dictionary-panel {
  position: fixed; z-index: 30; inset: 0 0 0 auto; width: 364px;
  max-width: 100%; height: 100dvh; padding: 24px 22px;
  overflow: clip;
  background: #fff; color: #1c2430; border-left: 1px solid #dde2ea;
  box-shadow: -8px 0 28px #263a6012; font: 16px/1.65 var(--ui-font);
  animation: dictionary-enter 160ms ease-out;
}
#dictionary-panel:not([hidden]) { display: flex; flex-direction: column; }
#dictionary-panel > * { flex-shrink: 0; }
#dictionary-panel #dictionary-body {
  flex: 1 1 0; min-height: 0; display: flex; flex-direction: column;
  overflow-y: auto; overscroll-behavior: contain;
}
#dictionary-body > * { flex-shrink: 0; }
#dictionary-panel .dictionary-search { z-index: 2; }
#dictionary-panel [lang="ja"] { font-family: "Noto Sans JP", "Hiragino Sans", "Yu Gothic", sans-serif; }
.dictionary-heading { position: sticky; top: -24px; z-index: 1; background: #fff; padding: 12px 0; display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
#dictionary-title { margin: 0; font-size: 22px; font-weight: 600; }
#dictionary-panel .dictionary-heading p { margin: 4px 0 0; color: #5b6574; font-size: 13px; }
#dictionary-panel button { box-shadow: none; border-radius: 8px; font: inherit; font-size: 14px; min-height: 40px; transition: background-color 120ms; }
#dictionary-close { width: 40px; padding: 0; border: 1px solid #dde2ea; background: #fff; color: #5b6574; font-size: 24px !important; flex-shrink: 0; }
#dictionary-form { display: flex; gap: 8px; }
#dictionary-query { width: 100%; min-width: 0; min-height: 42px; padding: 8px 10px; border: 1px solid #bac4d2; border-radius: 8px; color: #1c2430; background: #fff; font: inherit; font-size: 16px; }
#dictionary-form button { flex-shrink: 0; background: #e4ebf8; color: #2b4a8b; padding: 8px 12px; border: 1px solid transparent; }
#dictionary-panel button:not(.ios-sheet-grip):hover, #dictionary-toggle:hover, #dictionary-selection:hover { background: #e4ebf8; }
#dictionary-panel :focus-visible, #dictionary-toggle:focus-visible, #dictionary-selection:focus-visible { outline: 2px solid #2b4a8b; outline-offset: 3px; }
html #dictionary-query[data-pointer-focus]:focus { outline: none; box-shadow: none; }
#dictionary-status { color: #5b6574; font-size: 14px; line-height: 1.6; margin: 16px 0; }
#dictionary-status[data-error="true"] { color: #a34440; }
/* The submit icon already shows local-query progress; keep one loading ring. */
#dictionary-panel:has(#dictionary-form button[aria-busy="true"]) #dictionary-status::before { display: none; }
#dictionary-input-hint { display: flex; justify-content: flex-end; margin: 6px 0 10px; color: var(--muted); font-size: 12px; }
#dictionary-count { font-variant-numeric: tabular-nums; }
#dictionary-history { margin: 0 0 16px; padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.dictionary-history-heading { margin: 6px 10px 4px; color: var(--muted); font-size: 12px; line-height: 1.5; }
#dictionary-history-list { max-height: min(320px, 42dvh); overflow-y: auto; overscroll-behavior: contain; }
#dictionary-panel .dictionary-history-option { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 44px; padding: 10px; border: 0; background: transparent; color: var(--ink); text-align: left; line-height: 1.6; }
.dictionary-history-query { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.dictionary-history-kind { flex: none; color: var(--muted); font-size: 12px; }
.dictionary-history-row { display:grid; grid-template-columns:minmax(0,1fr) auto; align-items:center; border-radius:7px; }
.dictionary-history-row > [role="gridcell"] { min-width:0; }
.dictionary-history-row:has(.dictionary-history-option:is(:hover,:focus-visible)),
.dictionary-history-row[aria-selected="true"]:not(:has(.dictionary-history-remove:is(:hover,:focus-visible))) { background:var(--surface-muted); }
#dictionary-panel #dictionary-history-list button,
#dictionary-panel #dictionary-history-list button:is(:hover,:active,:focus-visible) {
  background:transparent; box-shadow:none; transform:none; color:var(--ink); border:0;
}
#dictionary-history-list .dictionary-history-remove {
  display:grid; place-items:center; width:44px; min-height:44px; padding:0;
}
.dictionary-remove-icon {
  display:grid; place-items:center; width:26px; height:26px; border-radius:50%; color:var(--muted);
}
.dictionary-remove-icon::before {
  content:''; width:14px; height:14px; background:currentColor;
  mask:url('../vendor/lucide/x.svg') center / contain no-repeat;
}
.dictionary-history-remove:is(:hover,:focus-visible) .dictionary-remove-icon {
  color:var(--error); background:color-mix(in srgb, var(--error) 12%, var(--surface));
}
.dictionary-history-remove:active .dictionary-remove-icon { background:color-mix(in srgb, var(--error) 19%, var(--surface)); }
#dictionary-panel #dictionary-history-list button:focus-visible { outline:2px solid var(--accent); outline-offset:-3px; }
#dictionary-ai { padding: 14px 0 0; border-top: 1px solid #dde2ea; }
#dictionary-ai-search { width: 100%; background: #e4ebf8; border: 1px solid #bac4d2; color: #2b4a8b; font-weight: 600 !important; }
#dictionary-ai-hint { font-size: 13px; color: #5b6574; margin: 8px 0 16px; }
.dictionary-ai-entry { overflow-wrap: anywhere; }
.dictionary-ai-entry h3 { font-size: 16px; margin: 16px 0 8px; }
.dictionary-ai-entry p { margin: 6px 0 12px; }
.dictionary-ai-basics { margin: 8px 0 20px; }
.dictionary-ai-basics > div { display: grid; grid-template-columns: 5.5em minmax(0, 1fr); gap: 8px; padding: 7px 0; }
.dictionary-ai-basics dt { color: #5b6574; font-size: 14px; }
.dictionary-ai-basics dd { margin: 0; font-size: 15px; line-height: 1.75; }
.dictionary-ai-examples { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 14px; line-height: 1.7; }
.dictionary-ai-examples caption { text-align: left; color: #5b6574; font-size: 13px; margin-bottom: 8px; }
.dictionary-ai-examples th, .dictionary-ai-examples td { border: 1px solid #dde2ea; padding: 9px 8px; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.dictionary-ai-examples th { background: #eef1f5; font-weight: 600; }
.dictionary-ai-examples th:first-child { width: 3.5em; white-space: nowrap; }
.dictionary-ai-translation { font-size: 18px; font-weight: 600; color: #1c2430; }
.dictionary-ai-note { padding: 10px 12px; background: #eef1f5; border-left: 2px solid #bac4d2; font-size: 14px; color: #5b6574; }
#dictionary-panel button:disabled { cursor: not-allowed; opacity: .65; }
.dictionary-entry { border-top: 1px solid #dde2ea; padding: 18px 0; overflow-wrap: anywhere; }
.dictionary-entry h3 { font-size: 23px; font-weight: 600; margin: 0 0 4px; line-height: 1.5; }
.dictionary-reading { margin: 0 0 8px; color: #5b6574; font-size: 15px; }
.dictionary-match { display: block; color: #2b4a8b; font-size: 13px; margin-bottom: 10px; }
.dictionary-senses { padding-left: 24px; margin: 12px 0 0; }
.dictionary-senses li { padding-left: 2px; margin: 0 0 14px; }
.dictionary-senses li::marker { color: #5b6574; font-variant-numeric: tabular-nums; }
.dictionary-senses p { margin: 0; }
.dictionary-label { display: block; font-size: 13px; color: #5b6574; line-height: 1.6; margin-bottom: 3px; }
.dictionary-senses details { font-size: 13px; color: #5b6574; margin-top: 4px; }
.dictionary-senses summary, .dictionary-footer summary { cursor: pointer; }
.dictionary-entry > details { margin-top: 14px; }
#dictionary-panel .dictionary-suggestion { margin: 4px 8px 4px 0; border: 1px solid #dde2ea; background: #fff; padding: 6px 12px; color: #2b4a8b; }
.dictionary-footer { border-top: 1px solid #dde2ea; margin-top: auto; padding: 16px 0 max(12px, env(safe-area-inset-bottom)); color: #5b6574; font-size: 13px; }
.dictionary-footer summary { list-style: none; text-decoration: underline; text-underline-offset: 4px; }
.dictionary-footer summary::-webkit-details-marker { display: none; }
.dictionary-footer a { color: #2b4a8b; text-underline-offset: 3px; }
html[data-design='classic'] body.dictionary-open #dictionary-toggle { visibility: hidden; }
/* Reserve the dictionary rail and reflow the exercise beside it. */
@media (min-width: 1200px) {
  body.dictionary-open { padding-right: 364px; }
  body.dictionary-open #view-listening .has-figure { grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: 16px; }
  body.dictionary-open #view-listening .listening-toolbar { flex-wrap: wrap; }
}
@media (max-width: 1199px) {
  /* A temporary overlay instead of squeezing the answer sheet into a sliver.
     Closing returns to the exact previous scroll position and live audio. */
  #dictionary-panel { width: min(420px, 100%); }
}
@media (min-width: 1200px) and (max-width: 1439px) {
  /* The reading workspace already has an editor and a reading column. Do not
     force a third narrow column; listening retains its existing layout. */
  body.dictionary-open:has(> #workspace-viewport:not(.is-inactive)) { padding-right: 0; }
}
@media (max-width: 500px) { #dictionary-panel { width: 100%; padding: 18px; } }
@keyframes dictionary-enter { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { #dictionary-panel { animation: none; } }
.dictionary-ai-entry h3 { overflow-wrap: anywhere; }
.dictionary-ai-meaning { font-size: 1rem; color: var(--ink); margin-block: 16px; }
.dictionary-ai-formation { color: var(--muted); font-size: .9rem; line-height: 1.7; }
.dictionary-ai-chunks { margin: 20px 0; display: grid; gap: 14px; }
.dictionary-ai-chunks > div { border-left: 2px solid var(--line); padding-left: 12px; }
.dictionary-ai-chunks dt { font-weight: 600; color: var(--ink); }
.dictionary-ai-chunks dd { margin: 3px 0 0; font-size: .9rem; line-height: 1.7; color: var(--muted); }

/* Compact search chrome; suggestions float, so they never push the answer down. */
html #dictionary-panel { padding: 16px var(--utility-inset,22px) 24px; }
html #dictionary-panel .dictionary-search { position: relative; margin-bottom: 18px; }
html #dictionary-panel #dictionary-form { align-items: center; gap: 0; border-bottom: 1px solid var(--line); }
html #dictionary-panel #dictionary-form:focus-within { border-color: var(--accent); }
html #dictionary-panel #dictionary-query { flex: 1; width: 0; min-height: 44px; padding: 8px 4px; border: 0; border-radius: 0; outline: none; box-shadow: none; background: transparent; font-size: 16px; }
html #dictionary-panel #dictionary-form > button { width: 32px; height: 36px; min-height: 36px; padding: 4px; border: 0; background: transparent; color: var(--muted); }
html #dictionary-panel #dictionary-form > button svg { width: 18px; height: 18px; }
html #dictionary-panel #dictionary-input-hint { flex: none; margin: 0 4px; font-size: 11px; line-height: 1; }
html #dictionary-panel #dictionary-input-hint[hidden] { display: none; }
html #dictionary-panel #dictionary-count { font-size: 11px; }
html #dictionary-panel #dictionary-history { position: absolute; inset: calc(100% + 4px) 0 auto; z-index: 4; margin: 0; border-radius: 8px; box-shadow: var(--popover-shadow); }
html #dictionary-panel .dictionary-history-kind { max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
html #dictionary-panel #dictionary-status { margin: 0 0 12px; }
html #dictionary-panel #dictionary-results:empty { display: none; }
html #dictionary-panel #dictionary-ai[data-has-result='true'] { border: 0; padding: 0; }
html #dictionary-panel .dictionary-ai-entry > .dictionary-match { color: var(--muted); font-size: 12px; margin: 0 0 6px; }
html #dictionary-panel .dictionary-expression-heading { align-items: flex-start; gap: 8px; }
html #dictionary-panel .dictionary-expression-heading h3 { margin: 0 0 6px; font-size: 18px; line-height: 1.6; }
html #dictionary-panel .dictionary-expression-heading .expression-save { min-height: 32px; width: 32px; padding: 4px; }
html #dictionary-panel .dictionary-entry:first-child { border-top: 0; padding-top: 0; }
@media (pointer: coarse) {
  html #dictionary-panel .dictionary-expression-heading .expression-save { width:44px; min-height:44px; }
  html #dictionary-panel #dictionary-form > button { width: 44px; height: 44px; min-height: 44px; }
}
/* The whole interactive passage must opt out: Safari can otherwise promote a
   hold on a non-selectable ruby token to its selectable paragraph ancestor.
   Source text, dictionary definitions and editors retain normal copying. */
@media (pointer: coarse) {
  html.dictionary-touch-lookup,
  html.dictionary-touch-lookup body {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }
  html.dictionary-touch-lookup :is(#dictionary-panel,#study-sidebar,input,textarea,[contenteditable='true']) {
    -webkit-touch-callout: default;
  }
  #shadowing-panel #current-sentence,
  #shadowing-panel #current-sentence *,
  #listening-review .listening-lookup-word[data-dictionary-query] {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }
}
