.novel-lookup-hint {
  color: color-mix(in srgb, var(--muted) 80%, var(--text));
  font: 500 0.8rem / 1.5 system-ui, sans-serif;
}

[data-novel-lookup]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

[data-novel-lookup-ui] {
  --lookup-edge: max(12px, env(safe-area-inset-right));
  --lookup-start: max(12px, env(safe-area-inset-left));
  --lookup-bottom: calc(68px + env(safe-area-inset-bottom));
}

.novel-lookup-trigger,
.novel-lookup-panel {
  position: fixed;
  z-index: 54;
  right: var(--lookup-edge);
  bottom: var(--lookup-bottom);
  color: var(--text);
  font-family: system-ui, sans-serif;
}

.novel-lookup-trigger,
.novel-lookup-translate,
.novel-lookup-close,
.novel-lookup-retry,
.novel-lookup-language {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card2);
  color: var(--text);
  font: 650 0.875rem / 1.3 system-ui, sans-serif;
}

.novel-lookup-trigger,
.novel-lookup-translate {
  padding: 0 0.95em;
  border-color: transparent;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
}

.novel-lookup-trigger {
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.novel-lookup-panel {
  display: grid;
  gap: 11px;
  width: min(360px, calc(100vw - var(--lookup-start) - var(--lookup-edge)));
  max-height: min(500px, calc(100dvh - var(--lookup-bottom) - 14px - env(safe-area-inset-top)));
  padding: 0 15px 15px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 0.875rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.novel-lookup-panel :where(p, dl, dd, h2) { margin: 0; }
.novel-lookup-panel p:empty:not([role]), .novel-lookup-definitions:empty { display: none; }
.novel-lookup-panel [role="status"]:empty, .novel-lookup-definition-status.has-results { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.novel-lookup-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-inline: -15px;
  padding: 13px 15px 4px;
  background: var(--card);
}
.novel-lookup-title { color: var(--text); font-size: 1.125rem; font-weight: 750; }
.novel-lookup-close { width: 44px; flex: none; padding: 0; font-size: 1.5rem; cursor: pointer; }
.novel-lookup-retry { justify-self: start; padding-inline: 0.95em; cursor: pointer; }
.novel-lookup-excerpt { padding: 9px 12px; border-inline-start: 3px solid var(--accent); border-radius: 8px; background: var(--card2); }
.novel-lookup-definitions { padding-inline: 1px; }
.novel-lookup-definitions dt { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 7px; font-weight: 700; }
.novel-lookup-definitions dt:not(:first-child) { margin-top: 8px; }
.novel-lookup-part-of-speech { font-size: 0.8rem; font-style: italic; font-weight: 500; }
.novel-lookup-attribution, .novel-lookup-translation-status, .novel-lookup-definition-status { color: color-mix(in srgb, var(--muted) 75%, var(--text)); font-size: 0.8rem; }
.novel-lookup-attribution a, .novel-lookup-signin { color: var(--text); text-decoration: underline; text-underline-offset: 0.16em; }
.novel-lookup-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.novel-lookup-language-label { display: grid; min-width: 0; gap: 4px; font-size: 0.8rem; }
.novel-lookup-language { width: 100%; min-width: 0; padding: 0 6px; }
.novel-lookup-translate:disabled, .novel-lookup-retry:disabled { opacity: 0.65; cursor: default; }
.novel-lookup-translation { font-weight: 550; }
.novel-lookup-signin { justify-self: start; padding: 5px 0; font-weight: 650; }
[data-novel-lookup-ui] :is(button, select, a):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 600px), (pointer: coarse) {
  .novel-lookup-panel {
    inset-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right));
    width: auto;
    max-width: 520px;
    max-height: min(56dvh, calc(100dvh - var(--lookup-bottom) - 8px - env(safe-area-inset-top)));
    margin-inline: auto;
  }
  .novel-lookup-language { font-size: 1rem; }
}

@media (max-width: 260px) {
  .novel-lookup-controls { grid-template-columns: minmax(0, 1fr); }
}
