:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --border: #dfe3ec;
  --text: #0f172a;
  --muted: #5b6477;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-text: #ffffff;
  --ok: #15803d;
  --ok-bg: #e9f8ef;
  --err: #c2261d;
  --err-bg: #fdecea;
  --warn: #a15c00;
  --warn-bg: #fff5e0;
  --band: rgba(220, 38, 38, .12);
  --gutter-text: #9aa3b5;
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
  --line: 20px;
  --pad: 12px;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020; --surface: #121a2e; --surface-2: #18223a; --border: #26324f;
    --text: #e6eaf2; --muted: #94a0b8; --accent: #818cf8; --accent-hover: #a5b4fc; --accent-text: #0b1020;
    --ok: #4ade80; --ok-bg: rgba(74, 222, 128, .1); --err: #f87171; --err-bg: rgba(248, 113, 113, .12);
    --warn: #fbbf24; --warn-bg: rgba(251, 191, 36, .1); --band: rgba(248, 113, 113, .16); --gutter-text: #56627e;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1020; --surface: #121a2e; --surface-2: #18223a; --border: #26324f;
  --text: #e6eaf2; --muted: #94a0b8; --accent: #818cf8; --accent-hover: #a5b4fc; --accent-text: #0b1020;
  --ok: #4ade80; --ok-bg: rgba(74, 222, 128, .1); --err: #f87171; --err-bg: rgba(248, 113, 113, .12);
  --warn: #fbbf24; --warn-bg: rgba(251, 191, 36, .1); --band: rgba(248, 113, 113, .16); --gutter-text: #56627e;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 650; font-size: 17px; }
.logo {
  font-family: var(--mono); font-weight: 700; font-size: 14px;
  background: var(--accent); color: var(--accent-text); border-radius: 8px; padding: 3px 7px;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.privacy { color: var(--muted); font-size: 13px; }
.icon-btn {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 16px;
}

.wrap { width: 100%; max-width: 1200px; margin: 0 auto; padding: 18px 20px 24px; flex: 1; }

/* Toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; margin-bottom: 12px; }
.group { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-size: 14px; font-weight: 550; cursor: pointer;
  transition: background .15s, border-color .15s;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .icon-btn:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.danger:hover { color: var(--err); border-color: var(--err); }
.select select {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 28px 8px 10px; border-radius: 8px; font: inherit; font-size: 14px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%;
  background-size: 5px 5px; background-repeat: no-repeat;
}

/* Status */
.status {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); margin-bottom: 12px; font-size: 14px; min-height: 44px;
}
.status .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.status.ok { background: var(--ok-bg); border-color: transparent; color: var(--ok); }
.status.ok .dot { background: var(--ok); }
.status.err { background: var(--err-bg); border-color: transparent; color: var(--err); }
.status.err .dot { background: var(--err); }
.status #statusText { flex: 1; word-break: break-word; }
.status strong { font-weight: 700; }
.goto {
  border: 1px solid currentColor; background: transparent; color: inherit; border-radius: 6px;
  padding: 3px 10px; font: inherit; font-size: 13px; cursor: pointer; flex: none;
}

/* Editor */
.editor {
  position: relative; display: flex; height: min(62vh, 640px); min-height: 320px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden;
  font-family: var(--mono); font-size: 13.5px; line-height: var(--line);
}
.gutter {
  margin: 0; padding: var(--pad) 10px var(--pad) 12px; min-width: 52px; text-align: right;
  color: var(--gutter-text); background: var(--surface-2); border-right: 1px solid var(--border);
  overflow: hidden; user-select: none; font: inherit; line-height: var(--line); flex: none;
}
#input {
  flex: 1; border: 0; outline: 0; resize: none; margin: 0; padding: var(--pad) 14px;
  background: transparent; color: var(--text); font: inherit; line-height: var(--line);
  white-space: pre; overflow: auto; tab-size: 4; position: relative; z-index: 1;
}
#input::placeholder { color: var(--gutter-text); }
.band {
  position: absolute; left: 0; right: 0; height: var(--line); background: var(--band);
  border-left: 3px solid var(--err); pointer-events: none; z-index: 0;
}
.caret-mark {
  position: absolute; width: 2px; height: var(--line); background: var(--err); pointer-events: none; z-index: 2;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: .25; } }

.footer-bar {
  display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: 12.5px; padding: 8px 2px;
}
.footer-bar #stats { flex: 1; }
kbd {
  font-family: var(--mono); font-size: 11px; border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 4px; padding: 0 4px; background: var(--surface);
}

.warnings {
  background: var(--warn-bg); color: var(--warn); border-radius: var(--radius); padding: 10px 14px; font-size: 14px; margin-top: 6px;
}
.warnings ul { margin: 4px 0 0; padding-left: 18px; }
.warnings button { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }

.about { margin-top: 26px; color: var(--muted); font-size: 14px; }
.about h2 { color: var(--text); font-size: 16px; margin: 0 0 6px; }
.about ul { margin: 0; padding-left: 20px; }

.site-footer { text-align: center; color: var(--muted); font-size: 13px; padding: 18px; border-top: 1px solid var(--border); }
.site-footer a { color: var(--accent); text-decoration: none; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 8px; font-size: 14px;
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 640px) {
  .topbar { padding: 10px 16px; }
  .privacy { display: none; }
  .wrap { padding: 14px 16px 20px; }
  .toolbar, .group { gap: 6px; }
  .btn { padding: 7px 10px; font-size: 13px; }
  .editor { height: 58vh; font-size: 12.5px; }
  .gutter { min-width: 40px; padding-left: 6px; padding-right: 6px; }
  .kbd-hints { display: none; }
}
