/* 默认浅色；深色通过 html[data-theme="dark"] 切换 */
:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --bg-elevated: #ffffff;
  --bg-hover: #e8edf3;
  --border: #d0dae4;
  --text: #1a2433;
  --text-muted: #5a6b7d;
  --accent: #2563eb;
  --accent-dim: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --accent-soft-border: rgba(37, 99, 235, 0.22);
  --ok: #059669;
  --err: #dc2626;
  --warn: #b45309;
  --editor-bg: #ffffff;
  --editor-text: #1e3a5f;
  --header-bg: rgba(255, 255, 255, 0.92);
  --body-gradient-top: #fafbfc;
  --noise-opacity: 0.025;
  --primary-on-accent: #ffffff;
  --status-ok-bg: rgba(5, 150, 105, 0.08);
  --status-ok-border: rgba(5, 150, 105, 0.22);
  --status-err-bg: rgba(220, 38, 38, 0.06);
  --status-err-border: rgba(220, 38, 38, 0.2);
  --editor-ok-border: rgba(5, 150, 105, 0.45);
  --editor-err-border: rgba(220, 38, 38, 0.45);
  --editor-err-shadow: rgba(220, 38, 38, 0.12);
  --font-sans: "Noto Sans SC", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", "SF Mono", ui-monospace, monospace;
  --radius: 6px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0f12;
  --bg-elevated: #12171c;
  --bg-hover: #1a2229;
  --border: #2a3540;
  --text: #c8d4dc;
  --text-muted: #6b7d8a;
  --accent: #5eb8ff;
  --accent-dim: #3a8fd4;
  --accent-soft: rgba(94, 184, 255, 0.12);
  --accent-soft-border: rgba(94, 184, 255, 0.25);
  --ok: #3dd68c;
  --err: #f08070;
  --warn: #e8b84a;
  --editor-bg: #0a0e11;
  --editor-text: #a8d4f0;
  --header-bg: rgba(12, 15, 18, 0.92);
  --body-gradient-top: #0e1216;
  --noise-opacity: 0.04;
  --primary-on-accent: #0c0f12;
  --status-ok-bg: rgba(61, 214, 140, 0.08);
  --status-ok-border: rgba(61, 214, 140, 0.2);
  --status-err-bg: rgba(240, 128, 112, 0.08);
  --status-err-border: rgba(240, 128, 112, 0.25);
  --editor-ok-border: rgba(61, 214, 140, 0.4);
  --editor-err-border: rgba(240, 128, 112, 0.55);
  --editor-err-shadow: rgba(240, 128, 112, 0.1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, var(--accent-soft), transparent),
    linear-gradient(180deg, var(--body-gradient-top) 0%, var(--bg) 40%);
  transition: background-color 0.2s ease, color 0.2s ease;
}

.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: var(--noise-opacity);
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  z-index: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
  backdrop-filter: blur(12px);
}

.header-inner {
  position: relative;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 1rem;
  padding-right: 11rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.prompt {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--accent);
  font-size: 1.1rem;
}

h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.badge {
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-soft-border);
}

.header-actions {
  position: absolute;
  top: 1.25rem;
  right: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 4.5rem;
  justify-content: center;
}

.theme-toggle__icon {
  font-size: 0.95rem;
  line-height: 1;
}

.home-link {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--accent-soft-border);
  border-radius: var(--radius);
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.home-link:hover,
.home-link:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  filter: brightness(0.97);
}

[data-theme="dark"] .home-link:hover,
[data-theme="dark"] .home-link:focus-visible {
  filter: none;
  background: rgba(94, 184, 255, 0.13);
}

.subtitle {
  margin: 0.35rem 0 0.85rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.btn {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.4rem 0.75rem;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent-dim);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn--primary {
  color: var(--primary-on-accent);
  background: var(--accent);
  border-color: var(--accent);
}

.btn--primary:hover {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
}

.btn--ghost {
  color: var(--text-muted);
  background: transparent;
}

.indent-select select {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  padding: 0.4rem 0.55rem;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

.main {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.5rem 2rem;
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 1.25rem;
  min-height: calc(100vh - 200px);
}

.editor-panel {
  min-width: 0;
  padding-top: 1rem;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.meta {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.editor-wrap {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--editor-bg);
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.editor-wrap.is-error {
  border-color: var(--editor-err-border);
  box-shadow: 0 0 0 3px var(--editor-err-shadow);
}

.editor-wrap.is-ok {
  border-color: var(--editor-ok-border);
}

.line-gutter {
  position: absolute;
  top: 0;
  left: 0;
  width: 2.75rem;
  padding: 0.75rem 0.35rem 0.75rem 0;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.55;
  color: var(--text-muted);
  opacity: 0.55;
  pointer-events: none;
  user-select: none;
  white-space: pre;
}

.editor {
  display: block;
  width: 100%;
  min-height: 420px;
  max-height: calc(100vh - 280px);
  margin: 0;
  padding: 0.75rem 0.75rem 0.75rem 3.25rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--editor-text);
  background: transparent;
  border: none;
  outline: none;
  resize: vertical;
  tab-size: 2;
}

.editor::placeholder {
  color: var(--text-muted);
}

.status {
  margin: 0.65rem 0 0;
  font-size: 0.85rem;
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
}

.status--idle {
  color: var(--text-muted);
}

.status--ok {
  color: var(--ok);
  background: var(--status-ok-bg);
  border-color: var(--status-ok-border);
}

.status--err {
  color: var(--err);
  background: var(--status-err-bg);
  border-color: var(--status-err-border);
}

.info-panel {
  padding-top: 1rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.info-panel p {
  margin: 0 0 0.75rem;
}

.hints {
  margin: 0 0 1.25rem;
  padding: 0;
  list-style: none;
}

.hints li {
  margin-bottom: 0.35rem;
}

kbd {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text);
}

.footer {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1rem 1.5rem 2rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  background: var(--bg-elevated);
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  border-radius: var(--radius);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  pointer-events: none;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] .toast {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

@media (max-width: 860px) {
  .header-inner {
    padding-top: 1rem;
    padding-right: 1.5rem;
  }

  .header-actions {
    position: static;
    margin-top: 0.75rem;
    justify-content: flex-start;
  }

  .main {
    grid-template-columns: 1fr;
  }

  .info-panel {
    border-top: 1px solid var(--border);
    padding-top: 1.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}
