/* ==========================================================================
   Project Hub — "engineer's notebook" theme
   --------------------------------------------------------------------------
   The page is a desk with three things on it:
     1. a composition-notebook COVER  (header.cover)  — the title label
     2. an engineering-paper PAGE     (main.page)     — the project list
     3. STICKY NOTES stuck to the page (a.note)        — one per project

   ARTWORK SLOTS
   Every surface has an --art-* variable that defaults to `none`. Until you
   set one, the CSS draws a placeholder (grid lines, marble, flat note colour).
   To use real artwork, drop the file in /assets and set the variable, e.g.
       --art-paper: url("assets/paper.png");
   The artwork is layered ON TOP of the placeholder, so an opaque image hides
   it completely and a transparent PNG lets it show through.
   Visit the page with ?slots in the URL to outline every slot.
   See assets/README.md for the list of files and suggested sizes.
   ========================================================================== */

/* ---- Theme tokens: light = earthy, dark = night sky ---------------------- */
:root {
  /* Artwork slots (set to url("assets/…") when you have the art) */
  --art-desk: none;      /* tiling desk / table texture behind everything   */
  --art-cover: none;     /* composition-notebook marble cover               */
  --art-label: none;     /* the white title label on the cover              */
  --art-paper: none;     /* engineering paper (tiling)                      */
  --art-sticky: none;    /* sticky-note texture (paper grain, curl shadow)  */
  --art-tape: none;      /* strip of tape on top of each sticky note        */
  --art-doodle-1: none;  /* decorative doodle, e.g. a coffee ring           */
  --art-doodle-2: none;  /* decorative doodle, e.g. a pencil or paperclip   */

  /* Fonts. System handwriting fonts for now; to use a web font, add its
     <link> or @font-face and put its name first in the stack. */
  --font-hand: "Segoe Print", "Bradley Hand", "Chalkboard SE", "Comic Neue", cursive;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", monospace;

  /* Grid size of the engineering paper; major lines every 5 squares */
  --grid: 20px;

  /* Light palette — #FEFAE0 #283618 #606C38 #BC6C25 #DDA15E */
  --desk: #d8c79f;
  --paper: #fefae0;
  --grid-line: rgba(96, 108, 56, .16);
  --grid-major: rgba(96, 108, 56, .32);
  --margin-line: rgba(188, 108, 37, .55);
  --ink: #283618;
  --ink-muted: #606c38;
  --line: #d9c79c;
  --accent: #606c38;
  --accent-contrast: #fefae0;
  --accent-2: #bc6c25;
  --danger: #a8381e;
  --ok: #46512a;

  --cover-base: #283618;
  --cover-spine: #1a2410;
  /* fractal-noise "marble" in cream (#FEFAE0) */
  --cover-marble: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='m'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.04' numOctaves='4' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.996 0 0 0 0 0.98 0 0 0 0 0.878 16 0 0 0 -8.2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23m)'/%3E%3C/svg%3E");
  --label-bg: #fffdf2;
  --label-line: rgba(96, 108, 56, .35);

  --sticky-1: #f2d888;   /* yellow  */
  --sticky-2: #d6dcab;   /* olive   */
  --sticky-3: #f1c79a;   /* rust    */
  --sticky-4: #ece3c2;   /* kraft   */
  --note-ink: #283618;
  --stamp-soon: #8a4a14;
  --stamp-live: #3d4724;
  --tape: rgba(254, 250, 224, .62);

  --shadow-page: 0 2px 4px rgba(40, 54, 24, .12), 0 18px 40px -12px rgba(40, 54, 24, .35);
  --shadow-note: 0 1px 1px rgba(40, 54, 24, .15), 0 12px 18px -10px rgba(40, 54, 24, .45);
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Night palette — #051C24 #86A1C6 #947C91 #989084 #454B6E */
    --desk: #03141a;
    --paper: #0a2530;
    --grid-line: rgba(134, 161, 198, .12);
    --grid-major: rgba(134, 161, 198, .24);
    --margin-line: rgba(148, 124, 145, .6);
    --ink: #e7ecf4;
    --ink-muted: #a9a297;
    --line: #454b6e;
    --accent: #86a1c6;
    --accent-contrast: #051c24;
    --accent-2: #947c91;
    --danger: #e8899a;
    --ok: #a9c0de;

    --cover-base: #051c24;
    --cover-spine: #454b6e;
    /* same marble, in night blue (#86A1C6) */
    --cover-marble: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='m'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.04' numOctaves='4' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.525 0 0 0 0 0.631 0 0 0 0 0.776 16 0 0 0 -8.2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23m)'/%3E%3C/svg%3E");
    --label-bg: #e7ecf4;
    --label-line: rgba(69, 75, 110, .35);

    --sticky-1: #86a1c6;   /* sky blue */
    --sticky-2: #947c91;   /* mauve    */
    --sticky-3: #989084;   /* taupe    */
    --sticky-4: #b9c7db;   /* pale sky */
    --note-ink: #051c24;
    --stamp-soon: #051c24;
    --stamp-live: #051c24;
    --tape: rgba(231, 236, 244, .28);

    --shadow-page: 0 2px 4px rgba(0, 0, 0, .4), 0 18px 40px -12px rgba(0, 0, 0, .7);
    --shadow-note: 0 1px 1px rgba(0, 0, 0, .35), 0 12px 18px -10px rgba(0, 0, 0, .75);
  }
}

/* ---- Base / desk --------------------------------------------------------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background-color: var(--desk);
  background-image: var(--art-desk);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  position: relative;
  max-width: 960px;
  margin: 0 auto;
  padding: clamp(1.25rem, 4vw, 3rem) clamp(1rem, 4vw, 2rem) 4rem;
}

/* ---- Sign-in bar (sits on the desk, above the notebook) ------------------ */
.topbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1.25rem;
  min-height: 2.4rem; /* reserve space so layout doesn't jump on load */
}
.auth { width: 100%; max-width: 440px; }
.auth[hidden], .auth-form[hidden], .auth-user[hidden] { display: none; }
.auth-form, .auth-user {
  display: flex;
  gap: .5rem;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.auth input {
  flex: 1 1 150px;
  min-width: 0;
  padding: .5rem .6rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  font-size: .9rem;
}
.auth input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.auth button {
  padding: .5rem .85rem;
  border-radius: 4px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.auth button.secondary { background: var(--paper); color: var(--accent); }
.auth button:disabled { opacity: .55; cursor: default; }
.auth-user { color: var(--ink); font-size: .9rem; }
.auth-user strong { font-weight: 600; }
.auth-msg { margin: .5rem 0 0; font-size: .82rem; text-align: right; font-weight: 600; }
.auth-msg[hidden] { display: none; }
.auth-msg.error { color: var(--danger); }
.auth-msg.ok { color: var(--ok); }
.return-note { margin: 0 0 .4rem; font-size: .82rem; color: var(--ink); text-align: right; }
.return-note[hidden] { display: none; }

/* ---- 1. Composition-notebook cover -------------------------------------- */
.cover {
  position: relative;
  display: flex;
  justify-content: center;
  padding: clamp(1.75rem, 6vw, 3.5rem) 1.25rem clamp(1.75rem, 6vw, 3.5rem) calc(1.25rem + 28px);
  border-radius: 6px 10px 10px 6px;
  background-color: var(--cover-base);
  background-image: var(--art-cover), var(--cover-marble);
  box-shadow: var(--shadow-page);
  margin-bottom: 2rem;
}
/* cloth binding tape down the left edge */
.cover::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 28px;
  border-radius: 6px 0 0 6px;
  background: var(--cover-spine);
  box-shadow: inset -3px 0 4px rgba(0, 0, 0, .25);
}

.cover-label {
  position: relative;
  width: min(100%, 460px);
  padding: 1.1rem 1.4rem 1.2rem;
  border-radius: 14px;
  background-color: var(--label-bg);
  /* ruled lines on the label */
  background-image: var(--art-label),
    repeating-linear-gradient(to bottom, transparent 0 1.9rem, var(--label-line) 1.9rem calc(1.9rem + 1px));
  background-position: 0 0, 0 2.6rem;
  color: #283618;
  text-align: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}
.eyebrow {
  display: block;
  font-family: var(--font-mono);
  font-size: .75rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  font-weight: 700;
  color: #606c38;
  margin-bottom: .35rem;
}
h1 {
  font-family: var(--font-hand);
  font-size: clamp(1.7rem, 5vw, 2.5rem);
  font-weight: 700;
  line-height: 1.15;
  margin: 0 0 .5rem;
}
.subtitle {
  font-size: clamp(.95rem, 2.5vw, 1.05rem);
  margin: 0 auto;
  max-width: 38ch;
}
@media (prefers-color-scheme: dark) {
  .cover-label { color: #051c24; }
  .eyebrow { color: #454b6e; }
}

/* ---- 2. Engineering-paper page ------------------------------------------ */
.page {
  position: relative;
  padding: 1.25rem clamp(1rem, 4vw, 2.25rem) 1.5rem clamp(1.5rem, 7vw, 4.5rem);
  border-radius: 3px;
  background-color: var(--paper);
  background-image: var(--art-paper),
    linear-gradient(var(--grid-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-major) 1px, transparent 1px),
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: auto,
    calc(var(--grid) * 5) calc(var(--grid) * 5),
    calc(var(--grid) * 5) calc(var(--grid) * 5),
    var(--grid) var(--grid),
    var(--grid) var(--grid);
  box-shadow: var(--shadow-page);
}
/* left margin rule */
.page::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: clamp(1rem, 5vw, 3.25rem);
  width: 2px;
  background: var(--margin-line);
}

/* engineer's-notebook header boxes: Project / Book No. / Page */
.page-head, .page-foot {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1.5rem;
  font-family: var(--font-mono);
  font-size: .78rem;
}
.page-head {
  padding-bottom: .6rem;
  margin-bottom: 2rem;
  border-bottom: 2px solid var(--ink-muted);
}
.field { display: flex; align-items: baseline; gap: .5rem; }
.field:first-child { flex: 1 1 14rem; }
.field-label {
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--ink-muted);
}
.field-value {
  flex: 1;
  min-width: 3rem;
  padding: 0 .25rem;
  border-bottom: 1px solid var(--ink-muted);
  font-family: var(--font-hand);
  font-size: 1rem;
  color: var(--ink);
}

/* ---- 3. Sticky notes ---------------------------------------------------- */
.board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 2.25rem 1.75rem;
  padding-top: .75rem; /* room for the tape */
}

.note {
  --note-color: var(--sticky-1);
  --tilt: -1.5deg;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 220px;
  padding: 1.6rem 1.25rem 1.1rem;
  background-color: var(--note-color);
  /* slight darkening at the glued top edge */
  background-image: var(--art-sticky),
    linear-gradient(to bottom, rgba(0, 0, 0, .06), transparent 16%);
  background-size: cover, auto;
  color: var(--note-ink);
  text-decoration: none;
  box-shadow: var(--shadow-note);
  transform: rotate(var(--tilt));
  transition: transform .18s ease, box-shadow .18s ease;
}
.note--yellow { --note-color: var(--sticky-1); }
.note--olive  { --note-color: var(--sticky-2); }
.note--rust   { --note-color: var(--sticky-3); }
.note--kraft  { --note-color: var(--sticky-4); }

/* hand-placed look: vary the tilt */
.board > :nth-child(3n + 2) { --tilt: 1.25deg; }
.board > :nth-child(3n + 3) { --tilt: -.5deg; }

/* tape */
.note::before {
  content: "";
  position: absolute;
  top: -12px;
  left: 50%;
  width: 86px;
  height: 24px;
  transform: translateX(-50%) rotate(-3deg);
  background-color: var(--tape);
  background-image: var(--art-tape);
  background-size: 100% 100%;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .08);
}

a.note:hover {
  transform: rotate(0deg) translateY(-4px) scale(1.02);
  box-shadow: var(--shadow-note), 0 18px 28px -14px rgba(0, 0, 0, .35);
}
a.note:focus-visible {
  outline: 3px solid var(--accent-2);
  outline-offset: 4px;
}

.note-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .5rem;
}
.note h2 {
  font-family: var(--font-hand);
  font-size: 1.3rem;
  line-height: 1.2;
  margin: 0;
}
.note p {
  margin: 0;
  font-size: .95rem;
  flex: 1;
}
.note .go {
  margin-top: 1rem;
  font-family: var(--font-hand);
  font-size: 1rem;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

/* status tag drawn as a rubber stamp */
.tag {
  flex-shrink: 0;
  padding: .1rem .4rem;
  border: 2px solid currentColor;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
  transform: rotate(4deg);
}
.tag.soon { color: var(--stamp-soon); }
.tag.live { color: var(--stamp-live); }

/* empty slot for a future project: an outline where a note will go */
.note--blank {
  align-items: center;
  justify-content: center;
  text-align: center;
  background: transparent;
  border: 2px dashed var(--line);
  box-shadow: none;
  color: var(--ink-muted);
  font-family: var(--font-hand);
}
.note--blank::before { display: none; }
.note--blank .plus { font-size: 1.6rem; line-height: 1; margin-bottom: .3rem; }

/* page footer: "Recorded by / Witnessed by" lines */
.page-foot {
  margin-top: 2.5rem;
  padding-top: .6rem;
  border-top: 2px solid var(--ink-muted);
}
.page-foot .field { flex: 1 1 14rem; }

/* ---- Decorative doodles (only show once their art is set) --------------- */
.doodle {
  position: absolute;
  pointer-events: none;
  background-repeat: no-repeat;
  background-size: contain;
}
.doodle--1 {               /* e.g. coffee ring, top-right of the page */
  top: -30px;
  right: -20px;
  width: 140px;
  height: 140px;
  background-image: var(--art-doodle-1);
}
.doodle--2 {               /* e.g. pencil, bottom-left on the desk */
  bottom: 1rem;
  left: -10px;
  width: 220px;
  height: 60px;
  background-image: var(--art-doodle-2);
}

/* ---- ?slots debug view: outline every artwork slot ---------------------- */
.show-slots [data-art-slot] { outline: 2px dashed #e0457b; outline-offset: -2px; }
.show-slots [data-art-slot]::after {
  content: attr(data-art-slot);
  position: absolute;
  right: 4px;
  bottom: 4px;
  z-index: 5;
  padding: 1px 6px;
  background: #e0457b;
  color: #fff;
  font: 600 11px/1.5 var(--font-mono);
}

/* ---- Small screens & motion --------------------------------------------- */
@media (max-width: 520px) {
  .board { gap: 2rem; }
  .doodle { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .note { transition: none; }
  a.note:hover { transform: rotate(var(--tilt)); }
}
