:root {
  --ink: #f3e9dc;
  --ink-soft: rgba(243, 233, 220, 0.62);
  --ink-faint: rgba(243, 233, 220, 0.14);
  --night: #14121f;
  --dusk: #2a2140;
  --ember: #e8a25c;
  --rose: #c9707a;
  --card: rgba(20, 18, 31, 0.55);
  --serif: 'Fraunces', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { background: var(--night); }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  font: 15px/1.6 var(--sans);
  padding-inline: 20px;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Sky ---------- */
.sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: linear-gradient(180deg, #14121f 0%, #241c38 45%, #4a2c48 68%, #8a4a4c 82%, #c9765a 100%);
}

.horizon {
  position: absolute;
  inset: auto 0 0 0;
  height: 84px; /* the footer's height; see the narrow-screen footer below */
  background: linear-gradient(180deg, rgba(20, 18, 31, 0.6), var(--night) 70%);
  border-top: 1px solid rgba(255, 211, 154, 0.25);
}

/* ---------- Layout ---------- */
main {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding-block: 14vh 48px;
  flex: 1;
}

.hero { text-align: center; margin-bottom: 64px; }

h1 {
  font: 300 clamp(3.2rem, 11vw, 6rem)/1 var(--serif);
  letter-spacing: -0.03em;
  margin: 0 0 16px;
}

.tagline {
  margin: 0;
  color: var(--ink-soft);
  font: italic 300 1.15rem/1.4 var(--serif);
  /* Stays on one line: shrinks with the screen on phones */
  font-size: clamp(0.72rem, 3.7vw, 1.15rem);
  white-space: nowrap;
}

/* Color-flocking artwork (flock.js): 70×30 blocks, one canvas pixel each, scaled up crisp. */
.flock {
  display: block;
  width: 100%;
  aspect-ratio: 7 / 3;
  margin-top: 40px;
  border: 1px solid var(--ink-faint);
  border-radius: 16px;
  background: var(--night);
  image-rendering: pixelated;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35), 0 0 60px rgba(232, 162, 92, 0.08);
  cursor: crosshair;
}

/* Artwork speed slider, under the canvas: the flock's own palette, night to
   ember, with one lit block as the handle and a notch at 1×. */
.flock-speed {
  display: flex;
  margin-top: 14px;
}
.flock-speed[hidden] { display: none; }
.flock-speed input {
  --strip: linear-gradient(90deg,
    #14121f, #241c38, #4a2c48, #8a4a4c, #c9765a, #e8a25c, #ffd39a);
  --notch: linear-gradient(90deg, transparent calc(50% - 1px), var(--ink) 0 calc(50% + 1px), transparent 0);
  flex: 1;
  height: 22px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.flock-speed input::-webkit-slider-runnable-track {
  height: 8px;
  border: 1px solid var(--ink-faint);
  border-radius: 4px;
  background: var(--notch) center / 100% 4px no-repeat, var(--strip);
  background-origin: border-box;
  box-shadow: 0 0 18px rgba(232, 162, 92, 0.08);
}
.flock-speed input::-moz-range-track {
  height: 8px;
  border: 1px solid var(--ink-faint);
  border-radius: 4px;
  background: var(--notch) center / 100% 4px no-repeat, var(--strip);
  background-origin: border-box;
}
.flock-speed input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -5px;
  border: 2px solid var(--night);
  border-radius: 3px;
  background: #ffd39a;
  box-shadow: 0 0 0 1px rgba(255, 211, 154, 0.5), 0 0 14px rgba(255, 211, 154, 0.55);
  transition: transform 0.15s ease;
}
.flock-speed input::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 2px solid var(--night);
  border-radius: 3px;
  background: #ffd39a;
  box-shadow: 0 0 0 1px rgba(255, 211, 154, 0.5), 0 0 14px rgba(255, 211, 154, 0.55);
}
.flock-speed input:hover::-webkit-slider-thumb,
.flock-speed input:active::-webkit-slider-thumb { transform: scale(1.15); }
.flock-speed input:focus { outline: none; }
.flock-speed input:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--ember); outline-offset: 2px; }
.flock-speed input:focus-visible::-moz-range-thumb { outline: 2px solid var(--ember); outline-offset: 2px; }

/* ---------- Project cards ---------- */
.places {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  /* Sits below the Glimmers section */
  margin-top: 64px;
}
.pages[hidden] + .places { margin-top: 0; }

.place {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 26px 26px 28px;
  border: 1px solid var(--ink-faint);
  border-radius: 18px;
  background: var(--card);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: inherit;
  text-decoration: none;
  transition: transform 0.25s ease, border-color 0.25s ease, background 0.25s ease;
}

.place:hover, .place:focus-visible {
  transform: translateY(-3px);
  border-color: rgba(232, 162, 92, 0.5);
  background: rgba(30, 24, 44, 0.7);
  outline: none;
}

.place-kicker {
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ember);
}

.place-name { font: 500 1.6rem/1.2 var(--serif); }
.place-desc { color: var(--ink-soft); font-size: 0.92rem; padding-right: 24px; }

.place-arrow {
  position: absolute;
  right: 24px;
  bottom: 24px;
  color: var(--ink-soft);
  transition: transform 0.25s ease, color 0.25s ease;
}

.place:hover .place-arrow { transform: translateX(4px); color: var(--ember); }

/* ---------- Pages ---------- */
.pages-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--ink-faint);
  padding-bottom: 12px;
  margin-bottom: 8px;
}

h2 {
  margin: 0;
  font: 300 1.5rem/1.2 var(--serif);
}

.page-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: grid;
  /* 150px minimum: two across on a phone, four in the 760px column on wider screens */
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.page-card {
  position: relative;
  border: 1px solid var(--ink-faint);
  border-radius: 16px;
  background: var(--card);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  overflow: hidden;
  transition: transform 0.25s ease, border-color 0.25s ease;
}

.page-card:hover, .page-card:focus-within {
  transform: translateY(-3px);
  border-color: rgba(232, 162, 92, 0.5);
}

.page-link { display: block; color: inherit; text-decoration: none; outline: none; }

/* The iframe renders the page at desktop width and is scaled down to a thumbnail. */
.page-thumb {
  position: relative;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: #f4efe8;
  border-bottom: 1px solid var(--ink-faint);
}

.page-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
}

.page-thumb::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 55%, rgba(20, 18, 31, 0.35));
  transition: opacity 0.25s ease;
}

.page-card:hover .page-thumb::after { opacity: 0; }

.page-info { display: grid; gap: 4px; padding: 10px 12px 12px; }

.page-title {
  font: 500 0.98rem/1.3 var(--serif);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.2s ease;
}

.page-card:hover .page-title { color: var(--ember); }

.badge {
  justify-self: start;
  padding: 2px 8px;
  border: 1px solid var(--ink-faint);
  border-radius: 999px;
  color: var(--ink-soft);
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  line-height: 1.3;
}

.badge.public { border-color: rgba(232, 162, 92, 0.45); color: var(--ember); }
.badge.shared { border-color: rgba(143, 180, 232, 0.45); color: #8fb4e8; }

.page-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  color: var(--ink-soft);
  font-size: 0.72rem;
}

.page-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty { color: var(--ink-soft); font-style: italic; padding: 14px 2px; margin: 0; }

/* ---------- Stacks ---------- */
.head-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

/* A stack card looks like a pile: two rose-tinted sheets fanned out behind a card whose preview is a
   mosaic of its glimmers. The sheets fan out further on hover. */
.stack-card {
  border: 0;
  background: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  overflow: visible;
  isolation: isolate;
}
.stack-card::before, .stack-card::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border: 1px solid rgba(201, 112, 122, 0.35);
  border-radius: 16px;
  background: #2a1f33;
  transition: transform 0.3s ease;
}
.stack-card::before { transform: rotate(-3deg) translate(-2px, -3px); }
.stack-card::after { transform: rotate(2.5deg) translate(3px, -5px); opacity: 0.75; }
.stack-card:hover::before, .stack-card:focus-within::before { transform: rotate(-5deg) translate(-5px, -5px); }
.stack-card:hover::after, .stack-card:focus-within::after { transform: rotate(4.5deg) translate(6px, -8px); }
.stack-card .page-link {
  position: relative;
  height: 100%;
  border: 1px solid rgba(201, 112, 122, 0.5);
  border-radius: 16px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(201, 112, 122, 0.16), rgba(201, 112, 122, 0.05)), #1d1726;
  transition: border-color 0.25s ease;
}
.stack-card:hover .page-link, .stack-card:focus-within .page-link { border-color: #e39aa2; }
.stack-card:hover .page-title { color: #e39aa2; }
.stack-card.drop-target .page-link { border-color: var(--ember); box-shadow: 0 0 0 2px var(--ember); }
.stack-mosaic {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 4px;
  padding: 6px;
  background: rgba(10, 8, 18, 0.35);
  border-bottom-color: rgba(201, 112, 122, 0.3);
}
.stack-mosaic::after { content: none; }
.stack-count {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(20, 18, 31, 0.85);
  border: 1px solid rgba(201, 112, 122, 0.55);
  color: #e39aa2;
  font-size: 0.72rem;
  font-weight: 500;
}
.stack-count svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
/* Tiles fill the card whatever the count: 1 full, 2 side by side, 3 one tall and two stacked, 4 a 2×2 grid */
.stack-mosaic.n0, .stack-mosaic.n1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.stack-mosaic.n2 { grid-template-rows: 1fr; }
.stack-mosaic.n3 .stack-tile:first-child { grid-row: span 2; }
.stack-empty { place-self: center; color: var(--ink-soft); font-size: 0.75rem; font-style: italic; }
.stack-tile { overflow: hidden; border-radius: 7px; background: rgba(243, 233, 220, 0.08); }
.stack-tile picture, .stack-tile img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: top; }
.badge.stack-badge { border-color: rgba(201, 112, 122, 0.5); color: #e39aa2; }

.stack-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
  margin-top: 12px;
}
.stack-head h3 { margin: 0; flex: 1 1 auto; min-width: 0; font: 300 1.25rem/1.3 var(--serif); overflow-wrap: anywhere; }
.stack-back { color: var(--ink-soft); font-size: 0.85rem; text-decoration: none; }
.stack-back:hover { color: var(--ember); }
.stack-tools { display: flex; gap: 6px; }
#stack-delete:hover { color: #ff9d9d; }

.move-list { display: grid; gap: 6px; max-height: 45vh; overflow-y: auto; }
.move-option {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--ink-faint);
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}
.move-option:hover:not(:disabled) { border-color: var(--ember); color: var(--ember); }
.move-option.here { opacity: 0.6; cursor: default; }
.move-option span { color: var(--ink-soft); font-size: 0.75rem; }
.move-new { display: flex; gap: 8px; }
.move-new input { flex: 1; min-width: 0; }
.move-new .solid { white-space: nowrap; }

/* ---------- Upload panel ---------- */
.panel {
  margin: 16px 0 20px;
  padding: 20px;
  border: 1px solid var(--ink-faint);
  border-radius: 16px;
  background: var(--card);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: grid;
  gap: 14px;
}

.drop {
  display: grid;
  place-items: center;
  min-height: 96px;
  padding: 16px;
  text-align: center;
  border: 1.5px dashed rgba(243, 233, 220, 0.25);
  border-radius: 12px;
  color: var(--ink-soft);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.drop:hover, .drop.over { border-color: var(--ember); background: rgba(232, 162, 92, 0.06); }
.drop.has-file { color: var(--ink); border-style: solid; }
.drop input { display: none; }

.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.row > label { flex: 1 1 220px; display: grid; gap: 6px; font-size: 0.82rem; color: var(--ink-soft); }
.row.end { justify-content: flex-end; }

input[type="text"], input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--ink-faint);
  border-radius: 10px;
  background: rgba(20, 18, 31, 0.6);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
}

input:focus { outline: none; border-color: var(--ember); }

.slug-wrap {
  display: flex;
  align-items: center;
  border: 1px solid var(--ink-faint);
  border-radius: 10px;
  background: rgba(20, 18, 31, 0.6);
  overflow: hidden;
}

.slug-wrap:focus-within { border-color: var(--ember); }
.slug-prefix { padding-left: 12px; color: var(--ink-soft); font-size: 0.9rem; white-space: nowrap; }
.slug-wrap input { border: 0; background: transparent; padding-left: 2px; }

.check { display: flex; gap: 8px; align-items: center; font-size: 0.85rem; color: var(--ink-soft); }
.check input { accent-color: var(--ember); }

.msg { margin: 0; margin-right: auto; font-size: 0.85rem; color: var(--ink-soft); }
.msg.err { color: #ff9d9d; }

/* ---------- Buttons ---------- */
button { font: inherit; cursor: pointer; }

.solid, .ghost {
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 0.88rem;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.solid { border: 0; background: var(--ember); color: var(--night); font-weight: 500; }
.solid:hover { background: #f2b679; }
.solid:disabled { opacity: 0.6; cursor: progress; }

.ghost { border: 1px solid var(--ink-faint); background: transparent; color: var(--ink); }
.ghost:hover { border-color: var(--ember); color: var(--ember); }

.link { border: 0; background: none; color: var(--ink-soft); padding: 4px; font-size: 0.82rem; }
.link:hover { color: var(--ember); }
a.link { text-decoration: none; }

.delete, .star, .share, .move {
  position: absolute;
  top: 6px;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(243, 233, 220, 0.2);
  border-radius: 50%;
  background: rgba(20, 18, 31, 0.8);
  color: var(--ink);
  font-size: 0.75rem;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.delete { right: 6px; }
.star { left: 6px; font-size: 0.9rem; }
.share { right: 38px; }
.move { right: 70px; }
.move svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.move:hover { color: #e39aa2; }
.move.on { color: #e39aa2; border-color: rgba(201, 112, 122, 0.6); }
.share svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }

.page-card:hover .delete, .delete:focus-visible,
.page-card:hover .star, .star:focus-visible, .star.on,
.page-card:hover .share, .share:focus-visible, .share.on,
.page-card:hover .move, .move:focus-visible { opacity: 1; }
.share:hover { color: #8fb4e8; }
.share.on { color: #8fb4e8; border-color: rgba(143, 180, 232, 0.6); }
.share:disabled { cursor: progress; }
.delete:hover { background: #d9696b; color: #fff; border-color: transparent; }
.star:hover { color: var(--ember); }
.star.on { color: var(--ember); border-color: rgba(232, 162, 92, 0.6); }
.star:disabled { cursor: progress; }

@media (hover: none) {
  .delete, .star, .share, .move { opacity: 1; }
}

/* ---------- Footer / dialog ---------- */
footer {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding-block: 24px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

dialog {
  width: min(360px, calc(100vw - 40px));
  padding: 24px;
  border: 1px solid var(--ink-faint);
  border-radius: 18px;
  background: #1c1829;
  color: var(--ink);
}

dialog::backdrop { background: rgba(10, 8, 18, 0.6); backdrop-filter: blur(4px); }
dialog h3 { margin: 0 0 16px; font: 300 1.4rem/1.2 var(--serif); }
.login-hint { margin: -8px 0 4px; color: var(--ink-soft); font-size: 0.88rem; }
dialog form { display: grid; gap: 12px; }
#share-dialog { width: min(440px, calc(100vw - 40px)); }
#share-url { font-size: 0.8rem; }
.share-block { display: grid; gap: 10px; padding: 12px 0; border-top: 1px solid var(--ink-faint); }
.share-block[hidden] { display: none; }
.share-block h4 { margin: 0; font-size: 0.9rem; font-weight: 500; }
#share-revoke { margin-right: auto; color: #ff9d9d; }
#share-revoke:hover { border-color: #d9696b; }

.solid.danger { background: #d9696b; color: #fff; }
.solid.danger:hover { background: #e57f81; }

.footer-left { display: flex; align-items: center; gap: 10px; }

/* Narrow screens: two centered rows, the links above and the copyright with Sign in/out
   below. The horizon grows to the footer's new height. */
@media (max-width: 560px) {
  footer { flex-wrap: wrap; justify-content: center; gap: 2px 6px; padding-block: 20px 28px; }
  footer::before { content: ''; order: 1; flex-basis: 100%; } /* the row break */
  .footer-left { display: contents; }
  footer .link { white-space: nowrap; }
  .footer-left > span:first-child, #auth-btn { order: 2; }
  .horizon { height: 110px; }
}

/* Ambient music toggle (ambiance.js) */
.ambiance { display: inline-flex; align-items: center; gap: 4px; }
.ambiance.on { color: var(--ember); }
.ambiance.on .ambiance-icon { animation: ambiance-breathe 4s ease-in-out infinite; }
@keyframes ambiance-breathe { 50% { opacity: 0.4; } }
@media (prefers-reduced-motion: reduce) { .ambiance.on .ambiance-icon { animation: none; } }
