@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&family=Source+Serif+4:opsz,wght@8..60,400;8..60,500;8..60,600&display=swap');

/* =========================================================================
   WordLab — warm "paper / editorial" design system.
   Light (paper) is the default; a warm dark variant mirrors it.
   ========================================================================= */
:root, [data-theme="light"] {
  --bg: #f6f4ef;          /* page: warm cream */
  --bg-2: #f6f4ef;        /* header blends with page */
  --bg-3: #efeada;        /* subtle raised / hover */
  --panel: #fffdf9;       /* cards: near-white warm */
  --text: #1a1a1a;        /* ink */
  --text-strong: #1a1a1a;
  --editor-text: #262420;
  --text-dim: #96907f;    /* muted labels (taupe) */
  --text-mut: #55503f;    /* secondary / button text */
  --border: #e8e3d6;      /* soft warm border */
  --border-2: #e2ddce;    /* button border */
  --accent: #b0472f;      /* terracotta — links, active, focus */
  --accent-soft: #f0e6dd;
  --accent-2: #5a8f3a;    /* green — success / readability */
  --good: #5a8f3a;
  --warn: #b98a1f;        /* gold */
  --danger: #b0472f;      /* rust */
  --ink: #1a1a1a;         /* dark buttons */
  --ink-text: #f6f4ef;
  --radius: 16px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20,16,0,.03);
  --shadow-pop: 0 8px 30px rgba(20,16,0,.10);
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
[data-theme="dark"] {
  --bg: #1a1815;
  --bg-2: #1a1815;
  --bg-3: #2a2620;
  --panel: #211e1a;
  --text: #f4f0e4;
  --text-strong: #fffdf9;
  --editor-text: #ece7da;
  --text-dim: #a49d87;
  --text-mut: #c5bda8;
  --border: #35322a;
  --border-2: #3d392f;
  --accent: #dd8163;      /* lighter terracotta */
  --accent-soft: #34281f;
  --accent-2: #86bd66;
  --good: #86bd66;
  --warn: #d8ab4e;
  --danger: #e08a72;
  --ink: #f4f0e4;         /* "dark" button inverts on dark bg */
  --ink-text: #1a1815;
  --shadow: 0 1px 2px rgba(0,0,0,.25);
  --shadow-pop: 0 10px 34px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background .25s ease, color .25s ease;
}
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
small { color: var(--text-dim); }
::selection { background: var(--accent-soft); }

/* ========= Header ========= */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 18px 24px;
  background: var(--bg-2);
  position: sticky; top: 0; z-index: 20;
  border-bottom: 1px solid transparent;
}
.brand { display: flex; align-items: center; gap: 13px; text-decoration: none; color: inherit; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 11px; display: block;
  background: var(--ink); object-fit: contain;
}
.brand-text h1, .brand-name { font-size: 20px; font-weight: 700; letter-spacing: -.02em; color: var(--text-strong); display: block; }
.tagline { margin: 2px 0 0; font-size: 12px; color: var(--text-dim); font-family: var(--mono); letter-spacing: -.02em; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.privacy-pill {
  font-size: 12px; font-family: var(--mono); padding: 6px 11px; border-radius: 999px;
  background: transparent; color: var(--text-dim); border: 1px solid var(--border-2);
  white-space: nowrap; letter-spacing: -.02em;
}

/* ========= Site navigation ========= */
.site-nav { display: flex; gap: 2px; flex-wrap: wrap; }
.site-nav a {
  color: var(--text-mut); text-decoration: none; font-size: 14px; font-weight: 500;
  padding: 8px 12px; border-radius: var(--radius-sm); transition: .15s;
}
.site-nav a:hover { color: var(--text); background: var(--bg-3); }
.site-nav a.active { color: var(--accent); }
.footer-nav { display: flex; gap: 4px 18px; justify-content: center; flex-wrap: wrap; margin-bottom: 10px; }
.footer-nav a { color: var(--text-mut); text-decoration: none; font-size: 14px; }
.footer-nav a:hover { color: var(--accent); }

/* ========= Buttons ========= */
.btn {
  font: inherit; font-size: 14px; cursor: pointer; color: var(--text-mut);
  background: var(--panel); border: 1px solid var(--border-2);
  border-radius: var(--radius-sm); padding: 8px 14px; transition: .15s; line-height: 1.2;
}
.btn:hover { border-color: var(--text-dim); color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn.sm { padding: 7px 13px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn-ico { display: inline-flex; align-items: center; vertical-align: -0.15em; margin-right: 6px; }
.btn-ico svg { width: 14px; height: 14px; display: block; }
#themeToggle { display: inline-flex; align-items: center; justify-content: center; }
#themeToggle svg { width: 15px; height: 15px; display: block; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--ink-text); font-weight: 600; }
.btn.primary:hover { opacity: .9; color: var(--ink-text); }
.linkbtn { background: none; border: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }

/* ========= Layout ========= */
.layout {
  display: grid; grid-template-columns: 1fr 340px;
  gap: 20px; padding: 20px 24px; align-items: start; max-width: 1200px; margin: 0 auto;
}
.editor-pane { display: flex; flex-direction: column; min-width: 0; }
.editor-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; align-items: center; }
.toolbar-group { display: flex; gap: 6px; flex-wrap: wrap; }
.push-right { margin-left: auto; }
.file-btn { display: inline-flex; align-items: center; }

.drop-zone { position: relative; }
.editor {
  width: 100%; min-height: 46vh; resize: vertical;
  background: var(--panel); color: var(--editor-text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 26px 28px; font-size: 18px; line-height: 1.65;
  font-family: var(--serif); box-shadow: var(--shadow);
}
.editor::placeholder { color: var(--text-dim); }
.editor:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); }
.drop-zone.dragover .editor { border-color: var(--accent); border-style: dashed; }
.drop-hint {
  position: absolute; inset: 0; display: none; place-items: center;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border-radius: var(--radius); font-weight: 600; color: var(--accent); pointer-events: none;
}
.drop-zone.dragover .drop-hint { display: grid; }

.editor-footer { display: flex; justify-content: space-between; margin-top: 10px; font-size: 13px; }
.mini-count { color: var(--text-dim); font-family: var(--mono); letter-spacing: -.02em; }
.save-state { color: var(--good); font-size: 12px; font-family: var(--mono); }

/* ========= Telemetry ========= */
.telemetry {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; position: sticky; top: 92px;
  box-shadow: var(--shadow);
}
.panel-title { font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--text-dim); margin-bottom: 14px; font-weight: 600; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: transparent; border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.stat b { display: block; font-family: var(--mono); font-weight: 700; font-size: 24px; color: var(--text-strong); letter-spacing: -.03em; }
.stat.primary b { color: var(--text-strong); }
.stat small { font-size: 12px; color: var(--text-dim); }

.time-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-top: 12px; }
.time-card { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 12px; padding: 10px; }
.time-ico { font-size: 16px; opacity: .8; display: inline-flex; align-items: center; justify-content: center; color: var(--text-strong); }
.time-ico svg { width: 16px; height: 16px; display: block; }
.time-card b { font-family: var(--mono); font-weight: 700; font-size: 15px; color: var(--text-strong); letter-spacing: -.02em; }
.time-card small { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-dim); }

.readlevel { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 14px; }
.readlevel-row { display: flex; justify-content: space-between; font-size: 14px; padding: 4px 0; }
.readlevel-row span { color: var(--text-dim); }
.readlevel-row b { color: var(--text-strong); }

/* ========= Detail / tabs ========= */
.detail { padding: 8px 24px 48px; max-width: 1200px; margin: 0 auto; }
.tabs {
  display: flex; gap: 2px; flex-wrap: wrap; border-bottom: 1px solid var(--border);
  margin-bottom: 20px; position: sticky; top: 80px; background: var(--bg); z-index: 10; padding-top: 6px;
}
.tab {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  padding: 11px 15px; font: inherit; font-size: 14px; font-weight: 500; border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-panel { display: none; animation: fade .2s ease; }
.tab-panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: none; } }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 12px; margin-bottom: 20px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); }
.card b { display: block; font-family: var(--mono); font-weight: 700; font-size: 24px; color: var(--text-strong); letter-spacing: -.03em; word-break: break-word; }
.card small { font-size: 13px; color: var(--text-mut); }
.card .card-sub { font-size: 11px; color: var(--text-dim); margin-top: 3px; }
.card.grade b { color: var(--accent-2); }

.note { color: var(--text-dim); font-size: 13px; margin: 4px 0 18px; }

.split-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.split-2 h3 { font-size: 15px; margin-bottom: 10px; font-weight: 650; }
.excerpt {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; font-size: 15px; font-family: var(--serif); color: var(--text-mut); max-height: 170px; overflow: auto;
}

/* Frequency tables */
.freq-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 12px; }
.freq-head h3 { font-size: 15px; font-weight: 650; }
.chk { font-size: 13px; color: var(--text-dim); display: flex; gap: 6px; align-items: center; cursor: pointer; white-space: nowrap; }
.freq-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.freq-table th, .freq-table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); }
.freq-table th { color: var(--text-dim); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.freq-table td:first-child { color: var(--text-dim); font-family: var(--mono); font-size: 12px; }
.freq-table td:last-child, .freq-table th:last-child { text-align: right; font-family: var(--mono); }
.freq-table tbody tr:hover { background: var(--bg-3); }
.bar-cell { position: relative; font-family: var(--mono); font-size: 13px; }
.density-bar { display: inline-block; height: 7px; border-radius: 4px; background: var(--ink); vertical-align: middle; margin-right: 8px; }

/* SEO */
.seo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 20px; }
.field label { display: block; font-size: 13px; margin-bottom: 6px; color: var(--text-mut); font-weight: 500; }
.field input, .field textarea, .ai-config input {
  width: 100%; background: var(--panel); color: var(--text);
  border: 1px solid var(--border-2); border-radius: var(--radius-sm); padding: 10px 12px; font: inherit; font-size: 14px;
}
.field input:focus, .field textarea:focus, .ai-config input:focus { outline: none; border-color: var(--accent); }
.meter { height: 8px; background: var(--bg-3); border-radius: 999px; overflow: hidden; margin: 10px 0 5px; }
.meter.big { height: 12px; }
.meter-fill { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .25s ease, background .25s; }
.meter-fill.good { background: var(--good); }
.meter-fill.warn { background: var(--warn); }
.meter-fill.over { background: var(--danger); }
.outline { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; font-size: 14px; }
.outline .h { display: block; padding: 3px 0; }
.outline .h1 { font-weight: 700; }
.outline .h2 { padding-left: 16px; }
.outline .h3 { padding-left: 32px; color: var(--text-dim); }
.outline .h4 { padding-left: 48px; color: var(--text-dim); }
.hl { background: color-mix(in srgb, var(--warn) 26%, transparent); border-radius: 3px; padding: 0 2px; }

/* Social */
.social-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px,1fr)); gap: 12px; }
.social-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.social-card .sc-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.social-card .sc-name { font-weight: 600; font-size: 14px; }
.social-card .sc-count { font-family: var(--mono); font-size: 12px; color: var(--text-dim); }
.social-card.over .sc-count { color: var(--danger); font-weight: 700; }
.social-card small { font-size: 12px; }

/* Goals */
.goals-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px,1fr)); gap: 16px; }
.goal-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); }
.goal-card label { display: block; font-size: 14px; margin-bottom: 10px; font-weight: 500; }
.goal-card input { width: 100%; margin-top: 8px; background: var(--bg); color: var(--text); border: 1px solid var(--border-2); border-radius: var(--radius-sm); padding: 9px 11px; font: inherit; font-family: var(--mono); }
.goal-card small { font-size: 12px; }

/* Utilities */
.util-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(265px,1fr)); gap: 16px; }
.util-group { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); }
.util-group h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-dim); margin-bottom: 12px; font-weight: 600; }
.util-group .btn { margin: 0 5px 7px 0; }

/* Dropdown */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-pop); padding: 6px; min-width: 195px; display: flex; flex-direction: column; gap: 2px;
}
.dropdown-menu button { text-align: left; background: none; border: none; color: var(--text); padding: 9px 11px; border-radius: var(--radius-sm); cursor: pointer; font: inherit; font-size: 14px; }
.dropdown-menu button:hover { background: var(--bg-3); }
.dropdown-menu[hidden] { display: none; }

/* AI */
.ai-warning { background: color-mix(in srgb, var(--warn) 12%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 38%, transparent); border-radius: 12px; padding: 14px 16px; font-size: 14px; margin-bottom: 16px; }
.ai-config { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px,1fr)); gap: 12px; margin-bottom: 16px; }
.ai-config label { display: block; font-size: 13px; color: var(--text-mut); font-weight: 500; }
.ai-config input { margin-top: 6px; }
.ai-output { margin-top: 18px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; white-space: pre-wrap; font-size: 15px; font-family: var(--serif); box-shadow: var(--shadow); }
.ai-output .ai-actions { margin-top: 14px; display: flex; gap: 8px; }

/* Footer + toast */
.app-footer { border-top: 1px solid var(--border); padding: 24px; color: var(--text-dim); font-size: 13px; text-align: center; }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--ink-text); border: 1px solid var(--ink);
  padding: 11px 18px; border-radius: 10px; box-shadow: var(--shadow-pop);
  opacity: 0; pointer-events: none; transition: .25s; z-index: 100; font-size: 14px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ========= Content pages ========= */
.page-main { max-width: 760px; margin: 0 auto; padding: 40px 24px 72px; }
.prose h1 { font-family: var(--serif); font-size: 36px; line-height: 1.15; margin-bottom: 8px; font-weight: 600; letter-spacing: -.02em; }
.prose .lede { color: var(--text-mut); font-size: 18px; margin: 0 0 28px; font-family: var(--serif); }
.prose h2 { font-family: var(--serif); font-size: 23px; margin: 38px 0 12px; font-weight: 600; }
.prose h3 { font-size: 17px; margin: 26px 0 8px; font-weight: 650; }
.prose p, .prose li { font-size: 16px; line-height: 1.8; color: var(--text); }
.prose ul, .prose ol { padding-left: 24px; margin: 8px 0 16px; }
.prose li { margin: 5px 0; }
.prose a { color: var(--accent); text-underline-offset: 2px; }
.prose strong { font-weight: 650; }
.prose code { font-family: var(--mono); font-size: 13px; background: var(--bg-3); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; }
.prose .callout { background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 10px; padding: 14px 18px; margin: 18px 0; font-size: 15px; box-shadow: var(--shadow); }
.prose .updated { color: var(--text-dim); font-size: 13px; margin-bottom: 30px; font-family: var(--mono); }
.prose table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 14px 0 22px; }
.prose th, .prose td { text-align: left; padding: 9px 11px; border-bottom: 1px solid var(--border); vertical-align: top; }
.prose th { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }

/* FAQ accordions */
.faq-item { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; overflow: hidden; box-shadow: var(--shadow); }
.faq-item summary { cursor: pointer; padding: 16px 18px; font-weight: 600; font-size: 16px; list-style: none; position: relative; }
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: '+'; position: absolute; right: 18px; color: var(--text-dim); font-size: 20px; font-family: var(--mono); }
.faq-item[open] summary::after { content: '–'; }
.faq-item summary:hover { color: var(--accent); }
.faq-item .faq-body { padding: 0 18px 16px; }
.faq-item .faq-body p { margin: 6px 0; line-height: 1.75; }

/* Cookie / storage notice */
.cookie-banner {
  position: fixed; bottom: 18px; left: 18px; right: 18px; max-width: 620px; margin: 0 auto; z-index: 90;
  display: flex; gap: 14px; align-items: center;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 18px; box-shadow: var(--shadow-pop); font-size: 13.5px; line-height: 1.5;
}
.cookie-banner[hidden] { display: none; }
.cookie-banner a { color: var(--accent); }
.cookie-banner .btn { flex-shrink: 0; }

/* ========= Zen mode ========= */
body.zen .telemetry,
body.zen .detail,
body.zen .editor-toolbar,
body.zen .app-footer,
body.zen .site-nav,
body.zen .editor-footer .save-state { display: none; }
body.zen .layout { grid-template-columns: 1fr; max-width: 760px; margin: 0 auto; }
body.zen .editor { min-height: 74vh; font-size: 20px; }
body.zen .editor-footer { justify-content: center; }
body.zen .mini-count { font-size: 15px; }

/* ========= Responsive ========= */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .telemetry { position: static; }
  .split-2, .seo-grid { grid-template-columns: 1fr; }
  .tabs { position: static; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .app-header { flex-wrap: wrap; }
}
@media (max-width: 520px) {
  .tagline { display: none; }
  .editor { padding: 20px; font-size: 17px; }
  .prose h1 { font-size: 29px; }
  .app-header { padding: 14px 16px; }
  .layout, .detail { padding-left: 16px; padding-right: 16px; }
}

/* Print */
@media print {
  .app-header, .editor-toolbar, .tabs, .telemetry, .app-footer, .editor-footer, .header-actions, .site-nav, .cookie-banner { display: none !important; }
  body { background: #fff; color: #000; }
  .tab-panel { display: block !important; }
}
