/* Shell, cards, chips and home/values/search layouts (spec §3.2–§3.4, §5.7). Mobile first:
   600 px → 2-column grids, 768 px → 3 columns, 1024 px → content centred at 960 px. */

/* ── Header ─────────────────────────────────────────────── */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  min-height: calc(var(--tap) + 17px); /* reserve the header's height before JS fills it */
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.logo { text-decoration: none; display: inline-flex; min-height: var(--tap); align-items: center; }
.logo__word { position: relative; font-family: var(--font-head); font-weight: 800; font-size: 26px; line-height: 1; color: var(--ink); }
.logo__dot {
  position: absolute; left: .98em; top: -.16em;
  width: .26em; height: .26em; border-radius: 50%;
  background: var(--glow); box-shadow: 0 0 .35em .12em var(--glow);
}
.top__actions { display: flex; align-items: center; gap: 4px; }
.iconbtn {
  display: inline-flex; align-items: center; justify-content: center; gap: 2px;
  min-width: var(--tap); min-height: var(--tap); padding: 0 8px;
  border: 0; border-radius: 999px; background: transparent;
  font-size: 20px; text-decoration: none;
}
.iconbtn:hover { background: var(--line); }
.script-toggle { font-family: var(--font-head); font-size: 18px; color: var(--ink-soft); }
.script-toggle .on { color: var(--ink); font-weight: 800; }
.pill { font-size: 13px; padding: 2px 10px; border-radius: 999px; background: var(--line); color: var(--ink); }

/* ── Page ───────────────────────────────────────────────── */
main { display: block; outline: none; }
.page { padding: 16px max(16px, env(safe-area-inset-left)) 48px; max-width: var(--content-max); margin: 0 auto; display: grid; gap: 20px; }
.page > * { min-width: 0; }
.soft { color: var(--ink-soft); }
.loading { text-align: center; padding: 30vh 0; font-size: 32px; }
h1:focus { outline: none; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 8px 18px;
  border: 2px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink);
  font-family: var(--font-head); font-weight: 600; font-size: 18px; text-decoration: none;
}
.btn--primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn--link { border: 0; background: none; text-decoration: underline; text-decoration-color: var(--glow); text-underline-offset: 4px; padding: 8px 4px; }

/* ── Chips ──────────────────────────────────────────────── */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 8px; scrollbar-width: none; scroll-snap-type: x proximity; }
.chips::-webkit-scrollbar { display: none; }
.chips--wrap { flex-wrap: wrap; overflow: visible; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 4px;
  min-height: var(--tap); padding: 6px 14px;
  border: 2px solid var(--v, var(--line)); border-radius: 999px;
  background: color-mix(in srgb, var(--v, var(--surface)) 45%, var(--surface));
  color: var(--ink); font-size: 16px; text-decoration: none; scroll-snap-align: start;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip--all { background: var(--surface); }
[data-theme="night"] .chip { background: var(--surface); border-color: color-mix(in srgb, var(--v, var(--line)) 60%, transparent); }
[data-theme="night"] .chip[aria-pressed="true"] { background: var(--ink); }

/* ── Story cards ────────────────────────────────────────── */
.card {
  display: grid; grid-template-rows: auto 1fr;
  background: var(--surface); border-radius: var(--radius); overflow: hidden;
  color: var(--ink); text-decoration: none;
  box-shadow: 0 1px 0 var(--line), 0 6px 18px rgb(43 35 64 / .08);
  transition: box-shadow .6s ease, transform .2s ease;
}
.card:active { transform: scale(.98); }
.cover { width: 100%; height: auto; aspect-ratio: 3 / 4; object-fit: cover; background: var(--line); }
.card__body { display: grid; gap: 4px; padding: 10px 12px 12px; }
.card__title { font-family: var(--font-head); font-weight: 600; font-size: 18px; line-height: 1.3; }
.card__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 14px; color: var(--ink-soft); }
.badge { font-size: 13px; padding: 0 8px; border-radius: 999px; border: 1px solid var(--clay); color: var(--ink); }
.dots { display: inline-flex; gap: 4px; }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.card--big .card__title { font-size: 22px; }
.card--glow { box-shadow: 0 0 0 3px var(--glow), 0 0 28px 6px color-mix(in srgb, var(--glow) 55%, transparent); }

.img-fallback { display: grid; place-items: center; align-content: center; gap: 8px; padding: 16px; background: var(--surface); color: var(--ink-soft); text-align: center; font-size: 14px; }

/* ── Home ───────────────────────────────────────────────── */
.hello { display: flex; align-items: center; gap: 12px; }
.hello__jugnu { flex: none; animation: float 4s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(calc(-6px * var(--motion))); } }

.magic { display: grid; gap: 10px; padding: 16px; border-radius: calc(var(--radius) + 4px); background: color-mix(in srgb, var(--glow) 14%, var(--surface)); }
.magic__head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.magic__when { color: var(--ink-soft); font-size: 15px; }
.magic__stage { position: relative; }
.magic__stage .card { max-width: 340px; margin: 0 auto; grid-template-columns: 40% 1fr; grid-template-rows: auto; align-items: center; }
.magic__jugnu { position: absolute; z-index: 1; left: -8px; top: -20px; pointer-events: none; }
.is-flying .magic__jugnu { animation: fly 1.2s ease-in-out both; }
.is-flying .card { opacity: .35; animation: land .4s ease-out 1.1s forwards; }
@keyframes fly {
  0% { transform: translate(-40px, 60px) rotate(-10deg); }
  50% { transform: translate(calc(50% + 120px), -10px) rotate(8deg); }
  100% { transform: translate(0, 0); }
}
@keyframes land { to { opacity: 1; } }
.magic__done { color: var(--ink-soft); text-align: center; }
.magic .btn--link { justify-self: center; }

.searchbar { display: flex; gap: 8px; }
.searchbar input {
  flex: 1; min-width: 0; min-height: var(--tap); padding: 8px 16px;
  border: 2px solid var(--line); border-radius: 999px; background: var(--surface);
}

.shelf { display: grid; gap: 8px; }
.shelf__row { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(150px, 42%); gap: 12px; overflow-x: auto; padding: 4px 2px 12px; scroll-snap-type: x proximity; scrollbar-width: thin; }
.shelf__row > * { scroll-snap-align: start; }

/* ── Values ─────────────────────────────────────────────── */
.value-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.value-tile {
  display: grid; gap: 4px; justify-items: start; min-height: 120px; padding: 14px;
  border-radius: var(--radius); background: color-mix(in srgb, var(--v) 40%, var(--surface));
  color: var(--ink); text-decoration: none;
}
[data-theme="night"] .value-tile { background: var(--surface); border: 2px solid color-mix(in srgb, var(--v) 60%, transparent); }
.value-tile__icon { font-size: 30px; }
.value-tile__label { font-family: var(--font-head); font-weight: 600; font-size: 18px; line-height: 1.3; }
.value-tile__count { font-size: 14px; color: var(--ink); }
.value-title { display: inline-flex; gap: 6px; align-items: center; border-bottom: 4px solid var(--v); padding-bottom: 4px; justify-self: start; }
.parent-note { padding: 12px 16px; border-left: 4px solid var(--glow); background: var(--surface); border-radius: 8px; }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.filters { display: grid; gap: 4px; }

/* ── Empty and error states ─────────────────────────────── */
.empty { display: grid; justify-items: center; gap: 12px; padding: 40px 16px; text-align: center; grid-column: 1 / -1; }
.empty__text { font-size: 20px; max-width: 15em; }
h1.empty__text { font-size: 22px; font-weight: 600; }

@media (min-width: 600px) {
  .shelf__row { grid-auto-columns: minmax(170px, 30%); }
  .value-grid { grid-template-columns: repeat(3, 1fr); }
  .grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 768px) {
  .value-grid { grid-template-columns: repeat(4, 1fr); }
  .grid { grid-template-columns: repeat(4, 1fr); }
  .shelf__row { grid-auto-columns: minmax(180px, 22%); }
}

/* ── Shelf tabs and settings (spec §3.8, §3.10) ─────────── */
.tabs { display: flex; gap: 6px; overflow-x: auto; }
.tab {
  flex: none; display: inline-flex; align-items: center; min-height: var(--tap); padding: 6px 14px;
  border-radius: 999px; border: 2px solid var(--line); text-decoration: none; color: var(--ink);
}
.tab[aria-current="page"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.choice { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
.choice legend { font-family: var(--font-head); font-weight: 600; font-size: 18px; margin-bottom: 6px; }
.choice__row { display: flex; flex-wrap: wrap; gap: 8px; }
.choice__opt {
  display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); padding: 6px 14px;
  border: 2px solid var(--line); border-radius: 999px; background: var(--surface); cursor: pointer;
}
.choice__opt:has(input:checked) { border-color: var(--glow); }
.choice__opt input { accent-color: var(--ink); width: 20px; height: 20px; margin: 0; }
.choice--size .choice__opt:nth-child(1) span { font-size: 14px; }
.choice--size .choice__opt:nth-child(3) span { font-size: 25px; }
.choice input[type="time"] { min-height: var(--tap); border: 2px solid var(--line); border-radius: 12px; padding: 4px 10px; background: var(--surface); }
.about { display: grid; gap: 6px; }
