:root {
  --bg: #0a0c10;
  --surface: #12141a;
  --card: #181c24;
  --card-hover: #1e2230;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-dim: rgba(99, 102, 241, 0.15);
  --success: #22c55e;
  --success-dim: rgba(34, 197, 94, 0.15);
  --warning: #f59e0b;
  --warning-dim: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --danger-dim: rgba(239, 68, 68, 0.15);
  --info: #3b82f6;
  --info-dim: rgba(59, 130, 246, 0.15);
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #1e293b;
  --border-light: #2d3748;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.4);
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'Outfit', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --transition: 0.2s ease;
  --transition-slow: 0.35s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body { font-family: var(--font-body); background: var(--bg); color: var(--text); min-height: 100vh; overflow-x: hidden; }
input, textarea, button, select { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }

/* Views */
.view { display: none; min-height: 100vh; }
.view.active { display: block; animation: fadeUp .4s ease; }
@keyframes fadeUp { from { opacity:0; transform:translateY(16px); } to { opacity:1; transform:translateY(0); } }

/* Start View */
.start-container { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; padding: 2rem; }
.logo-section { text-align: center; margin-bottom: 2.5rem; }
.logo { font-family: var(--font-display); font-size: 3rem; font-weight: 800; display: flex; align-items: center; justify-content: center; gap: .5rem; }
.logo-icon { color: var(--primary); font-size: 2.5rem; }
.tagline { font-size: 1.1rem; color: var(--text-secondary); margin-top: .5rem; font-weight: 300; }

.template-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; max-width: 640px; width: 100%; }
.template-card { background: var(--card); border: 2px solid var(--border); border-radius: var(--radius-xl); padding: 1.5rem; cursor: pointer; transition: all var(--transition); position: relative; overflow: hidden; }
.template-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.template-card .tc-name { font-family: var(--font-display); font-size: 1.15rem; font-weight: 700; margin-bottom: .4rem; }
.template-card .tc-desc { font-size: .85rem; color: var(--text-secondary); line-height: 1.4; margin-bottom: .75rem; }
.template-card .tc-btn { font-size: .82rem; color: var(--primary); font-weight: 600; }
.template-card:hover .tc-btn { text-decoration: underline; }

.restore-banner { background: var(--card); border: 1px solid var(--warning); border-radius: var(--radius); padding: .75rem 1.25rem; margin-top: 1.5rem; max-width: 640px; width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 1rem; animation: fadeUp .3s ease; }
.restore-banner p { font-size: .9rem; color: var(--text-secondary); }
.restore-banner .restore-actions { display: flex; gap: .5rem; flex-shrink: 0; }

/* Top Bar */
.top-bar { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; }
.top-bar-left { flex-shrink: 0; }
.top-bar-logo { font-family: var(--font-display); font-size: 1.2rem; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: .3rem; }
.top-bar-logo .logo-icon { font-size: 1rem; }
.top-bar-center { display: flex; align-items: center; gap: .5rem; }
.type-badge { padding: .2rem .7rem; border-radius: 100px; font-size: .75rem; font-weight: 600; color: #fff; }
.top-bar-right { display: flex; align-items: center; gap: .5rem; flex-shrink: 0; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .5rem 1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); color: var(--text); font-weight: 500; cursor: pointer; transition: all var(--transition); white-space: nowrap; }
.btn:hover { background: var(--card-hover); border-color: var(--border-light); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-secondary { background: transparent; border-color: var(--border); color: var(--text-secondary); }
.btn-secondary:hover { border-color: var(--text-secondary); color: var(--text); }
.btn-sm { padding: .3rem .7rem; font-size: .82rem; }
.btn-xs { padding: .2rem .5rem; font-size: .75rem; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-dim); border-color: var(--danger); }
.btn-icon { background: none; border: none; color: var(--text-muted); font-size: 1rem; cursor: pointer; padding: .2rem; transition: color var(--transition); line-height: 1; }
.btn-icon:hover { color: var(--text); }
.btn-block { width: 100%; }

/* Dropdown */
.dropdown { position: relative; }
.dropdown-menu { display: none; position: absolute; right: 0; top: calc(100% + 4px); background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); min-width: 180px; z-index: 100; overflow: hidden; }
.dropdown-menu.open { display: block; animation: fadeUp .15s ease; }
.dropdown-item { display: block; width: 100%; padding: .55rem 1rem; background: none; border: none; color: var(--text); text-align: left; cursor: pointer; font-size: .88rem; transition: background var(--transition); }
.dropdown-item:hover { background: var(--surface); }

/* Editor Layout */
.editor-layout { display: flex; gap: 0; max-width: 100%; min-height: calc(100vh - 56px); }
.editor-main { flex: 1; max-width: 820px; margin: 0 auto; padding: 1.5rem; overflow-y: auto; }
.editor-main.with-preview { max-width: 50%; margin: 0; }

/* Toast */
#toast-container { position: fixed; bottom: 1rem; right: 1rem; z-index: 9999; display: flex; flex-direction: column-reverse; gap: .5rem; pointer-events: none; }
.toast { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: .65rem 1.1rem; color: var(--text); font-size: .88rem; box-shadow: var(--shadow-lg); pointer-events: auto; animation: toastIn .3s ease; max-width: 360px; }
.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error { border-left: 3px solid var(--danger); }
.toast.toast-warning { border-left: 3px solid var(--warning); }
.toast.toast-info { border-left: 3px solid var(--info); }
.toast.toast-out { animation: toastOut .3s ease forwards; }
@keyframes toastIn { from { opacity:0; transform:translateX(40px); } to { opacity:1; transform:translateX(0); } }
@keyframes toastOut { from { opacity:1; } to { opacity:0; transform:translateX(40px); } }

.hidden { display: none !important; }

/* Responsive */
@media (max-width: 1024px) {
  .editor-main.with-preview { max-width: 100%; }
  .top-bar-center { display: none; }
}
@media (max-width: 768px) {
  .template-grid { grid-template-columns: 1fr; }
  .logo { font-size: 2.2rem; }
  .top-bar { padding: .5rem 1rem; }
  .top-bar-right { flex-wrap: wrap; gap: .3rem; }
  .editor-main { padding: 1rem; }
}
