/* The Tomasetti Coloring Co. — warm cream paper + crayon colors.
   Same register as the rest of the family's things: cozy, a little funny,
   never busy. */

:root {
  --paper: #FBF6EA;
  --paper-deep: #F3EAD8;
  --ink: #3A3226;
  --ink-soft: #6E6250;
  --line: #E2D6BC;
  --red: #E4572E;
  --blue: #2F6690;
  --green: #4E9C57;
  --yellow: #F2B134;
  --purple: #8A5A9E;
  --teal: #2E8B8B;
  --shadow: 0 6px 24px rgba(58, 50, 38, .14);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Author display rules (flex/grid) must never beat the hidden attribute. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Nunito", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  padding-bottom: var(--safe-bottom);
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(242, 177, 52, .14), transparent 60%),
    radial-gradient(900px 420px at -10% 30%, rgba(46, 139, 139, .08), transparent 55%),
    var(--paper);
}

h1, h2, p { margin: 0; }

button {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

/* ---------- masthead ---------- */

.mast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + var(--safe-top)) 18px 10px;
  border-bottom: 3px solid var(--ink);
}

.mast-brand { display: flex; align-items: center; gap: 12px; }

.crayon-box { width: 52px; height: 32px; flex: none; filter: drop-shadow(0 2px 2px rgba(58,50,38,.18)); }

.mast-kicker {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.mast h1 {
  font-size: 26px;
  line-height: 1;
  letter-spacing: .01em;
  font-weight: 900;
}

.who-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  font-weight: 800;
  font-size: 14px;
  box-shadow: 2px 2px 0 var(--ink);
}

.who-dot {
  width: 12px; height: 12px; border-radius: 50%; display: inline-block;
  border: 2px solid var(--ink);
}
.who-dot.nova { background: var(--purple); }
.who-dot.breanna { background: var(--red); }
.who-dot.tj { background: var(--blue); }
.who-dot.other { background: var(--ink-soft); }

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 2px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(6px);
}

.tab {
  flex: 1;
  padding: 10px 12px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 15px;
  color: var(--ink-soft);
}
.tab.is-active { background: var(--ink); color: var(--paper); }

/* ---------- views ---------- */

.view { padding: 16px 14px 60px; max-width: 900px; margin: 0 auto; }

/* ---------- library ---------- */

.shelves {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.shelf-card {
  position: relative;
  text-align: left;
  padding: 18px 16px 16px;
  border-radius: var(--radius);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  overflow: hidden;
  min-height: 118px;
}
.shelf-card.nova { background: linear-gradient(135deg, #EFE3F6, #E3D1F0); }
.shelf-card.breanna { background: linear-gradient(135deg, #FBE3DA, #F7D2C4); }
.shelf-card.general { background: linear-gradient(135deg, #FBF0D5, #F6E7C2); }
.shelf-card::after {
  content: "✦";
  position: absolute;
  right: -6px;
  bottom: -26px;
  font-size: 90px;
  color: rgba(58, 50, 38, .08);
}

.shelf-card h2 { font-size: 19px; font-weight: 900; letter-spacing: .01em; }
.shelf-card p { font-size: 13px; color: var(--ink-soft); margin: 4px 0 10px; line-height: 1.4; }
.shelf-count {
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .7);
  border: 1.5px solid var(--ink);
}

.filter-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 12px;
  scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  padding: 8px 14px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: #fff;
  font-size: 13px;
  font-weight: 800;
  color: var(--ink-soft);
}
.chip.is-on { border-color: var(--ink); background: var(--ink); color: var(--paper); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 14px;
}

.card {
  position: relative;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: #fff;
  box-shadow: 3px 3px 0 var(--ink);
  overflow: hidden;
  padding: 0;
  text-align: left;
}

.card-img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: contain;
  background:
    repeating-conic-gradient(#f3ead8 0 25%, #fff 0 50%) 0 0 / 22px 22px;
  padding: 8px;
  display: block;
}

.card-meta {
  padding: 8px 10px 10px;
  border-top: 1.5px solid var(--line);
}
.card-title {
  font-size: 13px;
  font-weight: 800;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.6em;
}
.card-sub {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 5px;
}
.card-shelf {
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1.5px solid var(--ink);
}
.card-shelf.nova { background: #EFE3F6; color: #5A3370; }
.card-shelf.breanna { background: #FBE3DA; color: #93351B; }
.card-shelf.general { background: #FBF0D5; color: #7A5C14; }

.fav-btn {
  font-size: 17px;
  line-height: 1;
  padding: 4px 6px;
  opacity: .55;
  filter: grayscale(1);
}
.fav-btn.is-fav { opacity: 1; filter: none; }

.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 48px 20px;
  font-size: 15px;
  line-height: 1.6;
}

.footnote {
  text-align: center;
  color: var(--ink-soft);
  font-size: 12px;
  margin-top: 28px;
}

/* ---------- coloring view ---------- */

#view-color {
  max-width: none;
  padding: 8px 10px 0;
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 64px);
}

.color-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 8px;
}

.round-btn {
  flex: none;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: #fff;
  font-size: 18px;
  font-weight: 900;
  box-shadow: 2px 2px 0 var(--ink);
}

.color-title {
  flex: 1;
  font-weight: 900;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.finish-btn {
  flex: none;
  padding: 10px 18px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--red);
  color: #fff;
  font-weight: 900;
  box-shadow: 2px 2px 0 var(--ink);
}

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: #FDFBF4;
  overflow: hidden;
  touch-action: none;
}

#cv {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.zoom-hint {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, .85);
  border-radius: 999px;
  padding: 5px 12px;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity .4s;
  border: 1px solid var(--line);
}

/* ---------- toolbar ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px calc(8px + var(--safe-bottom));
  overflow-x: auto;
  scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }

.tool-group { display: flex; gap: 6px; flex: none; }

.tool {
  width: 46px; height: 46px;
  border-radius: 12px;
  border: 2px solid var(--ink);
  background: #fff;
  font-size: 20px;
  box-shadow: 2px 2px 0 var(--ink);
  flex: none;
}
.tool.is-on { background: var(--ink); }
.tool:disabled { opacity: .35; box-shadow: none; border-color: var(--line); }

.palette {
  display: flex;
  gap: 7px;
  align-items: center;
  flex: none;
}

.swatch {
  flex: none;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2.5px solid #fff;
  outline: 2px solid var(--ink);
  transition: transform .1s;
}
.swatch.is-on { transform: scale(1.22); outline-color: var(--red); }

.custom-color {
  flex: none;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 2.5px solid #fff;
  outline: 2px dashed var(--ink-soft);
  overflow: hidden;
  position: relative;
  background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
}
.custom-color input {
  position: absolute; inset: -8px;
  opacity: 0;
  cursor: pointer;
}

/* ---------- gallery ---------- */

.gallery-blurb {
  font-size: 13.5px;
  color: var(--ink-soft);
  margin-bottom: 14px;
  line-height: 1.5;
}

.gallery-card .card-img { aspect-ratio: 3 / 4; }

.gal-stamp {
  font-size: 10.5px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
}
.gal-date { font-size: 10.5px; color: var(--ink-soft); }

.gal-actions { display: flex; gap: 8px; align-items: center; }

.gal-btn {
  font-size: 11.5px;
  font-weight: 800;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1.5px solid var(--ink);
  background: #fff;
}

/* ---------- overlays ---------- */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(58, 50, 38, .5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
  padding: 16px;
}
@media (min-width: 640px) {
  .scrim { align-items: center; }
}

.sheet {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 22px;
  width: 100%;
  max-width: 460px;
  max-height: 88dvh;
  overflow-y: auto;
}
.sheet h2 { font-size: 21px; font-weight: 900; }
.sheet-sub { font-size: 13.5px; color: var(--ink-soft); margin: 4px 0 14px; }

.who-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.who-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-radius: 14px;
  border: 2px solid var(--ink);
  background: #fff;
  font-weight: 900;
  font-size: 15px;
  box-shadow: 2px 2px 0 var(--ink);
}
.who-card .who-dot { width: 16px; height: 16px; }

.finish-preview {
  border: 2px solid var(--ink);
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
  margin-bottom: 14px;
  max-height: 46dvh;
  display: flex;
  justify-content: center;
}
.finish-preview img {
  max-width: 100%;
  max-height: 46dvh;
  object-fit: contain;
  image-rendering: auto;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.text-field {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid var(--ink);
  background: #fff;
  font: inherit;
  font-size: 15px;
  margin-bottom: 10px;
}

.finish-state { font-size: 13px; font-weight: 700; color: var(--ink-soft); margin: 4px 0 12px; min-height: 1.2em; }
.finish-state.ok { color: var(--green); }

.sheet-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.primary-btn {
  padding: 12px 20px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--green);
  color: #fff;
  font-weight: 900;
  box-shadow: 2px 2px 0 var(--ink);
}
.primary-btn:disabled { opacity: .5; }

.ghost-btn {
  padding: 12px 18px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: #fff;
  font-weight: 800;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 12px 20px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 14px;
  z-index: 80;
  box-shadow: var(--shadow);
  animation: toast-in .25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
