/* Story Break - prototype styles
   Direction: saa (Thai mulberry) paper + mauhom indigo.
   Serif for the literary content, clean sans for UI chrome only.
   No em-dash or en-dash anywhere, plain hyphens only. */

:root {
  /* palette */
  --paper: #efeee6;          /* saa paper, soft neutral-warm white */
  --paper-raised: #f7f6f1;   /* slips and cards, a touch lighter */
  --ink: #26262b;            /* warm near-black ink */
  --ink-soft: #6e6a62;       /* faded ink, meta and captions */
  --ink-faint: #a9a49a;      /* very faint, hairlines and disabled */
  --indigo: #33476b;         /* mauhom indigo, the single accent */
  --indigo-deep: #263552;    /* indigo, pressed and hover */
  --rule: #ddd9cd;           /* soft rule and perforation on paper */

  /* type */
  --serif-th: "Noto Serif Thai", Georgia, serif;
  --serif-en: "Newsreader", Georgia, serif;
  --sans: "IBM Plex Sans Thai", system-ui, sans-serif;

  /* shell: mobile-web-first, a phone-width column on a warm-dark backdrop */
  --shell-bg: #201b16;       /* warm dark, the paper appears lit against it */
  --app-max: 27rem;          /* ~432px, phone width */

  /* space */
  --page-pad: clamp(1.25rem, 5cqw, 2.5rem);
  --measure: 34rem;          /* comfortable reading width */

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--shell-bg);
  /* a gentle glow behind the phone */
  background-image:
    radial-gradient(120% 55% at 50% -8%, rgba(255, 248, 235, 0.07), transparent 60%);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 18px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  padding: 1.5rem;
  overscroll-behavior: contain;
}

/* the phone: a device frame for desktop review, full-bleed on a real phone */
.device {
  position: relative;
  container-type: inline-size;   /* in-frame layout sizes to the phone, not the window */
  width: 24.375rem;                              /* 390px */
  height: min(52.75rem, calc(100dvh - 7rem));    /* ~844px, capped; leaves room for .shell-nav */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 44px;
  background: var(--paper);
  /* a whisper of saa-paper grain, only on the paper */
  background-image:
    radial-gradient(rgba(120, 110, 90, 0.035) 1px, transparent 1.2px);
  background-size: 3px 3px;
  box-shadow:
    0 0 0 10px #14110d,
    0 0 0 12px #2b2620,
    0 34px 60px -24px rgba(0, 0, 0, 0.7);
}

/* faux phone status bar (desktop review only) */
.statusbar {
  flex: 0 0 auto;
  height: 2.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem 0 1.7rem;
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
}
.statusbar .sb-icons { display: inline-flex; align-items: center; gap: 0.45rem; }
.statusbar svg { display: block; }

/* the scroll area inside the phone */
.app {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
}

/* on a real phone: drop the fake frame, let the device supply its own chrome */
@media (max-width: 30rem) {
  body { padding: 0; gap: 0; align-items: stretch; }
  .device {
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    box-shadow: none;
  }
  .statusbar { display: none; }
  .app { padding-top: var(--safe-top); }
}

/* the literary content is serif, split by language */
:lang(th) { font-family: var(--serif-th); }
:lang(en) { font-family: var(--serif-en); }

/* UI chrome stays sans regardless of language */
.topbar, .lang-toggle, .eyebrow, .pick-label, .card-meta, .card-tag,
.btn, .back, .story-est, .story-source, .end-note, .home-sub, .ethos,
.wordmark-text, .skip-link {
  font-family: var(--sans);
}

/* ---- accessibility helpers ---- */
.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -3rem;
  z-index: 20;
  background: var(--indigo);
  color: var(--paper);
  padding: 0.5rem 0.9rem;
  border-radius: 0.4rem;
  font-size: 0.85rem;
  transition: top 0.15s var(--ease);
}
.skip-link:focus { top: 0.5rem; }

:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 3px;
  border-radius: 3px;
}

/* ---- top bar ---- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem var(--page-pad);
}

/* main fills the remaining phone height so short views can center */
main {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--ink);
}
.wordmark-mark {
  width: 1.05rem;
  height: 1.35rem;
  border: 1.5px solid var(--indigo);
  border-radius: 3px;
  position: relative;
  background: var(--paper-raised);
}
.wordmark-mark::after {
  /* the perforation, the tear-off */
  content: "";
  position: absolute;
  left: 12%;
  right: 12%;
  top: 62%;
  border-top: 1.5px dotted var(--indigo);
}
.wordmark-text {
  font-size: 0.98rem;
  letter-spacing: 0.14em;
  font-weight: 500;
  color: var(--ink-soft);
}

.topbar-right {
  display: inline-flex;
  align-items: center;
  gap: 0.9rem;
}

/* Quiet back-link to the parent 212Cafe Games library. Paper/indigo theme,
   secondary weight (matches the language toggle). Never a "more content" hook.
   Hidden during the immersive reading view so the ritual stays clean. */
.games-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: color 0.15s var(--ease), opacity 0.3s var(--ease);
}
.games-link:hover { color: var(--indigo); }
.games-glyph {
  position: relative;
  flex: 0 0 0.7rem;
  width: 0.7rem;
  height: 0.7rem;
  color: var(--ink-faint);
}
.games-link:hover .games-glyph { color: var(--indigo); }
/* a tiny 2x2 "all games" grid, one dot plus three shadows */
.games-glyph::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 4px;
  border-radius: 1px;
  background: currentColor;
  box-shadow:
    7px 0 0 currentColor,
    0 7px 0 currentColor,
    7px 7px 0 currentColor;
}
/* On desktop the back-link lives OUTSIDE the phone, in the page chrome
   (.shell-nav). The in-header copy is only for the full-bleed real-phone view. */
.topbar-right .games-link { display: none; }

/* fade the in-header back-link while reading (mobile full-bleed view) */
:root[data-view="read"] .topbar-right .games-link {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* page-level back-link on the dark shell, above the phone frame (desktop).
   Styled for the dark backdrop: quiet light pill, brightens on hover. */
.shell-nav {
  width: 24.375rem;
  max-width: 100%;
  display: flex;
  justify-content: flex-end;
}
.shell-nav .games-link {
  color: rgba(239, 238, 230, 0.68);
  padding: 0.42rem 0.85rem;
  border: 1px solid rgba(239, 238, 230, 0.16);
  border-radius: 999px;
  background: rgba(239, 238, 230, 0.04);
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.shell-nav .games-link:hover {
  color: #f6f3ec;
  border-color: rgba(239, 238, 230, 0.34);
}
.shell-nav .games-glyph { color: rgba(239, 238, 230, 0.6); }
.shell-nav .games-link:hover .games-glyph { color: #f6f3ec; }

@media (max-width: 22rem) {
  .games-text { display: none; }
}

.lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
}
.lang-btn {
  border: 0;
  background: none;
  cursor: pointer;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  padding: 0.35rem 0.4rem;
  transition: color 0.15s var(--ease);
}
.lang-btn:hover { color: var(--ink-soft); }
.lang-btn.is-active { color: var(--indigo); font-weight: 600; }
.lang-sep { color: var(--ink-faint); font-size: 0.8rem; }

/* ---- views ---- */
.view {
  flex: 1 0 auto;
  padding: 0 var(--page-pad) 4rem;
}
.view[hidden] { display: none; }

/* stagger-in on becoming active */
.view.is-active .reveal,
.view.is-active .home-inner > * {
  animation: rise 0.7s var(--ease) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

/* ---- home ---- */
.view-home {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.home-inner {
  max-width: 40rem;
  width: 100%;
}
.home-inner > * { animation-delay: 0.05s; }
.home-inner > .home-prompt { animation-delay: 0.12s; }
.home-inner > .home-sub { animation-delay: 0.2s; }
.home-inner > .picks { animation-delay: 0.3s; }
.home-inner > .ethos { animation-delay: 0.44s; }

.eyebrow {
  font-size: 0.78rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 1.1rem;
}

.home-prompt {
  font-family: var(--serif-th);
  font-weight: 500;
  font-size: clamp(2rem, 1.3rem + 3.4cqw, 3.3rem);
  line-height: 1.35;
  margin: 0 0 1rem;
  letter-spacing: 0.01em;
}
:lang(en) .home-prompt, .home-prompt:lang(en) { font-family: var(--serif-en); }

.home-sub {
  color: var(--ink-soft);
  font-size: 1rem;
  margin: 0 auto 2.75rem;
  max-width: 28rem;
  line-height: 1.7;
}

.picks {
  display: flex;
  justify-content: center;
  gap: clamp(0.75rem, 3cqw, 1.75rem);
  flex-wrap: wrap;
}
.pick {
  flex: 1 1 0;
  min-width: 6.5rem;
  max-width: 10rem;
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 1.5rem 0.75rem 1.1rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  transition: transform 0.2s var(--ease), border-color 0.2s var(--ease),
              box-shadow 0.2s var(--ease), background 0.2s var(--ease);
}
.pick:hover {
  transform: translateY(-4px);
  border-color: var(--indigo);
  box-shadow: 0 10px 30px -18px rgba(38, 53, 82, 0.5);
}
.pick:active { transform: translateY(-1px); }
.pick-num {
  font-family: var(--serif-en);
  font-weight: 400;
  font-size: clamp(2.8rem, 2rem + 3cqw, 4rem);
  line-height: 1;
  color: var(--indigo);
}
.pick-label {
  font-size: 0.82rem;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
  text-transform: lowercase;
}

.ethos {
  margin: 3rem auto 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
  max-width: 26rem;
  line-height: 1.6;
  position: relative;
  padding-top: 1.6rem;
}
.ethos::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 2.5rem;
  border-top: 1px solid var(--rule);
}

/* ---- back control ---- */
.back {
  background: none;
  border: 0;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.5rem 0;
  margin: 0.5rem 0 1.5rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: color 0.15s var(--ease);
}
.back:hover { color: var(--indigo); }
.back::before { content: "\2190"; font-size: 1rem; }

/* ---- card: the printed slip ---- */
.view-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.view-card .back { align-self: flex-start; }

.slip {
  background: var(--paper-raised);
  border-radius: 4px;
  max-width: 26rem;
  width: 100%;
  box-shadow: 0 22px 50px -30px rgba(38, 53, 82, 0.45);
  animation: slip-in 0.5s var(--ease) both;
}
@keyframes slip-in {
  from { opacity: 0; transform: translateY(18px) scale(0.99); }
  to { opacity: 1; transform: none; }
}
.slip-body { padding: 2.4rem 2rem 2.6rem; }

/* perforation strip at top and bottom of the slip */
.slip-perf {
  height: 12px;
  background-image: radial-gradient(circle at center, var(--paper) 46%, transparent 47%);
  background-size: 14px 14px;
  background-position: center;
  background-repeat: repeat-x;
}
.slip-perf-top { border-radius: 4px 4px 0 0; }
.slip-perf-bottom { border-radius: 0 0 4px 4px; }

.card-title {
  font-family: var(--serif-th);
  font-weight: 600;
  font-size: clamp(1.6rem, 1.2rem + 1.8cqw, 2.2rem);
  line-height: 1.3;
  margin: 0.2rem 0 0.6rem;
}
.card-title:lang(en) { font-family: var(--serif-en); font-style: italic; font-weight: 500; }

.card-author {
  font-family: var(--serif-en);
  font-style: italic;
  color: var(--ink-soft);
  font-size: 1.02rem;
  margin: 0 0 1.4rem;
}

.card-meta {
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  color: var(--ink);
  margin: 0 0 0.5rem;
}
.card-tag {
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin: 0;
}

.card-actions {
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  max-width: 26rem;
}

/* ---- buttons ---- */
.btn {
  cursor: pointer;
  border-radius: 999px;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  padding: 0.85rem 2rem;
  border: 1px solid transparent;
  transition: transform 0.15s var(--ease), background 0.2s var(--ease),
              color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--indigo);
  color: var(--paper);
  min-width: 12rem;
}
.btn-primary:hover { background: var(--indigo-deep); }
.btn-quiet {
  background: none;
  color: var(--ink-soft);
  border-color: transparent;
}
.btn-quiet:hover { color: var(--indigo); }

/* ---- reading: the finite scroll ---- */
.read-progress {
  position: sticky;
  top: 0;
  width: 100%;
  height: 3px;
  background: transparent;
  z-index: 10;
}
.read-progress-fill {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--indigo);
  transition: width 0.08s linear;
}

.view-read .back { margin-top: 1rem; }

.story {
  max-width: var(--measure);
  margin: 0 auto;
}
.story-head {
  text-align: center;
  padding: 1rem 0 2.4rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 2.4rem;
}
.story-title {
  font-family: var(--serif-th);
  font-weight: 600;
  font-size: clamp(1.7rem, 1.3rem + 1.8cqw, 2.4rem);
  line-height: 1.3;
  margin: 0 0 0.7rem;
}
.story-title:lang(en) { font-family: var(--serif-en); font-weight: 500; }
.story-author {
  font-family: var(--serif-en);
  font-style: italic;
  color: var(--ink-soft);
  font-size: 1.05rem;
  margin: 0 0 0.9rem;
}
.story-est {
  font-size: 0.76rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0;
}

.story-body { }
.story-body p {
  margin: 0 0 1.4rem;
  font-size: clamp(1.12rem, 1.02rem + 0.4cqw, 1.28rem);
}
.story-body:lang(th) p { line-height: 2.05; }
.story-body:lang(en) p { line-height: 1.78; }
/* a gentle drop of the first line, literary opening */
.story-body p:first-of-type::first-letter {
  color: var(--indigo);
}

/* ---- end of story: tear-off ---- */
.story-foot { text-align: center; margin-top: 2.5rem; }
.tear {
  height: 16px;
  margin: 0 -0.5rem 2rem;
  background-image: radial-gradient(circle at center, var(--paper) 46%, transparent 47%);
  background-size: 16px 16px;
  background-position: center;
  background-repeat: repeat-x;
  border-top: 1px dashed var(--rule);
  padding-top: 8px;
}
.end-mark {
  font-family: var(--serif-th);
  font-size: 1.2rem;
  letter-spacing: 0.16em;
  color: var(--indigo);
  margin: 0 0 0.6rem;
  padding-left: 0.16em;
}
.end-mark:lang(en) { font-family: var(--serif-en); font-style: italic; letter-spacing: 0.08em; padding-left: 0.08em; }
.end-note {
  color: var(--ink-soft);
  font-size: 0.9rem;
  margin: 0 auto 1.8rem;
  max-width: 22rem;
  line-height: 1.6;
}
.credit-label {
  font-size: 0.66rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 0.4rem;
}
.story-source {
  font-size: 0.74rem;
  color: var(--ink-soft);
  line-height: 1.55;
  max-width: 22rem;
  margin: 0 auto 2rem;
}
.end-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

/* ---- motion off ---- */
@media (prefers-reduced-motion: reduce) {
  * , *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---- small screens ---- */
@media (max-width: 30rem) {
  .picks { gap: 0.6rem; }
  .pick { min-width: 5rem; padding: 1.15rem 0.4rem 0.9rem; }
  .btn-primary { min-width: 10rem; }
  /* real phone has no "outside": hide the shell nav, use the in-header copy.
     Placed here (after the base .shell-nav rules) so it wins the cascade. */
  .shell-nav { display: none; }
  .topbar-right .games-link { display: inline-flex; }
}
