/* ─── Reset & Root ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-input: #0d1117;
  --bg-hover: #1c2333;
  --bg-sidebar: #10141c;
  --border: #30363d;
  --border-focus: #58a6ff;
  --text: #e6edf3;
  --text-muted: #7d8590;
  --text-link: #58a6ff;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --success: #3fb950;
  --warning: #d29922;
  --danger: #f85149;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', monospace;
  --sidebar-w: 240px;
}

html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--text-link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Layout ─── */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 10;
}
.sidebar__logo {
  padding: 20px 16px 16px;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  cursor: pointer;
}
.sidebar__nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.sidebar__item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px;
  color: var(--text-muted);
  font-size: .92rem;
  cursor: pointer;
  transition: background .15s, color .15s;
  border: none; background: none; width: 100%; text-align: left;
  font-family: var(--font);
}
.sidebar__item:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.sidebar__item--active { color: var(--text); background: var(--bg-hover); }
.sidebar__divider { height: 1px; background: var(--border); margin: 8px 16px; }
.sidebar__footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: .85rem; color: var(--text-muted);
  display: flex; align-items: center; justify-content: space-between;
}

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 24px 32px;
  max-width: 1200px;
}

/* ─── Header ─── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px; gap: 16px; flex-wrap: wrap;
}
.page-header h1 { font-size: 1.5rem; font-weight: 600; }
.page-header__actions { display: flex; gap: 8px; }

/* ─── Breadcrumbs ─── */
.breadcrumbs {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 16px; font-size: .85rem; color: var(--text-muted);
}
.breadcrumbs a { color: var(--text-muted); }
.breadcrumbs a:hover { color: var(--text); }
.breadcrumbs__sep::before { content: '/'; margin: 0 2px; }

/* ─── Cards ─── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.card:hover { border-color: var(--border-focus); box-shadow: var(--shadow); }
.card__title { font-size: 1.1rem; font-weight: 600; margin-bottom: 6px; }
.card__meta {
  font-size: .85rem; color: var(--text-muted);
  display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 8px;
}
.card__desc { font-size: .9rem; color: var(--text-muted); }
.card__footer { margin-top: 12px; display: flex; gap: 8px; align-items: center; }

/* ─── Badges ─── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: .75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .02em;
}
.badge--draft { background: #30363d; color: var(--text-muted); }
.badge--active { background: rgba(63,185,80,.15); color: var(--success); }
.badge--completed { background: rgba(88,166,255,.15); color: var(--text-link); }
.badge--idea { background: #30363d; color: var(--text-muted); }
.badge--designing { background: rgba(210,153,34,.15); color: var(--warning); }
.badge--prototyped { background: rgba(88,166,255,.15); color: var(--text-link); }
.badge--tested { background: rgba(63,185,80,.15); color: var(--success); }
.badge--built { background: rgba(233,69,96,.15); color: var(--accent); }
.badge--easy { background: rgba(63,185,80,.15); color: var(--success); }
.badge--medium { background: rgba(210,153,34,.15); color: var(--warning); }
.badge--hard { background: rgba(248,81,73,.15); color: var(--danger); }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-family: var(--font);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); }
.btn--ghost {
  background: transparent; color: var(--text-muted);
  border-color: var(--border);
}
.btn--ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn--danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn--danger:hover { background: rgba(248,81,73,.1); }
.btn--sm { padding: 4px 10px; font-size: .82rem; }
.btn--icon { padding: 6px; min-width: 32px; justify-content: center; }

/* ─── Forms ─── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; margin-bottom: 4px;
  font-size: .85rem; color: var(--text-muted); font-weight: 500;
}
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: .9rem;
  transition: border-color .15s;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none; border-color: var(--border-focus);
}
.form-group textarea { resize: vertical; min-height: 80px; font-family: var(--font-mono); }
.form-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}

/* ─── Puzzle list ─── */
.puzzle-list { display: flex; flex-direction: column; gap: 8px; }
.puzzle-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  cursor: pointer;
  transition: border-color .15s;
}
.puzzle-item:hover { border-color: var(--border-focus); }
.puzzle-item__handle {
  cursor: grab; color: var(--text-muted); font-size: 1.2rem;
  user-select: none;
}
.puzzle-item__handle:active { cursor: grabbing; }
.puzzle-item__order {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-hover); border-radius: 50%;
  font-size: .8rem; font-weight: 600; color: var(--text-muted);
  flex-shrink: 0;
}
.puzzle-item__body { flex: 1; min-width: 0; }
.puzzle-item__title { font-weight: 500; }
.puzzle-item__meta {
  font-size: .82rem; color: var(--text-muted);
  display: flex; gap: 8px; flex-wrap: wrap;
}
.puzzle-item__actions { display: flex; gap: 4px; }

/* ─── Tabs ─── */
.tabs {
  display: flex; gap: 0; border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  padding: 10px 16px;
  font-size: .9rem;
  color: var(--text-muted);
  cursor: pointer;
  border: none; background: none;
  border-bottom: 2px solid transparent;
  font-family: var(--font);
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab--active { color: var(--text); border-bottom-color: var(--accent); }

/* ─── Playground ─── */
.playground { display: flex; flex-direction: column; gap: 16px; height: calc(100vh - 160px); }
.playground__editor {
  flex: 1; min-height: 200px;
  font-family: var(--font-mono);
  font-size: .85rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  color: var(--text);
  resize: none;
  tab-size: 2;
}
.playground__editor:focus { outline: none; border-color: var(--border-focus); }
.playground__preview {
  flex: 1; min-height: 200px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
}
.playground__preview iframe {
  width: 100%; height: 100%; border: none;
  border-radius: var(--radius-sm);
}
.playground__split { display: flex; gap: 16px; flex: 1; min-height: 0; }
.playground__split > * { flex: 1; }

/* ─── Toast ─── */
#toast-container {
  position: fixed; top: 16px; right: 16px;
  z-index: 1000;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 10px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .85rem;
  box-shadow: var(--shadow);
  animation: toast-in .2s ease-out;
  max-width: 360px;
}
.toast--success { border-color: var(--success); }
.toast--error { border-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; } }

/* ─── Modal ─── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  min-width: 400px;
  max-width: 560px;
  width: 100%;
  box-shadow: var(--shadow);
}
.modal__title {
  font-size: 1.15rem; font-weight: 600;
  margin-bottom: 16px;
}
.modal__actions {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 20px;
}

/* ─── Auth pages ─── */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
}
.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 400px;
}
.auth-card h1 {
  font-size: 1.3rem; font-weight: 600; margin-bottom: 4px;
  color: var(--accent);
}
.auth-card p { color: var(--text-muted); margin-bottom: 20px; font-size: .9rem; }
.auth-card .form-group { margin-bottom: 14px; }
.auth-card .btn { width: 100%; justify-content: center; }
.auth-card__footer {
  margin-top: 16px; text-align: center;
  font-size: .85rem; color: var(--text-muted);
}

/* ─── Detail panels ─── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.detail-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.detail-section__title {
  font-size: .95rem; font-weight: 600;
  margin-bottom: 12px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em;
}

/* ─── Components table ─── */
.comp-table {
  width: 100%; border-collapse: collapse; font-size: .85rem;
}
.comp-table th {
  text-align: left; padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted); font-weight: 500;
}
.comp-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

/* ─── Hints ─── */
.hint-list { list-style: none; }
.hint-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0;
}
.hint-item input { flex: 1; }
.hint-item .btn { flex-shrink: 0; }

/* ─── Empty state ─── */
.empty-state {
  text-align: center; padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state__icon { font-size: 3rem; margin-bottom: 12px; opacity: .5; }
.empty-state__title { font-size: 1.1rem; font-weight: 500; margin-bottom: 6px; color: var(--text); }
.empty-state__desc { font-size: .9rem; margin-bottom: 20px; }

/* ─── Save indicator ─── */
.save-indicator {
  font-size: .82rem; color: var(--text-muted);
  display: flex; align-items: center; gap: 6px;
}
.save-indicator--saving { color: var(--warning); }
.save-indicator--saved { color: var(--success); }

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .playground__split { flex-direction: column; }
  .modal { min-width: auto; margin: 16px; }
}
