@font-face { font-family: 'Inter'; font-style: normal; font-weight: 100 900; font-display: swap; src: url('fonts/inter-latin-wght-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 100 900; font-display: swap; src: url('fonts/inter-vietnamese-wght-normal.woff2') format('woff2'); unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB; }

/* Ink on white, one grey for secondary text, one line colour, and one main
   colour: a deep steel blue, calm and solid (7.1:1 on white). Red only where
   it means something: the mark, an error, a page marked for deletion. The
   tools' tiles are tinted by the kind of job, each glyph at least 4.5:1 on
   its own tint. */
:root {
  --text: #18181b;
  --muted: #5f6470;
  --line: #e3e5ea;
  --soft: #f3f5f8;
  --main: #2d5b88;
  --main-hover: #244a70;
  --main-soft: #e9f0f7;
  --red: #d92d20;
  --bar-h: 76px;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #fff;
  color: var(--text);
  font: 17px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
button, input { font: inherit; color: inherit; }
button, a, label { touch-action: manipulation; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--main); outline-offset: 2px; }
.skip { position: absolute; left: 12px; top: -60px; z-index: 30; padding: 10px 14px; border-radius: 10px; background: var(--main); color: #fff; text-decoration: none; font-weight: 600; }
.skip:focus { top: 12px; }
.ico { display: inline-flex; width: 20px; height: 20px; flex: none; }
.ico svg { width: 100%; height: 100%; }

header, main, footer {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}
header { display: flex; align-items: center; justify-content: space-between; padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: 6px; }
.brand { display: flex; align-items: center; gap: 8px; min-height: 44px; font-weight: 700; font-size: 19px; text-decoration: none; letter-spacing: -0.01em; }
main { flex: 1; padding-bottom: 32px; }
footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 10px; }
.lang { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 4px; border: 0; background: none; color: var(--muted); font-size: 14px; cursor: pointer; }
.lang:hover { color: var(--text); }
.lang svg { flex: none; width: 21px; height: 14px; border-radius: 2px; box-shadow: 0 0 0 1px var(--line); }
/* The Datlab mark, top right, links home to datlab.dev. It sits in the
   background, a maker's stamp: grey and faint until pointed at or focused,
   so the eye stays on the tool. Still 3:1 on white, the floor for a graphic
   that is the whole of a link. */
.maker { display: inline-grid; place-items: center; width: 44px; height: 44px; margin-right: -7px; border-radius: 12px; opacity: .55; filter: grayscale(1); transition: opacity .2s, filter .2s; }
.maker img { width: 30px; height: 30px; }
.maker:is(:hover, :focus-visible) { opacity: 1; filter: none; }
footer { padding-top: 8px; padding-bottom: max(16px, env(safe-area-inset-bottom)); font-size: 14px; color: var(--muted); }
body:has(.bar) footer { padding-bottom: calc(var(--bar-h) + 16px + env(safe-area-inset-bottom)); }

/* ----------------------------------------------------------------- buttons */
.btn {
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 12px 20px; width: 100%;
  border: 1px solid var(--main); border-radius: 12px;
  background: var(--main); color: #fff; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: background-color .15s, border-color .15s, transform .1s;
}
.btn:not(:disabled):hover { background: var(--main-hover); border-color: var(--main-hover); }
.btn:not(:disabled):active { transform: scale(.985); }
.btn:disabled { background: var(--soft); border-color: var(--line); color: var(--muted); cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--text); border-color: var(--line); }
.btn.ghost:not(:disabled):hover { background: var(--soft); border-color: #cfd3da; }
.btn.small { width: auto; min-height: 40px; padding: 8px 14px; font-size: 15px; font-weight: 500; }
.btn.small .ico { width: 18px; height: 18px; }
.link { border: 0; background: none; padding: 10px 4px; min-height: 44px; color: var(--muted); font-size: 15px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.icon { display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none; border: 0; border-radius: 10px; background: none; color: var(--muted); cursor: pointer; padding: 0; }
.icon:active { background: var(--soft); }

/* -------------------------------------------------------------------- home */
.intro { margin: 6px 0 16px; color: var(--muted); }
.find { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.search { position: relative; display: flex; align-items: center; }
.search > .ico { position: absolute; left: 14px; width: 20px; height: 20px; color: var(--muted); pointer-events: none; }
.search input { width: 100%; min-height: 50px; padding: 12px 48px 12px 44px; border: 1px solid #cfd3da; border-radius: 12px; background: #fff; font-size: 17px; -webkit-appearance: none; appearance: none; transition: border-color .15s, box-shadow .15s; }
.search input::-webkit-search-cancel-button { display: none; }
.search input:focus { outline: none; border-color: var(--main); box-shadow: 0 0 0 3px var(--main-soft); }
.search .clear { position: absolute; right: 3px; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 8px 16px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font-size: 15px; font-weight: 500; cursor: pointer; white-space: nowrap; transition: background-color .15s, color .15s, border-color .15s; }
.chip .n { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: var(--main); border-color: var(--main); color: #fff; }
.chip[aria-pressed="true"] .n { color: rgba(255, 255, 255, .8); }
@media (hover: hover) { .chip[aria-pressed="false"]:hover { background: var(--soft); } }

.tools { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.tools li[hidden] { display: none; }
.tools a { display: grid; grid-template-columns: auto 1fr; column-gap: 14px; align-items: center; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: #fff; text-decoration: none; transition: border-color .15s, background-color .15s; }
.tools .tile { grid-row: 1 / 3; }
.tools b { font-weight: 600; align-self: end; }
.tools a > span:last-child { grid-column: 2; color: var(--muted); font-size: 14.5px; line-height: 1.4; align-self: start; }
@media (hover: hover) { .tools a:hover { border-color: #c5ccd6; background: #fbfcfd; } }
.tools a:active { background: var(--soft); }
.empty { padding: 24px 0; text-align: center; color: var(--muted); }
.empty p { margin: 0 0 12px; }

/* the tile: the glyph in its colour on a soft tint of it */
.tile { display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none; border-radius: 12px; }
.tile svg { width: 24px; height: 24px; }
.tile.coral { background: #fdece7; color: #b8432a; }
.tile.green { background: #e5f4ec; color: #22744a; }
.tile.amber { background: #fdf1dc; color: #95600a; }
.tile.teal { background: #e0f2f1; color: #1d6b6a; }
.tile.blue { background: #e7eef8; color: #2d5b88; }
.tile.slate { background: #eceff3; color: #485466; }

@media (min-width: 721px) {
  body:has(.tools) :is(header, main, footer) { max-width: 1040px; }
  .find { flex-direction: row; align-items: center; }
  .search { flex: 1; max-width: 460px; }
  .tools { grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 14px; }
  .tools a { grid-template-columns: 1fr; align-content: start; row-gap: 4px; height: 100%; padding: 20px; }
  .tools .tile { grid-row: auto; margin-bottom: 10px; width: 48px; height: 48px; }
  .tools b { align-self: auto; }
  .tools a > span:last-child { grid-column: 1; }
}

/* -------------------------------------------------------------------- tool */
.back { display: inline-flex; align-items: center; gap: 2px; min-height: 44px; margin-left: -6px; padding-right: 8px; color: var(--muted); text-decoration: none; font-size: 15px; }
.head { display: flex; gap: 14px; align-items: flex-start; margin: 4px 0 20px; }
.head .tile { width: 52px; height: 52px; border-radius: 14px; margin-top: 2px; }
.head .tile svg { width: 28px; height: 28px; }
h1 { margin: 0 0 2px; font-size: 28px; line-height: 1.2; letter-spacing: -0.02em; }
h1:focus { outline: none; }
.lead { margin: 0; color: var(--muted); }

.drop { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 32px 16px; border: 1.5px dashed #c4c4ca; border-radius: 16px; text-align: center; cursor: pointer; }
.drop .btn { max-width: 320px; pointer-events: none; }
.hint { font-size: 14px; color: var(--muted); }
.drop:focus-within { outline: 2px solid var(--main); outline-offset: 2px; }
.drop { transition: border-color .15s, background-color .15s; }
@media (hover: hover) { .drop:hover { border-color: var(--main); background: var(--main-soft); } }
@media (hover: none) { .or-drop { display: none; } }

.note { display: flex; gap: 8px; align-items: flex-start; margin: 16px 0 0; font-size: 14px; color: var(--muted); }
.note .ico { width: 18px; height: 18px; margin-top: 2px; }
.msg { margin: 12px 0 0; color: var(--red); font-size: 15px; }
.msg:empty { display: none; }
.help { margin: 6px 0 0; font-size: 14px; color: var(--muted); }

.files { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.file { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); background: #fff; }
.file .thumb { width: 44px; height: 56px; }
.meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.meta b { font-weight: 500; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta small { color: var(--muted); font-size: 14px; }
.grip { display: inline-grid; place-items: center; width: 32px; height: 44px; margin-right: -8px; color: #a1a1aa; cursor: grab; touch-action: none; }
.moving { opacity: .35; }
.add { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 52px; border-bottom: 1px solid var(--line); color: var(--text); font-weight: 500; cursor: pointer; }

.thumb { position: relative; display: grid; place-items: center; overflow: hidden; background: var(--soft); border: 1px solid var(--line); border-radius: 4px; }
.thumb img { max-width: 100%; max-height: 100%; opacity: 0; transform: rotate(var(--rot, 0deg)); transition: opacity .2s, transform .2s; }
.thumb.ready img { opacity: 1; }
.thumb.ready { background: #fff; }
.thumb.blank { color: var(--muted); }

/* page grid */
.pages-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 16px 0 10px; }
.pages-head .help { margin: 0; }
.pages { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 12px; }
.pick { margin-top: 16px; }
.page { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.page .thumb { width: 100%; aspect-ratio: 1 / 1.3; }
.page .thumb img { max-width: 86%; max-height: 86%; }
.num { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.page-tools { display: flex; gap: 2px; }
.page-tools .icon { width: 44px; height: 40px; }
.page.deleted .thumb { opacity: .3; }
.page.deleted .del { color: #fff; background: var(--red); }
.page.deleted .num { text-decoration: line-through; }
.pages.pick .page { cursor: pointer; }
.pages.pick .thumb { border-width: 2px; }
.page.picked .thumb { border-color: var(--main); }
.tick { position: absolute; top: 8px; right: 8px; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid #a1a1aa; background: #fff; color: #fff; }
.tick .ico { width: 16px; height: 16px; }
.page.picked .tick { background: var(--main); border-color: var(--main); }

/* options */
.options:empty { display: none; }
.field { margin: 20px 0 0; padding: 0; border: 0; min-width: 0; }
.field > legend, .field > label { display: block; margin-bottom: 8px; padding: 0; font-weight: 600; font-size: 15px; }
.choices { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.choices.stack { grid-auto-flow: row; }
.choice { position: relative; cursor: pointer; }
.choice + .choice { border-left: 1px solid var(--line); }
.choices.stack .choice + .choice { border-left: 0; border-top: 1px solid var(--line); }
.choice input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.choice > span { display: flex; flex-direction: column; justify-content: center; min-height: 48px; padding: 8px 12px; text-align: center; font-size: 15px; }
.choices.stack .choice > span { text-align: left; padding: 10px 14px 10px 44px; }
.choices.stack .choice > span::before { content: ""; position: absolute; left: 14px; top: 50%; width: 18px; height: 18px; margin-top: -9px; border-radius: 50%; border: 1.5px solid #a1a1aa; background: #fff; }
.choices.stack .choice input:checked + span::before { border: 6px solid var(--main); }
.choice b { font-weight: 500; }
.choice small { color: var(--muted); font-size: 13.5px; }
.choices:not(.stack) .choice input:checked + span { background: var(--main); color: #fff; }
.choices.stack .choice input:checked + span { background: var(--main-soft); }
.choice > span { transition: background-color .15s, color .15s; }
.choice input:focus-visible + span { outline: 2px solid var(--main); outline-offset: -4px; }
.field input:not([type=radio]) { width: 100%; min-height: 48px; padding: 10px 12px; border: 1px solid #c4c4ca; border-radius: 10px; background: #fff; font-size: 17px; }
.field input:focus { outline: 2px solid var(--main); outline-offset: -1px; }
.pw { display: flex; gap: 8px; align-items: center; }

/* the run button, with its progress drawn inside it */
.bar { margin-top: 24px; }
.run .fill { position: absolute; inset: 0; background: rgba(255, 255, 255, .22); transform-origin: left; transform: scaleX(0); transition: transform .25s; }
body.busy .run:disabled { background: var(--main); border-color: var(--main); color: #fff; cursor: progress; }
.run .label { position: relative; font-variant-numeric: tabular-nums; }
@media (max-width: 720px) {
  .bar { position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; margin: 0; padding: 12px max(16px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); background: rgba(255, 255, 255, .96); border-top: 1px solid var(--line); }
}

/* result */
.result { display: flex; flex-direction: column; gap: 12px; }
.out { display: flex; flex-direction: column; margin: 0; padding: 16px; border: 1px solid var(--line); border-radius: 12px; }
.out b { font-weight: 600; word-break: break-all; }
.out small { color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
.result .note { margin: 0; }
.outs { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow: auto; border-top: 1px solid var(--line); }
.outs li { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.outs a { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.outs small { color: var(--muted); white-space: nowrap; }
.again { align-self: center; }

/* overlays */
.veil { position: fixed; inset: 0; z-index: 20; display: none; place-items: center; pointer-events: none; }
.veil.drag { background: rgba(233, 240, 247, .88); border: 3px dashed var(--main); }
body.dragging .veil.drag, body.reading .veil.read { display: grid; }
.veil.read { background: rgba(255, 255, 255, .6); pointer-events: auto; }
.spin { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--main); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(1turn); } }

@media (min-width: 721px) {
  body { font-size: 16px; }
  .pages { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}
/* Motion, each with a cause: the tool's tile carries over between the list
   and its page; the result arrives; nothing else moves on its own. */
::view-transition-group(*) { animation-duration: 240ms; animation-timing-function: cubic-bezier(.2, .8, .2, 1); }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 160ms; }
.result > * { animation: rise .22s cubic-bezier(.2, .8, .2, 1) both; }
.result > :nth-child(2) { animation-delay: 40ms; }
.result > :nth-child(3) { animation-delay: 80ms; }
.result > :nth-child(n+4) { animation-delay: 110ms; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation-duration: 0s !important; } }
