/* ── Design tokens ────────────────────────────────────────────── */
:root {
  --bg:           #fffdf5;
  --bg-secondary: #ffffff;
  --bg-editor:    #ffffff;
  --bg-nav:       #ffffff;
  --border:       #fde68a;
  --text:         #1c1400;
  --text-muted:   #78540a;
  --primary:      #d97706;
  --primary-hover:#b45309;
  --primary-light:#fffbeb;
  --accent:       #ea580c;
  --success:      #059669;
  --error:        #dc2626;
  --warning:      #d97706;
  --radius:       10px;
  --radius-sm:    6px;
  --shadow:       0 1px 3px rgba(217,119,6,0.08);
  --shadow-md:    0 4px 16px rgba(217,119,6,0.12);
  --font:         -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono:    "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
  --nav-h:        56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:           #1c1400;
    --bg-secondary: #2d1f00;
    --bg-editor:    #2d1f00;
    --bg-nav:       #2d1f00;
    --border:       #78540a;
    --text:         #fef3c7;
    --text-muted:   #fbbf24;
    --primary:      #fbbf24;
    --primary-hover:#fcd34d;
    --primary-light:#78540a;
    --accent:       #fb923c;
    --shadow:       0 1px 3px rgba(0,0,0,0.5);
    --shadow-md:    0 4px 16px rgba(0,0,0,0.6);
  }
}

[data-theme="dark"] {
  --bg:           #1c1400;
  --bg-secondary: #2d1f00;
  --bg-editor:    #2d1f00;
  --bg-nav:       #2d1f00;
  --border:       #78540a;
  --text:         #fef3c7;
  --text-muted:   #fbbf24;
  --primary:      #fbbf24;
  --primary-hover:#fcd34d;
  --primary-light:#78540a;
  --accent:       #fb923c;
  --shadow:       0 1px 3px rgba(0,0,0,0.5);
  --shadow-md:    0 4px 16px rgba(0,0,0,0.6);
}

[data-theme="light"] {
  --bg:           #fffdf5;
  --bg-secondary: #ffffff;
  --bg-editor:    #ffffff;
  --bg-nav:       #ffffff;
  --border:       #fde68a;
  --text:         #1c1400;
  --text-muted:   #78540a;
  --primary:      #d97706;
  --primary-hover:#b45309;
  --primary-light:#fffbeb;
  --accent:       #ea580c;
  --shadow:       0 1px 3px rgba(217,119,6,0.08);
  --shadow-md:    0 4px 16px rgba(217,119,6,0.12);
}

/* ── Reset ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  font-weight: 400;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Nav ──────────────────────────────────────────────────────── */
.nav {
  height: var(--nav-h);
  background: #ffffff;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 12px rgba(217,119,6,0.15);
}
[data-theme="dark"] .nav { background: var(--bg-nav); box-shadow: none; }
.nav::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: linear-gradient(to right, #d97706, #f59e0b, #ea580c);
}
[data-theme="dark"] .nav::after {
  background: linear-gradient(to right, #fbbf24, #fcd34d, #fb923c);
}
.nav-inner {
  width: 100%;
  max-width: 1560px;
  margin: 0 auto;
  padding: 0 calc(160px + 32px);
  display: flex;
  align-items: center;
  gap: 4px;
}
@media (max-width: 1200px) { .nav-inner { padding: 0 20px; } }

.nav-logo {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--primary);
  text-decoration: none;
  margin-right: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.nav-links { display: flex; align-items: center; gap: 2px; list-style: none; }
.nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 400;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}
.nav-links a:hover { color: var(--primary); background: var(--primary-light); }
.nav-links a.active { color: var(--primary); font-weight: 600; background: var(--primary-light); }

.nav-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.btn-support {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: none;
  text-decoration: none;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-support:hover { background: var(--primary-hover); color: #fff; }
.btn-theme {
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  border: 2px solid color-mix(in srgb, var(--primary) 35%, var(--border));
  background: var(--bg-secondary);
  color: var(--text-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  transition: background 0.15s, color 0.15s;
}
.btn-theme:hover { background: var(--primary-light); color: var(--primary); }

.nav-sister {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}
.nav-sister a { display: flex; align-items: center; justify-content: center; width: 120px; height: 34px; opacity: 0.8; transition: opacity 0.15s; padding: 4px 8px; border: 2px solid color-mix(in srgb, var(--primary) 35%, var(--border)); border-radius: var(--radius-sm); background: var(--bg-secondary); }
.nav-sister a:hover { opacity: 1; }
.nav-sister img { width: 112px; height: auto; }

/* ── Layout ───────────────────────────────────────────────────── */
.page-wrapper {
  flex: 1;
  display: grid;
  grid-template-columns: 160px 1fr 160px;
  gap: 16px;
  max-width: 1560px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px;
  align-items: start;
}
.side-col { width: 160px; position: sticky; top: calc(var(--nav-h) + 24px); }
.side-slot {
  width: 160px; min-height: 600px;
  background: transparent; border: none;
  display: flex; align-items: center; justify-content: center;
  color: transparent; font-size: 0.75rem; text-align: center;
}
main { min-width: 0; padding: 0; grid-column: 2; }

/* ── Page header ──────────────────────────────────────────────── */
.page-header { margin-bottom: 24px; }
.page-header h1 { font-size: 1.6rem; font-weight: 700; margin-bottom: 4px; }
.page-header p { color: var(--text-muted); font-size: 0.95rem; }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 0.875rem; font-weight: 500; cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap; font-family: var(--font);
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-secondary { background: var(--bg-secondary); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--primary-light); border-color: var(--text-muted); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--primary-light); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }

/* ── Select ───────────────────────────────────────────────────── */
select {
  -webkit-appearance: none; appearance: none;
  background: var(--bg-secondary); border: 2px solid color-mix(in srgb, var(--primary) 35%, var(--border));
  color: var(--text); padding: 7px 28px 7px 10px;
  border-radius: var(--radius-sm); font-size: 0.875rem;
  cursor: pointer; font-family: var(--font);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
}
select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

/* ── Editor panels ────────────────────────────────────────────── */
.editor-layout { display: grid; gap: 16px; }
.editor-layout.two-col {
  grid-template-columns: 1fr 1fr;
  height: calc(100vh - 220px);
  min-height: 400px;
}
.editor-layout.two-col .editor-panel { height: 100%; min-height: 0; overflow: hidden; }
.editor-panel {
  display: flex; flex-direction: column;
  border: 2px solid color-mix(in srgb, var(--primary) 35%, var(--border)); border-radius: var(--radius);
  overflow: hidden; background: var(--bg-editor); min-height: 0;
}
.editor-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px; height: 40px; min-height: 40px;
  border-bottom: 1px solid var(--border);
  background: var(--primary); gap: 8px;
}
.editor-panel-title { font-size: 0.8rem; font-weight: 600; color: #fff !important; text-transform: uppercase; letter-spacing: 0.05em; }
.editor-panel-actions { display: flex; gap: 4px; }
.editor-panel-actions .btn-ghost { color: rgba(255,255,255,0.75); }
.editor-panel-actions .btn-ghost:hover { background: rgba(255,255,255,0.15); color: #fff; }

/* ── Line number gutter ───────────────────────────────────────── */
.editor-with-lines { display: flex; flex: 1; min-height: 0; overflow: hidden; }
.line-gutter {
  padding: 16px 10px 16px 12px;
  background: var(--bg-secondary); color: var(--text-muted);
  font-family: var(--font-mono); font-size: 0.9rem; line-height: 1.7;
  text-align: right; user-select: none; min-width: 48px;
  border-right: 1px solid var(--border); overflow: hidden; flex-shrink: 0;
}
.line-gutter div { height: calc(0.9rem * 1.7); }
textarea {
  flex: 1 1 0; width: 100%; height: 100%; min-height: 0;
  padding: 16px; border: none; resize: none;
  font-family: var(--font-mono); font-size: 0.9rem; line-height: 1.7;
  background: var(--bg-editor); color: var(--text);
  outline: none; white-space: pre; overflow-x: auto; overflow-y: auto;
}
textarea::placeholder { color: var(--text-muted); opacity: 0.6; }
.output-area {
  flex: 1; min-height: 0; padding: 16px;
  font-family: var(--font-mono); font-size: 0.9rem; line-height: 1.7;
  overflow: auto; white-space: pre;
}

/* ── Status bar ───────────────────────────────────────────────── */
.status-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; border-top: 1px solid var(--border);
  background: var(--primary-light); font-size: 0.8rem;
  color: var(--text-muted); flex-wrap: wrap; min-height: 36px;
}
.status-badge { display: inline-flex; align-items: center; gap: 4px; font-weight: 500; }
.status-badge.valid   { color: var(--success); }
.status-badge.invalid { color: var(--error); }
.status-badge.idle    { color: var(--text-muted); }

/* ── Toast ────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: var(--radius);
  font-size: 0.875rem; font-weight: 500;
  box-shadow: var(--shadow-md); opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none; z-index: 999;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ── Error message ────────────────────────────────────────────── */
.error-msg {
  color: var(--error);
  background: color-mix(in srgb, var(--error) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--error) 25%, transparent);
  padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 0.875rem; font-family: var(--font-mono);
  margin-top: 8px; display: none;
}
.error-msg.visible { display: block; }

/* ── Diff ─────────────────────────────────────────────────────── */
.diff-added   { background: color-mix(in srgb, var(--success) 12%, transparent); color: var(--success); }
.diff-removed { background: color-mix(in srgb, var(--error)   12%, transparent); color: var(--error); }
.diff-changed { background: color-mix(in srgb, var(--warning)  12%, transparent); color: var(--warning); }
.diff-line    { display: block; padding: 1px 4px; border-radius: 2px; margin: 1px 0; font-family: var(--font-mono); font-size: 0.875rem; }
.diff-key     { font-weight: 600; }
.diff-summary { display: flex; gap: 16px; font-size: 0.875rem; flex-wrap: wrap; }

/* ── Footer ───────────────────────────────────────────────────── */
footer { margin-top: auto; background: #1c1000; color: #8892c8; font-size: 0.875rem; }
.footer-grid {
  max-width: 1560px; margin: 0 auto;
  padding: 40px 20px 32px;
  display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 1fr; gap: 40px;
}
.footer-brand .footer-logo { font-size: 1.1rem; font-weight: 700; color: #fcd34d; margin-bottom: 10px; }
.footer-brand p { color: #78540a; font-size: 0.85rem; line-height: 1.7; max-width: 300px; }
.footer-col h3 { font-size: 0.8rem; font-weight: 600; color: #fcd34d; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 12px; }
.footer-col ul { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.footer-col a { color: #78540a; text-decoration: none; transition: color 0.15s; }
.footer-col a:hover { color: #fcd34d; }
.footer-bottom {
  border-top: 1px solid #78540a;
  max-width: 1560px; margin: 0 auto;
  padding: 16px 20px;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.8rem; color: #78540a; flex-wrap: wrap; gap: 8px;
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 1200px) {
  .page-wrapper { grid-template-columns: 1fr; }
  .side-col { display: none; }
}
@media (max-width: 768px) {
  .editor-layout.two-col { grid-template-columns: 1fr; height: 80vh; }
  .page-header h1 { font-size: 1.3rem; }
  .nav-links a { padding: 6px 8px; font-size: 0.85rem; }
}
@media (max-width: 1200px) { .nav-inner { padding: 0 24px; } }
@media (max-width: 480px) { .page-wrapper { padding: 16px; } .nav-inner { padding: 0 16px; } }
