/* TxTtran… — "Paper & Laser"
   The world this tool lives in: text becoming a barcode — ink on paper,
   read by a laser. Neutral paper ground, ink-black structure, one
   laser-red signal. Display face: Space Grotesk. Data face: JetBrains Mono. */

@font-face {
  font-family: "Space Grotesk";
  src: url("fonts/space-grotesk-latin-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Space Grotesk";
  src: url("fonts/space-grotesk-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/jetbrains-mono-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/jetbrains-mono-latin-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}

:root {
  color-scheme: light dark;

  --paper: #f6f6f4;
  --panel: #ffffff;
  --ink: #17171a;
  --muted: #6e6d68;
  --line: #e3e2dd;
  --signal: #e11d2e;
  --ok: #15803d;
  --warn: #b45309;
  --over: #c0292f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(23, 23, 26, 0.05), 0 12px 32px -12px rgba(23, 23, 26, 0.14);

  --font-body: system-ui, -apple-system, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --font-display: "Space Grotesk", var(--font-body);
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", "Cascadia Mono",
    Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121214;
    --panel: #1b1b1e;
    --ink: #edede8;
    --muted: #9a998f;
    --line: #2c2c30;
    --signal: #ff4d5a;
    --ok: #34d399;
    --warn: #fbbf24;
    --over: #ff6b6b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 12px 32px -12px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }

::selection { background: color-mix(in srgb, var(--signal) 22%, transparent); }

:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 40px 20px;
}

.app {
  width: 100%;
  max-width: 960px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

/* ── Header ── */

.app-header {
  grid-column: 1 / -1;
  padding: 4px 2px 16px;
}
.app-header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 30px;
  letter-spacing: -0.02em;
}
.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.7;
  letter-spacing: 0.01em;
}

/* ── Panels ── */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.input-panel { display: flex; flex-direction: column; gap: 12px; }

#input {
  width: 100%;
  min-height: 320px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.65;
}
#input::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
#input:focus {
  outline: 2px solid var(--ink);
  outline-offset: -1px;
}

.input-actions { display: flex; justify-content: flex-end; }

.privacy-hint {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--warn) 55%, var(--line));
  border-radius: 10px;
  background: color-mix(in srgb, var(--warn) 9%, transparent);
  color: var(--ink);
  font-size: 13px;
}
.privacy-hint.hidden { display: none; }
.info-hint {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--ink) 25%, var(--line));
  border-radius: 10px;
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  color: var(--muted);
  font-size: 13px;
}
.info-hint.hidden { display: none; }
@media (prefers-color-scheme: dark) {
  .privacy-hint {
    border-color: color-mix(in srgb, var(--warn) 75%, var(--line));
    background: color-mix(in srgb, var(--warn) 15%, transparent);
  }
}

/* ── QR stage ── */

.qr-panel { display: flex; flex-direction: column; align-items: center; gap: 14px; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  border: 1px solid var(--line);
  color: var(--muted);
}
.status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 14%, transparent);
}
.status[data-level="ok"]   { color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 45%, var(--line));   background: color-mix(in srgb, var(--ok) 8%, transparent); }
.status[data-level="warn"] { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); background: color-mix(in srgb, var(--warn) 8%, transparent); }
.status[data-level="over"] { color: var(--over); border-color: color-mix(in srgb, var(--over) 45%, var(--line)); background: color-mix(in srgb, var(--over) 8%, transparent); }

.output {
  position: relative;
  overflow: hidden;
  min-height: 340px;
  display: flex;
  justify-content: center;
  align-items: center;
  align-self: stretch;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff; /* the scan surface stays paper-white in both modes */
  padding: 16px 16px;
}
.output svg { width: 100%; height: auto; max-width: 400px; display: block; position: relative; z-index: 1; }
.placeholder { color: var(--muted); font-size: 14px; text-align: center; line-height: 1.8; }

.meta {
  min-height: 20px;
  color: var(--muted);
  font-size: 12px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
/* ── 分片工具条 ── */

.shard-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  justify-content: center;
}
.shard-bar.hidden { display: none; }
.shard-progress {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.shard-dots { display: inline-flex; gap: 5px; }
.shard-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line);
  transition: background 0.15s;
}
.shard-dot.active { background: var(--signal); box-shadow: 0 0 5px color-mix(in srgb, var(--signal) 60%, transparent); }

.output-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

/* ── History ── */

.history-panel { grid-column: 1 / -1; }

.history-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.history-head h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: 0.02em; }
.history-count { color: var(--muted); font-size: 12px; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.history-spacer { flex: 1; }

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--panel);
  cursor: pointer;
  transition: border-color 0.15s;
}
.history-item:hover { border-color: var(--signal); }
.history-item .h-preview {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item .h-time {
  color: var(--muted);
  font-size: 11px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.history-item .h-del {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}
.history-item .h-del:hover { color: var(--signal); background: color-mix(in srgb, var(--signal) 10%, transparent); }
.history-empty { margin: 8px 0 0; }

/* ── Buttons ── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 9px;
  padding: 9px 16px;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 13.5px;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s, transform 0.1s;
}
.btn:hover:not(:disabled) { border-color: var(--ink); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn.primary:hover:not(:disabled) { background: var(--signal); border-color: var(--signal); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { color: var(--signal); border-color: transparent; }
.btn.small { padding: 5px 12px; font-size: 13px; border-radius: 8px; }
.btn.link {
  border: none;
  background: none;
  color: var(--ink);
  padding: 0 4px;
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.btn.link:hover { color: var(--signal); }

/* ── Toast ── */

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 16px);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── Responsive ── */
/* ── 模式切换、域名设置、解码页 ── */

.mode-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  background: var(--paper);
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 13px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.seg-btn:hover:not([aria-pressed="true"]) { color: var(--ink); }
.mode-hint {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

/* ── 解码页（扫码打开 #d= 链接）── */

#decode { display: none; max-width: 640px; margin: 40px auto 0; }
.decode-mode #decode { display: flex; flex-direction: column; gap: 14px; }
.decode-mode .app { display: none; }
.decode-text {
  width: 100%;
  min-height: 320px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.65;
}
.decode-error { color: var(--over); font-size: 13px; }
.decode-note { margin: 0; color: var(--muted); font-size: 12px; text-align: center; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .history-panel { grid-column: 1; }
  #input { min-height: 180px; }
  .output { min-height: 260px; }
  .app-header h1 { font-size: 26px; }
  .mode-row { flex-wrap: wrap; }
  .mode-hint { flex-basis: 100%; }
  .decode-text { min-height: 220px; }
  #decode { margin-top: 20px; }
}
