/* Tablet and desktop layout. Every rule needs html.tf-wide, which the app
   adds only when WIDE_LAYOUT is on and the viewport is at least 768px.
   Flag off, and phone width, never get the class, so these rules do not paint. */

html.tf-wide {
  --tf-gutter: 32px;
  --tf-content-max: 1200px;
  --tf-reader-measure: 680px;
  --tf-hero-max: 560px;
  --tf-wall: var(--tf-paper);
  --tf-wall-vignette: rgba(70, 50, 25, 0.07);
  --tf-arrow-size: 44px;
  --tf-arrow-bg: var(--tf-paper);
  --tf-arrow-icon: var(--tf-ink);
  --tf-arrow-border: var(--tf-line);
  --tf-arrow-shadow: 0 2px 8px rgba(44, 38, 32, 0.16);
  --tf-badge-size: 24px;
  --tf-badge-bg: transparent;
  --tf-badge-ink: var(--tf-ink);
  --tf-badge-border: var(--tf-ink);
  --tf-choice-hover: var(--tf-chip);
  --tf-field-bg: var(--tf-card);
}

html.tf-wide[data-theme="dark"] {
  --tf-wall-vignette: rgba(0, 0, 0, 0.38);
  --tf-arrow-icon: var(--tf-gold);
  --tf-arrow-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  --tf-badge-bg: var(--tf-gold);
  --tf-badge-ink: var(--tf-gold-ink);
  --tf-badge-border: var(--tf-gold);
  --tf-choice-hover: #2C231C;
}

@media (prefers-color-scheme: dark) {
  html.tf-wide:not([data-theme="light"]) {
    --tf-wall-vignette: rgba(0, 0, 0, 0.38);
    --tf-arrow-icon: var(--tf-gold);
    --tf-arrow-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
    --tf-badge-bg: var(--tf-gold);
    --tf-badge-ink: var(--tf-gold-ink);
    --tf-badge-border: var(--tf-gold);
    --tf-choice-hover: #2C231C;
  }
}

@media (min-width: 1200px) {
  html.tf-wide {
    --tf-gutter: 48px;
    --tf-book-w: 96px;
    --tf-book-h: 128px;
    --tf-book-gap: 18px;
  }
  /* --h is the phone height of a short book. A bare var(--h) is invalid when
     unset and would wipe height at computed-value time, so the fallback is the
     phone full height (112). Full books land on 128; short books scale with them. */
  html.tf-wide .tf-shelf .book-lean {
    height: calc(var(--h, 112px) * 128 / 112);
  }
  html.tf-wide .tf-shelf .feat .book-stage {
    --tf-book-w: 90px;
    --tf-book-h: 120px;
  }
  html.tf-wide .tf-shelf .feat .book-lean {
    width: 90px;
    height: 120px;
  }
  html.tf-wide .tf-shelf .ribbon {
    left: 70px;
  }
}

html.tf-wide .tf-wide-frame {
  background-image: radial-gradient(ellipse at center, transparent 58%, var(--tf-wall-vignette));
  background-attachment: fixed;
}

html.tf-wide [data-testid="home-shelf"],
html.tf-wide [data-testid="mood-page"],
html.tf-wide [data-testid="story-list"],
html.tf-wide [data-testid="progress-page"] {
  width: min(var(--tf-content-max), calc(100% - 2 * var(--tf-gutter))) !important;
  max-width: var(--tf-content-max);
  margin-left: auto !important;
  margin-right: auto !important;
  align-self: center;
  /* The page carries the paper and the vignette. An opaque column, or the
     shelf's own lamp gradient, paints a second shade with hard side edges. */
  background-color: transparent !important;
  background-image: none !important;
}

html.tf-wide [data-testid="home-shelf"]::before,
html.tf-wide [data-testid="mood-page"]::before,
html.tf-wide [data-testid="story-list"]::before,
html.tf-wide [data-testid="progress-page"]::before {
  display: none;
}

/* Sticky bars sample the same fixed vignette as the page, so they cover
   scrolling text without a flat paper strip. */
html.tf-wide .tf-wall-bar {
  background-color: var(--tf-paper) !important;
  background-image: radial-gradient(ellipse at center, transparent 58%, var(--tf-wall-vignette)) !important;
  background-attachment: fixed !important;
}

html.tf-wide .tf-shelf .feat {
  max-width: var(--tf-hero-max);
}

html.tf-wide .tf-shelf .row-scroll[data-overflow="0"] {
  overflow-x: hidden;
}

/* shelf.css sizes the track with content-box min-width:100% and 20px of
   padding on each side, so the border box is 40px wider than the scroller.
   A row whose books fit still overflows, the right bracket sits in that
   sliver, and the fade paints. Pull the minimum in by the padding so a
   fitting row spans the content column and keeps both brackets in view.
   An overflowing row stays max-content, so its right bracket remains at
   the end of the scrolled track. */
html.tf-wide .tf-shelf .track {
  min-width: calc(100% - 2 * var(--tf-screen-pad, 20px));
}

.tf-shelf-fade {
  position: fixed;
  width: 48px;
  z-index: 4;
  pointer-events: none;
  background: linear-gradient(to right, transparent, var(--tf-paper));
}

.tf-shelf-arrow {
  position: fixed;
  width: var(--tf-arrow-size, 44px);
  height: var(--tf-arrow-size, 44px);
  border-radius: 22px;
  border: 1px solid var(--tf-arrow-border, var(--tf-line));
  background: var(--tf-arrow-bg, var(--tf-paper));
  color: var(--tf-arrow-icon, var(--tf-ink));
  box-shadow: var(--tf-arrow-shadow);
  z-index: 5;
  cursor: pointer;
  display: grid;
  place-items: center;
  font: 600 22px/1 "Source Sans 3", system-ui, sans-serif;
  padding: 0;
}

html.tf-wide .tf-mood-rows {
  display: grid !important;
  grid-template-columns: 1fr 1fr;
  gap: 12px !important;
  width: 100%;
}

@media (min-width: 1200px) {
  html.tf-wide .tf-mood-rows {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

@media (min-width: 768px) and (max-height: 820px) {
  html.tf-wide .tf-shelf .shelf-row { margin-top: 12px; }
  html.tf-wide .tf-shelf-bar { height: 46px !important; }
}

html.tf-wide [data-testid="theme-menu"] {
  position: fixed !important;
  top: 50% !important;
  left: 50% !important;
  right: auto !important;
  width: min(560px, calc(100vw - 48px)) !important;
  transform: translate(-50%, -50%);
  z-index: 40;
  padding: 12px !important;
  box-shadow: 0 16px 48px rgba(23, 18, 14, 0.28);
}

html.tf-wide .tf-wide-reader {
  width: min(var(--tf-reader-measure), 100%);
  background-color: transparent !important;
  background-image: none !important;
}

html.tf-wide [data-testid="premise-card"] {
  max-height: 90vh !important;
  overflow-y: auto !important;
}

html.tf-wide .tf-scene-banner,
html.tf-wide [data-testid^="scene-banner"] {
  display: block;
  width: 100% !important;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 6px;
  max-height: clamp(220px, 40vh, 382px) !important;
  margin: 0 0 16px !important;
}

html.tf-wide [data-testid^="scene-banner"] img {
  object-fit: cover;
}

@media (min-width: 1000px) and (max-width: 1199px) and (max-height: 800px) {
  html.tf-wide .tf-scene-banner,
  html.tf-wide [data-testid^="scene-banner"] { max-height: 360px !important; }
}

@media (min-width: 1200px) and (max-height: 900px) {
  html.tf-wide .tf-scene-banner,
  html.tf-wide [data-testid^="scene-banner"] { max-height: 232px !important; }
}

html.tf-wide a:focus-visible,
html.tf-wide button:focus-visible,
html.tf-wide [role="button"]:focus-visible,
html.tf-wide input:focus-visible,
html.tf-wide textarea:focus-visible {
  outline: 2px solid var(--tf-focus, #2C2620);
  outline-offset: 2px;
}

html.tf-wide [role="button"],
html.tf-wide a.book,
html.tf-wide a.see,
html.tf-wide .tf-choice {
  cursor: pointer;
}

@media (hover: hover) {
  html.tf-wide .tf-story-row:hover {
    transform: translateY(-2px);
  }
  html.tf-wide .tf-choice:hover {
    background-color: var(--tf-choice-hover) !important;
    border-color: var(--tf-line) !important;
  }
  html.tf-wide .tf-shelf-arrow:hover {
    background-color: var(--tf-chip);
  }
}

.tf-skip {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 20;
  background: var(--tf-gold, #FFCF5C);
  color: var(--tf-gold-ink, #2C2620);
  padding: 8px 12px;
  border-radius: 8px;
  font: 600 14px/20px "Source Sans 3", system-ui, sans-serif;
  text-decoration: none;
}

.tf-skip:focus {
  top: 8px;
}

@media (prefers-reduced-motion: reduce) {
  html.tf-wide .tf-story-row,
  html.tf-wide .tf-shelf-arrow,
  .tf-skip {
    transition: none !important;
  }
}
