/* ═══════════════════════════════════════════════
   Rust Koans — Ink-Wash Scroll Presentation
   ═══════════════════════════════════════════════ */

:root {
  --rice-paper: #f5edda;
  --rice-paper-warm: #f0e4ce;
  --rice-paper-deep: #e8d9be;
  --ink: #1a120a;
  --ink-soft: #3d2e22;
  --ink-muted: #6b5544;
  --ink-ghost: #a08b78;
  --vermillion: #b34233;
  --vermillion-soft: rgba(179, 66, 51, 0.12);
  --gold-accent: #8b6914;
  --seam-color: rgba(90, 65, 45, 0.15);
  --scroll-shadow: 0 0 60px rgba(20, 12, 6, 0.12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100dvh;
  overflow: hidden;
}

body {
  font-family: "Crimson Pro", Georgia, "Times New Roman", serif;
  color: var(--ink);
  background: #d8ccb4;
  background-image:
    radial-gradient(ellipse at 30% 20%, rgba(245, 237, 218, 0.6), transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(180, 160, 130, 0.2), transparent 50%);
}

/* Subtle linen texture overlay */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  opacity: 0.06;
  background-image:
    repeating-linear-gradient(
      45deg,
      rgba(80, 60, 40, 0.3) 0, rgba(80, 60, 40, 0.3) 1px,
      transparent 1px, transparent 4px
    );
}

/* ── Scroll Frame (the whole viewport) ── */

.scroll-frame {
  height: 100dvh;
  display: flex;
  flex-direction: row;
  background:
    radial-gradient(circle at 15% 15%, rgba(255, 252, 244, 0.5), transparent 40%),
    linear-gradient(135deg, var(--rice-paper) 0%, var(--rice-paper-warm) 50%, var(--rice-paper-deep) 100%);
  box-shadow: var(--scroll-shadow);
  position: relative;
}

/* Rice paper fiber texture */
.scroll-frame::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.25;
  background-image:
    repeating-linear-gradient(0deg, rgba(116, 88, 62, 0.04) 0, rgba(116, 88, 62, 0.04) 1px, transparent 1px, transparent 3px),
    repeating-linear-gradient(90deg, rgba(116, 88, 62, 0.025) 0, rgba(116, 88, 62, 0.025) 1px, transparent 1px, transparent 5px);
}

/* ── Left Panel: Painting ── */

.scroll-painting {
  flex: 0 0 42%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  position: relative;
  z-index: 2;
  transition: flex-basis 700ms cubic-bezier(0.4, 0, 0.2, 1);
}

.painting-inner {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  width: 100%;
}

.painting-inner {
  cursor: pointer;
}

.painting-inner img {
  max-width: 100%;
  max-height: 72vh;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  border-radius: 6px;
  filter: saturate(0.92) contrast(1.02);
  /* Ink-wash shadow: soft, asymmetric, like a painted edge */
  box-shadow:
    4px 6px 20px rgba(20, 12, 6, 0.15),
    0 0 0 1px rgba(90, 65, 45, 0.08);
}

.painting-caption {
  flex-shrink: 0;
  margin-top: 1rem;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 0.85rem;
  font-weight: 400;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-ghost);
  text-align: center;
  transition: opacity 300ms ease;
}

/* ── QR Badge ── */

.qr-badge {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.5rem;
  transition: opacity 300ms ease;
}

.qr-badge img {
  width: clamp(64px, 8vw, 96px);
  height: auto;
  border-radius: 4px;
}

.qr-badge span {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 0.6rem;
  letter-spacing: 0.05em;
  color: var(--ink-ghost);
}

/* Hide QR on mobile — you're already on the site */
@media (max-width: 720px) {
  .qr-badge, .intro-qr { display: none; }
}

/* ── Intro Overlay ── */

.intro-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 0 2rem 4rem;
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  transition: opacity 500ms ease;
}

.intro .intro-overlay {
  opacity: 1;
  pointer-events: auto;
}

.intro-card {
  background: rgba(245, 237, 218, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(109, 79, 60, 0.18);
  border-radius: 12px;
  padding: 1.5rem 2.5rem 1.8rem;
  text-align: center;
  box-shadow: 0 8px 32px rgba(20, 12, 6, 0.1);
}

.intro-eyebrow {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 0.85rem;
  font-weight: 400;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 0.3rem;
}

.intro-title {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: clamp(2.4rem, 5vw, 4rem);
  font-weight: 700;
  color: var(--ink);
  line-height: 1.1;
  text-align: center;
  margin: 0;
}

.intro-subtitle {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(1rem, 1.8vw, 1.3rem);
  font-style: italic;
  color: var(--ink-muted);
  margin-top: 0.4rem;
}

.intro-prompt {
  margin-top: 1.5rem;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-ghost);
  animation: pulse-prompt 2.5s ease-in-out infinite;
}

@keyframes pulse-prompt {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.intro-qr {
  margin-top: 1rem;
}

.intro-qr img {
  width: clamp(80px, 10vw, 120px);
  height: auto;
  border-radius: 4px;
}

.intro-url {
  display: block;
  margin-top: 0.25rem;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
}

.intro-links,
.footer-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
}

.intro-links { margin-top: 1.2rem; }

.intro-links a,
.footer-links a {
  color: var(--ink-ghost);
  text-decoration: none;
  display: flex;
  align-items: center;
  transition: color 150ms ease;
}

.intro-links a:hover,
.footer-links a:hover {
  color: var(--vermillion);
}

.link-label {
  margin-left: 0.3rem;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 0.75rem;
  font-weight: 600;
}

@media (max-width: 720px) {
  .link-label { display: none; }
}

/* ── Intro State ── */

.intro .scroll-painting {
  flex-basis: 100%;
}

.intro .scroll-seam {
  opacity: 0;
}

.intro .scroll-text {
  flex: 0 0 0;
  opacity: 0;
  overflow: hidden;
}

.intro .painting-caption,
.intro .qr-badge {
  opacity: 0;
}

/* ── Vertical Seam ── */

.scroll-seam {
  flex: 0 0 1px;
  background: var(--seam-color);
  position: relative;
  z-index: 3;
  transition: opacity 400ms ease 300ms;
}

.scroll-seam::before,
.scroll-seam::after {
  content: "";
  position: absolute;
  left: -3px;
  width: 7px;
  height: 24px;
  background: var(--seam-color);
  border-radius: 2px;
}

.scroll-seam::before { top: 15%; }
.scroll-seam::after  { bottom: 15%; }

/* ── Right Panel: Koan Text ── */

.scroll-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  z-index: 2;
  padding: 0;
  transition: flex 700ms cubic-bezier(0.4, 0, 0.2, 1),
              opacity 400ms ease 350ms;
}

/* ── Koan Header ── */

.koan-header {
  flex-shrink: 0;
  padding: clamp(0.8rem, 2vh, 1.5rem) clamp(1.5rem, 3vw, 2.5rem) 0;
}

.koan-number {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: clamp(0.8rem, 1.2vw, 0.95rem);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.header-rule {
  margin-top: 0.5rem;
  height: 2px;
  background: linear-gradient(90deg,
    var(--vermillion) 0%,
    var(--vermillion) 30px,
    var(--seam-color) 30px,
    var(--seam-color) 100%
  );
  border-radius: 1px;
}

/* ── Koan Body (the slide) ── */

.koan-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(1rem, 2.5vh, 2rem) clamp(1.5rem, 3vw, 2.5rem);
  outline: none;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--ink-ghost) transparent;
}

.koan-title {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: clamp(1.5rem, 2.8vw, 2.4rem);
  font-weight: 700;
  line-height: 1.2;
  color: var(--ink);
  margin-bottom: clamp(0.6rem, 1.5vh, 1.2rem);
  position: relative;
}

/* Decorative brush stroke under title */
.koan-title::after {
  content: "";
  display: block;
  margin-top: 0.4rem;
  width: 2.5em;
  height: 3px;
  background: var(--vermillion);
  border-radius: 2px;
  opacity: 0.7;
}

/* ── Dialogue layout ── */

.koan-dialogue {
  display: flex;
  flex-direction: column;
  gap: clamp(0.5rem, 1.2vh, 0.9rem);
  max-width: 42em;
}

.dialogue-row {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}

.dialogue-master {
  flex-direction: row;
  padding-right: 1.5rem;
}

.dialogue-novice {
  flex-direction: row-reverse;
  padding-left: 1.5rem;
}

.dialogue-avatar {
  width: clamp(56px, 7vw, 80px);
  height: clamp(56px, 7vw, 80px);
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(20, 12, 6, 0.15);
}

.dialogue-bubble {
  font-size: clamp(0.95rem, 1.5vw, 1.15rem);
  line-height: 1.65;
  color: var(--ink-soft);
  padding: 0.45rem 0.85rem;
  border-radius: 10px;
  position: relative;
}

.dialogue-master .dialogue-bubble {
  background: rgba(90, 65, 45, 0.06);
  border: 1px solid rgba(90, 65, 45, 0.12);
  border-top-left-radius: 3px;
}

.dialogue-novice .dialogue-bubble {
  background: rgba(179, 66, 51, 0.05);
  border: 1px solid rgba(179, 66, 51, 0.1);
  border-top-right-radius: 3px;
}

/* Stage directions: italic action text */
.dialogue-stage-direction {
  font-style: italic;
  color: var(--ink-ghost);
  border-style: dashed;
}

/* Action bubbles: animated thinking dots */
.dialogue-action {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0.55rem 0.9rem;
  min-height: 0;
}

.action-dot {
  display: block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-ghost);
  opacity: 0.5;
  animation: dot-pulse 1.4s ease-in-out 3;
}

.action-dot:nth-child(2) { animation-delay: 0.2s; }
.action-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
  0%, 60%, 100% { opacity: 0.25; transform: scale(0.85); }
  30%           { opacity: 1;    transform: scale(1.1); }
}

.dialogue-bubble code {
  font-family: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.88em;
  background: rgba(90, 65, 45, 0.08);
  border: 1px solid rgba(90, 65, 45, 0.15);
  border-radius: 3px;
  padding: 0.1em 0.35em;
  color: var(--vermillion);
}

.koan-code {
  margin: 0.8rem 0;
  padding: 0.8rem 1rem;
  border-radius: 6px;
  border-left: 3px solid var(--vermillion);
  background: rgba(255, 252, 244, 0.6);
  color: var(--ink-soft);
  font-family: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: clamp(0.82rem, 1.1vw, 0.95rem);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.koan-reflection {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--seam-color);
  color: var(--ink-muted);
  font-style: italic;
  font-size: clamp(0.9rem, 1.3vw, 1.05rem);
  line-height: 1.6;
}

/* ── Footer / Navigation ── */

.koan-footer {
  flex-shrink: 0;
  padding: 0 clamp(1.5rem, 3vw, 2.5rem) clamp(0.6rem, 1.5vh, 1.2rem);
}

.progress-track {
  height: 3px;
  border-radius: 2px;
  background: rgba(90, 65, 45, 0.1);
  margin-bottom: 0.7rem;
  overflow: hidden;
}

.progress-ink {
  width: 0;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--ink-soft), var(--ink-muted));
  transition: width 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-btn {
  appearance: none;
  flex-shrink: 0;
  border: 1px solid rgba(90, 65, 45, 0.25);
  background: transparent;
  color: var(--ink-soft);
  border-radius: 4px;
  padding: 0.35rem 0.75rem;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 150ms ease;
  letter-spacing: 0.03em;
}

.nav-btn:hover:not(:disabled) {
  background: var(--vermillion-soft);
  border-color: var(--vermillion);
  color: var(--vermillion);
}

.nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.nav-arrow {
  font-weight: 400;
}

/* Numbered jump nav */
.nav-pips {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0 0.3rem;
}

.pip {
  appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(90, 65, 45, 0.2);
  background: transparent;
  color: var(--ink-ghost);
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 200ms ease;
}

.pip:hover {
  background: var(--vermillion-soft);
  border-color: var(--vermillion);
  color: var(--vermillion);
}

.pip.active {
  background: var(--vermillion);
  border-color: var(--vermillion);
  color: var(--rice-paper);
}

.nav-hint {
  margin-top: 0.4rem;
  font-size: 0.72rem;
  color: var(--ink-ghost);
  letter-spacing: 0.05em;
}

.footer-links { margin-top: 0.4rem; }

/* ── Slide transition ── */

.koan-body.fade-out {
  opacity: 0;
  transform: translateY(6px);
}

.koan-body {
  transition: opacity 180ms ease, transform 180ms ease;
}

/* ── Touch swipe visual feedback ── */

.scroll-text.swiping-left  .koan-body { transform: translateX(-8px); opacity: 0.7; }
.scroll-text.swiping-right .koan-body { transform: translateX(8px); opacity: 0.7; }

/* ═══════════════════════════════════════════════
   Responsive: Tablet
   ═══════════════════════════════════════════════ */

@media (max-width: 960px) {
  .scroll-painting {
    flex: 0 0 38%;
    padding: 1.5rem 1rem;
  }

  .painting-inner img {
    max-height: 65vh;
  }
}

/* ═══════════════════════════════════════════════
   Responsive: Mobile — stacked layout
   ═══════════════════════════════════════════════ */

@media (max-width: 720px) {
  .scroll-frame {
    flex-direction: column;
  }

  .intro .scroll-painting {
    flex: 1 0 100%;
  }

  .intro .intro-overlay {
    padding-bottom: 3rem;
  }

  .scroll-painting {
    flex: 0 0 auto;
    padding: 0.8rem 1rem 0.4rem;
  }

  .painting-inner {
    flex: 0 0 auto;
  }

  .painting-inner img {
    max-height: 25vh;
    max-width: 80vw;
  }

  .painting-caption {
    margin-top: 0.3rem;
    font-size: 0.7rem;
  }

  .scroll-seam {
    flex: 0 0 1px;
    width: 100%;
  }

  .scroll-seam::before,
  .scroll-seam::after {
    display: none;
  }

  .koan-header {
    padding: 0.6rem 1.2rem 0;
  }

  .koan-body {
    padding: 0.8rem 1.2rem;
  }

  .koan-footer {
    padding: 0 1.2rem 0.5rem;
  }

  .nav-hint {
    display: none;
  }

  .dialogue-master { padding-right: 1rem; }
  .dialogue-novice { padding-left: 1rem; }

  .nav-pips .pip {
    display: none;
  }

  .nav-pips .pip.active {
    display: flex;
    width: 28px;
    height: 28px;
    font-size: 0.8rem;
  }

  .dialogue-avatar {
    width: 44px;
    height: 44px;
  }
}

/* ── Mobile page picker overlay ── */

.page-picker-overlay {
  display: none;
}

@media (max-width: 720px) {
  .page-picker-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgba(26, 18, 10, 0.3);
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms ease;
  }

  .page-picker-overlay.open {
    opacity: 1;
    pointer-events: auto;
  }

  .page-picker-sheet {
    background: var(--rice-paper);
    border-top: 1px solid rgba(90, 65, 45, 0.2);
    border-radius: 16px 16px 0 0;
    padding: 1rem 1.2rem 1.5rem;
    width: 100%;
    max-width: 400px;
    transform: translateY(100%);
    transition: transform 250ms cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 -8px 32px rgba(20, 12, 6, 0.15);
  }

  .page-picker-overlay.open .page-picker-sheet {
    transform: translateY(0);
  }

  .page-picker-label {
    font-family: "Cormorant Garamond", Georgia, serif;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-muted);
    text-align: center;
    margin-bottom: 0.7rem;
  }

  .page-picker-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
  }

  .page-picker-btn {
    appearance: none;
    width: 100%;
    aspect-ratio: 1;
    border-radius: 50%;
    border: 1px solid rgba(90, 65, 45, 0.2);
    background: transparent;
    color: var(--ink-ghost);
    font-family: "Cormorant Garamond", Georgia, serif;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .page-picker-btn.current {
    background: var(--vermillion);
    border-color: var(--vermillion);
    color: var(--rice-paper);
  }
}

/* ═══════════════════════════════════════════════
   Responsive: Very short viewports (landscape phone)
   ═══════════════════════════════════════════════ */

@media (max-height: 500px) {
  .scroll-painting {
    padding: 0.5rem;
  }

  .painting-inner img {
    max-height: 60vh;
  }

  .painting-caption {
    display: none;
  }

  .koan-header {
    padding-top: 0.3rem;
  }

  .header-rule {
    margin-top: 0.3rem;
  }

  .koan-body {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }

  .koan-title {
    font-size: 1.2rem;
    margin-bottom: 0.4rem;
  }

  .dialogue-bubble {
    font-size: 0.9rem;
    line-height: 1.5;
  }

  .dialogue-avatar {
    width: 36px;
    height: 36px;
  }
}

/* ═══════════════════════════════════════════════
   Responsive: Very small phones
   ═══════════════════════════════════════════════ */

@media (max-width: 400px) {
  .painting-inner img {
    max-height: 20vh;
  }

  .koan-title {
    font-size: 1.3rem;
  }

  .dialogue-bubble {
    font-size: 0.9rem;
    padding: 0.35rem 0.65rem;
  }

}

/* ═══════════════════════════════════════════════
   Fullscreen refinements
   ═══════════════════════════════════════════════ */

:fullscreen .scroll-frame {
  border-radius: 0;
}

:fullscreen .painting-inner img {
  max-height: 80vh;
}
