/* Speech-bubble translation for manga pages. Sizes inside .bubble-layer are source-image pixels; the layer is scaled
   to the page, so lines that must stay crisp divide by --scale. */
@font-face { font-family: 'Comic Neue'; src: url('/static/ComicNeue-Regular.ttf') format('truetype'); font-weight: 400; font-display: swap; }
.bubble-open { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.bubble-open[hidden] { display: none; }
.bubble-open[aria-pressed="true"] { color: var(--accent); }

.bubble-layer { position: absolute; z-index: 3; transform-origin: 0 0; pointer-events: none; }
.bubble-layer[hidden] { display: none; }
/* Bubble: invisible until pressed. A quick tap passes through to the reader (page turn / menus); a still press shows
   a soft ring after 150 ms, so the hold is felt before the card opens at 450 ms, while ordinary taps never flash. */
.bubble-hit {
  position: absolute;
  border-radius: 12px;
  pointer-events: auto;
  contain: layout;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  transition: box-shadow .15s ease;
}
.bubble-hit:active { box-shadow: 0 0 0 calc(3px / var(--scale, 1)) color-mix(in srgb, var(--accent, #ff7149) 70%, transparent); transition-delay: .15s; }
.bubble-hit:focus-visible, .bubble-hit.is-peek { box-shadow: 0 0 0 calc(3px / var(--scale, 1)) var(--accent, #ff7149); transition-delay: 0s; }
/* Translated bubble: balloon-coloured patch over the original lettering, text in the lettering colour. */
.bubble-hit.is-text {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: var(--fill);
  color: var(--ink);
  font-family: 'Comic Neue', 'Comic Sans MS', 'Chalkboard SE', system-ui, sans-serif;
  font-weight: 400;
  line-height: 1.1;
  text-align: center;
}
/* Peek: the original lettering shows through while its card is open. Art: huge display lettering stays as drawn. */
.bubble-hit.is-text:is(.is-peek, .is-art) { background: transparent; }
.bubble-hit:is(.is-peek, .is-art) .bubble-words { visibility: hidden; }
.bubble-words {
  display: block;
  width: 100%;
  white-space: pre-line;
  overflow-wrap: normal;
  hyphens: auto;
  text-wrap: balance;
  -webkit-text-stroke: .045em currentColor; /* Comic Neue Regular reads thin next to inked lettering */
}
.is-tight .bubble-words { overflow-wrap: anywhere; }
.is-vertical .bubble-words { width: auto; height: 100%; writing-mode: vertical-rl; }
.bubble-upright { text-combine-upright: all; } /* "12", "!?" upright in one cell of vertical text */
/* Japanese/Chinese: no line may start with 。、ー or small kana; Korean: words are not split between syllables. */
.bubble-words:is(:lang(ja), :lang(zh)) { line-break: strict; }
.bubble-words:lang(ko) { word-break: keep-all; }
.bubble-words:lang(ja) { font-family: 'Hiragino Maru Gothic ProN', 'Yu Gothic UI', 'Noto Sans CJK JP', 'Noto Sans JP', sans-serif; }
.bubble-words:lang(zh) { font-family: 'PingFang SC', 'Microsoft YaHei', 'Noto Sans CJK SC', 'Noto Sans SC', sans-serif; }
.bubble-words:lang(ko) { font-family: 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans CJK KR', sans-serif; }
.bubble-words:lang(ar) { font-family: 'Noto Sans Arabic', 'Geeza Pro', 'Segoe UI', sans-serif; line-height: 1.35; }
.bubble-words:is(:lang(ja), :lang(zh), :lang(ko), :lang(ar)) { -webkit-text-stroke: 0; font-weight: 600; }

/* ---------- toast, panel and bubble sheet ---------- */
.bubble-status {
  position: fixed;
  z-index: 57;
  left: 50%;
  bottom: calc(72px + env(safe-area-inset-bottom));
  max-width: min(520px, calc(100vw - 24px));
  margin: 0;
  padding: 10px 14px;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
  color: var(--text);
  font: 0.875rem / 1.4 system-ui, sans-serif;
  text-align: center;
  pointer-events: none;
}
.bubble-status[hidden] { display: none; }
.bubble-status[data-kind="error"] { border-color: var(--danger, #e5484d); }
/* Bottom sheet: reachable with a thumb on phones, never covers the page header. */
.bubble-sheet {
  position: fixed;
  z-index: 58;
  inset-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right));
  bottom: calc(8px + env(safe-area-inset-bottom));
  display: grid;
  gap: 12px;
  max-width: 520px;
  max-height: min(70dvh, 560px);
  margin-inline: auto;
  padding: 0 16px 16px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  box-shadow: var(--shadow);
  color: var(--text);
  font: 0.9375rem / 1.45 system-ui, sans-serif;
}
.bubble-sheet[hidden], .bubble-sheet [hidden] { display: none; }
.bubble-sheet.is-top { top: calc(8px + env(safe-area-inset-top)); bottom: auto; }
.bubble-sheet :where(p, h2, h3) { margin: 0; }
.bubble-sheet-head { position: sticky; z-index: 1; top: 0; display: flex; align-items: center; gap: 8px; margin-inline: -16px; padding: 12px 16px 4px; background: var(--card); }
.bubble-sheet-title { flex: 1; font-size: 1rem; font-weight: 750; }
.bubble-sheet-title:focus { outline: none; }
.bubble-sheet :is(.bubble-sheet-close, .bubble-sheet-listen, .bubble-language, .bubble-tool) {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card2);
  color: var(--text);
  font: 600 0.9375rem / 1.2 system-ui, sans-serif;
}
.bubble-sheet-close { width: 44px; flex: none; font-size: 1.5rem !important; cursor: pointer; }
.bubble-sheet-translation { font-size: 1.125rem; font-weight: 650; white-space: pre-line; }
.bubble-sheet-translation.is-loading { color: var(--muted); font-weight: 500; }
.bubble-sheet-label { color: var(--muted); font-size: 0.75rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; }
.bubble-sheet-original { padding-inline-start: 10px; border-inline-start: 2px solid var(--line); line-height: 1.9; }
/* Words look like text but are buttons: a dotted underline says "tappable", the chosen word is highlighted. */
.bubble-word { padding: 2px 1px; margin: 0; border: 0; border-radius: 4px; background: none; color: inherit; font: inherit;
  text-decoration: underline dotted color-mix(in srgb, currentColor 45%, transparent); text-underline-offset: 4px; cursor: pointer; }
.bubble-word[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 22%, transparent); text-decoration: none; }
.bubble-meaning { padding: 10px 12px; border-radius: 10px; background: var(--card2); }
.bubble-sheet-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.bubble-sheet-listen { padding: 0 14px; cursor: pointer; }
.bubble-sheet-signin { color: var(--text); font-weight: 650; text-decoration: underline; }
.bubble-sheet-note { color: var(--muted); font-size: 0.75rem; }
.bubble-sheet-note:empty { display: none; }
.bubble-sheet :is(button, select, a, input):focus-visible, .bubble-menu-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.bubble-field { display: grid; gap: 6px; font-weight: 650; }
.bubble-language { width: 100%; padding: 0 10px; font-size: 1rem !important; } /* 16px stops iOS zooming on focus */
.bubble-switch { display: flex; align-items: center; gap: 12px; min-height: 44px; font-weight: 600; cursor: pointer; }
.bubble-switch input { width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--accent); }
.bubble-panel-status { color: var(--muted); }
.bubble-panel-status:empty { display: none; }
.bubble-panel-status[data-kind="error"] { color: var(--danger, #e5484d); }
.bubble-queue { display: grid; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.bubble-queue-title { font-weight: 700; }
.bubble-queue-item { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.bubble-queue-item > p { grid-column: 1 / -1; color: var(--muted); font-size: 0.875rem; overflow-wrap: anywhere; }
.bubble-tool[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.bubble-tool-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bubble-tool { display: inline-flex; align-items: center; justify-content: center; padding: 0 12px; text-decoration: none; cursor: pointer; }
.bubble-tool:is([aria-disabled="true"], :disabled) { opacity: .5; cursor: default; pointer-events: none; }
.bubble-tool-note { color: var(--muted); font-size: 0.8125rem; }
.bubble-tool-result { padding: 10px 12px; border-radius: 10px; background: var(--card2); font-size: 0.875rem; white-space: pre-line; overflow-wrap: anywhere; }
.bubble-tool-result[data-kind="error"] { color: var(--danger, #e5484d); }
.bubble-tool-result[data-kind="warn"] { border-inline-start: 3px solid #e0a100; }
@media (max-width: 360px) { .bubble-tool-row { grid-template-columns: 1fr; } }
