/* Histia refine: a polish pass, loaded after styles.css and home.css.
 *
 * Source of the rules: the apple-design skill (Apple WWDC talks, translated to
 * the web). Nothing here changes the content, the palette or the layout of the
 * sections: the vellum, the ink, the madder and the theatre stay as they are.
 * What changes is how the page feels under the finger and the eye.
 *
 *   1. Materials   the header is glass and adapts to the section under it
 *   2. Response    every control answers on press, not on release
 *   3. Type        tracking and leading follow the size
 *   4. Depth       three shadow weights, bigger surfaces read thicker
 *   5. Motion      critically damped (no overshoot) except where a gesture
 *                  carried momentum; reduced-motion gets a cross-fade
 *   6. Accessible  reduced-transparency, more-contrast, one focus ring
 */

:root {
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);   /* settles without overshoot */
  --press: 90ms;
  --header-h: 76px;

  --glass-light: rgba(251, 247, 239, 0.72);
  --glass-dark: rgba(21, 16, 12, 0.52);

  --shadow-chip: 0 1px 2px rgba(35, 28, 18, 0.08), 0 2px 6px rgba(35, 28, 18, 0.06);
  --shadow-card: 0 1px 2px rgba(35, 28, 18, 0.06), 0 8px 24px rgba(35, 28, 18, 0.1);
  --shadow-lift: 0 2px 4px rgba(35, 28, 18, 0.06), 0 20px 44px rgba(35, 28, 18, 0.18);
}

/* ---------- 1. Materials ---------- */

.site-header {
  background: var(--glass-light);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
  border-bottom-color: transparent; /* the edge appears with the scroll, below */
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
  transition: background-color 0.4s var(--ease-out), box-shadow 0.4s var(--ease-out), color 0.4s;
}
/* On the home page the hero runs under the glass instead of starting under a
 * solid bar: the theatre is dark all the way to the top. */
.site-header.over-hero { margin-bottom: calc(var(--header-h) * -1); }

.site-header.is-scrolled {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    0 1px 0 rgba(35, 28, 18, 0.09),
    0 10px 24px -14px rgba(35, 28, 18, 0.28);
}

/* Over a dark section the material turns dark and the type turns light. */
.site-header[data-tone="dark"] {
  background: var(--glass-dark);
  box-shadow: inset 0 1px 0 rgba(243, 220, 168, 0.1);
}
.site-header[data-tone="dark"].is-scrolled {
  box-shadow:
    inset 0 1px 0 rgba(243, 220, 168, 0.1),
    0 1px 0 rgba(243, 220, 168, 0.12),
    0 10px 24px -14px rgba(0, 0, 0, 0.55);
}
.site-header[data-tone="dark"] .brand, .site-header[data-tone="dark"] .brand span { color: var(--cream); }
.site-header[data-tone="dark"] .main-nav a { color: rgba(246, 241, 231, 0.78); }
.site-header[data-tone="dark"] .main-nav a:hover { color: var(--gold-hi); }
.site-header[data-tone="dark"] .menu-toggle span { background: var(--cream); }

.main-nav a { transition: color 0.2s; letter-spacing: 0.005em; }

/* The header never wraps. Labels stay on one line, and below 880 px (where
 * the eight links of the inner pages no longer fit) they fold into the menu
 * the phone already uses, instead of breaking "How it / works" on two lines. */
.main-nav a, .nav-wrap > .cta { white-space: nowrap; }

@media (min-width: 641px) and (max-width: 880px) {
  .main-nav {
    display: none;
    position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; gap: 0; padding: 8px 4%;
  }
  .main-nav a { padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 0.95rem; }
  .main-nav a:last-child { border-bottom: 0; }
  .main-nav.open { display: flex; }
  .menu-toggle { display: block; }
  .nav-wrap > .cta-small { font-size: 0.9rem; padding: 9px 18px; }
}

/* The menu is a solid sheet under the glass: a blur cannot reach past its
 * parent's own backdrop, and links must stay legible. It slides 6 px down and
 * fades in, without a filter (a filter under a backdrop-filter let the hero
 * show through). */
@keyframes menu-in { from { opacity: 0; transform: translateY(-6px); } }
@media (max-width: 880px) {
  .site-header .main-nav {
    background: var(--paper);
    border-bottom-color: transparent;
    box-shadow: 0 26px 40px -22px rgba(35, 28, 18, 0.35);
    animation: menu-in 0.3s var(--ease-out) backwards;
  }
  .site-header[data-tone="dark"] .main-nav {
    background: var(--night);
    box-shadow: 0 26px 40px -22px rgba(0, 0, 0, 0.7);
  }
  .site-header[data-tone="dark"] .main-nav a { border-bottom-color: rgba(243, 220, 168, 0.14); color: var(--cream); }
}

/* Vibrancy: text over a material gets a touch more weight, never a flat gray. */
.site-header .main-nav a { font-weight: 600; }

/* The consent notice is a sheet of the same material, and it arrives like one. */
html #histia-consent {
  background: rgba(255, 253, 248, 0.8);
  -webkit-backdrop-filter: blur(24px) saturate(170%);
  backdrop-filter: blur(24px) saturate(170%);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 20px;
  max-width: 560px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 22px 54px rgba(35, 28, 18, 0.24);
  animation: sheet-in 0.55s var(--ease-out) both;
}
html #histia-consent button { border-radius: 12px; transition: background-color 0.2s, transform var(--press) var(--ease-out); }
html #histia-consent button:active { transform: scale(0.97); }
@keyframes sheet-in {
  from { opacity: 0; transform: translateY(14px) scale(0.98); filter: blur(6px); }
  to   { opacity: 1; transform: none; filter: blur(0); }
}

/* ---------- 2. Response: the press answers instantly ---------- */

.cta, .ghost, .stage-next, .fade-controls button, .option, .bf-cta,
.guide-tile, .library-card, .faq-item summary, .menu-toggle {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.cta, .ghost, .stage-next, .fade-controls button, .bf-cta {
  transition:
    transform var(--press) var(--ease-out),
    background-color 0.2s, border-color 0.2s, color 0.2s,
    box-shadow 0.3s var(--ease-out);
}
.cta:active, .ghost:active, .stage-next:active, .fade-controls button:active, .bf-cta:active, .option:active {
  transform: scale(0.97);
  transition-duration: 60ms;
}

/* One radius for every primary action. */
.cta, .fade-controls button { border-radius: 12px; }
.cta {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 1px 2px rgba(120, 30, 20, 0.3), 0 8px 20px rgba(176, 56, 42, 0.26);
}
.cta-large { letter-spacing: -0.005em; }
.v2-hero .cta { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.4), 0 14px 32px rgba(0, 0, 0, 0.4); }

/* Hover lifts only where a pointer can hover: no sticky hover on a phone. */
@media (hover: hover) {
  .cta:hover { transform: translateY(-1px); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 2px 4px rgba(120, 30, 20, 0.3), 0 12px 26px rgba(176, 56, 42, 0.34); }
  .cta:active { transform: scale(0.97); }
}

/* The answer options give way under the finger. */
.option { transition: background-color 0.2s, border-color 0.2s, opacity 0.3s, transform var(--press) var(--ease-out); }

/* Details rows: the whole row is the target, and it shows it on press. */
.faq-item summary { transition: background-color 0.2s; border-radius: 10px; }
.faq-item summary:active { background: rgba(35, 28, 18, 0.05); }
.faq-item summary::after {
  content: "+";
  display: inline-block;
  transition: transform 0.35s var(--ease-out);
}
.faq-item[open] summary::after { content: "+"; transform: rotate(45deg); }

/* Where the browser can animate it, the answer unfolds instead of popping. */
:root { interpolate-size: allow-keywords; }
.faq-item::details-content {
  block-size: 0;
  overflow: clip;
  transition: block-size 0.38s var(--ease-out), content-visibility 0.38s allow-discrete;
}
.faq-item[open]::details-content { block-size: auto; }

@media (max-width: 959px) {
  .site-header.over-hero + * .v2-hero-grid, .v2-hero-grid { padding-top: 48px; }
}

/* ---------- 3. Type: tracking and leading follow the size ---------- */

body { text-rendering: optimizeLegibility; }
h1, h2, h3 { font-optical-sizing: auto; }

.v2-hero h1 { letter-spacing: -0.028em; line-height: 1; }

.v2-play .section-head h2, .v2-notebook h2, .v2-world h2, .v2-devices h2,
.section-head h2, .final-cta h2, .faq-layout h2 { letter-spacing: -0.022em; line-height: 1.06; }

.play-step h3, .world-card h3 { letter-spacing: -0.018em; line-height: 1.12; }
.lesson-card h2 { letter-spacing: -0.012em; }
.guide-tile h3, .library-card h3, .library-list h3 { letter-spacing: -0.01em; }
.faq-item summary { letter-spacing: -0.006em; }

/* Large display text is tightened above; labels and small print open up. */
.eyebrow, .guide-tag { letter-spacing: 0.12em; }
.store-note, .stage-caption, figcaption, .counter-place { letter-spacing: 0.012em; }

/* Body copy: no widows or one-word last lines. */
p, li, .lead { text-wrap: pretty; }
.v2-hero .lead { line-height: 1.55; }

/* Links inside running text: a thinner, lower underline. */
a:not([class]) { text-underline-offset: 0.18em; text-decoration-thickness: 0.06em; }

/* Fix: a madder link on the dark teal library was unreadable (about 2:1). */
.library .section-head a, .v2-world .section-head a, .guides .section-head a {
  color: var(--brass-light);
  text-decoration-color: rgba(224, 192, 142, 0.55);
}

/* ---------- 4. Depth: bigger surfaces read thicker ---------- */

.guide-tile, .library-card {
  border-radius: 20px;
  transition:
    transform 0.4s var(--ease-out), box-shadow 0.4s var(--ease-out), border-color 0.25s;
}
.guide-tile { box-shadow: var(--shadow-card); }
.library-card {
  box-shadow: inset 0 1px 0 rgba(247, 240, 227, 0.06), 0 14px 34px rgba(8, 20, 24, 0.3);
}
.guide-tile img, .library-card img { transition: transform 0.8s var(--ease-out); }
.guide-tile, .library-card { overflow: hidden; }

@media (hover: hover) {
  .guide-tile:hover { transform: translateY(-4px); box-shadow: var(--shadow-lift); }
  .library-card:hover { transform: translateY(-4px); box-shadow: inset 0 1px 0 rgba(247, 240, 227, 0.08), 0 22px 46px rgba(8, 20, 24, 0.4); }
  .guide-tile:hover img, .library-card:hover img { transform: scale(1.035); }
}
.guide-tile:active, .library-card:active { transform: scale(0.985); transition-duration: var(--press); }

.devices-row img, #screenshots .shot img { box-shadow: var(--shadow-card); }
.mini-phone { box-shadow: var(--shadow-lift), inset 0 0 0 1px rgba(255, 255, 255, 0.08); }

/* The Black Friday pill: a quiet glass chip, not a dashed coupon, and never an
 * ellipse once the text wraps on a phone. */
.bf-promo { border-style: solid; border-width: 1px; border-radius: 14px; box-shadow: var(--shadow-chip); }
.bf-promo:hover { border-style: solid; }
.v2-hero .bf-promo {
  background: rgba(246, 241, 231, 0.07);
  -webkit-backdrop-filter: blur(14px) saturate(150%);
  backdrop-filter: blur(14px) saturate(150%);
  border-color: rgba(243, 220, 168, 0.26);
  box-shadow: inset 0 1px 0 rgba(243, 220, 168, 0.08);
}
.v2-badge { -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); background: rgba(246, 241, 231, 0.05); }

/* ---------- 5. Motion ---------- */

/* Cards arrive as the page is read, from 14 px below, without overshoot. The
 * attribute is set by refine.js only where IntersectionObserver exists. It is a
 * keyframe animation, not a transition, so once a card has arrived its own hover
 * and press transforms are untouched. */
.js-reveal [data-reveal]:not(.is-in) { opacity: 0; transform: translateY(14px); }
.js-reveal [data-reveal].is-in {
  animation: reveal-in 0.75s var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * 45ms);
}
@keyframes reveal-in {
  from { opacity: 0; transform: translateY(14px); }
}

.play-step { transition: opacity 0.5s var(--ease-out); }
.play-phone img { transition: opacity 0.5s var(--ease-out); }

/* ---------- 6. Accessibility ---------- */

:focus-visible { outline: 2px solid var(--accent-deep); outline-offset: 3px; }
.v2-hero :focus-visible, .v2-world :focus-visible, .guides :focus-visible,
.library :focus-visible, .final-cta :focus-visible, .site-header[data-tone="dark"] :focus-visible { outline-color: var(--gold-hi); }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .cta:hover, .guide-tile:hover, .library-card:hover { transform: none; }
  .guide-tile:hover img, .library-card:hover img { transform: none; }
  .js-reveal [data-reveal]:not(.is-in) { transform: none; }
  .js-reveal [data-reveal].is-in { animation: reveal-fade 0.3s ease backwards; animation-delay: 0s; }
  @keyframes reveal-fade { from { opacity: 0; } }
  .faq-item::details-content { transition: none; }
  .faq-item summary::after { transition: none; }
  html #histia-consent { animation: sheet-fade 0.3s ease both; }
  @keyframes sheet-fade { from { opacity: 0; } to { opacity: 1; } }
}

@media (prefers-reduced-transparency: reduce) {
  .site-header, .site-header[data-tone="dark"] { -webkit-backdrop-filter: none; backdrop-filter: none; }
  .site-header { background: var(--paper); }
  .site-header[data-tone="dark"] { background: var(--night); }
  html #histia-consent { -webkit-backdrop-filter: none; backdrop-filter: none; background: #fffdf8; }
  .v2-hero .bf-promo, .v2-badge { -webkit-backdrop-filter: none; backdrop-filter: none; }
  .v2-hero .bf-promo { background: #2a1f15; }
}

@media (prefers-contrast: more) {
  .site-header, .site-header.is-scrolled { border-bottom: 1px solid var(--ink); }
  .site-header[data-tone="dark"] { border-bottom-color: var(--gold-hi); }
  .store-note, .v2-hero .store-note, .v2-hero .store-note a { color: var(--cream); }
  .guide-tile, .library-card { border-color: currentColor; }
  .v2-hero .lead, .world-card p { color: var(--cream); }
}

/* No backdrop-filter: the glass becomes the solid it was before. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .site-header { background: rgba(251, 247, 239, 0.96); }
  .site-header[data-tone="dark"] { background: rgba(21, 16, 12, 0.94); }
  html #histia-consent { background: #fffdf8; }
}
