/* Studio: the private editor. Same palette as the site, laid out as a tool. */
:root {
  --bg: #0b0d12; --bg-elev: #141720; --bg-code: #10131a;
  --text: #e8e9ef; --strong: #ffffff; --muted: #9aa1b3; --line: #242936;
  --accent: #8f7dff; --accent-2: #3fd9c3; --accent-3: #f2b65a; --danger: #ff6b6b;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, Menlo, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f5f0; --bg-elev: #ffffff; --bg-code: #efede6;
    --text: #1c1e26; --strong: #0b0d12; --muted: #5f6577; --line: #e2dfd6; --danger: #c43d3d;
    color-scheme: light;
  }
}

*, *::before, *::after { box-sizing: border-box; }
/* The script toggles elements with the `hidden` attribute; it must win over any display rule below. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: 0.9em; background: var(--bg-code); border: 1px solid var(--line); border-radius: 5px; padding: 0.05em 0.3em; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-rows: auto 1fr; grid-template-columns: 300px minmax(0, 1fr); height: 100dvh; }
.bar {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 0.75rem; min-height: 50px;
  padding: 0.45rem 0.9rem; border-bottom: 1px solid var(--line); background: var(--bg-elev);
}
.brand { font-family: var(--serif); font-size: 1.1rem; color: var(--strong); }
.status { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 0.85rem; }
.status[data-kind="dirty"] { color: var(--accent-3); }
.status[data-kind="ok"] { color: var(--accent-2); }
.status[data-kind="error"] { color: var(--danger); }
.bar-actions { display: flex; gap: 0.4rem; align-items: center; }

.list { border-right: 1px solid var(--line); background: var(--bg-elev); overflow: auto; display: flex; flex-direction: column; }
.list-head { display: flex; gap: 0.5rem; padding: 0.75rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg-elev); z-index: 1; }
.list-head input { flex: 1; min-width: 0; }
.list h2 { margin: 1rem 0.9rem 0.3rem; font: 500 0.72rem var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.list h2 .count { opacity: 0.7; margin-left: 0.3em; }
.list p { margin: 0.25rem 0.9rem; }
.entry { display: block; padding: 0.5rem 0.9rem; text-decoration: none; color: var(--text); border-left: 3px solid transparent; }
.entry:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.entry.active { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.entry-title { display: block; color: var(--strong); line-height: 1.3; }
.entry-meta { display: block; font: 0.72rem var(--mono); color: var(--muted); margin-top: 0.15rem; }
.badge {
  display: inline-block; margin-left: 0.4rem; padding: 0.05rem 0.45rem; border-radius: 999px; vertical-align: middle;
  background: var(--accent-3); color: #0b0d12; font: 600 0.62rem var(--mono); letter-spacing: 0.08em; text-transform: uppercase;
}

.entry-meta .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--pillar); margin-right: 0.35em; vertical-align: 0.05em; }

.editor { min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.empty { margin: auto; max-width: 34rem; padding: 2rem; text-align: center; color: var(--muted); }
.empty h1 { font: 500 1.6rem/1.2 var(--serif); color: var(--strong); margin: 0 0 0.75rem; }
.pane-wrap { display: flex; flex-direction: column; height: 100%; }

/* details panel: the frontmatter as fields */
.details { border-bottom: 1px solid var(--line); background: var(--bg-elev); }
.details-head { display: flex; align-items: center; gap: 0.75rem; padding: 0.4rem 0.9rem; flex-wrap: wrap; }
.path { flex: 1; min-width: 8rem; font: 0.78rem var(--mono); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tools { display: flex; gap: 0.35rem; flex-wrap: wrap; }
#btn-details { display: none; }
.fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0.5rem 0.9rem; padding: 0.15rem 0.9rem 0.8rem; }
.field { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }
.field-text, .field-textarea, .field-tags { grid-column: 1 / -1; }
.field-label { font: 500 0.66rem var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.field input, .field textarea {
  width: 100%; padding: 0.45rem 0.65rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit; font-size: 0.95rem; resize: vertical;
}
.field input[data-key="title"] { font-family: var(--serif); font-size: 1.4rem; padding: 0.3rem 0.65rem; color: var(--strong); }
.field input[type="date"] { max-width: 12rem; }
.field-other { grid-column: 1 / -1; margin: 0; }
.tags-field { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.chip {
  padding: 0.25rem 0.75rem; border-radius: 999px; border: 1px solid var(--line); background: none;
  color: var(--muted); font: inherit; font-size: 0.82rem; cursor: pointer;
}
.chip::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--pillar); margin-right: 0.45em; opacity: 0.5; }
.chip[aria-pressed="true"] { color: var(--strong); border-color: var(--pillar); background: color-mix(in srgb, var(--pillar) 12%, transparent); }
.chip[aria-pressed="true"]::before { opacity: 1; }
.tags-input { flex: 1; min-width: 11rem; }

/* "While writing" group */
.field-group { grid-column: 1 / -1; border: 1px solid var(--line); border-radius: 10px; padding: 0 0.75rem; }
.field-group summary {
  cursor: pointer; padding: 0.5rem 0; list-style: none;
  font: 500 0.66rem var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted);
}
.field-group summary::before { content: "▸"; display: inline-block; margin-right: 0.5em; transition: transform 0.15s; }
.field-group[open] summary::before { transform: rotate(90deg); }
.field-group .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 0.5rem 0.9rem; padding: 0 0 0.75rem; }
.field-group .field { grid-column: auto; }
.weather-field { display: flex; gap: 0.4rem; align-items: stretch; }
.weather-field input { flex: 1; min-width: 0; }
.field input[type="time"] { max-width: 9rem; }

/* formatting bar */
.toolbar { display: flex; align-items: center; gap: 0.15rem; padding: 0.3rem 0.6rem; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.toolbar button, .toolbar .tb {
  flex: none; padding: 0.3rem 0.55rem; border: 1px solid transparent; border-radius: 6px;
  background: none; color: var(--muted); font: 0.8rem var(--mono); cursor: pointer; line-height: 1.2;
}
.toolbar button:hover, .toolbar .tb:hover { color: var(--strong); border-color: var(--line); background: var(--bg-elev); }
.counts { white-space: nowrap; }
.panes { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr); min-height: 0; }
.panes.split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
textarea {
  width: 100%; height: 100%; resize: none; border: 0; outline: 0; margin: 0;
  background: var(--bg); color: var(--text); font: 16px/1.65 var(--mono); padding: 1rem 1.25rem 4rem; tab-size: 2;
}
.preview { overflow: auto; padding: 1rem 1.5rem 4rem; border-left: 1px solid var(--line); background: var(--bg); }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.45rem 0.9rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-size: 0.88rem; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--muted); color: var(--strong); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: linear-gradient(120deg, var(--accent), var(--accent-2)); color: #0b0d12; border-color: transparent; font-weight: 600; }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.small { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.on { border-color: var(--accent-3); color: var(--accent-3); }
.icon-btn { display: none; background: none; border: 0; color: var(--text); font-size: 1.3rem; cursor: pointer; padding: 0 0.2rem; }
input[type="search"] {
  padding: 0.4rem 0.75rem; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-size: 0.88rem;
}
input:focus-visible, .btn:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- picker (wikilink search) ---------- */
.picker {
  position: fixed; top: 100px; left: 50%; transform: translateX(-50%); z-index: 20; width: min(92vw, 28rem);
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 16px 50px rgba(0,0,0,0.4); overflow: hidden;
}
.picker button {
  display: flex; justify-content: space-between; gap: 1rem; width: 100%; text-align: left; padding: 0.55rem 0.9rem;
  background: none; border: 0; border-bottom: 1px solid var(--line); color: var(--strong); font: inherit; cursor: pointer;
}
.picker button:last-child { border-bottom: 0; }
.picker button:hover, .picker button.active { background: color-mix(in srgb, var(--accent) 16%, transparent); }

/* ---------- sign-in ---------- */
.login { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: var(--bg); padding: 1rem; }
.login .card { max-width: 24rem; text-align: center; padding: 2rem; border: 1px solid var(--line); border-radius: 16px; background: var(--bg-elev); }
.login h1 { font: 500 2rem var(--serif); margin: 0 0 0.5rem; color: var(--strong); }
.login p { color: var(--muted); margin: 0 0 1.5rem; }

/* ---------- preview typography (a compact copy of the site's) ---------- */
.prose { max-width: 68ch; font-size: 1rem; line-height: 1.65; }
.prose h1 { font: 500 2rem/1.1 var(--serif); color: var(--strong); margin: 0 0 1rem; }
.prose h2, .prose h3, .prose h4 { font-family: var(--serif); font-weight: 500; color: var(--strong); margin: 1.8em 0 0.5em; line-height: 1.2; }
.prose h2 { font-size: 1.5rem; } .prose h3 { font-size: 1.2rem; } .prose h4 { font-size: 1.05rem; }
.prose p, .prose ul, .prose ol { margin: 0 0 1.1em; }
.prose blockquote { margin: 1.3em 0; padding: 0.2em 0 0.2em 1.1em; border-left: 3px solid var(--accent); color: var(--muted); font-style: italic; }
.prose pre { background: var(--bg-code); border: 1px solid var(--line); border-radius: 10px; padding: 0.9rem 1rem; overflow-x: auto; }
.prose pre code { background: none; border: 0; padding: 0; }
.prose img { max-width: 100%; height: auto; border-radius: 10px; display: block; margin: 1.3em auto; }
.prose hr { border: 0; height: 1px; background: var(--line); margin: 2.5em 0; }
.prose table { width: 100%; border-collapse: collapse; }
.prose th, .prose td { text-align: left; padding: 0.5em 0.7em; border-bottom: 1px solid var(--line); }
.prose a.wikilink { text-decoration-style: dotted; }
.prose .wikilink.missing { color: var(--muted); border-bottom: 1px dashed var(--muted); }
.prose ul.task-list { list-style: none; padding-left: 0.25em; }

/* ---------- phones ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .icon-btn { display: inline-block; }
  .list { position: fixed; top: 50px; bottom: 0; left: 0; width: min(86vw, 320px); z-index: 10; transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: 0 0 40px rgba(0,0,0,0.4); }
  .app.show-list .list { transform: none; }
  .bar-actions .ghost, .counts { display: none; }
  #btn-details { display: inline-flex; }
  .fields { display: none; grid-template-columns: minmax(0, 1fr); }
  .details.open .fields { display: grid; }
  .panes.split { grid-template-columns: minmax(0, 1fr); grid-template-rows: 1fr 1fr; }
  .preview { border-left: 0; border-top: 1px solid var(--line); }
  textarea { padding: 0.9rem 1rem 4rem; }
}
