:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #f2f4f7;
  --border: #e2e5ea;
  --ink: #16181d;
  --ink-soft: #5a616d;
  --ink-faint: #8a909b;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --danger: #c0392b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.05);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; flex-direction: column; min-height: 100%; height: 100%; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  width: 34px; height: 34px; flex: none; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 17px;
  display: grid; place-items: center;
}

.brand h1 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: 0.01em; }
.brand-sub { margin: 0; font-size: 12px; color: var(--ink-faint); }
.brand-sub.is-warn { color: #a35b00; }

.tabs { display: inline-flex; background: var(--surface-muted); border-radius: 999px; padding: 3px; }

.tab {
  border: 0; background: transparent; color: var(--ink-soft); font: inherit; font-size: 13px;
  padding: 6px 16px; border-radius: 999px; cursor: pointer;
}
.tab.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

main { flex: 1; min-height: 0; padding: 18px 20px 24px; display: flex; }

.panel-view { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.panel-view[hidden] { display: none; }

.toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.direction { display: flex; align-items: center; gap: 8px; }
.field-label { font-size: 12px; color: var(--ink-faint); }

select {
  appearance: none; border: 1px solid var(--border); background: var(--surface);
  border-radius: 9px; padding: 7px 30px 7px 12px; font: inherit; font-size: 13px; color: var(--ink);
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%), linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}

.counter { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--ink-faint); }
.counter.is-over { color: var(--danger); font-weight: 600; }

.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.card {
  display: flex; flex-direction: column; min-height: 240px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}

.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px 10px 16px; border-bottom: 1px solid var(--border);
  font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-faint);
}
.card-actions { display: flex; gap: 6px; }

textarea, .output {
  flex: 1; min-height: 0; width: 100%; border: 0; padding: 14px 16px; font: inherit;
  background: transparent; color: var(--ink); resize: none; outline: none;
}
textarea { line-height: 1.7; }
textarea::placeholder { color: var(--ink-faint); }
.output { overflow: auto; white-space: pre-wrap; word-break: break-word; line-height: 1.7; }
.output .placeholder { color: var(--ink-faint); margin: 0; }

.card-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border-top: 1px solid var(--border); background: #fcfcfd;
  font-size: 12px; color: var(--ink-faint);
}

.btn {
  font: inherit; font-size: 13px; border-radius: 8px; border: 1px solid transparent;
  padding: 7px 14px; cursor: pointer; transition: background 0.15s ease, border-color 0.15s ease;
  background: var(--surface-muted); color: var(--ink-soft);
}
.btn:hover:not(:disabled) { background: #e8ebf0; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #1a5fd0; }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-muted); }
.btn.danger { color: var(--danger); }
.btn.icon { padding: 6px 10px; font-size: 15px; line-height: 1; }

.alert {
  border-radius: 10px; padding: 10px 14px; font-size: 13px;
  background: #fdf0ee; color: #8f2b1e; border: 1px solid #f6d5cf;
}
.alert.is-info { background: var(--accent-soft); color: #17427f; border-color: #d3e2fb; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 12px);
  background: rgba(22, 24, 29, 0.92); color: #fff; font-size: 13px; padding: 9px 16px;
  border-radius: 999px; opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: min(90vw, 420px); text-align: center;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.history-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.history-head h2 { margin: 0 0 4px; font-size: 15px; }
.muted { margin: 0; color: var(--ink-faint); font-size: 12px; }

.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.history-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; display: grid; gap: 8px;
}
.history-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--ink-faint); }
.badge { background: var(--surface-muted); border-radius: 999px; padding: 2px 8px; color: var(--ink-soft); }
.history-pair { display: grid; gap: 6px; }
.history-text { margin: 0; font-size: 13px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
.history-text.source { color: var(--ink-soft); }
.history-actions { display: flex; justify-content: flex-end; gap: 6px; }

.empty { color: var(--ink-faint); font-size: 13px; padding: 28px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }

.connecting { display: grid; place-items: center; gap: 10px; padding: 40px; color: var(--ink-soft); font-size: 14px; }

@media (max-width: 860px) {
  main { padding: 12px; }
  .workspace { grid-template-columns: 1fr; }
  .card { min-height: 200px; }
  .topbar { padding: 12px 14px; }
  .brand h1 { font-size: 15px; }
}

.stack { display: flex; flex-direction: column; gap: 12px; flex: 1; min-height: 0; }
.stack .card { flex: 1; min-height: 150px; }
.sidebar-note { font-size: 12px; color: var(--ink-faint); margin: 0; }
