:root {
  --bg: #14161b;
  --panel: #1e2129;
  --panel-hi: #272b36;
  --border: #353a48;
  --text: #e8eaf0;
  --muted: #9aa0b2;
  --accent: #2ec4a6;
  --warning: #f5b942;
  --error: #ff7a7a;
  /* Text on the accent color: white on it doesn't reach the 4.5:1 contrast
     WCAG asks for, this dark ink does. */
  --on-color: #10131a;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Buttons get display: inline-flex below, which would otherwise beat the
   browser's own rule for the hidden attribute. */
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.sprite { display: none; }

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--panel-hi);
}

h1 { margin: 0; font-size: 22px; }
h2 { margin: 0 0 4px; font-size: 20px; }
h3 { margin: 0; font-size: 15px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -0.3px; }
.brand img { display: block; }
.tagline { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

/* The language picker and its list. */
.lang-picker { position: relative; }
.lang-picker .chevron { width: 14px; height: 14px; color: var(--muted); }
.menu {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 6px);
  z-index: 20;
  min-width: 200px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--panel-hi);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
.menu li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.menu li:hover, .menu li:focus-visible { background: var(--panel-hi); outline: none; }
.menu .check { margin-inline-start: auto; visibility: hidden; color: var(--accent); }
.menu [aria-selected="true"] .check { visibility: visible; }
.flag { width: 22px; height: 15px; flex: none; border-radius: 3px; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12); object-fit: cover; }

main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(200px, 250px) minmax(0, 760px);
  gap: 24px;
  padding: 24px;
  justify-content: center;
}

@media (max-width: 760px) {
  main { grid-template-columns: 1fr; padding: 16px; }
  header { padding: 16px; }
}

/* Tool picker: real radio buttons, so arrows, Tab and screen readers work
   as usual; the label around each one is the visible card. */
.tools { display: flex; flex-direction: column; gap: 14px; }
.tools-heading { margin: 0; font-size: 15px; }
.tool-group { margin: 0; padding: 0; border: 0; display: flex; flex-direction: column; gap: 4px; }
.tool-group legend { padding: 0 0 6px; color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.tool {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
}
.tool:hover { background: var(--panel); }
.tool input { position: absolute; opacity: 0; pointer-events: none; }
.tool:has(input:checked) { background: var(--panel-hi); border-color: var(--accent); }
.tool:has(input:focus-visible) { outline: 2px solid #fff; outline-offset: 2px; }
.tool .icon { color: var(--accent); }

.workspace {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}
.workspace > p { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon .solid { fill: currentColor; stroke: none; }
.icon.big { width: 36px; height: 36px; color: var(--muted); }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone p { margin: 8px 0 0; }
.dropzone.dragging { border-color: var(--accent); background: var(--panel-hi); }

.button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-hi);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}
.button:hover { border-color: var(--muted); }
.button.primary { align-self: flex-start; background: var(--accent); border-color: var(--accent); color: var(--on-color); font-weight: 700; padding: 10px 18px; }
.button:disabled { opacity: 0.55; cursor: not-allowed; }

.link-button { background: none; border: 0; padding: 4px; color: var(--muted); font: inherit; font-size: 13px; text-decoration: underline; cursor: pointer; }
.link-button:hover { color: var(--text); }

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.icon-button:hover:not(:disabled) { color: var(--text); background: var(--panel-hi); }
.icon-button:disabled { opacity: 0.35; cursor: default; }

.files-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.file-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.file-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 8px 8px 12px;
  background: var(--panel-hi);
  border-radius: 8px;
  border: 1px solid transparent;
}
.file-list li.invalid { border-color: var(--error); }
.file-list li.invalid .muted { color: var(--error); }
.file-info { display: flex; flex-direction: column; min-width: 0; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-actions { display: flex; gap: 2px; flex: none; }

/* Organize pages: a grid of page cards with a thumbnail and actions. */
.field-label { font-weight: 600; }
.page-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.page-card { display: flex; flex-direction: column; gap: 6px; padding: 8px; background: var(--panel-hi); border: 1px solid transparent; border-radius: 10px; cursor: grab; }
.page-card.dragging { opacity: 0.4; }
.page-card.drop-target { border-color: var(--accent); }
.page-card.deleted .thumb { opacity: 0.25; }
.page-card.deleted .page-number { text-decoration: line-through; }
.thumb { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; border-radius: 6px; background: var(--bg); }
.thumb img { max-width: 100%; max-height: 100%; transition: transform 0.15s; box-shadow: 0 1px 4px rgb(0 0 0 / 40%); }
.page-number { font-size: 13px; color: var(--muted); text-align: center; }
.page-actions { display: flex; justify-content: center; gap: 0; flex-wrap: wrap; }
.page-actions .icon-button { width: 26px; height: 26px; }
.page-actions .icon { width: 16px; height: 16px; }
/* Earlier and later follow the reading direction: mirrored right to left. */
[dir="rtl"] .page-actions [data-action="earlier"] .icon, [dir="rtl"] .page-actions [data-action="later"] .icon { transform: scaleX(-1); }

/* Sign: the pad shows on a light, paper-like background, but what is drawn
   stays on a transparent canvas, so only the ink goes on the page. */
.signature-pad { width: 100%; max-width: 520px; height: 180px; background: #f4f3ee; border-radius: 8px; touch-action: none; cursor: crosshair; }

.options { display: flex; flex-direction: column; gap: 14px; border-top: 1px solid var(--panel-hi); padding-top: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label:first-child { font-weight: 600; }
.field p { margin: 0; }
input[type="text"], input[type="password"], input[type="number"], select {
  max-width: 320px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.checkbox-group { margin: 0; padding: 0; border: 0; }
.checkbox-group legend { padding: 0 0 6px; font-weight: 600; }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 12px; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; }

.notice { margin: 0; padding: 10px 14px; border-radius: 8px; border-inline-start: 4px solid; background: var(--panel-hi); }
.notice.warning { border-color: var(--warning); }
.notice.info { border-color: var(--accent); }
.notice.error { border-color: var(--error); margin: 16px 24px 0; }
.demo-notice { margin: 16px 24px 0; }
.notice a { color: var(--accent); }

.progress-row { display: flex; align-items: center; gap: 12px; }
.progress-row progress { flex: 1; height: 8px; accent-color: var(--accent); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.status:empty { display: none; }
.status { margin: 0; padding: 10px 14px; border-radius: 8px; background: var(--panel-hi); }
.status.success { border-inline-start: 4px solid var(--accent); }
.status.warning { border-inline-start: 4px solid var(--warning); }
.status.error { border-inline-start: 4px solid var(--error); }

footer { padding: 16px 24px; color: var(--muted); font-size: 13px; text-align: center; }

/* A clear focus ring for keyboard users. */
:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

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