/* ---------------------------------------------------------------- tokens and themes */
:root {
  --bg: #eceae6; --bar: #ffffff; --ink: #1d1d1f; --muted: #6b6b70; --line: #dcd9d3;
  --hover: rgba(0, 0, 0, .05); --accent: #c4581a; --accent-ink: #fff; --flag: rgba(220, 50, 50, .75);
  --page: #fff; --shadow: 0 1px 4px rgba(0, 0, 0, .15);
  --sent: rgba(255, 214, 92, .4); --word: rgba(255, 140, 40, .55); --weak: rgba(255, 140, 40, .18); --weak-line: rgba(255, 140, 40, .9);
  --head: 52px; --foot: 150px; --ui: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1b1d; --bar: #26262a; --ink: #ececee; --muted: #a0a0a8; --line: #3a3a40;
    --hover: rgba(255, 255, 255, .07); --accent: #ff9a52; --accent-ink: #1b1b1d; --shadow: 0 1px 6px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1b1d; --bar: #26262a; --ink: #ececee; --muted: #a0a0a8; --line: #3a3a40;
  --hover: rgba(255, 255, 255, .07); --accent: #ff9a52; --accent-ink: #1b1b1d; --shadow: 0 1px 6px rgba(0, 0, 0, .6);
  color-scheme: dark;
}
/* highlight colours (sentence / word / structural link) */
:root[data-hl="blue"]  { --sent: rgba(120, 180, 255, .35); --word: rgba(40, 120, 255, .45); --weak: rgba(40, 120, 255, .15); --weak-line: rgba(40, 120, 255, .85); }
:root[data-hl="green"] { --sent: rgba(140, 220, 120, .38); --word: rgba(40, 170, 60, .45);  --weak: rgba(40, 170, 60, .15);  --weak-line: rgba(40, 170, 60, .85); }
:root[data-hl="pink"]  { --sent: rgba(255, 160, 200, .38); --word: rgba(235, 60, 140, .42); --weak: rgba(235, 60, 140, .14); --weak-line: rgba(235, 60, 140, .85); }
:root[data-ui="small"] { --ui: 13px; --head: 48px; }
:root[data-ui="large"] { --ui: 15.5px; --head: 56px; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: var(--ui)/1.5 system-ui, "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", sans-serif; }
body { display: flex; flex-direction: column; overflow: hidden; }

/* ---------------------------------------------------------------- header */
header { position: relative; flex: none; height: var(--head); display: flex; align-items: center; gap: 12px; padding: 0 12px;
  background: var(--bar); border-bottom: 1px solid var(--line); }
.brand { flex: none; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font: 600 16px/1 "taiyaku JP", serif; }
.doc { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.doc h1 { font-size: 1em; font-weight: 600; margin: 0; line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#status { font-size: .82em; color: var(--muted); line-height: 1.3; min-height: 1.3em; transition: color .3s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#status.busy::before { content: ""; display: inline-block; width: .55em; height: .55em; margin-right: .45em; border-radius: 50%;
  background: var(--accent); vertical-align: .05em; animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.tools { flex: none; display: flex; align-items: center; gap: 6px; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 2px; }
/* the bar fades in and out and glides between values; a new stage starting from 0 jumps back */
#progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; overflow: hidden;
  opacity: 1; transition: opacity .4s ease; }
#progress[hidden] { display: block; opacity: 0; }
#progress > div { height: 100%; width: 0; background: var(--accent); border-radius: 0 2px 2px 0;
  transition: width .6s cubic-bezier(.22, .61, .36, 1); }
#progress.reset > div { transition: none; }
/* busy without a known fraction: a soft sweep */
#progress.indet > div { width: 30% !important; transition: none; animation: sweep 1.4s ease-in-out infinite; }
@keyframes sweep { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
#status.swap { animation: statusIn .35s ease; }
@keyframes statusIn { from { opacity: .35; transform: translateY(2px); } to { opacity: 1; transform: none; } }

.btn { font: inherit; font-size: .93em; height: 32px; padding: 0 12px; border-radius: 7px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); background: var(--bar); color: var(--ink); white-space: nowrap; }
.btn:hover:not(:disabled) { background: var(--hover); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.icon { width: 32px; padding: 0; justify-content: center; font-size: 1.05em; }
.file input { display: none; }
.zoom { display: inline-flex; }
.zoom .btn { border-radius: 0; margin-left: -1px; }
.zoom .btn:first-child { border-radius: 7px 0 0 7px; margin-left: 0; }
.zoom .btn:last-child { border-radius: 0 7px 7px 0; }
.zoom .zl { width: 58px; justify-content: center; font-variant-numeric: tabular-nums; font-size: .85em; color: var(--muted); }

/* ---------------------------------------------------------------- panes */
main { position: relative; flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; }
.pane { overflow: auto; padding: 16px; scrollbar-gutter: stable; }
.pane + .pane { border-left: 1px solid var(--line); }
#drop { position: absolute; inset: 24px; display: grid; place-content: center; gap: 12px; justify-items: center;
  border: 2px dashed var(--line); border-radius: 12px; color: var(--muted); font-size: 1.07em; background: var(--bg); text-align: center; padding: 20px; }
#drop.over { border-color: var(--accent); color: var(--accent); }
#drop[hidden] { display: none; }

/* bundled fonts (data/fonts, OFL): the screen shows exactly what a saved PDF embeds */
@font-face { font-family: "taiyaku JP"; src: url(data/fonts/NotoSerifJP-Regular.ttf) format("truetype"); font-display: block; }
@font-face { font-family: "taiyaku JP Sans"; src: url(data/fonts/NotoSansJP-Regular.ttf) format("truetype"); font-display: block; }
@font-face { font-family: "taiyaku Math"; src: url(data/fonts/STIXTwoText-Regular.ttf) format("truetype"); font-display: block; }
@font-face { font-family: "taiyaku Math"; font-style: italic; src: url(data/fonts/STIXTwoText-Italic.ttf) format("truetype"); font-display: block; }

.pane { user-select: none; }                       /* dragging moves the page */
.pane.dragging, .pane.dragging * { cursor: grabbing !important; }

.page { position: relative; margin: 0 auto 16px; background: var(--page); box-shadow: var(--shadow); overflow: hidden; }
.page canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.sheet { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.sheet > div { position: absolute; }
.sheet .s { z-index: 1; border-radius: 2px; mix-blend-mode: multiply; }
.sheet .w { z-index: 2; cursor: help; border-radius: 2px; mix-blend-mode: multiply; }
.sheet .t { z-index: 6; pointer-events: none; }
.sheet .on, .sheet .js.on { background: var(--sent); }
.sheet .w.on { background: var(--word); }
/* linked by sentence structure (the -> its noun, is -> the verb's ending): lighter, outlined */
.sheet .w.on.weak { background: var(--weak); outline: 1.5px dashed var(--weak-line); outline-offset: -1px; }
.sheet .pin { outline: 2px solid var(--accent); }
.sheet .wo { background: #fff; z-index: 3; }
.sheet .frame { z-index: 4; color: #111; text-align: justify; line-break: strict; overflow: hidden;
  overflow-wrap: anywhere; word-break: normal; }
.sheet .frame.center { text-align: center; }
.sheet .frame.on-dark { color: #f4f4f4; }
.sheet .frame .m { font-family: "taiyaku Math", "STIX Two Text", "Cambria Math", "Times New Roman", serif; }
.sheet .js { border-radius: 1px; cursor: help; }
.sheet .js.fl { text-decoration: underline wavy var(--flag); text-decoration-thickness: 1px; text-underline-offset: 2px; }

body.noflags .sheet .js.fl { text-decoration: none; }
/* dark pages: the page image and the translated text are inverted together */
body.dark-pages .page canvas, body.dark-pages .sheet .wo, body.dark-pages .sheet .frame { filter: invert(.88) hue-rotate(180deg); }
body.dark-pages .sheet .s, body.dark-pages .sheet .w { mix-blend-mode: screen; }
/* figures and photos found by the layout model keep their own colours */
.page canvas.fig { display: none; inset: auto; }
body.dark-pages .page canvas.fig { display: block; filter: none; }

/* ---------------------------------------------------------------- dictionary panel and its splitter */
/* order: the panel sits above the pages (default) or below them; the dictionary left or right */
header { order: 0; }
footer { order: 1; }
#splitter { order: 2; }
main { order: 3; }
:root[data-panel^="bottom"] main { order: 1; }
:root[data-panel^="bottom"] footer { order: 3; }
#splitter { flex: none; height: 9px; margin: -4px 0; position: relative; z-index: 10; cursor: ns-resize; touch-action: none; }
#splitter::after { content: ""; position: absolute; left: 50%; top: 3px; width: 44px; height: 3px; margin-left: -22px;
  border-radius: 2px; background: var(--line); transition: background .15s; }
#splitter:hover::after, #splitter.active::after { background: var(--accent); }
body.resizing, body.resizing * { cursor: ns-resize !important; user-select: none; }
footer { flex: none; height: var(--foot); display: grid; grid-template-columns: 1.15fr 1fr 1fr; gap: 1px;
  background: var(--line); border-bottom: 1px solid var(--line); font-size: .9em; overflow: hidden; }
:root[data-panel^="bottom"] footer { border-bottom: 0; border-top: 1px solid var(--line); }
:root[data-panel$="right"] footer { grid-template-columns: 1fr 1fr 1.15fr; }
:root[data-panel$="right"] #dictCell { order: 3; }
footer.collapsed { height: 0; border-width: 0; }
footer .cell { padding: 8px 14px; overflow: auto; color: var(--muted); background: var(--bar); min-width: 0; }
#fdst .flag { color: var(--flag); display: block; margin-top: 4px; }
#dictCell { color: var(--ink); font-size: 1.04em; }
#dictPanel .hint { color: var(--muted); font-size: .92em; }
#dictPanel h2 { margin: 0 0 2px; font-size: 1.23em; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
#dictPanel h2 small { font-weight: 400; color: var(--muted); font-size: .75em; }
#dictPanel .pin { font-size: .7em; color: var(--accent); }
#dictPanel .here { font-size: .92em; margin: 2px 0 4px; }
#dictPanel .here b { color: var(--accent); }
#dictPanel ul { margin: 2px 0; padding-left: 18px; }
#dictPanel .en { color: var(--muted); border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }
#dictPanel .pos { display: inline-block; min-width: 34px; font-size: .85em; color: var(--accent); }
#dictCell button.small { font: inherit; font-size: .8em; padding: 2px 8px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bar); color: var(--ink); white-space: nowrap; }
#dictPanel h2 button { margin-left: auto; }

/* ---------------------------------------------------------------- dialogs */
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--bar); color: var(--ink); width: min(620px, 94vw);
  padding: 18px 20px; box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
dialog::backdrop { background: rgba(0, 0, 0, .3); }
dialog h2 { margin: 0 0 10px; font-size: 1.15em; }
dialog fieldset { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 8px 0 6px; }
dialog legend { font-size: .82em; font-weight: 600; color: var(--muted); padding: 0 6px 0 0; }
dialog label { display: block; margin: 8px 0; font-size: .93em; }
dialog label.row { display: flex; gap: 8px; align-items: center; }
dialog label.line { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
dialog label.line select { width: auto; min-width: 180px; }
dialog textarea, dialog select, dialog input[type=text] { width: 100%; font: inherit; background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; }
dialog input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
dialog .note { font-size: .85em; color: var(--muted); margin: 6px 0 0; min-height: 1em; }
dialog menu { padding: 0; margin: 14px 0 0; display: flex; gap: 8px; justify-content: flex-end; }
dialog menu .spacer { flex: 1; }
dialog label.row small.sub { display: block; flex-basis: 100%; margin-left: 24px; color: var(--muted); font-size: .85em; }
dialog label.row:has(small.sub) { flex-wrap: wrap; row-gap: 0; }
/* saved data */
.store-head { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: .88em; }
.store-head span { flex: 1; color: var(--muted); }
.btn.small-btn { height: 26px; font-size: .82em; padding: 0 10px; }
.store-wrap { max-height: 190px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
#storeList { width: 100%; border-collapse: collapse; font-size: .82em; }
#storeList td { padding: 4px 8px; border-top: 1px solid var(--line); vertical-align: middle; }
#storeList tr:first-child td { border-top: 0; }
#storeList td.name { width: 100%; word-break: break-all; }
#storeList td.name small { display: block; color: var(--muted); }
#storeList td.size { white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
#storeList .curtag { margin-left: 6px; padding: 0 6px; border-radius: 8px; font-size: .85em; background: var(--accent); color: var(--accent-ink); }
#storeList td:last-child { white-space: nowrap; width: 1px; }
#storeList tr.sys td { color: var(--muted); }
#storeList button { font: inherit; padding: 1px 8px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bar); color: var(--ink); cursor: pointer; }
.keys { display: grid; grid-template-columns: max-content 1fr; gap: 3px 16px; margin: 6px 0; font-size: .88em; }
.keys dt { font-family: ui-monospace, Consolas, monospace; color: var(--muted); }
.keys dd { margin: 0; }
.gtable-wrap { max-height: 50vh; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
#gtable { width: 100%; border-collapse: collapse; }
#gtable th { position: sticky; top: 0; background: var(--bar); font-size: .85em; text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }
#gtable td { padding: 3px 4px; }
#gtable td:last-child { width: 32px; }
#gtable td button { font: inherit; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bar); color: var(--ink); cursor: pointer; }
.gbuttons { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

@media (max-width: 760px) {
  main { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .pane + .pane { border-left: 0; border-top: 1px solid var(--line); }
  footer, :root[data-panel$="right"] footer { grid-template-columns: 1fr 1fr; }
  #fsrc { display: none; }
  .sep, #glossaryBtn, .zoom, .brand { display: none; }
}

/* "PDF保存" (Shift + click): print the translated pages only, one PDF page per sheet */
@media print {
  header, footer, #splitter, #src, #drop { display: none !important; }
  html, body { background: #fff; height: auto; overflow: visible; display: block; }
  main { display: block; height: auto; }
  #dst { overflow: visible; padding: 0; border: 0; }
  .page { margin: 0; box-shadow: none; break-after: page; }
  .page canvas, .sheet .wo, .sheet .frame { filter: none !important; }
  .sheet .s, .sheet .w, .sheet .t { display: none; }
  .sheet .js.on { background: none; }
  .sheet .js.fl { text-decoration: none; }
}
