/* ==========================================================================
   Shared CSPT look. This base block is identical in cspt-hub/public/style.css
   and cspt-lab/levels/<L>/public/style.css; site-specific rules follow it.
   ========================================================================== */

:root {
  --bg: #f7f7f9;
  --surface: #ffffff;
  --surface-2: #f1f1f4;
  --fg: #27272a;
  --ink: #09090b;
  --muted: #71717a;
  --line: #e4e4e7;
  --accent: #6d5efc;
  --accent-2: #22b8cf;
  --accent-fg: #ffffff;
  --accent-soft: rgba(109, 94, 252, .1);
  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, .1);
  --ok: #16a34a;
  --ok-soft: rgba(22, 163, 74, .1);
  --gold: #d49b0b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 18px rgba(16, 24, 40, .06);
  --shadow-lg: 0 2px 4px rgba(16, 24, 40, .05), 0 12px 32px rgba(16, 24, 40, .1);
  --header-bg: rgba(247, 247, 249, .8);
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --bg: #0b0b0f;
    --surface: #141419;
    --surface-2: #1d1d24;
    --fg: #d4d4d8;
    --ink: #fafafa;
    --muted: #a1a1aa;
    --line: #27272f;
    --accent: #8b7dff;
    --accent-2: #3bc9db;
    --accent-fg: #0b0b0f;
    --accent-soft: rgba(139, 125, 255, .14);
    --danger: #ff6b6b;
    --danger-soft: rgba(255, 107, 107, .12);
    --ok: #4ade80;
    --ok-soft: rgba(74, 222, 128, .12);
    --gold: #fbbf24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, .45);
    --header-bg: rgba(11, 11, 15, .75);
  }
}
:root[data-theme=dark] {
  --bg: #0b0b0f;
  --surface: #141419;
  --surface-2: #1d1d24;
  --fg: #d4d4d8;
  --ink: #fafafa;
  --muted: #a1a1aa;
  --line: #27272f;
  --accent: #8b7dff;
  --accent-2: #3bc9db;
  --accent-fg: #0b0b0f;
  --accent-soft: rgba(139, 125, 255, .14);
  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, .12);
  --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, .12);
  --gold: #fbbf24;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, .45);
  --header-bg: rgba(11, 11, 15, .75);
}

* { box-sizing: border-box; }

:root { color-scheme: light dark; }
:root[data-theme=light] { color-scheme: light; }
:root[data-theme=dark] { color-scheme: dark; }

html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
main { flex: 1; min-width: 0; width: 100%; margin: 0 auto; padding: 40px 32px 72px; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

::selection { background: var(--accent-soft); }

/* ---- header ---------------------------------------------------------- */

header.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 64px;
  padding: 0 max(20px, calc((100% - 1240px) / 2 + 20px));
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
header.topbar .brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -.01em;
  color: var(--ink);
}
header.topbar .brand .name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
header.topbar .brand:hover { text-decoration: none; }
header.topbar .mark {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 9px;
  background: #fff;
  object-fit: contain;
  box-shadow: 0 0 0 1px var(--line);
}

/* account corner: theme toggle, who you are, log out */
header.topbar .account {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  font-size: 14px;
  font-weight: 500;
}
header.topbar .account a,
header.topbar .account span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 11px;
  border-radius: 8px;
  color: var(--muted);
  white-space: nowrap;
  transition: background .15s, color .15s;
}
header.topbar .account a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
header.topbar .account .user { color: var(--ink); }
header.topbar img.avatar { width: 26px; height: 26px; margin: -4px 0; border-radius: 50%; object-fit: cover; }

button.theme {
  margin: 0 4px 0 0;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
}
button.theme:hover { background: var(--surface-2); color: var(--ink); filter: none; }
button.theme svg { width: 18px; height: 18px; display: block; }

/* ---- layout: sidebar + content ---------------------------------------- */

.shell { flex: 1; display: flex; width: 100%; max-width: 1240px; margin: 0 auto; }
nav.sidebar {
  flex: none;
  width: 210px;
  position: sticky;
  top: 64px;
  align-self: flex-start;
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 40px 12px 24px 20px;
  font-size: 14px;
  font-weight: 500;
}
nav.sidebar a {
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--muted);
  white-space: nowrap;
  transition: background .15s, color .15s;
}
nav.sidebar a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
nav.sidebar a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
nav.sidebar .section {
  margin: 22px 12px 6px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
}

/* ---- type ------------------------------------------------------------ */

h1, h2, h3 { color: var(--ink); letter-spacing: -.02em; }
h1 { font-size: clamp(28px, 4.5vw, 36px); line-height: 1.15; font-weight: 750; margin: 0 0 10px; }
h2 { font-size: 20px; line-height: 1.3; font-weight: 700; margin: 0 0 8px; }
p.lede { color: var(--muted); font-size: 17px; margin: 0 0 32px; max-width: 62ch; }
code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--muted); }
.eyebrow {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
}

/* ---- surfaces -------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 16px;
}
.meta { color: var(--muted); font-size: 14px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  padding: 5px 9px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---- forms ----------------------------------------------------------- */

label { display: block; margin: 18px 0 6px; font-size: 14px; font-weight: 600; color: var(--ink); }
input[type=text], input[type=password], input[type=url], textarea {
  width: 100%;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  transition: border-color .15s, box-shadow .15s;
}
input[type=file] {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1px dashed var(--line);
  background: var(--surface-2);
  color: var(--muted);
  font: 14px var(--sans);
}
input[type=file]::file-selector-button {
  margin-right: 12px; padding: 7px 12px; border: 0; border-radius: 8px;
  background: var(--surface); color: var(--ink); font: 600 13px var(--sans); cursor: pointer;
  box-shadow: var(--shadow);
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }

button, a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 20px;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-fg);
  font: 600 14px/1.2 var(--sans);
  white-space: nowrap;
  cursor: pointer;
  transition: filter .15s, transform .05s, background .15s;
}
button:hover, a.button:hover { filter: brightness(1.08); text-decoration: none; }
button:active, a.button:active { transform: translateY(1px); }
button.secondary, a.button.secondary { background: var(--surface-2); color: var(--ink); }
button.danger { background: transparent; border-color: var(--line); color: var(--danger); }
button.danger:hover { background: var(--danger-soft); filter: none; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.checkline { display: flex; gap: 10px; align-items: center; margin-top: 18px; }
.checkline label { margin: 0; font-weight: 500; }

.msg { margin-top: 14px; font-size: 14px; }
.msg:empty { display: none; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--ok); }

/* ---- footer ---------------------------------------------------------- */

footer.colophon {
  padding: 28px 20px 40px;
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
footer.colophon a { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
footer.colophon a:hover { color: var(--ink); }

/* narrow: the sidebar becomes a scrolling tab strip under the header */
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  nav.sidebar {
    z-index: 9;
    width: auto;
    max-height: none;
    align-self: stretch;
    flex-direction: row;
    overflow-x: auto;
    padding: 8px 16px;
    background: var(--header-bg);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--line);
  }
  nav.sidebar .section { display: none; }
  nav.sidebar a { padding: 6px 12px; }
  main { padding: 32px 20px 64px; }
}
@media (max-width: 640px) {
  main { padding: 28px 16px 56px; }
  header.topbar { padding: 0 12px 0 16px; gap: 8px; }
  header.topbar .account { gap: 0; }
  header.topbar .account a, header.topbar .account span { padding: 6px 8px; }
  .card { padding: 20px; }
}

/* ==========================================================================
   Site-specific
   ========================================================================== */

/* Lab: a blog. Narrow reading column, posts as cards on the feed. */

main { max-width: 760px; }

.hero { margin-bottom: 40px; }
.hero h1 { font-size: clamp(32px, 6vw, 46px); letter-spacing: -.035em; }
.hero h1 span {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p { color: var(--muted); font-size: 18px; margin: 0; }

.section-title, #mine > h2 {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 0 0 14px;
}
#mine > h2 { margin-top: 40px; }

/* ---- posts ----------------------------------------------------------- */

article.card {
  padding: 28px;
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s;
}
article.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
article.card h2 { font-size: 22px; line-height: 1.25; margin-bottom: 10px; }
article.card h2 a { color: var(--ink); }
article.card h2 a:hover { color: var(--accent); text-decoration: none; }

.card .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.card .meta img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.card .meta span:first-of-type:not(:only-child) { color: var(--fg); font-weight: 500; }

.card .body {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 18px 0 0;
  color: var(--fg);
  font-size: 16px;
  line-height: 1.75;
}
.card .body img { max-width: 100%; height: auto; border-radius: 10px; }
.card .body pre { font-family: var(--mono); font-size: 14px; background: var(--surface-2); padding: 14px; border-radius: 10px; overflow-x: auto; }
.card .body blockquote { margin: 1em 0; padding: 2px 0 2px 18px; border-left: 3px solid var(--accent); color: var(--muted); }

.badge.public { color: var(--ok); background: var(--ok-soft); }
.badge.private { color: var(--danger); background: var(--danger-soft); }
/* hub links sit at the foot of the sidebar, away from the lab's own pages */
@media (min-width: 861px) {
  nav.sidebar { height: calc(100vh - 64px); }
  nav.sidebar .section.hub { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line); }
}
.card.pinned { position: relative; }
.card.pinned > h2 { padding-right: 32px; }
.pin-mark { position: absolute; top: 18px; right: 18px; width: 22px; height: 22px; color: #ea580c; transform: rotate(35deg); }
.pin-mark svg { width: 100%; height: 100%; display: block; }
@media (prefers-color-scheme: dark) { :root:not([data-theme=light]) .pin-mark { color: #fb923c; } }
:root[data-theme=dark] .pin-mark { color: #fb923c; }
body[data-page=post] .pin-mark { top: 6px; right: 0; }
button:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.meta button.pin { margin: 0 0 0 auto; padding: 4px 12px; font-size: 13px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); border: 0; }

/* single post: the article is the page, not a card in a list */
body[data-page=post] article.card {
  background: none; border: 0; box-shadow: none; padding: 0; margin-bottom: 40px; transform: none;
}
body[data-page=post] article.card h2 { font-size: clamp(30px, 5.5vw, 42px); line-height: 1.12; letter-spacing: -.03em; margin-bottom: 16px; }
body[data-page=post] article.card .body { font-size: 18px; line-height: 1.8; margin-top: 28px; }

/* ---- attachments ----------------------------------------------------- */

ul.attachments { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 8px; }
ul.attachments li {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px;
  padding: 10px 14px; border-radius: 10px; background: var(--surface-2); font-size: 14px;
}
ul.attachments li a { font-weight: 600; }
ul.attachments li .muted { font-size: 13px; }
ul.attachments li button.remove {
  margin: 0 0 0 auto; padding: 3px 10px; font-size: 12px; border-radius: 7px;
  background: transparent; color: var(--danger); border: 1px solid var(--line);
}
ul.attachments li button.remove:hover { background: var(--danger-soft); filter: none; }

/* ---- page bits ------------------------------------------------------- */

textarea { min-height: 260px; resize: vertical; font-size: 16px; line-height: 1.7; }
input[type=text]#t { font-size: 18px; font-weight: 600; }

#owner h2, body[data-page=profile] .card h2 { font-size: 17px; }

body[data-page=login] main, body[data-page=register] main { max-width: 440px; }

/* objectives panel */
#objectives .card { background: var(--accent-soft); border-color: transparent; box-shadow: none; }
ul.objectives { list-style: none; margin: 0; padding: 0; }
ul.objectives li { display: flex; gap: 10px; align-items: baseline; padding: 4px 0; }
ul.objectives li .tick { width: 1em; color: var(--muted); }
ul.objectives li.done .tick { color: var(--ok); }
ul.objectives li .name { font-weight: 600; min-width: 11em; }

@media (max-width: 640px) {
  article.card { padding: 22px; }
  ul.objectives li { flex-wrap: wrap; }
}

/* L2: post bodies are plain text, so keep their line breaks. */
.card .body { white-space: pre-wrap; }
button.danger:disabled:hover { background: transparent; }

/* Attachment viewer */
.viewer .preview { margin: 20px 0; }
.viewer .preview img { max-width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--line); }
.viewer .row { margin-top: 16px; }
