/* ============================================================
   Glow UI - Markdown Editor
   Dark mode default, light mode via [data-theme="light"]
   ============================================================ */

:root {
  --bg: #121212;
  --bg-card: #181818;
  --bg-hover: #282828;
  --border: #404040;
  --text-muted: #535353;
  --text-secondary: #B3B3B3;
  --text-primary: #FFFFFF;
  --green: #1DB954;
  --green-hover: #1ed760;
  --red: #C0392B;
  --font: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', Menlo, Consolas, monospace;
  --code-bg: #0d1117;
}

[data-theme="light"] {
  --bg: #FFFFFF;
  --bg-card: #F5F5F5;
  --bg-hover: #E8E8E8;
  --border: #D0D0D0;
  --text-muted: #999999;
  --text-secondary: #666666;
  --text-primary: #121212;
  --green: #1DB954;
  --green-hover: #17a349;
  --code-bg: #f6f8fa;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  transition: background 0.2s, color 0.2s;
}

/* ---- Header ---- */
.header {
  background: rgba(18, 18, 18, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  height: 64px;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--border);
}

[data-theme="light"] .header {
  background: rgba(255, 255, 255, 0.9);
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 24px;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 24px;
}

.logo {
  color: var(--green);
  font-weight: 800;
  font-size: 20px;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.header-nav {
  display: flex;
  gap: 8px;
  flex: 1;
}

.header-nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 4px;
  transition: color 0.15s;
}

.header-nav a:hover,
.header-nav a.active {
  color: var(--text-primary);
}

.theme-toggle {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.theme-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ---- 3-column layout ---- */
.layout-3col {
  display: grid;
  grid-template-columns: 180px 1fr 300px;
  gap: 24px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 32px 24px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 88px;
}

/* ---- Main content ---- */
.main-content {
  min-width: 0;
}

.page-header {
  margin-bottom: 16px;
}

.page-header h1 {
  font-size: 36px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: 8px;
}

.page-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
}

/* ---- Toolbar ---- */
.md-toolbar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.md-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.md-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.md-btn:active {
  border-color: var(--green);
  color: var(--green);
}

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

/* ---- Tabs (mobile only) ---- */
.md-tabs {
  display: none;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0;
}

.md-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.md-tab.is-active {
  color: var(--text-primary);
  border-bottom-color: var(--green);
}

/* ---- Split pane ---- */
.md-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
  background: var(--bg-card);
  overflow: hidden;
  min-height: 480px;
}

.md-pane {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.md-pane--editor {
  border-right: 1px solid var(--border);
}

.md-input {
  width: 100%;
  height: 100%;
  min-height: 480px;
  padding: 16px;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.7;
  border: none;
  outline: none;
  resize: vertical;
  tab-size: 2;
}

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

.md-pane--preview {
  background: var(--bg);
}

.md-preview {
  padding: 16px 20px;
  height: 100%;
  min-height: 480px;
  overflow-y: auto;
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.7;
  word-wrap: break-word;
}

/* ---- Preview content styling ---- */
.md-preview h1,
.md-preview h2,
.md-preview h3,
.md-preview h4,
.md-preview h5,
.md-preview h6 {
  color: var(--text-primary);
  font-weight: 700;
  line-height: 1.3;
  margin: 18px 0 10px;
}

.md-preview h1 { font-size: 28px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.md-preview h2 { font-size: 22px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.md-preview h3 { font-size: 18px; }
.md-preview h4 { font-size: 16px; }
.md-preview h5 { font-size: 14px; }
.md-preview h6 { font-size: 13px; color: var(--text-secondary); }

.md-preview p {
  margin: 0 0 12px;
  color: var(--text-primary);
}

.md-preview a {
  color: var(--green);
  text-decoration: underline;
}

.md-preview a:hover {
  color: var(--green-hover);
}

.md-preview strong { font-weight: 700; }
.md-preview em { font-style: italic; }
.md-preview del,
.md-preview s { text-decoration: line-through; color: var(--text-secondary); }

.md-preview ul,
.md-preview ol {
  margin: 0 0 12px;
  padding-left: 24px;
}

.md-preview li {
  margin: 4px 0;
}

.md-preview li > input[type="checkbox"] {
  margin-right: 6px;
}

.md-preview blockquote {
  border-left: 3px solid var(--green);
  padding: 4px 14px;
  margin: 12px 0;
  color: var(--text-secondary);
  background: var(--bg-hover);
  border-radius: 0 4px 4px 0;
}

.md-preview blockquote p { margin: 0; }

.md-preview code {
  font-family: Menlo, Consolas, monospace;
  font-size: 13px;
  background: var(--bg-hover);
  color: var(--green);
  padding: 2px 6px;
  border-radius: 4px;
}

.md-preview pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 12px 0;
}

.md-preview pre code {
  background: transparent;
  color: #e6edf3;
  padding: 0;
  font-size: 13px;
  line-height: 1.6;
}

[data-theme="light"] .md-preview pre code {
  color: #24292f;
}

.md-preview hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}

.md-preview img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}

.md-preview table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 14px;
}

.md-preview th,
.md-preview td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}

.md-preview th {
  background: var(--bg-hover);
  font-weight: 600;
}

.md-preview tbody tr:nth-child(even) {
  background: var(--bg-card);
}

/* ---- Stats bar ---- */
.md-stats {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  margin-top: 16px;
}

.md-stat {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.md-stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--green);
}

.md-stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.md-stat--saved {
  margin-left: auto;
}

.md-saved {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.md-saved::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
}

.md-saved.is-saving::before {
  background: var(--text-muted);
}

/* ---- Action buttons ---- */
.md-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
  margin-bottom: 24px;
}

.btn-primary,
.btn-secondary {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 10px 22px;
  border-radius: 9999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
}

.btn-primary {
  background: var(--green);
  color: #000;
  border: 1px solid var(--green);
}

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

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--green);
  color: var(--green);
}

.btn-clear:hover {
  border-color: var(--red);
  color: var(--red);
}

/* ---- Toast ---- */
.md-toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%) translateY(20px);
  background: var(--text-primary);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 9999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 1000;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

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

/* ---- Mobile ad ---- */
.ad-slot--mobile {
  display: none;
  margin-bottom: 24px;
}

/* ---- Info & FAQ sections ---- */
.info-section {
  margin-bottom: 40px;
}

.info-section h2,
.faq-section h2,
.cross-links h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.section-desc {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.info-section h3 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 20px 0 8px;
}

.info-section p,
.faq-item p {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.75;
  margin-bottom: 12px;
}

.info-section code,
.faq-item code {
  font-family: Menlo, Consolas, monospace;
  font-size: 13px;
  background: var(--bg-hover);
  color: var(--green);
  padding: 1px 6px;
  border-radius: 4px;
}

/* ---- Cheat table ---- */
.cheat-table-wrap {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.cheat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.cheat-table thead th {
  background: var(--bg-hover);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.cheat-table tbody tr {
  border-bottom: 1px solid var(--border);
}

.cheat-table tbody tr:last-child {
  border-bottom: none;
}

.cheat-table tbody tr:hover {
  background: var(--bg-hover);
}

.cheat-table tbody td {
  padding: 10px 16px;
  color: var(--text-primary);
}

.cheat-table tbody td:first-child {
  width: 45%;
}

.cheat-table tbody code {
  font-family: Menlo, Consolas, monospace;
  font-size: 13px;
  background: var(--bg-hover);
  color: var(--green);
  padding: 2px 8px;
  border-radius: 4px;
}

/* ---- FAQ ---- */
.faq-section {
  margin-bottom: 40px;
}

.faq-item {
  border-top: 1px solid var(--border);
  padding: 20px 0;
}

.faq-item h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
}

/* ---- Cross-links ---- */
.cross-links {
  padding: 32px 0;
  border-top: 1px solid var(--border);
  margin-bottom: 24px;
}

.cross-links-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.service-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.service-card:hover {
  background: var(--bg-hover);
  border-color: var(--green);
  transform: scale(1.02);
}

.service-icon {
  font-size: 24px;
}

.service-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.service-desc {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ---- Ad slots ---- */
.ad-slot {
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bg-card);
  border-radius: 4px;
  overflow: hidden;
}

.ad-slot--bottom {
  margin-bottom: 24px;
}

.ad-slot--sticky {
  position: sticky;
  top: 88px;
}

/* ---- Footer ---- */
.footer {
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 32px 24px;
  text-align: center;
}

.footer-links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin-bottom: 12px;
}

.footer-links a {
  color: var(--text-secondary);
  font-size: 14px;
  text-decoration: none;
  transition: color 0.15s;
}

.footer-links a:hover {
  color: var(--text-primary);
}

.footer-copyright {
  font-size: 13px;
  color: var(--text-muted);
}

/* ---- Responsive ---- */

/* 1024px: collapse left + right sidebars per spec */
@media (max-width: 1024px) {
  .layout-3col {
    grid-template-columns: 1fr;
  }
  .sidebar-left,
  .sidebar-right {
    display: none;
  }
  .ad-slot--mobile {
    display: flex;
  }
}

/* 768px: stack panes vertically with tab switcher */
@media (max-width: 768px) {
  .layout-3col {
    padding: 16px;
    gap: 16px;
  }
  .page-header h1 {
    font-size: 28px;
  }
  .header-nav {
    display: none;
  }

  .md-tabs {
    display: flex;
  }

  .md-split {
    grid-template-columns: 1fr;
    min-height: 400px;
  }

  .md-pane {
    display: none;
    min-height: 400px;
  }

  .md-pane--editor.editor-pane--active,
  .md-pane--preview.preview-pane--active {
    display: flex;
  }

  .md-pane--editor {
    border-right: none;
  }

  .md-input,
  .md-preview {
    min-height: 400px;
  }

  .cross-links-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  .md-toolbar {
    gap: 2px;
  }
  .md-btn {
    width: 32px;
    height: 32px;
    font-size: 13px;
  }
  .md-divider {
    margin: 0 2px;
  }
  .cross-links-grid {
    grid-template-columns: 1fr;
  }
  .md-actions .btn-primary,
  .md-actions .btn-secondary {
    flex: 1 1 calc(50% - 4px);
    padding: 10px 12px;
    font-size: 12px;
  }
}
