:root {
  --bg: #0d0f14;
  --surface: #151820;
  --surface2: #1c2030;
  --surface3: #232840;
  --accent: #6c8fff;
  --accent2: #a78bfa;
  --gold: #f4c97e;
  --text: #e8ecf4;
  --muted: #7a83a0;
  --border: #2a3050;
  --success: #4ade80;
  --danger: #f87171;
  --radius: 12px;
  --radius-lg: 20px;
  --shadow: 0 8px 32px rgba(0,0,0,0.35);
  --transition: 0.18s ease;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: 15px;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── LAYOUT ── */
.app { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.mobile-topbar { display: none; }

/* ── SIDEBAR ── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  z-index: 200;
}
.sidebar-overlay { display: none; }
.sidebar-close-btn { display: none; }
.sidebar-logo {
  padding: 28px 24px 20px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo h1 {
  font-family: 'Playfair Display', serif;
  font-size: 22px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}
.sidebar-logo p { font-size: 12px; color: var(--muted); margin-top: 4px; }

.sidebar-nav { padding: 16px 12px; flex: 1; }
.nav-group { margin-bottom: 8px; }
.nav-group-label {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 1.5px; color: var(--muted); padding: 8px 12px 4px;
}
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px; border-radius: 8px;
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-family: inherit; font-size: 14px;
  transition: all var(--transition); text-align: left;
}
.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active {
  background: linear-gradient(135deg, #1a2050, #1e1840);
  color: var(--accent);
}
.nav-btn .icon { width: 18px; height: 18px; opacity: 0.85; flex-shrink: 0; }
.nav-badge {
  margin-left: auto; background: var(--accent); color: white;
  font-size: 10px; padding: 2px 6px; border-radius: 20px; font-weight: 600;
}

/* ── MAIN ── */
.main { overflow-y: auto; }
.panel { display: none; padding: 40px 48px; min-height: 100vh; animation: fadeIn 0.25s ease; }
.panel.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.panel-header { margin-bottom: 36px; }
.panel-header h2 {
  font-family: 'Playfair Display', serif; font-size: 32px;
  background: linear-gradient(135deg, var(--text), var(--muted));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.panel-header p { color: var(--muted); margin-top: 6px; font-size: 14px; }

/* ── FORM ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
label {
  font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.8px;
}
input, textarea, select {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-family: inherit;
  font-size: 14px; padding: 10px 14px; transition: border var(--transition);
  outline: none; width: 100%;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
select option { background: var(--surface2); }

/* ── SECTION CARD ── */
.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  margin-bottom: 28px;
}
.section-card h3 {
  font-family: 'Playfair Display', serif; font-size: 18px;
  margin-bottom: 20px; display: flex; align-items: center; gap: 10px;
}
.section-card h3 .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  flex-shrink: 0;
}

/* ── TEMPLATE GRID ── */
.template-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.template-card {
  border: 2px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: all 0.2s; position: relative;
}
.template-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.template-card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(108,143,255,0.2); }
.template-preview {
  height: 120px; display: flex; flex-direction: column;
  justify-content: center; align-items: center; gap: 6px;
  font-size: 11px; padding: 12px; position: relative; overflow: hidden;
}
.tpl-classic { background: linear-gradient(160deg, #1a1e30 0%, #0e1120 100%); }
.tpl-modern  { background: linear-gradient(160deg, #0d1a1a 0%, #0a1510 100%); }
.tpl-minimal { background: linear-gradient(160deg, #1a1510 0%, #100e08 100%); }
.tpl-academic{ background: linear-gradient(160deg, #12101a 0%, #0a0812 100%); }
.tpl-bold    { background: linear-gradient(160deg, #1a0a10 0%, #0e0510 100%); }
.tpl-elegant { background: linear-gradient(160deg, #0a1218 0%, #060e14 100%); }
.tpl-bar { width: 60%; height: 2px; border-radius: 2px; }
.tpl-classic .tpl-bar { background: #6c8fff; }
.tpl-modern  .tpl-bar { background: #4ade80; }
.tpl-minimal .tpl-bar { background: #f4c97e; }
.tpl-academic .tpl-bar { background: #a78bfa; }
.tpl-bold .tpl-bar { background: #f87171; }
.tpl-elegant .tpl-bar { background: #67e8f9; }
.tpl-line { width: 80%; height: 1px; background: rgba(255,255,255,0.1); }
.tpl-line.short { width: 50%; }
.tpl-name {
  font-size: 12px; text-align: center; padding: 8px;
  background: var(--surface2); color: var(--text); font-weight: 500;
}
.template-card.selected .tpl-name { background: rgba(108,143,255,0.15); color: var(--accent); }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 22px; border-radius: 8px; border: none;
  cursor: pointer; font-family: inherit;
  font-size: 14px; font-weight: 500; transition: all var(--transition);
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
}
.btn-primary:hover { opacity: 0.92; transform: translateY(-1px); box-shadow: 0 8px 24px rgba(108,143,255,0.3); }
.btn-secondary {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-success { background: linear-gradient(135deg, #22c55e, #16a34a); color: white; }
.btn-success:hover { opacity: 0.92; }
.btn-danger { background: var(--surface2); border: 1px solid var(--danger); color: var(--danger); }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 24px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none !important; }

/* ── PREVIEW ── */
#preview-frame {
  background: white; border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: 0 0 0 1px var(--border), 0 24px 80px rgba(0,0,0,0.5);
  min-height: 500px;
}
.preview-cover {
  min-height: 500px; padding: 60px;
  display: flex; flex-direction: column;
  position: relative; overflow: hidden;
  color: #1a1a2e;
  font-family: 'Times New Roman', serif;
}

/* ── REFERENCE STYLES ── */
.ref-entry {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px;
}
.ref-entry-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.ref-entry-title { font-weight: 500; color: var(--text); font-size: 14px; flex: 1; }
.ref-entry-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.ref-formatted {
  font-size: 13px; color: var(--text); margin-top: 10px;
  padding: 10px 12px; background: var(--surface3); border-radius: 6px;
  font-family: 'DM Mono', monospace; line-height: 1.6;
  border-left: 2px solid var(--accent);
}
.ref-actions { display: flex; gap: 6px; flex-shrink: 0; }
.ref-btn {
  background: var(--surface3); border: 1px solid var(--border);
  color: var(--muted); padding: 4px 10px; border-radius: 6px;
  cursor: pointer; font-size: 12px; transition: all var(--transition);
}
.ref-btn:hover { border-color: var(--accent); color: var(--accent); }
.ref-type-badge {
  font-size: 10px; padding: 2px 8px; border-radius: 20px;
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
}
.badge-journal { background: rgba(108,143,255,0.2); color: var(--accent); }
.badge-book { background: rgba(167,139,250,0.2); color: var(--accent2); }
.badge-website { background: rgba(244,201,126,0.2); color: var(--gold); }
.badge-thesis { background: rgba(74,222,128,0.2); color: var(--success); }
.badge-conference { background: rgba(248,113,113,0.2); color: var(--danger); }

/* ── TABS ── */
.style-tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.style-tab {
  padding: 7px 16px; border-radius: 20px; cursor: pointer;
  font-size: 13px; font-weight: 500; border: 1px solid var(--border);
  background: var(--surface2); color: var(--muted); transition: all var(--transition);
}
.style-tab.active { background: var(--accent); border-color: var(--accent); color: white; }
.style-tab:hover:not(.active) { border-color: var(--accent); color: var(--accent); }

/* ── PASTE AREA ── */
.paste-area {
  background: var(--surface2); border: 2px dashed var(--border);
  border-radius: var(--radius); padding: 20px; transition: border-color var(--transition);
}
.paste-area:focus-within { border-color: var(--accent); }
.paste-area textarea {
  background: none; border: none; padding: 0; resize: none;
  min-height: 120px; width: 100%; color: var(--text);
}

/* ── DESIGN OPTIONS ── */
.design-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.design-opt {
  border: 2px solid var(--border); border-radius: var(--radius);
  padding: 14px 10px; cursor: pointer; text-align: center;
  transition: all 0.2s; font-size: 12px; color: var(--muted);
}
.design-opt:hover { border-color: var(--accent); color: var(--text); }
.design-opt.active {
  border-color: var(--accent);
  background: rgba(108,143,255,0.08);
  color: var(--accent);
}
.design-opt .opt-icon { font-size: 22px; margin-bottom: 6px; }
.color-swatch {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer;
  transition: all var(--transition); display: inline-block;
}
.color-swatch.active { border-color: white; transform: scale(1.15); }
.color-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ── TOAST ── */
#toast {
  position: fixed; bottom: 30px; right: 30px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 20px;
  font-size: 14px; color: var(--text);
  box-shadow: var(--shadow);
  transform: translateY(20px); opacity: 0;
  transition: all 0.3s; z-index: 999; pointer-events: none;
}
#toast.show { transform: translateY(0); opacity: 1; }
#toast.success { border-color: var(--success); }

/* ── CHIPS ── */
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.chip {
  padding: 4px 12px; border-radius: 20px; font-size: 12px;
  background: var(--surface3); color: var(--muted); border: 1px solid var(--border);
  cursor: pointer; transition: all var(--transition);
}
.chip:hover, .chip.active {
  background: rgba(108,143,255,0.15); color: var(--accent); border-color: var(--accent);
}

/* ── EDITOR ── */
.editor-toolbar {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  padding: 10px 12px; background: var(--surface2);
  border: 1px solid var(--border); border-bottom: none;
  border-radius: 8px 8px 0 0;
}
.tb-btn {
  background: var(--surface3); border: 1px solid var(--border);
  color: var(--text); width: 34px; height: 34px; border-radius: 6px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 13px; transition: all var(--transition);
}
.tb-btn:hover { border-color: var(--accent); color: var(--accent); }
.tb-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
#body-editor {
  background: white; color: #111; min-height: 420px;
  border: 1px solid var(--border); border-radius: 0 0 8px 8px;
  padding: 0.6in; outline: none; overflow-y: auto;
}
#body-editor table { border-collapse: collapse; width: 100%; margin: 12px 0; }
#body-editor table td, #body-editor table th {
  border: 1px solid #999; padding: 6px 10px; min-width: 40px;
}
#body-editor img { max-width: 100%; height: auto; display: block; margin: 12px auto; }
#body-editor .hanging-indent { text-indent: -0.5in; margin-left: 0.5in; }
#body-editor .page-break-marker {
  page-break-before: always; height: 0; margin: 24px 0;
  border-top: 2px dashed #bbb; text-align: center; position: relative;
}
#body-editor .page-break-marker::after {
  content: 'Page Break'; position: absolute; top: -8px; left: 50%;
  transform: translateX(-50%); background: white; padding: 0 8px;
  font-size: 10px; color: #999;
}
#body-editor blockquote {
  border-left: 3px solid #999; padding-left: 14px;
  color: #555; font-style: italic; margin: 12px 0;
}
#body-editor[contenteditable]:empty:before {
  content: attr(placeholder); color: #999;
}
.word-count { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* ── INFO BOX ── */
.info-box {
  background: rgba(108,143,255,0.08); border: 1px solid rgba(108,143,255,0.2);
  border-radius: var(--radius); padding: 14px 16px; font-size: 13px; color: var(--muted);
}
.info-box strong { color: var(--accent); }
.info-box.warn {
  background: rgba(244,201,126,0.08); border-color: rgba(244,201,126,0.25);
}
.info-box.warn strong { color: var(--gold); }

/* ── SIMILARITY ── */
.sim-score {
  font-size: 42px; font-weight: 700; font-family: 'Playfair Display', serif;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.sim-bar {
  height: 8px; background: var(--surface3); border-radius: 4px;
  overflow: hidden; margin: 12px 0 8px;
}
.sim-bar-fill {
  height: 100%; border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.5s ease;
}
.phrase-card {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px;
}
.phrase-card .phrase {
  font-family: 'DM Mono', monospace; font-size: 13px;
  color: var(--text); margin-bottom: 8px; line-height: 1.5;
}
.phrase-card .match {
  font-size: 13px; color: var(--muted); padding: 8px 0;
  border-top: 1px solid var(--border);
}
.phrase-card .match a { color: var(--accent); text-decoration: none; }
.phrase-card .match a:hover { text-decoration: underline; }
.phrase-card .no-match { font-size: 13px; color: var(--success); }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── DIVIDER ── */
.divider { height: 1px; background: var(--border); margin: 28px 0; }

/* ── RANGE ── */
input[type=range] {
  padding: 0; height: 4px; background: var(--border); border-radius: 4px;
  cursor: pointer; accent-color: var(--accent);
}

/* ── HINT ── */
.hint { font-size: 11px; color: var(--muted); }

/* ── PRINT ── */
@media print {
  body { background: white; }
  .app { display: block; }
  .sidebar, .panel-header, .btn-row, .mobile-topbar, .sidebar-overlay, .editor-toolbar { display: none !important; }
  .panel { display: block !important; padding: 0; }
  #preview-frame, #full-doc-render { box-shadow: none; }
}

/* ── MOBILE ── */
@media (max-width: 860px) {
  .app { display: block; }
  .mobile-topbar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 150;
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: 12px 16px;
  }
  .mobile-topbar h1 {
    font-family: 'Playfair Display', serif; font-size: 18px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
  }
  .hamburger-btn {
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 8px; width: 40px; height: 40px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    color: var(--text); cursor: pointer;
  }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: 280px;
    max-width: 82vw;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 12px 0 40px rgba(0,0,0,0.5);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close-btn {
    display: block; position: absolute; top: 20px; right: 16px;
    background: none; border: none; color: var(--muted);
    font-size: 22px; cursor: pointer; line-height: 1;
  }
  .sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.55); z-index: 190;
  }
  .sidebar-overlay.open { display: block; }
  .panel { padding: 20px 18px; }
  .panel-header h2 { font-size: 24px; }
  .form-grid, .design-options, .template-grid { grid-template-columns: 1fr 1fr; }
  .template-grid { grid-template-columns: repeat(2, 1fr); }
  .btn-row { flex-direction: column; align-items: stretch; }
  .btn-row .btn { justify-content: center; }
  #body-editor { padding: 0.4in !important; }
  .style-tabs { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  .sim-score { font-size: 32px; }
}

@media (max-width: 480px) {
  .form-grid, .design-options, .template-grid { grid-template-columns: 1fr; }
  .section-card { padding: 20px 18px; }
}
