:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #1f2937;
  --text-muted: #6b7280;
  --text-dim: #9ca3af;
  --primary: #1f2937;
  --primary-hover: #111827;
  --danger: #dc2626;
  --warn: #d97706;
  --success: #16a34a;
  --gaia-yellow: #FFD400;
  --gaia-yellow-hover: #EAC400;
  --radius: 8px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); }

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-text { display: flex; flex-direction: column; gap: 0.1rem; }

.brand h1 {
  font-size: 1.1rem;
  margin: 0;
  font-weight: 700;
  line-height: 1.2;
  color: #0d1117;
}

.brand .subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.logo-square {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--gaia-yellow);
  border-radius: 10px;
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.logo-square img {
  width: 70%;
  height: 70%;
  object-fit: contain;
  display: block;
}
.logo-square.small {
  width: 28px;
  height: 28px;
  border-radius: 7px;
}
a.back:hover .logo-square { background: var(--gaia-yellow-hover); }

.topbar .back {
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.875rem;
}
.topbar .back:hover { color: var(--text); }

#new-skill-btn,
.bar-actions {
  margin-left: auto;
}

.bar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn {
  font: inherit;
  font-size: 0.9rem;
  padding: 0.45rem 0.95rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: border-color 0.12s, background 0.12s;
}
.btn:hover { border-color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: var(--gaia-yellow);
  border-color: var(--gaia-yellow);
  color: #0d1117;
  font-weight: 600;
}
.btn.primary:hover {
  background: var(--gaia-yellow-hover);
  border-color: var(--gaia-yellow-hover);
}
.btn.ghost { background: transparent; }

.section {
  padding: 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
}
.section + .section { padding-top: 0.5rem; }
.section-head { margin-bottom: 1rem; }
.section-head h2 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
  font-weight: 600;
}
.section-sub {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.875rem;
  line-height: 1.5;
  max-width: 70ch;
}
.section-sub code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.05em 0.35em;
  border-radius: 3px;
}
.section-sub.future-note {
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  font-style: italic;
}

#skills-grid {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.group {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.group-head {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: lowercase;
  letter-spacing: 0.02em;
  padding-bottom: 0.3rem;
  border-bottom: 1px dashed var(--border);
}
.group-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}
.crumbs {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-bottom: 0.1rem;
  line-height: 1.4;
}
.crumbs .sep { padding: 0 0.3em; color: var(--text-dim); }
.card-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.3;
}
.editor-bar h1#skill-title .crumbs {
  display: inline;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-right: 0.3rem;
}
.editor-bar h1#skill-title .title-leaf {
  font-weight: 600;
}

/* Markdown guide — single compact card */
.section-guide {
  border-top: 1px solid var(--border);
  margin-top: 1rem;
  padding-top: 2rem;
  padding-bottom: 3rem;
}
.guide-card.single {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}
.guide-card.single h2 {
  margin: 0 0 0.85rem;
  font-size: 1.05rem;
  font-weight: 600;
}
.md-list {
  margin: 0;
  padding: 0 0 0 1.4rem;
  columns: 2;
  column-gap: 2rem;
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--text);
}
.md-list > li {
  break-inside: avoid;
  padding: 0.05rem 0;
}
.md-list strong { font-weight: 600; }
.md-list code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: #f4f4f5;
  border: 1px solid var(--border);
  padding: 0.05em 0.4em;
  border-radius: 3px;
  color: var(--text);
}
@media (max-width: 720px) {
  .md-list { columns: 1; }
}
kbd {
  display: inline-block;
  padding: 1px 5px;
  font-family: var(--mono);
  font-size: 0.78em;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 3px;
  background: #fff;
  color: var(--text);
}

.empty {
  color: var(--text-muted);
  grid-column: 1 / -1;
  padding: 2rem;
  text-align: center;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: border-color 0.12s, box-shadow 0.12s;
  text-decoration: none;
  color: inherit;
  min-height: 160px;
}
.card:hover {
  border-color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.card h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
}
.card .meta {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-family: var(--mono);
}
.card .snippet {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Editor page */
body.editor-page {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.editor-bar {
  padding: 0.65rem 1rem;
}
.editor-bar h1#skill-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}
.save-status {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 7em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.save-status.dirty { color: var(--warn); }
.save-status.saved { color: var(--success); }
.save-status.saving { color: var(--primary); }
.save-status.error  { color: var(--danger); }

.editor-main {
  flex: 1;
  overflow: hidden;
  display: flex;
  background: var(--surface);
}
.editor-main .EasyMDEContainer {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-radius: 0;
}
.editor-main .EasyMDEContainer .CodeMirror {
  flex: 1;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.5;
}
.editor-main .editor-toolbar {
  border-top: 0;
  border-left: 0;
  border-right: 0;
  border-radius: 0;
}

.conflict-banner {
  background: #fef3c7;
  border-bottom: 1px solid #fbbf24;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.9rem;
}
.conflict-banner.hidden { display: none; }
.conflict-banner .btn { margin-left: auto; }

dialog#new-skill-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 480px;
  width: 90%;
}
dialog#new-skill-dialog::backdrop {
  background: rgba(0,0,0,0.3);
}
dialog#new-skill-dialog h3 { margin: 0 0 1rem; }
dialog#new-skill-dialog label {
  display: block;
  margin: 0.75rem 0;
  font-size: 0.875rem;
  color: var(--text);
  font-weight: 500;
}
dialog#new-skill-dialog input {
  display: block;
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  margin-top: 0.35rem;
  font: inherit;
  font-family: var(--mono);
  font-size: 0.9rem;
}
dialog#new-skill-dialog small {
  display: block;
  margin-top: 0.3rem;
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.75rem;
}
dialog#new-skill-dialog .actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

@media (max-width: 640px) {
  .topbar { padding: 0.75rem 1rem; }
  main#skills-grid { padding: 1rem; }
  .editor-bar h1#skill-title { font-size: 0.9rem; }
  .save-status { min-width: 0; }
}
