/* webapp-design-language base.css — vendor a copy into each app's static/.
   Dark-first, minimal utilitarian. Default palette: Nord.

   PALETTE CONTRACT: each scheme below defines exactly these slots (semantic
   names ARE the contract now — no separate base-palette layer). To swap
   palettes, replace ONE delimited "=== palette: NAME (scheme) ===" block
   wholesale (both dark and light halves) and touch nothing else in
   this file. Element rules below only ever consume these slot names.

   slots: --bg --bg-raised --bg-hover(optional) --border --fg --fg-muted
          --accent --accent-fg --danger --ok */

:root {
  /* === palette: nord (dark) === */
  --bg: #2e3440;          /* nord0 */
  --bg-raised: #3b4252;   /* nord1 */
  --border: #4c566a;      /* nord3 */
  --fg: #eceff4;          /* nord6 */
  --fg-muted: #d8dee9;    /* nord4 */
  --accent: #88c0d0;      /* nord8 */
  --accent-fg: #2e3440;   /* nord0 */
  --danger: #bf616a;      /* nord11 */
  --ok: #a3be8c;          /* nord14 */
  /* === /palette: nord (dark) === */

  /* ---- scales (Open Props style, ≤6 steps) ---- */
  --size-1: 4px;
  --size-2: 8px;
  --size-3: 16px;
  --size-4: 24px;
  --size-5: 40px;

  --radius-1: 4px;
  --radius-2: 6px;

  --font-size-0: 0.85rem;
  --font-size-1: 1rem;
  --font-size-2: 1.25rem;
  --font-size-3: 1.75rem;

  --font-ui: system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    /* === palette: nord (light) === */
    --bg: #eceff4;          /* nord6 */
    --bg-raised: #e5e9f0;   /* nord5 */
    --border: #d8dee9;      /* nord4 */
    --fg: #2e3440;          /* nord0 */
    --fg-muted: #4c566a;    /* nord3 */
    --accent: #5e81ac;      /* nord10, darker for contrast on light */
    --accent-fg: #eceff4;   /* nord6 */
    --danger: #a54452;      /* nord11 darkened (aurora, light contrast) */
    --ok: #7a9c66;          /* nord14 darkened (aurora, light contrast) */
    /* === /palette: nord (light) === */
  }
}

/* Alternate palette example — Andreas's previous default (caps blue),
   preserved verbatim. To restore: uncomment both halves below and delete
   the "nord" blocks above (and their @media wrapper contents).

:root {
  === palette: caps (dark) ===
  --bg: #14161a;
  --bg-raised: #1c1f24;
  --border: #2c3038;
  --fg: #e6e8eb;
  --fg-muted: #9aa1ab;
  --accent: #4d8dff;
  --accent-fg: #0a0d12;
  --danger: #ef5b5b;
  --ok: #4caf7d;
  === /palette: caps (dark) ===
}

@media (prefers-color-scheme: light) {
  :root {
    === palette: caps (light) ===
    --bg: #f7f7f8;
    --bg-raised: #ffffff;
    --border: #dde0e5;
    --fg: #1a1c20;
    --fg-muted: #5c6270;
    --accent: #2563eb;
    --accent-fg: #ffffff;
    --danger: #c0392b;
    --ok: #227a53;
    === /palette: caps (light) ===
  }
}
*/

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: var(--font-size-1);
  line-height: 1.5;
}

/* mobile: same proportions as desktop, no horizontal overflow */
img, svg, video, canvas { max-width: 100%; height: auto; }

header, main, footer {
  padding: var(--size-4);
  max-width: 960px;
  margin: 0 auto;
}

h1, h2, h3 {
  font-weight: 600;
  line-height: 1.2;
  margin: 0 0 var(--size-3);
}
h1 { font-size: var(--font-size-3); }
h2 { font-size: var(--font-size-2); }
h3 { font-size: var(--font-size-1); }

p { color: var(--fg-muted); }

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover, a:focus-visible { text-decoration: underline; }

button, .btn {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: var(--radius-2);
  padding: var(--size-2) var(--size-3);
  font-family: var(--font-ui);
  font-size: var(--font-size-0);
  cursor: pointer;
}
button:hover { filter: brightness(1.1); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.secondary {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
}

input, textarea, select {
  background: var(--bg-raised);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  padding: var(--size-2);
  font-family: var(--font-ui);
  font-size: var(--font-size-1);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-0);
}
th, td {
  text-align: left;
  padding: var(--size-2) var(--size-3);
  border-bottom: 1px solid var(--border);
}
th {
  color: var(--fg-muted);
  font-weight: 500;
}
tbody tr:hover { background: var(--bg-raised); }

code, pre {
  font-family: var(--font-mono);
  font-size: var(--font-size-0);
}
pre {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  padding: var(--size-3);
  overflow-x: auto;
}
code { background: var(--bg-raised); padding: 2px 4px; border-radius: var(--radius-1); }

.panel {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  padding: var(--size-3);
}

/* ---- app shell: topbar, centered main, opt-in tile grid ---- */

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: none;
  padding: var(--size-2) var(--size-4);
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
}
header.topbar strong { font-weight: 600; }
header.topbar nav, header.topbar .status {
  display: flex;
  align-items: center;
  gap: var(--size-3);
}

main {
  max-width: 72ch;
  width: 100%;
  padding: var(--size-3) var(--size-4);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--size-3);
}

/* Fixed-aspect content (grids, boards, canvases): shrinks to fit viewport
   width while staying square, so a square board keeps its proportions on a
   phone instead of overflowing or letterboxing. Swap aspect-ratio for a
   non-1:1 need; the min(100%, cap) part is what does the fitting. */
.fit-square {
  width: min(100%, 480px);
  aspect-ratio: 1;
}

@media (max-width: 720px) {
  header.topbar { flex-wrap: wrap; gap: var(--size-2); }
  main { padding: var(--size-2) var(--size-3); }
}

footer {
  color: var(--fg-muted);
  font-size: var(--font-size-0);
  border-top: 1px solid var(--border);
}
