:root {
  --bg: #fbfaf7;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --faint: #a1a1a6;
  --amber: #c27a1e;
  --glow: rgba(242, 180, 92, 0.28);
  --slot-border: rgba(194, 122, 30, 0.55);
  --slot-fill: linear-gradient(180deg, #fff3dc, #fde4b8);
  --slot-shadow: 0 0 36px rgba(242, 180, 92, 0.55), inset 0 0 18px rgba(255, 255, 255, 0.7);
  --q-shadow: 0 0 14px rgba(242, 180, 92, 0.6);
  --spine-line: rgba(255, 255, 255, 0.35);
  --plank: linear-gradient(180deg, #cdb391, #a88a66);
  --plank-shadow: 0 18px 28px -14px rgba(90, 60, 30, 0.45);
  --grain: 0.03;
  color-scheme: light;
  /* Apple devices render SF Pro + Apple's Thai system font (no download).
     Everyone else falls back to Anuphan for Thai and their system UI font. */
  --display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", "Sukhumvit Set", "Anuphan", system-ui, sans-serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Sukhumvit Set", "Anuphan", system-ui, sans-serif;
  --thai: "Sukhumvit Set", -apple-system, BlinkMacSystemFont, "Anuphan", system-ui, sans-serif;
}

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

html, body { height: 100%; }

body {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Ambient light coming from the empty slot */
.glow {
  position: fixed;
  inset: -20% -10% auto;
  height: 80vh;
  background: radial-gradient(ellipse 40% 45% at 50% 40%, var(--glow), transparent 70%);
  pointer-events: none;
  animation: breathe 6s ease-in-out infinite;
}

.grain {
  position: fixed;
  inset: 0;
  opacity: var(--grain);
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Header */
.top {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: max(20px, env(safe-area-inset-top)) clamp(20px, 5vw, 48px) 0;
  z-index: 2;
}

.wordmark {
  font-family: var(--display);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--ink);
  text-decoration: none;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 0 rgba(242, 180, 92, 0.6);
  animation: ping 2.4s ease-out infinite;
}

/* Stage */
.stage {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
}

/* Bookshelf */
.shelf {
  width: min(380px, 86vw);
  margin-bottom: 48px;
  opacity: 0;
  animation: rise 1.1s cubic-bezier(.2, .7, .2, 1) 0.1s forwards;
}

.books {
  height: 150px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
}

.b {
  width: var(--w);
  height: var(--h);
  background:
    linear-gradient(90deg, rgba(255,255,255,0.08), transparent 30%, transparent 70%, rgba(0,0,0,0.35)),
    var(--c);
  border-radius: 2px 2px 0 0;
  position: relative;
}

.b::before,
.b::after {
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  height: 1px;
  background: var(--spine-line);
}
.b::before { top: 14%; }
.b::after  { bottom: 12%; }

.b.tilt {
  transform-origin: bottom right;
  transform: rotate(-7deg) translateX(-3px);
}

/* The reserved slot */
.slot {
  width: 46px;
  height: 100%;
  margin: 0 6px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.mystery {
  width: 100%;
  height: 94%;
  border-radius: 3px 3px 0 0;
  border: 1px solid var(--slot-border);
  background: var(--slot-fill);
  box-shadow: var(--slot-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  animation: hover 4s ease-in-out infinite;
}

.mystery::after {
  content: "";
  position: absolute;
  inset: -40% -100%;
  background: linear-gradient(100deg, transparent 40%, rgba(255, 236, 200, 0.35) 50%, transparent 60%);
  animation: sheen 3.6s ease-in-out infinite;
}

.q {
  font-family: var(--display);
  font-weight: 600;
  font-size: 28px;
  color: var(--amber);
  text-shadow: var(--q-shadow);
}

.plank {
  height: 10px;
  border-radius: 2px;
  background: var(--plank);
  box-shadow: var(--plank-shadow);
}

/* Type */
.eyebrow,
.headline .line,
.thai,
.sub,
.back {
  opacity: 0;
  animation: rise 1s cubic-bezier(.2, .7, .2, 1) forwards;
}

.eyebrow {
  font-size: 12px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--amber);
  margin-bottom: 22px;
  animation-delay: 0.35s;
}

.headline {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(42px, 8.5vw, 96px);
  line-height: 1.05;
  letter-spacing: -0.035em;
}

.headline .line { display: block; }
.headline .line:nth-child(1) { animation-delay: 0.5s; }
.headline .line:nth-child(2) { animation-delay: 0.65s; }

.headline em {
  font-style: normal;
  background: linear-gradient(90deg, var(--ink), var(--amber) 120%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.thai {
  margin-top: 26px;
  font-family: var(--thai);
  font-size: clamp(19px, 2.6vw, 24px);
  font-weight: 500;
  line-height: 1.5;
  letter-spacing: 0;
  color: var(--ink);
  animation-delay: 0.85s;
}

.sub {
  margin-top: 10px;
  font-size: clamp(15px, 2vw, 17px);
  /* Fixed line box so swapping Latin ↔ Thai fonts never changes the height */
  height: 1.8em;
  line-height: 1.8em;
  color: var(--muted);
  animation-delay: 1s;
}

.rotator {
  display: inline-block;
  height: 1.8em;
  line-height: 1.8em;
  vertical-align: top;
  color: var(--ink);
  font-weight: 500;
}

#word {
  display: inline-block;
  height: 1.8em;
  line-height: 1.8em;
  vertical-align: top;
  transition: opacity .45s ease, transform .45s ease, filter .45s ease;
}

#word.out {
  opacity: 0;
  transform: translateY(-6px);
  filter: blur(4px);
}

.back {
  margin-top: 56px;
  font-size: 13px;
  color: var(--faint);
  letter-spacing: 0.02em;
  animation-delay: 1.2s;
}

.back span { margin-left: 6px; }

/* Footer */
.foot {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 0 24px max(24px, env(safe-area-inset-bottom));
  font-size: 12px;
  color: var(--faint);
}

/* Motion */
@keyframes rise {
  from { opacity: 0; transform: translateY(16px); filter: blur(6px); }
  to   { opacity: 1; transform: none; filter: none; }
}

@keyframes breathe {
  0%, 100% { opacity: 0.75; }
  50%      { opacity: 1; }
}

@keyframes hover {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-5px); }
}

@keyframes sheen {
  0%, 55% { transform: translateX(-60%); }
  100%    { transform: translateX(60%); }
}

@keyframes ping {
  0%   { box-shadow: 0 0 0 0 rgba(242, 180, 92, 0.6); }
  80%, 100% { box-shadow: 0 0 0 10px rgba(242, 180, 92, 0); }
}

@media (max-width: 480px) {
  .status { font-size: 11px; }
  .books { height: 120px; }
  .shelf { margin-bottom: 36px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition: none !important;
  }
}

/* Thai text anywhere gets the Thai face */
.th { font-family: var(--thai); }
