/* Notebook screens (public/notebook.js), on the shared tokens (public/ui/tokens.css) and ui- components.
   Loaded from index.html like the other portal styles. Age skins: little ones get bigger swatches
   and buttons, teens a calmer shelf. */

.nb-screen { display: grid; gap: var(--space-5); grid-template-columns: minmax(0, 1fr); } /* [a11y] shrinks with big text */
.nb-draw { box-shadow: var(--glow-accent); }

/* ---------- bookshelf ---------- */
.nb-shelf {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(120px, 100%), 1fr)); gap: var(--space-4); padding-bottom: var(--space-3);
  border-bottom: 10px solid color-mix(in srgb, #8A6A4F 70%, var(--surface)); border-radius: 0 0 6px 6px;
}
a.nb-book {
  --cover: #2F86C4;
  aspect-ratio: 3 / 4; border-radius: 6px var(--radius-md) var(--radius-md) 6px; padding: 14px 12px 12px 18px; text-decoration: none; color: #fff;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.22) 0 8px, rgba(255, 255, 255, 0.12) 8px 10px, transparent 10px), var(--cover);
  display: grid; align-content: space-between; box-shadow: var(--shadow-2); transition: transform var(--dur-fast) var(--press-ease, ease);
}
.nb-book:hover, .nb-book:focus-visible { transform: translateY(-4px) rotate(-1deg); }
.nb-book:active { transform: scale(var(--press-scale)); }
.nb-book-title { font: var(--weight-display) var(--text-lg) / 1.15 var(--font-display); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35); overflow-wrap: anywhere; }
.nb-book-sub { display: flex; align-items: center; gap: 4px; font-size: var(--text-xs); font-weight: var(--weight-strong); opacity: 0.92; }
:where([data-skin="little"]) .nb-shelf { grid-template-columns: repeat(auto-fill, minmax(min(140px, 100%), 1fr)); }
:where([data-skin="teen"], [data-skin="grown"]) .nb-shelf { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--space-3); }
:where([data-skin="teen"], [data-skin="grown"]) .nb-book-title { font-size: var(--text-md); }

/* Round color buttons (pen colors and covers), radio semantics. */
.nb-colors { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.nb-swatch {
  width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 0 0 2px var(--line-strong), inset 0 0 0 1px rgba(255, 255, 255, 0.45); /* dark colors stay visible at night */
  cursor: pointer; padding: 0; position: relative; flex: none;
}
.nb-swatch::after { content: ""; position: absolute; inset: -5px; } /* 44px tap area */
.nb-swatch[aria-checked="true"] { box-shadow: 0 0 0 3px var(--accent), 0 0 0 5px var(--surface); transform: scale(1.08); }
:where([data-skin="little"]) .nb-swatch { width: 46px; height: 46px; }
.nb-name-row { display: flex; gap: var(--space-2); align-items: stretch; }
.nb-name-row > .ui-input { flex: 1; min-width: 0; }

/* ---------- one notebook ---------- */
.nb-cover-head {
  --cover: #2F86C4; position: relative; display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4) var(--space-3) 26px;
  border-radius: 6px var(--radius-md) var(--radius-md) 6px; background: var(--cover); color: #fff; font-weight: var(--weight-strong);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); box-shadow: var(--shadow-1);
}
.nb-cover-spine { position: absolute; left: 0; top: 0; bottom: 0; width: 12px; border-radius: 6px 0 0 6px; background: rgba(0, 0, 0, 0.22); }
.nb-mini { width: 40px; height: 52px; border-radius: 4px 8px 8px 4px; flex: none; display: grid; place-items: center; object-fit: cover; background: #fff; border: 1px solid var(--line); color: #fff; }

.nb-pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: var(--space-4); }
:where([data-skin="little"]) .nb-pages { grid-template-columns: repeat(auto-fill, minmax(min(140px, 100%), 1fr)); }
a.nb-page-tile, button.nb-page-tile {
  display: grid; gap: 6px; justify-items: center; text-decoration: none; color: var(--ink-muted); font-size: var(--text-sm); font-weight: var(--weight-strong);
  border: 0; background: none; padding: 0; cursor: pointer; font-family: inherit;
}
.nb-page-tile:active { transform: scale(var(--press-scale)); }
.nb-thumb {
  display: block; width: 100%; aspect-ratio: 3 / 4; border-radius: var(--radius-sm); overflow: hidden; background-color: #fff;
  border: 1px solid var(--line); box-shadow: var(--shadow-1);
}
.nb-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.nb-add-art { display: grid; place-items: center; background: var(--surface-sunken); border: 2px dashed var(--line-strong); box-shadow: none; color: var(--ink-muted); }
.nb-add:hover .nb-add-art { border-color: var(--accent); color: var(--accent-text); }
.nb-thumb--row { width: 44px; flex: none; }

/* ---------- paper ---------- */
.nb-paper {
  position: relative; width: 100%; max-width: 720px; margin: 0 auto; aspect-ratio: 3 / 4; background-color: #FFFDF8;
  border-radius: 10px; box-shadow: var(--shadow-2); overflow: hidden; container-type: inline-size;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.nb-lined { background-image: linear-gradient(90deg, transparent 0 11%, rgba(224, 101, 79, 0.45) 11% calc(11% + 2px), transparent calc(11% + 2px)), repeating-linear-gradient(180deg, transparent 0 calc(7cqw - 1px), rgba(47, 134, 196, 0.35) calc(7cqw - 1px) 7cqw); background-position: 0 0, 0 8cqw; }
.nb-grid { background-image: repeating-linear-gradient(90deg, transparent 0 calc(4cqw - 1px), rgba(47, 134, 196, 0.25) calc(4cqw - 1px) 4cqw), repeating-linear-gradient(180deg, transparent 0 calc(4cqw - 1px), rgba(47, 134, 196, 0.25) calc(4cqw - 1px) 4cqw); }
.nb-dots { background-image: radial-gradient(circle, rgba(47, 134, 196, 0.45) calc(0.35cqw + 0.6px), transparent calc(0.35cqw + 1px)); background-size: 4.5cqw 4.5cqw; background-position: 2.25cqw 2.25cqw; }
.nb-swatch--any { background: conic-gradient(#E0654F, #F7D046, #3F9661, #2B9A94, #2F86C4, #7B5DBE, #E882B4, #E0654F) !important; }
.nb-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; cursor: crosshair; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; } /* [ios] no loupe or callout on a long press */
.nb-paper.readonly .nb-canvas { cursor: default; }
.nb-text {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; border: 0; border-radius: 0; resize: none; background: transparent;
  color: #1C2233; font-family: var(--font-hand); font-weight: 700; font-size: 22px; font-size: 5.2cqw; line-height: 7cqw;
  padding: 8cqw 5cqw 4cqw 13cqw; pointer-events: none; white-space: pre-wrap; overflow: hidden; min-height: 0;
}
.nb-paper.nb-blank .nb-text, .nb-paper.nb-grid .nb-text { padding-left: 5cqw; }
.nb-paper.typing .nb-text { pointer-events: auto; overflow-y: auto; background: rgba(255, 253, 248, 0.35); }
.nb-paper.typing .nb-text:focus { border: 0; outline: 3px dashed var(--accent); outline-offset: -6px; }
div.nb-text { overflow-y: auto; pointer-events: auto; }
/* Beat the portal's older form-field rule (style.css) so the words sit on the paper. */
.nb-paper textarea.nb-text { border: 0; border-radius: 0; background: transparent; min-height: 0; color: #1C2233; font-family: var(--font-hand); font-weight: 700; font-size: max(16px, 5.2cqw); /* [ios] 16px+: no zoom when typing */ padding: 8cqw 5cqw 4cqw 13cqw; }
.nb-paper.nb-blank textarea.nb-text, .nb-paper.nb-grid textarea.nb-text { padding-left: 5cqw; }
.nb-paper.typing textarea.nb-text { background: rgba(255, 253, 248, 0.35); }
.nb-paper:not(.typing) .nb-text::placeholder { color: transparent; }

/* ---------- editor ---------- */
.nb-editor { max-width: 760px; width: 100%; margin: 0 auto; display: grid; gap: var(--space-3); }
.nb-toolbar { display: flex; align-items: center; gap: var(--space-2); }
.nb-modes { flex: 1; min-width: 0; }
.nb-modes span { display: inline-flex; align-items: center; justify-content: center; gap: 4px; white-space: nowrap; }
.nb-toolbar-end { display: flex; gap: 2px; flex: none; }
.nb-tool { background: var(--surface-sunken); }
.nb-tool[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.nb-tool-gap { width: var(--tap); height: var(--tap); flex: none; }
.nb-tools { display: grid; gap: var(--space-2); }
.nb-tool-row { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.nb-sizes { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.nb-size {
  width: var(--tap); height: var(--tap); border-radius: var(--radius-sm); border: 2px solid var(--line); background: #FFFDF8;
  display: grid; place-items: center; cursor: pointer; padding: 0;
}
.nb-size[aria-checked="true"] { border-color: var(--accent); background: #FFE7C2; }
.nb-size span { border-radius: 50%; display: block; border: 1px solid rgba(0, 0, 0, 0.15); }
.nb-stickers { display: flex; flex-wrap: wrap; gap: 6px; }
.nb-sticker {
  font-size: 28px; width: 50px; height: 50px; border-radius: var(--radius-sm); border: 2px solid var(--line); background: var(--surface);
  cursor: pointer; padding: 0; line-height: 1;
}
.nb-sticker[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
:where([data-skin="little"]) .nb-sticker { width: 60px; height: 60px; font-size: 34px; }
.nb-type-hint { text-align: center; }
.nb-under { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); flex-wrap: wrap; max-width: 720px; width: 100%; margin: 0 auto; min-height: var(--tap); }
.nb-nav { display: flex; align-items: center; gap: var(--space-2); font-weight: var(--weight-strong); font-size: var(--text-sm); }
.nb-status { margin-left: auto; font-size: var(--text-xs); font-weight: var(--weight-strong); color: var(--ink-muted); padding: 4px 10px; border-radius: var(--radius-full); }
.nb-status:empty { display: none; }
.nb-status[data-kind="ok"] { background: var(--success-soft); color: var(--success-text, var(--success)); }
.nb-status[data-kind="bad"] { background: var(--danger-soft); color: var(--danger-text); }
.nb-actions {
  display: flex; align-items: center; gap: var(--space-2); max-width: 720px; width: 100%; margin: 0 auto;
  position: sticky; bottom: calc(var(--tabbar-h, 0px) + env(safe-area-inset-bottom, 0px) + var(--space-2)); z-index: 3;
  padding: var(--space-2); border-radius: var(--radius-lg); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(6px);
}
.nb-actions > .ui-btn { flex: 1; min-width: 0; } /* [nb-tools] never wider than a phone */
.nb-more { flex: none; }
.nb-group { display: grid; gap: 2px; }
.nb-group + .nb-group { margin-top: var(--space-3); }

/* ---------- pages for you, fridge ---------- */
.nb-from { gap: var(--space-3); }
.nb-heart { color: var(--danger); }
.nb-fridge {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: var(--space-5) var(--space-4); padding: var(--space-4);
  background: color-mix(in srgb, var(--surface-sunken) 70%, #DFE6EE); border-radius: var(--radius-lg);
}
a.nb-magnet { --tilt: 0deg; position: relative; display: grid; gap: 4px; justify-items: center; text-decoration: none; color: inherit; transform: rotate(var(--tilt)); }
.nb-magnet::before {
  content: ""; position: absolute; top: -7px; left: 50%; width: 18px; height: 18px; margin-left: -9px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35); z-index: 1;
}
.nb-magnet-hearts { display: inline-flex; align-items: center; gap: 3px; font-size: var(--text-xs); font-weight: var(--weight-strong); color: var(--danger-text); }

@media (max-width: 400px) {
  .nb-shelf { grid-template-columns: repeat(2, 1fr); }
  .nb-swatch { width: 32px; height: 32px; }
  :where([data-skin="little"]) .nb-swatch { width: 40px; height: 40px; }
  .nb-modes span { font-size: var(--text-xs); }
  .nb-modes .ui-icon { display: none; }
  :where([data-skin="little"]) .nb-modes .ui-icon { display: inline-block; }
  :where([data-skin="little"]) .nb-modes span { font-size: 0; } /* pictures only for little ones on a phone (the words stay for screen readers) */
  :where([data-skin="little"]) .nb-modes span .ui-icon { width: 28px; height: 28px; }
}

/* ---------- printing (also "Save as PDF" in the print dialog) ---------- */
#nb-print { display: none; }
@media print {
  @page { margin: 12mm; }
  body.nb-printing { background: #fff; padding: 0; }
  body.nb-printing > *:not(#nb-print) { display: none !important; }
  body.nb-printing #nb-print { display: block; }
  .nb-print-page { break-after: page; page-break-after: always; }
  .nb-print-page:last-child { break-after: auto; page-break-after: auto; }
  .nb-print-title { font: 700 14px var(--font-body); color: #586074; margin-bottom: 6px; }
  .nb-print-page .nb-paper { box-shadow: none; border: 1px solid #ccc; max-width: 180mm; max-height: 250mm; }
}
.nb-actions .ui-btn > span { white-space: nowrap; }
/* [helpers-ai] "Check my spelling" (Type mode) */
.nb-type-row { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.nb-type-row .nb-type-hint { margin: 0; }
.nb-spell { background: var(--surface); border: 2px solid var(--line-strong); border-radius: var(--radius-sm); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.nb-spell-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.nb-spell-text { margin: 0; font-family: var(--font-hand); font-weight: 700; font-size: 1.25rem; line-height: 2.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.nb-spell-word { display: inline-flex; flex-direction: column; align-items: center; vertical-align: bottom; line-height: 1.1; border: 0; padding: 2px 4px; margin: 0 1px; min-height: 40px; border-radius: 8px; background: var(--warning-soft); color: inherit; font: inherit; cursor: pointer; }
.nb-spell-was { text-decoration: underline wavy var(--warning); text-underline-offset: 4px; }
.nb-spell-fix { font-family: var(--font-body); font-size: 0.7rem; font-weight: 700; color: var(--success-text, var(--success)); }
.nb-spell-word:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- drawing tools (public/notebook-draw.js): pens, shapes, fill, zoom ---------- */
/* The stage holds the drawing and the words; two fingers zoom and pan it inside the paper. */
.nb-stage { position: absolute; inset: 0; transform-origin: 0 0; background-color: #FFFDF8; will-change: transform; }
.nb-fit { position: absolute; top: var(--space-2); right: var(--space-2); z-index: 2; box-shadow: var(--shadow-1); }
.nb-fit[hidden] { display: none; }
.nb-paper.zoomed { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Tool picker: one row that scrolls sideways on a phone (and never widens the page). */
.nb-editor { grid-template-columns: minmax(0, 1fr); }
.nb-tools { min-width: 0; grid-template-columns: minmax(0, 1fr); }
.nb-pens {
  display: flex; gap: 6px; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none;
  padding: 2px 2px 4px; margin: 0 -2px; scroll-snap-type: x proximity;
}
.nb-pens::-webkit-scrollbar { display: none; }
.nb-pen {
  flex: none; display: grid; justify-items: center; align-content: center; gap: 2px; min-width: 60px; height: 58px; padding: 4px 8px;
  border: 2px solid var(--line); border-radius: var(--radius-md); background: var(--surface); color: var(--ink);
  font: var(--weight-strong) var(--text-xs) / 1.1 var(--font-body); cursor: pointer; scroll-snap-align: start;
  transition: transform var(--dur-fast) var(--press-ease, ease);
}
.nb-pen:active { transform: scale(var(--press-scale)); }
.nb-pen[aria-checked="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.nb-pen:focus-visible, .nb-shape:focus-visible, .nb-perfect:focus-visible, .nb-size:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Shapes: which shape, outline or filled, and "Perfect" (even sides, straight lines). */
.nb-shape-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }
.nb-shape-row[hidden], .nb-fill-hint[hidden], .nb-sizes[hidden] { display: none; }
.nb-shapes { display: flex; flex-wrap: wrap; gap: 4px; padding: 3px; border-radius: var(--radius-md); background: var(--surface-sunken); }
.nb-shape {
  width: var(--tap); height: var(--tap); display: grid; place-items: center; padding: 0; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--ink); cursor: pointer;
}
.nb-shape[aria-checked="true"] { background: var(--surface); color: var(--accent-text); box-shadow: 0 0 0 2px var(--accent); }
.nb-perfect {
  display: inline-flex; align-items: center; gap: 4px; min-height: var(--tap); padding: 0 14px; border-radius: var(--radius-full);
  border: 2px solid var(--line); background: var(--surface); color: var(--ink-muted); font: var(--weight-strong) var(--text-sm) var(--font-body); cursor: pointer;
}
.nb-perfect .ui-icon { opacity: 0.25; }
.nb-perfect[aria-pressed="true"] { border-color: var(--accent); color: var(--ink); }
.nb-perfect[aria-pressed="true"] .ui-icon { opacity: 1; color: var(--success-text, var(--success)); }
.nb-fill-hint { margin: 0; }
.nb-stamp-size span.nb-stamp-demo { border: 0; border-radius: 0; line-height: 1; display: block; }

/* Little ones: big chunky buttons with pictures. */
:where([data-skin="little"]) .nb-pen { min-width: 76px; height: 76px; font-size: var(--text-sm); border-width: 3px; border-radius: var(--radius-lg); }
:where([data-skin="little"]) .nb-shape { width: 60px; height: 60px; }
:where([data-skin="little"]) .nb-size { width: 56px; height: 56px; }
/* Teens and grown-ups: a calmer, more compact picker (no big color block on the chosen tool). */
:where([data-skin="teen"], [data-skin="grown"]) .nb-pen { min-width: 54px; height: 50px; border-width: 1px; font-weight: var(--weight-body, 500); }
:where([data-skin="teen"], [data-skin="grown"]) .nb-pen[aria-checked="true"] { background: var(--accent-soft); color: var(--ink); border-color: var(--accent); box-shadow: inset 0 -3px 0 var(--accent); }

@media (max-width: 400px) {
  .nb-pen { min-width: 54px; height: 52px; padding: 4px 6px; }
  :where([data-skin="little"]) .nb-pen { min-width: 66px; height: 66px; }
  :where([data-skin="little"]) .nb-shape { width: 48px; height: 48px; } /* all six shapes on one line */
  .nb-shape-row { gap: var(--space-2); }
}
@media (prefers-reduced-motion: reduce) {
  .nb-pen { transition: none; }
}

/* [landscape] A screen wider than it is tall (a phone on its side, a tablet sideways): the page stands
   on the right, as tall as the screen allows (it keeps its 3 by 4 shape), and the tools, the page
   number and Send sit beside it on the left and scroll there when they need more room. */
@media (orientation: landscape) and (max-height: 900px) {
  .nb-editor {
    max-width: 1180px; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: repeat(7, auto) minmax(0, 1fr);
    column-gap: var(--space-3); row-gap: var(--space-2); align-items: start;
  }
  .nb-editor > * { grid-column: 1; min-width: 0; }
  .nb-editor > .nb-paper {
    grid-column: 2; grid-row: 1 / -1; align-self: start; width: auto; max-width: none;
    position: sticky; top: calc(var(--appbar-h) + env(safe-area-inset-top, 0px) + var(--space-2));
    /* as tall as the screen, but always leaving about 460px beside it for the tools */
    height: min(calc(100vh - var(--appbar-h) - 28px), max(250px, calc((100vw - var(--rail-w) - 460px) * 4 / 3)));
    height: min(calc(100dvh - var(--appbar-h) - env(safe-area-inset-top, 0px) - 28px), max(250px, calc((100vw - var(--rail-w) - 460px) * 4 / 3)));
  }
  .nb-under, .nb-actions { max-width: none; }
  .nb-actions { position: static; padding: 0; background: none; backdrop-filter: none; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .nb-pen { height: 50px; }
  :where([data-skin="little"]) .nb-pen { min-width: 64px; height: 60px; }
}
