:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --text: #1f1e1c;
  --muted: #6b6862;
  --border: #e2dfd8;
  --accent: #c96442;
  --accent-text: #ffffff;
  --danger: #b4372f;
  --ok: #2f8a4c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .04);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a18;
    --surface: #252421;
    --surface-2: #2e2c29;
    --text: #ece9e3;
    --muted: #a19d95;
    --border: #3a3834;
    --accent: #d97757;
    --danger: #e0645a;
    --ok: #5cbf7b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; margin-top: 1.5rem; }
a { color: var(--accent); }
.muted { color: var(--muted); font-weight: normal; }
.mono, pre, code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.error { color: var(--danger); margin: 0; min-height: 1.2em; font-size: .9rem; }
.grow { flex: 1; }

/* ---- Controls ---- */

input, select, textarea {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .55rem .7rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: .5rem; }
label.check input { width: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  font: inherit; font-weight: 500;
  padding: .5rem .9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.small { padding: .3rem .6rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---- Auth ---- */

.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card h1 { font-size: 1.5rem; }
.auth-card { width: min(400px, 100%); padding: 2rem; display: flex; flex-direction: column; gap: .9rem; }

/* ---- Top bar ---- */

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 1rem;
  padding: .75rem 1.25rem;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.1rem; white-space: nowrap; }
#search { max-width: 360px; }
.topbar-actions { display: flex; gap: .4rem; margin-left: auto; }

.filters { display: flex; flex-wrap: wrap; gap: .4rem; padding: 1rem 1.25rem 0; }
.chip {
  font: inherit; font-size: .85rem;
  padding: .25rem .75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

main { padding: 1.25rem; }

/* ---- Project grid ---- */

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }

.project {
  padding: 1rem;
  display: flex; flex-direction: column; gap: .6rem;
  transition: border-color .15s;
}
.project:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.project-head { display: flex; gap: .75rem; align-items: flex-start; }
.project-icon {
  flex: none; width: 44px; height: 44px;
  display: grid; place-items: center;
  font-size: 1.5rem;
  background: var(--surface-2);
  border-radius: 10px;
}
.project-title { font-weight: 600; font-size: 1.05rem; cursor: pointer; }
.project-title:hover { text-decoration: underline; }
.project-desc { color: var(--muted); font-size: .9rem; margin: 0; }
.project-meta { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; font-size: .78rem; color: var(--muted); }
.tag { background: var(--surface-2); padding: .05rem .5rem; border-radius: 999px; }
.kind { text-transform: uppercase; letter-spacing: .04em; font-weight: 600; font-size: .7rem; }
.pin { margin-left: auto; }
.project-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: auto; }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--border); }
.dot.up { background: var(--ok); }
.dot.down { background: var(--danger); }

.empty { text-align: center; padding: 4rem 1rem; color: var(--muted); }

/* ---- Dialogs ---- */

dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog.wide { width: min(1100px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
.dialog-body { padding: 1.5rem; display: flex; flex-direction: column; gap: .85rem; }
.dialog-body p { margin: 0; }
.dialog-actions { display: flex; gap: .5rem; margin-top: .5rem; }
.row { display: flex; gap: .75rem; }
.emoji-field { width: 80px; }
.emoji-field input { text-align: center; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: .75rem; display: flex; flex-direction: column; gap: .6rem; margin: 0; }
legend { font-size: .9rem; font-weight: 500; padding: 0 .3rem; }
.stack { display: flex; flex-direction: column; gap: .7rem; }

.detail-head { display: flex; align-items: center; gap: .5rem; }
.detail-head h2 { flex: 1; margin: 0; }
.detail-section { margin-top: .5rem; }
.detail-section h3 { margin: 0 0 .4rem; }
.notes { white-space: pre-wrap; background: var(--surface-2); padding: .75rem; border-radius: 8px; margin: 0; }
.embed { width: 100%; height: 65vh; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .4rem; }
.section-head h3 { margin: 0; }
.steps { margin: 0; padding-left: 1.25rem; display: flex; flex-direction: column; gap: .35rem; font-size: .92rem; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: block; }
#open-account { padding: .25rem; border-radius: 50%; }
.small { font-size: .85rem; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: .6rem 1rem; border-radius: 8px;
  box-shadow: var(--shadow); z-index: 100;
}

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: .6rem; padding: .75rem 16px; }
  .brand { flex: 1; }
  .topbar-actions { gap: .15rem; }
  .topbar .btn { padding: .45rem .55rem; }
  #search { order: 3; max-width: none; }
  .filters, main { padding-left: 16px; padding-right: 16px; }
  .grid { grid-template-columns: 1fr; }
}
