:root {
  --blue: #0c71c3;
  --blue-strong: #0a5da8;
  --orange: #ff9000;
  --orange-strong: #e07d00;

  --bg: #ffffff;
  --bg-alt: #f0f6fd;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --bg-source: #fbfcfe;

  --text: #1a1a2e;
  --text-muted: #4f4f4f;
  --text-inv: #ffffff;

  --border: #0c71c324;
  --border-strong: #0c71c340;

  --shadow: 0 4px 28px #0c71c31a;
  --shadow-card: 0 2px 16px #0c71c314;
  --shadow-h: 0 10px 48px #0c71c333;

  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;

  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);

  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --bg-alt: #111827;
  --bg-card: #161b22;
  --bg-input: #0d1117;
  --bg-source: #0a0e14;

  --text: #e6edf3;
  --text-muted: #8d96a0;

  --border: #ffffff14;
  --border-strong: #ffffff26;

  --shadow: 0 4px 28px #0000004d;
  --shadow-card: 0 2px 16px #0000004d;
  --shadow-h: 0 10px 48px #00000080;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 100% -10%, color-mix(in oklab, var(--blue) 12%, transparent), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, color-mix(in oklab, var(--orange) 8%, transparent), transparent 60%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--transition), color var(--transition);
}

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-strong) 60%, #083a6a 100%);
  box-shadow: 0 4px 16px color-mix(in oklab, var(--blue) 35%, transparent);
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 4px;
  background: color-mix(in oklab, white 90%, transparent);
  mask: linear-gradient(135deg, #000 35%, transparent 36% 64%, #000 65%);
  -webkit-mask: linear-gradient(135deg, #000 35%, transparent 36% 64%, #000 65%);
}
.brand-name {
  font-size: 15px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Popover (settings) ---------- */
.popover-host { position: relative; }
.popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(360px, calc(100vw - 32px));
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-h);
  padding: 12px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: popover-in 0.15s var(--ease-out);
}
@keyframes popover-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.popover[hidden] { display: none; }
.popover-section { display: flex; flex-direction: column; gap: 6px; }
.popover-section + .popover-section {
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.popover-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.popover .opt {
  display: flex;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  align-items: flex-start;
  transition: background var(--transition);
}
.popover .opt:hover { background: var(--bg-alt); }
.popover .opt input { margin-top: 3px; accent-color: var(--blue); }
.popover .opt > div { flex: 1; min-width: 0; }
.popover .opt > div > div:first-child {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.popover .opt-tag {
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--blue);
  color: #fff;
  padding: 2px 6px;
  border-radius: 999px;
}
.popover .opt-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-top: 2px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font: 500 13px/1 var(--font-sans);
  color: var(--text);
  background: transparent;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition);
  white-space: nowrap;
}
.btn svg {
  flex: none;
}
.btn:hover {
  background: var(--bg-alt);
}
.btn:active {
  transform: translateY(1px);
}
.btn.ghost {
  border-color: var(--border);
}
.btn.primary {
  color: var(--text-inv);
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-strong) 100%);
  box-shadow: 0 6px 20px color-mix(in oklab, var(--blue) 35%, transparent);
}
.btn.primary:hover {
  filter: brightness(1.08);
}
.btn.icon {
  width: 36px;
  padding: 0;
  justify-content: center;
  border: 1px solid var(--border);
}

.btn.icon .icon-moon {
  display: none;
}
[data-theme="dark"] .btn.icon .icon-sun {
  display: none;
}
[data-theme="dark"] .btn.icon .icon-moon {
  display: block;
}

/* ---------- Layout ---------- */
.shell {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 24px 48px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
}

.tg {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.tbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.tbtn:hover {
  background: color-mix(in oklab, var(--blue) 8%, transparent);
  color: var(--blue);
}
.tbtn.is-active {
  background: color-mix(in oklab, var(--blue) 14%, transparent);
  color: var(--blue);
}
.tbtn.color {
  position: relative;
  cursor: pointer;
}
.tbtn.color input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: 0;
  padding: 0;
}

.select {
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: 500 13px/1 var(--font-sans);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238d96a0' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 26px;
}
.select:hover {
  background-color: color-mix(in oklab, var(--blue) 8%, transparent);
}
.select option {
  background: var(--bg-card);
  color: var(--text);
}

.sep {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 4px;
}

/* ---------- Panes ---------- */
.panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: calc(100vh - 240px);
}
.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.pane + .pane {
  border-left: 1px solid var(--border);
}
.pane-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: color-mix(in oklab, var(--bg-alt) 50%, transparent);
}
.pane-title {
  flex: 1;
}
.pane-hint {
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: color-mix(in oklab, var(--blue) 12%, transparent);
  color: var(--blue);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.dot-blue { background: var(--blue); box-shadow: 0 0 0 3px color-mix(in oklab, var(--blue) 18%, transparent); }
.dot-orange { background: var(--orange); box-shadow: 0 0 0 3px color-mix(in oklab, var(--orange) 18%, transparent); }

/* ---------- Editor ---------- */
.editor {
  flex: 1;
  padding: 28px 32px;
  outline: none;
  overflow: auto;
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg-card);
  caret-color: var(--blue);
}
.editor:focus-visible {
  box-shadow: inset 0 0 0 2px color-mix(in oklab, var(--blue) 25%, transparent);
}
.editor h1, .editor h2, .editor h3 {
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 1.2em 0 0.5em;
}
.editor h1 { font-size: 1.875rem; }
.editor h2 { font-size: 1.5rem; }
.editor h3 { font-size: 1.25rem; }
.editor p { margin: 0.6em 0; }
.editor a { color: var(--blue); text-decoration: underline; text-underline-offset: 2px; }
.editor blockquote {
  margin: 1em 0;
  padding: 0.6em 1em;
  border-left: 3px solid var(--blue);
  color: var(--text-muted);
  background: color-mix(in oklab, var(--blue) 5%, transparent);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}
.editor pre {
  margin: 1em 0;
  padding: 1em;
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  white-space: pre-wrap;
  overflow: auto;
}
.editor code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 0.1em 0.4em;
  background: color-mix(in oklab, var(--blue) 8%, transparent);
  color: var(--blue);
  border-radius: 4px;
}
.editor pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}
.editor img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
}
.editor ul, .editor ol { padding-left: 1.5em; }
.editor hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.5em 0;
}
.editor :is(h1,h2,h3,p,ul,ol,blockquote,pre):first-child { margin-top: 0; }

/* ---------- Source ---------- */
.source {
  flex: 1;
  width: 100%;
  resize: none;
  border: 0;
  outline: none;
  padding: 28px 32px;
  font: 400 13.5px/1.6 var(--font-mono);
  color: var(--text);
  background: var(--bg-source);
  tab-size: 2;
  -moz-tab-size: 2;
}
.source:focus-visible {
  box-shadow: inset 0 0 0 2px color-mix(in oklab, var(--orange) 22%, transparent);
}

/* ---------- Footnote / kbd ---------- */
.footnote {
  text-align: center;
  margin: 24px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}
.footnote a {
  color: var(--blue);
  text-decoration: none;
  font-weight: 600;
}
.footnote a:hover { text-decoration: underline; }
.kbd {
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 20px);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-h);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
}
.toast.is-show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .panes { grid-template-columns: 1fr; }
  .pane + .pane { border-left: 0; border-top: 1px solid var(--border); }
  .topbar { padding: 14px 16px; }
  .topbar-actions .btn:not(.icon) span { display: none; }
  .topbar-actions .btn:not(.icon) { padding: 0; width: 36px; justify-content: center; }
  .shell { padding: 16px 12px 32px; }
  .editor, .source { padding: 20px; }
}

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