:root {
  --bg: #0b0d12;
  --bg-2: #11141b;
  --bg-3: #171b25;
  --line: #232936;
  --line-2: #2c3342;
  --ink: #e6e8ee;
  --ink-mute: #9aa3b2;
  --ink-dim: #6c7588;
  --primary: #6366f1;
  --primary-bright: #818cf8;
  --gold: #f5c451;
  --red: #f87171;
  --green: #34d399;
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  height: 100%;
}

.hidden { display: none !important; }

/* ====== Auth gate ====== */
.auth-gate {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.auth-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 40px 56px;
  text-align: center;
}
.auth-spin {
  width: 32px; height: 32px;
  margin: 0 auto 14px;
  border: 3px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.auth-msg { color: var(--ink-mute); font-size: 13px; }

/* ====== App shell ====== */
.app {
  display: flex; flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 18px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.back-link {
  color: var(--ink-mute); font-size: 12.5px; text-decoration: none;
  padding: 6px 10px; border-radius: var(--radius-sm);
}
.back-link:hover { color: var(--ink); background: var(--bg-3); }
.topbar-title { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.topbar-mark { font-size: 18px; }
.me-user { color: var(--ink-mute); font-size: 12.5px; }

/* ====== Layout ====== */
.layout {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 0;
  flex: 1;
  min-height: 0;
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
}

.panel-controls {
  border-right: 1px solid var(--line);
  background: var(--bg-2);
  padding: 18px;
  overflow-y: auto;
  max-height: calc(100vh - 53px);
}
.panel-preview {
  background: var(--bg-3);
  display: flex; flex-direction: column;
  min-height: 0;
}

/* ====== Blocks ====== */
.block {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.block-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-mute);
  margin-bottom: 10px;
  display: flex; align-items: center; justify-content: space-between;
}

.field {
  display: flex; flex-direction: column;
  margin-bottom: 10px;
}
.field:last-child { margin-bottom: 0; }
.field label {
  font-size: 12px;
  color: var(--ink-mute);
  margin-bottom: 4px;
  display: flex; align-items: center; gap: 8px;
}
.field .hint { color: var(--ink-dim); font-size: 11px; font-weight: 400; }
.field input[type="text"],
.field select {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
}
.field input[type="text"]:focus,
.field select:focus { outline: 1px solid var(--primary-bright); }

/* ====== Mode toggle ====== */
.mode-toggle {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  padding: 2px;
}
.mode-btn {
  background: transparent;
  border: none;
  color: var(--ink-mute);
  padding: 4px 12px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
}
.mode-btn.active {
  background: var(--primary);
  color: #fff;
}
.mode-help {
  font-size: 12px;
  color: var(--ink-mute);
  line-height: 1.55;
  padding-top: 4px;
}

/* ====== Color rows ====== */
.color-row {
  display: grid;
  grid-template-columns: 1fr 40px 110px;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
}
.color-row:last-child { border-bottom: none; }
.color-row-label {
  font-size: 12.5px;
  color: var(--ink);
}
.color-row-label small {
  display: block;
  font-size: 11px;
  color: var(--ink-dim);
  margin-top: 2px;
}
.color-row input[type="color"] {
  width: 40px; height: 32px;
  padding: 0; border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
}
.color-row input[type="text"] {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  width: 100%;
}

.lock-note {
  margin-top: 12px;
  padding: 9px 11px;
  background: var(--bg);
  border: 1px dashed var(--line-2);
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  color: var(--ink-dim);
  line-height: 1.55;
}

/* ====== Buttons ====== */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.btn:hover { background: var(--bg); }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-bright); }
.btn-ghost { background: transparent; }

/* ====== Code output ====== */
.code-out {
  margin-bottom: 8px;
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
}
.code-out summary {
  cursor: pointer;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-mute);
  user-select: none;
}
.code-out[open] summary {
  border-bottom: 1px solid var(--line);
}
.code-out textarea {
  width: 100%;
  min-height: 200px;
  background: var(--bg);
  color: var(--ink);
  border: none;
  padding: 12px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  line-height: 1.55;
  resize: vertical;
  display: block;
}

/* ====== Preview ====== */
.preview-bar {
  display: flex; align-items: baseline; gap: 12px;
  padding: 10px 18px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}
.preview-label { font-size: 13px; font-weight: 600; }
.preview-sub { font-size: 12px; color: var(--ink-mute); }
.preview-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #1a1a1a;
  min-height: 0;
}

/* ====== Toast ====== */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  color: var(--ink);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  z-index: 200;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  animation: toastIn 0.18s ease-out;
}
.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }
@keyframes toastIn {
  from { transform: translate(-50%, 8px); opacity: 0; }
  to   { transform: translate(-50%, 0);   opacity: 1; }
}
