/* Tandem Books viewer. Tokens follow /Users/xbohdpukc/dev/tandem-design-system/tokens/canonical-tokens.css */

.tb {
  --tandem-green: #135740;
  --tandem-green-hover: #0f4733;
  --tandem-green-highlight: #7dd3a8;
  --tb-band: #173c31;
  --tb-stage: #e7ebe8;
  --text-secondary: #4a4a5a;
  --shadow-sm: 0 1px 4px rgba(19, 87, 64, 0.06);
  --shadow-md: 0 2px 12px rgba(19, 87, 64, 0.08);
  --shadow-page: 0 10px 30px rgba(19, 60, 45, 0.18), 0 2px 6px rgba(19, 60, 45, 0.10);
  --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: minmax(0, 1fr); /* never wider than the screen, whatever the header holds */
  height: 100dvh;
  margin: 0;
  background: var(--tb-stage);
  color: var(--text-secondary);
  font-family: var(--font-body);
  overflow: hidden;
}

/* Brand bar */
.tb-bar {
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 56px;
  padding: 0 16px 0 24px;
  background: var(--tb-band);
  color: #fff;
  position: relative;
  z-index: 3; /* a turning page never covers the bar */
}
.tb-bar, .tb-stage, .tb-foot { min-width: 0; }
.tb-brand { display: flex; flex: none; }
.tb-brand img { display: block; height: 26px; width: auto; }
.tb-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: rgba(255, 255, 255, 0.86);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tb-tools { display: flex; gap: 4px; margin-left: auto; }
.tb-tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 44px;
  height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #fff;
  font: 500 0.81rem var(--font-body);
  text-decoration: none;
  cursor: pointer;
}
.tb-tool:hover { background: rgba(255, 255, 255, 0.10); }
.tb-tool[aria-pressed='true'] { background: rgba(255, 255, 255, 0.16); }
.tb[data-mode='spread'] .tb-tool--zoom { display: none; } /* zoom is for one page at a time */

/* Stage and book. The stage padding comes from layout.js (PADDING), per mode. */
.tb-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.tb-book { position: relative; transition: transform 700ms cubic-bezier(.45, .05, .35, 1); }
.tb-book.is-still { transition: none; }
/* page-flip (vendor/page-flip) positions every page inline; these rules size its wrappers to ours */
.tb .tb-flip.stf__parent { touch-action: pinch-zoom; } /* see touchGuard in flip.js */
.tb .tb-flip.stf__parent.is-zoomed { touch-action: pan-x pan-y pinch-zoom; }
.tb-flip .stf__wrapper { position: absolute; inset: 0; }
/* A fold shadow's clip box (fold-shadows.js), at the z-index page-flip gives its shadows */
.tb-fold { position: absolute; left: 0; top: 0; z-index: 10; overflow: hidden; pointer-events: none; transform-origin: 0 0; }
/* A plain shadow per page: a drop-shadow filter on the whole book halved the frame rate mid-turn */
.tb-page { background: #fff; overflow: hidden; box-shadow: var(--shadow-page); }
/* Spine shading: the inner edge of a bound page darkens slightly */
.tb-page[data-side]::after { content: ''; position: absolute; inset: 0; pointer-events: none; }
.tb-page[data-side='left']::after { background: linear-gradient(to left, rgba(19, 40, 32, 0.12), transparent 7%); }
.tb-page[data-side='right']::after { background: linear-gradient(to right, rgba(19, 40, 32, 0.14), transparent 7%); }
.tb-page-img {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-select: none;
}

/* Zoom: the page in view, larger, over the stage; scrolling pans it (zoom.js) */
.tb-zoom {
  position: absolute;
  inset: 0;
  z-index: 20; /* above page-flip's page layers */
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--tb-stage);
  touch-action: pan-x pan-y pinch-zoom;
  animation: tb-fade 200ms ease-out;
}
.tb-zoom:focus-visible { outline: 2px solid var(--tandem-green); outline-offset: -2px; }
.tb-zoom-sheet { width: max-content; margin: 0 auto; padding: 12px; }
.tb-zoom .tb-page { position: relative; }
@keyframes tb-fade { from { opacity: 0; } }

/* Links */
.tb-links { position: absolute; inset: 0; }
.tb-link {
  position: absolute;
  border-radius: 3px;
  transition: background-color 150ms ease-out, box-shadow 150ms ease-out;
}
.tb-link::after { content: ''; position: absolute; inset: -6px; } /* larger tap target */
.tb-link:hover { background: rgba(19, 87, 64, 0.10); box-shadow: 0 0 0 1px rgba(19, 87, 64, 0.35); }
.tb-link:focus-visible { outline: 2px solid var(--tandem-green); outline-offset: 2px; }
.tb-link.is-pulsing { animation: tb-pulse 1400ms ease-out 150ms 1; }
@keyframes tb-pulse {
  0% { background: rgba(125, 211, 168, 0); box-shadow: 0 0 0 0 rgba(19, 87, 64, 0); }
  30% { background: rgba(125, 211, 168, 0.45); box-shadow: 0 0 0 2px rgba(19, 87, 64, 0.35); }
  100% { background: rgba(125, 211, 168, 0); box-shadow: 0 0 0 0 rgba(19, 87, 64, 0); }
}

/* Side arrows (spread) and footer arrows (single) */
.tb-btn { display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.tb-btn svg, .tb-tool svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tb-side {
  position: absolute;
  top: 50%;
  width: 48px;
  height: 48px;
  margin-top: -24px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--tandem-green);
  box-shadow: var(--shadow-md);
  transition: transform 150ms ease-out, box-shadow 150ms ease-out, opacity 150ms ease-out;
}
.tb-side--prev { left: 24px; }
.tb-side--next { right: 24px; }
.tb-side:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(19, 87, 64, 0.15); }
.tb-btn:disabled { opacity: 0.35; cursor: default; }
.tb-btn:focus-visible, .tb-tool:focus-visible { outline: 2px solid var(--tandem-green-highlight); outline-offset: 2px; }

.tb-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap; /* a long button label moves to its own row */
  row-gap: 8px;
  min-height: 56px;
  padding: 0 16px calc(env(safe-area-inset-bottom) + 0px);
}
.tb-foot-mid { display: grid; justify-items: center; gap: 8px; }
.tb-count { margin: 0; font-size: 0.81rem; font-variant-numeric: tabular-nums; }
.tb-progress { width: 160px; height: 2px; background: rgba(19, 87, 64, 0.15); border-radius: 1px; }
.tb-progress-fill { display: block; height: 100%; background: var(--tandem-green); transition: width 300ms ease-out; }
.tb-foot-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: var(--tandem-green);
  box-shadow: var(--shadow-sm);
}
.tb[data-mode='spread'] .tb-foot-btn { display: none; }
.tb[data-mode='single'] .tb-side { display: none; }

/* Call-to-action button: the site's primary button, on every page */
.tb-foot-cta {
  display: inline-flex;
  min-width: 0;
  max-width: 100%;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 16px 0 20px;
  border-radius: 8px;
  background: var(--tandem-green);
  color: #fff;
  font: 600 0.9rem/1 var(--font-body);
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(19, 87, 64, 0.25);
  transition: background-color 150ms ease-out, transform 150ms ease-out, box-shadow 150ms ease-out;
}
.tb-foot-cta-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.tb-foot-cta svg { flex: none; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tb-foot-cta:hover { background: var(--tandem-green-hover); transform: translateY(-1px); box-shadow: 0 6px 20px rgba(19, 87, 64, 0.25); }
.tb-foot-cta:focus-visible { outline: 2px solid var(--tandem-green); outline-offset: 2px; }
@media (max-width: 560px) {
  /* phones: the arrows and count stay one row, the button gets a full-width row under them */
  .tb.has-cta .tb-foot { padding-top: 6px; padding-bottom: calc(env(safe-area-inset-bottom) + 8px); }
  .tb-foot-cta { flex: 0 1 100%; max-width: 420px; justify-content: center; }
}

@media (max-width: 600px) {
  .tb-bar { gap: 12px; padding: 0 8px 0 16px; }
  .tb-brand img { height: 22px; }
  .tb-title { font-size: 0.81rem; }
  .tb-tool-label { display: none; }
}

.tb-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: pre-line;
}

@media (max-width: 480px) {
  /* beside three tools a phone shows only "MCS …"; the cover carries the title, screen readers keep it */
  .tb-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}

/* Gate: a gated book's form over the stage (gate.js); the first pages stay faintly behind it */
.tb-gate {
  position: absolute;
  inset: 0;
  z-index: 30; /* above zoom and page-flip's layers */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  background: rgba(231, 235, 232, 0.88);
  animation: tb-fade 200ms ease-out;
}
.tb-gate[hidden] { display: none; }
.tb-gate-form {
  display: grid;
  gap: 16px;
  width: 100%;
  max-width: 440px;
  margin: auto;
  padding: 32px;
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--shadow-page);
}
.tb-gate-title { margin: 0; color: var(--tb-band); font: 400 1.49rem/1.25 Georgia, 'Times New Roman', serif; }
.tb-gate-text { margin: 0; font-size: 1rem; line-height: 1.55; }
.tb-gate-names { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tb-gate-field { display: grid; gap: 6px; color: #1a1a2e; font: 500 0.875rem var(--font-body); }
.tb-gate-input {
  width: 100%;
  box-sizing: border-box;
  height: 44px;
  padding: 0 12px;
  border: 1px solid #c5cfca;
  border-radius: 8px;
  background: #fff;
  color: #1a1a2e;
  font: 400 1rem var(--font-body); /* 16px: phones do not zoom into the field */
}
.tb-gate-input:focus { outline: 2px solid var(--tandem-green); outline-offset: 1px; border-color: var(--tandem-green); }
.tb-gate-check { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.tb-gate-msg { margin: 0; min-height: 1.4em; font-size: 0.875rem; }
.tb-gate-msg:empty { min-height: 0; margin-top: -16px; }
.tb-gate-msg.is-error { color: #b42318; }
.tb-gate-submit {
  height: 48px;
  border: 0;
  border-radius: 8px;
  background: var(--tandem-green);
  color: #fff;
  font: 600 1rem var(--font-body);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(19, 87, 64, 0.25);
  transition: background-color 150ms ease-out;
}
.tb-gate-submit:hover { background: var(--tandem-green-hover); }
.tb-gate-submit:disabled { opacity: 0.7; cursor: progress; }
.tb-gate-close {
  justify-self: center;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  background: none;
  color: var(--tandem-green);
  font: 500 0.875rem var(--font-body);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.tb-gate-submit:focus-visible, .tb-gate-close:focus-visible { outline: 2px solid var(--tandem-green); outline-offset: 2px; }
@media (max-width: 480px) {
  .tb-gate { padding: 12px; align-items: flex-start; }
  .tb-gate-form { padding: 24px 20px; gap: 14px; }
  .tb-gate-names { grid-template-columns: 1fr; gap: 14px; }
}
