:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-muted: #f5f8fb;
  --surface-sunken: #eef3f8;
  --ink: #10202f;
  --muted: #52657a;
  --line: #d5dfe9;
  --line-strong: #b9c8d6;
  --accent: #0e7e74;
  --accent-deep: #0a5f58;
  --accent-soft: #e4f6f2;
  --blue: #21598f;
  --blue-soft: #eaf2fb;
  --danger: #a02028;
  --danger-soft: #fdf0f1;
  --warn: #8a5a06;
  --warn-soft: #fdf7e7;
  --success: #14713c;
  --success-soft: #e9f7ee;
  --shadow-card: 0 1px 2px rgba(16, 32, 47, 0.06), 0 12px 32px rgba(16, 32, 47, 0.08);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 9px;
  --font-body: "Segoe UI Variable Text", "Segoe UI", "Aptos", -apple-system, "Helvetica Neue", sans-serif;
  --font-display: "Segoe UI Variable Display", "Bahnschrift", "Segoe UI", "Aptos", sans-serif;
  --font-mono: "Cascadia Code", ui-monospace, "SF Mono", "Consolas", monospace;
  --speed: 180ms;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(14, 126, 116, 0.05), transparent 320px),
    var(--bg);
}

a {
  color: var(--blue);
}

button,
select,
input,
textarea {
  font: inherit;
}

button,
select,
input[type="file"],
input[type="text"],
input[type="range"],
.linkBtn,
summary {
  transition: border-color var(--speed) ease, background-color var(--speed) ease, box-shadow var(--speed) ease, color var(--speed) ease;
}

button,
summary,
.linkBtn {
  cursor: pointer;
}

.page {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  gap: 20px;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  padding: 18px 22px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid rgba(14, 126, 116, 0.28);
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.eyebrow::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.brand h1 {
  margin: 8px 0 0;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 2.6vw, 2.1rem);
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.tagline {
  margin: 6px 0 0;
  max-width: 62ch;
  color: var(--muted);
  line-height: 1.55;
}

.topbarMeta {
  display: grid;
  gap: 10px;
  justify-items: end;
  min-width: 230px;
}

.statusPill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.pillLabel {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.busy {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-width: 88px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--blue-soft);
  border: 1px solid rgba(33, 89, 143, 0.2);
  color: var(--blue);
  font-weight: 700;
}

.busy.on {
  background: var(--accent-soft);
  border-color: rgba(14, 126, 116, 0.3);
  color: var(--accent-deep);
}

.aboutDetails {
  max-width: 420px;
}

.aboutDetails summary {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
  list-style: none;
  user-select: none;
}

.aboutDetails summary::-webkit-details-marker {
  display: none;
}

.aboutDetails summary:hover {
  border-color: var(--line-strong);
  color: var(--ink);
}

.aboutDetails[open] summary {
  border-color: rgba(14, 126, 116, 0.35);
  color: var(--accent-deep);
  background: var(--accent-soft);
}

.aboutBody {
  margin-top: 10px;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-muted);
  text-align: left;
}

.aboutBody p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.6;
}

.aboutBody p:last-child {
  margin-bottom: 0;
}

/* ---------- Workspace ---------- */

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(310px, 0.85fr);
  gap: 14px;
  align-items: start;
}

.mainPanel {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.toolbarStack {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.controlCard {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-muted);
}

.toolbarLabel,
.blockLabel,
.panelLabel {
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.toolbarRow,
.actionRow {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.toolbarNote {
  color: var(--muted);
  font-size: 0.88rem;
}

.toolbarHelper {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

button,
select,
input[type="file"],
.linkBtn {
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 0 14px;
  font-weight: 600;
}

button:hover:not(:disabled),
select:hover:not(:disabled),
input[type="file"]:hover:not(:disabled),
.linkBtn:hover {
  border-color: var(--line-strong);
  background: var(--surface-muted);
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible,
summary:focus-visible,
.linkBtn:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

button.primary {
  background: linear-gradient(160deg, var(--accent), var(--accent-deep));
  border-color: var(--accent-deep);
  color: #fff;
  font-weight: 700;
  padding: 0 22px;
}

button.primary:hover:not(:disabled) {
  background: linear-gradient(160deg, var(--accent-deep), var(--accent-deep));
  border-color: var(--accent-deep);
}

button.active {
  border-color: rgba(14, 126, 116, 0.5);
  background: var(--accent-soft);
  color: var(--accent-deep);
}

button.warn {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: rgba(160, 32, 40, 0.2);
}

button.warn:hover:not(:disabled) {
  background: #fbe4e6;
  border-color: rgba(160, 32, 40, 0.34);
}

button:disabled,
select:disabled,
input:disabled,
.linkBtn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

label.inline {
  min-height: 44px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  display: inline-flex;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92rem;
}

label.inlineSelect {
  padding-right: 6px;
}

label.inlineSelect select {
  min-width: 128px;
}

label.inline input[type="range"] {
  width: 110px;
  accent-color: var(--accent);
}

.textResolveRow {
  flex-wrap: nowrap;
}

.textResolveRow input[type="text"] {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

.textResolveRow input[type="text"]::placeholder {
  color: #8fa1b3;
  font-family: var(--font-body);
}

.textResolveRow input[type="text"]:focus {
  border-color: var(--blue);
}

/* ---------- Canvas ---------- */

.canvasWrap {
  position: relative;
  width: min(100%, 900px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--line-strong);
  background:
    linear-gradient(180deg, rgba(250, 253, 255, 0.97), rgba(255, 255, 255, 0.99)),
    repeating-linear-gradient(0deg, rgba(33, 89, 143, 0.04) 0, rgba(33, 89, 143, 0.04) 1px, transparent 1px, transparent 40px),
    repeating-linear-gradient(90deg, rgba(33, 89, 143, 0.04) 0, rgba(33, 89, 143, 0.04) 1px, transparent 1px, transparent 40px);
}

.canvasWrap.dropReady {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px rgba(14, 126, 116, 0.25);
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#textIn {
  position: absolute;
  display: none;
  min-width: 96px;
  max-width: 190px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--blue);
  box-shadow: 0 10px 24px rgba(33, 89, 143, 0.14);
  outline: none;
  z-index: 20;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.97);
}

.dropHint {
  position: absolute;
  inset: auto 16px 16px 16px;
  display: none;
  justify-content: center;
  align-items: center;
  min-height: 54px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px dashed rgba(14, 126, 116, 0.5);
  background: rgba(228, 246, 242, 0.95);
  color: var(--accent-deep);
  font-weight: 700;
  text-align: center;
  z-index: 10;
  pointer-events: none;
}

.canvasWrap.dropReady .dropHint {
  display: flex;
}

/* ---------- Identify bar & metrics ---------- */

.identifyBar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-muted);
}

.metrics {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-left: auto;
}

.metric {
  display: grid;
  gap: 2px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  min-width: 76px;
}

.metric span {
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.metric strong {
  font-size: 0.86rem;
  font-family: var(--font-mono);
  font-weight: 600;
}

/* ---------- Recovery card ---------- */

.recover {
  display: flex;
  gap: 14px;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(160, 32, 40, 0.3);
  background: var(--danger-soft);
}

.recover strong {
  color: var(--danger);
}

.recoverMsg {
  margin: 6px 0 0;
  color: var(--ink);
  line-height: 1.5;
}

.recoverTips {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

#retryIdentify {
  border-color: rgba(160, 32, 40, 0.35);
  color: var(--danger);
  background: var(--surface);
  font-weight: 700;
}

#retryIdentify:hover:not(:disabled) {
  background: #fbe4e6;
}

/* ---------- Side panel ---------- */

.sidePanel {
  padding: 18px;
  display: grid;
  gap: 16px;
}

.sideBlock {
  display: grid;
  gap: 10px;
}

.fieldRow {
  display: grid;
  gap: 6px;
}

.fieldHead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.miniBtn {
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--blue);
  border-color: rgba(33, 89, 143, 0.3);
  background: var(--surface);
}

.miniBtn:hover:not(:disabled) {
  background: var(--blue-soft);
  border-color: var(--blue);
}

.value {
  min-height: 48px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-muted);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}

.value.mono {
  font-family: var(--font-mono);
  font-size: 0.88rem;
}

.detailValue {
  font-size: 0.86rem;
  color: var(--muted);
}

.recogDetails summary {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 600;
  list-style: none;
  user-select: none;
}

.recogDetails summary::-webkit-details-marker {
  display: none;
}

.recogDetails summary:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.recogDetails[open] summary {
  color: var(--blue);
  border-color: rgba(33, 89, 143, 0.35);
  background: var(--blue-soft);
}

.recogDetails .value {
  margin-top: 8px;
}

.subtleText {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.notice {
  padding: 13px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

.notice strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
}

.linkBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  line-height: 1.4;
  padding: 8px 14px;
}

/* ---------- Batch panel ---------- */

.batchPanel {
  padding: 18px;
  display: grid;
  gap: 12px;
}

.batchHead {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
}

.batchTitle {
  margin: 6px 0 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.batchHelp {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.6;
  max-width: 96ch;
}

.batchProgress {
  display: grid;
  gap: 8px;
}

.progressTrack {
  height: 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-sunken);
  overflow: hidden;
}

.progressBar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--blue));
  transition: width 240ms ease;
}

.progressText {
  color: var(--muted);
  font-size: 0.9rem;
  font-family: var(--font-mono);
}

.batchLog {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  padding: 8px;
}

.batchLog li {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  line-height: 1.45;
}

.batchLog li::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  align-self: center;
}

.batchLog li[data-kind="ok"] {
  background: var(--success-soft);
  color: var(--success);
}

.batchLog li[data-kind="ok"]::before {
  background: var(--success);
}

.batchLog li[data-kind="fail"] {
  background: var(--danger-soft);
  color: var(--danger);
}

.batchLog li[data-kind="fail"]::before {
  background: var(--danger);
}

.batchSummary {
  display: block;
  margin: 0;
  padding: 13px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-muted);
  line-height: 1.55;
}

.batchSummary[data-tone="info"] {
  border-color: rgba(33, 89, 143, 0.22);
  background: var(--blue-soft);
}

.batchSummary[data-tone="success"] {
  border-color: rgba(20, 113, 60, 0.26);
  background: var(--success-soft);
}

.batchSummary[data-tone="mixed"] {
  border-color: rgba(138, 90, 6, 0.22);
  background: var(--warn-soft);
}

.batchSummary[data-tone="error"] {
  border-color: rgba(160, 32, 40, 0.22);
  background: var(--danger-soft);
}

/* ---------- Status ---------- */

.status {
  position: sticky;
  bottom: 12px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  background: #12283c;
  border: 1px solid #1d3a52;
  color: #dbe8fa;
  font-weight: 600;
  line-height: 1.5;
  box-shadow: 0 10px 30px rgba(16, 32, 47, 0.25);
}

.status.err {
  background: #43171d;
  border-color: #5d2129;
  color: #ffd9dc;
}

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .toolbarStack {
    grid-template-columns: 1fr;
  }

  .metrics {
    margin-left: 0;
  }
}

@media (max-width: 680px) {
  .page {
    padding: 12px;
  }

  .topbar,
  .mainPanel,
  .sidePanel,
  .batchPanel {
    padding: 14px;
  }

  .topbarMeta {
    justify-items: stretch;
    min-width: 0;
    width: 100%;
  }

  .toolbarRow,
  .actionRow {
    flex-direction: column;
    align-items: stretch;
  }

  .textResolveRow {
    flex-wrap: wrap;
  }

  .textResolveRow input[type="text"],
  .textResolveRow button {
    width: 100%;
  }

  button,
  select,
  input[type="file"],
  .linkBtn,
  label.inline {
    width: 100%;
  }

  .miniBtn {
    width: auto;
  }

  label.inline {
    justify-content: space-between;
  }

  .identifyBar {
    align-items: stretch;
    flex-direction: column;
  }

  .metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .recover {
    flex-direction: column;
    align-items: stretch;
  }
}

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