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

/* ── TOKENS (unchanged) ─────────────────────────────────────────────── */
:root {
  --bg: #f5f0e8;
  --surface: #ebe4d8;
  --border: rgba(0, 0, 0, 0.08);
  --text: #1e1a14;
  --muted: #7a7268;
  --accent: #9a7020;
  --accent-dim: rgba(154, 112, 32, 0.12);
  --flake-bg: #ffd9d5;
  --yes-text: #8c2e2e;
  --no-flake-bg: #d2f6d2;
  --no-text: #2a6e30;
  --transition: 0.9s cubic-bezier(0.16, 1, 0.3, 1);

  /* ── Grid sizing ─────────────────────────────────────────────────────
         Side columns are fluid gutters; they collapse to 0 on narrow
         viewports.  The center column holds the portrait content area.     */
  --col-side: minmax(0, 1fr);
  --col-center: minmax(0, 640px);

  /* Screen-transition timing — keep in sync with JS TRANSITION_MS */
  --transition-dur: 320ms;
  --transition-ease: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── BASE (unchanged) ──────────────────────────────────────────────── */
html,
body {
  height: 100%; /* needed so the grid fills the viewport */
  background: var(--bg);
  color: var(--text);
  font-family: "DM Mono", monospace;
  transition: background-color 6s var(--transition-ease);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  opacity: 0.25;
}

body::after {
  content: "";
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 600px;
  height: 600px;
  background: radial-gradient(
    ellipse,
    rgba(154, 112, 32, 0.07) 0%,
    transparent 70%
  );
  pointer-events: none;
  z-index: 0;
}

/* ══════════════════════════════════════════════════════════════════════
       APP CONTAINER
       Switched from flex-centering to a stacking context for the screens.
    ══════════════════════════════════════════════════════════════════════ */
#app {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ══════════════════════════════════════════════════════════════════════
       SCREEN LAYER
       All three screens occupy the same full-viewport slot (position:
       absolute; inset: 0).  Only the active one is visible at a time.

       State classes (toggled by showScreen() in JS):
         .screen              → off-stage right  (hidden, enters from right)
         .screen.screen--active → on-stage       (fully visible)
         .screen.screen--exit   → off-stage left (fading out to the left)
    ══════════════════════════════════════════════════════════════════════ */
.screen {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  opacity: 0;
  transform: translateX(32px);
  pointer-events: none;
  transition:
    opacity var(--transition-dur) var(--transition-ease),
    transform var(--transition-dur) var(--transition-ease);
}

.screen.screen--active {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.screen.screen--exit {
  opacity: 0;
  transform: translateX(-32px);
  pointer-events: none;
}

/* ══════════════════════════════════════════════════════════════════════
       TIC-TAC-TOE GRID LAYOUT
       Every screen uses the same 3 × 3 grid.

         Columns:  [gutter-left]  [content-center]  [gutter-right]
         Rows:     [spacer-top]   [content-mid]     [spacer-bot]

       The left/right gutter columns are decorative: they provide natural
       whitespace on wide screens and collapse to 0 on mobile.
       The center middle cell (.cell--main) hosts all visible content.
    ══════════════════════════════════════════════════════════════════════ */
.layout {
  display: grid;
  width: 100%;
  min-height: 100%;

  grid-template-columns: var(--col-side) var(--col-center) var(--col-side);
  grid-template-rows: 1fr auto 1fr;

  grid-template-areas:
    "side-tl  top-center  side-tr"
    "side-ml  main-cell   side-mr"
    "side-bl  bot-center  side-br";
}

/* Side columns collapse on narrow viewports */
@media (max-width: 480px) {
  .layout {
    grid-template-columns: 0 1fr 0;
  }
}

/* Named cells — sides and top/bot-center are intentionally empty */
.cell--top-left {
  grid-area: side-tl;
}
.cell--top-center {
  grid-area: top-center;
}
.cell--top-right {
  grid-area: side-tr;
}
.cell--mid-left {
  grid-area: side-ml;
}
.cell--mid-right {
  grid-area: side-mr;
}
.cell--bot-left {
  grid-area: side-bl;
}
.cell--bot-center {
  grid-area: bot-center;
}
.cell--bot-right {
  grid-area: side-br;
}

/* ── MAIN CONTENT CELL ─────────────────────────────────────────────────
       Flexbox column; centres children vertically.  Add padding so content
       never touches the viewport edge.  overflow-y: auto handles the rare
       case where a long result would otherwise clip on short screens.      */
.cell--main {
  grid-area: main-cell;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
}

/* ══════════════════════════════════════════════════════════════════════
       ALL CONTENT STYLES BELOW ARE UNCHANGED FROM THE ORIGINAL
    ══════════════════════════════════════════════════════════════════════ */

/* ── HERO ── */
#hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  text-align: center;
  width: 100%;
  /* animation is re-triggered by JS on every reset */
  animation: fadeUp 1s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.eyebrow {
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid rgba(154, 112, 32, 0.3);
  padding: 6px 16px;
  border-radius: 2px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2em;
}

.eyebrow-static {
  flex-shrink: 0;
}

.word-slot {
  position: relative;
  display: inline-block;
  overflow: hidden;
  height: 1.2em;
  vertical-align: middle;
  transition: width 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.word-slot-inner {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  transform: translateY(110%);
  opacity: 0;
  transition: none;
}

.word-slot-inner.slot-in {
  animation: slotIn 0.38s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.word-slot-inner.slot-out {
  animation: slotOut 0.28s cubic-bezier(0.4, 0, 1, 1) forwards;
}

@keyframes slotIn {
  from {
    transform: translateY(110%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}
@keyframes slotOut {
  from {
    transform: translateY(0);
    opacity: 1;
  }
  to {
    transform: translateY(-110%);
    opacity: 0;
  }
}

h1 {
  font-family: "Playfair Display", Georgia, serif;
  font-size: clamp(2.6rem, 7vw, 5.5rem);
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -0.02em;
}

h1 em {
  font-style: italic;
  color: var(--accent);
}

.sub {
  font-size: 14px;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-weight: 400;
}

/* ── INPUT ROW ── */
.input-row {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  width: 100%;
}

.input-row .field {
  flex: 1 1 180px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition:
    opacity 0.3s,
    transform 0.3s;
}

.field.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
}

.field label {
  font-size: 11px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--text);
  font-weight: 300;
}

.field input {
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(154, 112, 32, 0.3);
  color: var(--text);
  font-family: "DM Mono", monospace;
  font-size: 13px;
  font-weight: 300;
  letter-spacing: 0.1em;
  padding: 10px 0;
  outline: none;
  transition: border-color 0.3s;
  caret-color: var(--accent);
  width: 100%;
}

.field input::placeholder {
  color: rgba(30, 26, 20, 0.3);
}
.field input:focus {
  border-bottom-color: var(--accent);
}

/* ── BUTTON ── */
#tap-btn {
  position: relative;
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: "DM Mono", monospace;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  padding: 18px 52px;
  cursor: pointer;
  outline: none;
  transition:
    color 0.2s,
    transform 0.15s;
  overflow: hidden;
  margin-top: 8px;
}

#tap-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 0;
}

#tap-btn span {
  position: relative;
  z-index: 1;
}
#tap-btn:hover::before {
  transform: scaleX(1);
}
#tap-btn:hover {
  color: var(--bg);
}
#tap-btn:active {
  transform: scale(0.97);
}

/* ── FORECASTING ── */
#forecasting {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
  /* Content animation is re-triggered by JS via class toggle */
}

#forecasting.visible {
  animation: fadeUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.forecast-label {
  font-family: "Playfair Display", Georgia, serif;
  font-style: italic;
  font-size: clamp(1.6rem, 5vw, 2.8rem);
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.wave-dots {
  display: flex;
  gap: 10px;
  align-items: center;
}

.wave-dots span {
  display: block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: waveDot 1.2s ease-in-out infinite;
}

.wave-dots span:nth-child(1) {
  animation-delay: 0s;
}
.wave-dots span:nth-child(2) {
  animation-delay: 0.18s;
}
.wave-dots span:nth-child(3) {
  animation-delay: 0.36s;
}
.wave-dots span:nth-child(4) {
  animation-delay: 0.54s;
}
.wave-dots span:nth-child(5) {
  animation-delay: 0.72s;
}

@keyframes waveDot {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.25;
  }
  50% {
    transform: translateY(-12px);
    opacity: 1;
  }
}

/* ── RESULT ── */
#result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  text-align: center;
  padding: 0 24px;
}

/* Name — typed in via JS */
.flake-name {
  font-family: "Playfair Display", Georgia, serif;
  font-size: clamp(2.2rem, 8vw, 5rem);
  font-weight: 900;
  font-style: italic;
  line-height: 1;
  letter-spacing: -0.02em;
  min-height: 1em;
}

.flake-name.yes {
  color: var(--accent);
}
.flake-name.no {
  color: var(--accent);
}

/* Verdict phrase — shorter text, italic Playfair */
.verdict,
.outcome-text {
  opacity: 0;
}

.verdict.visible,
.outcome-text.visible {
  opacity: 1;
  transition: opacity 0.8s var(--transition-ease);
}

.verdict {
  font-family: "Playfair Display", Georgia, serif;
  font-size: clamp(1.8rem, 5vw, 3rem);
  font-style: italic;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

.verdict.yes {
  color: var(--yes-text);
}
.verdict.no {
  color: var(--no-text);
}

.outcome-text {
  font-size: clamp(14px, 2vw, 17px);
  font-weight: 300;
  letter-spacing: 0.05em;
  color: var(--text);
  line-height: 1.7;
  max-width: 40ch;
}

.outcome-text.visible {
  opacity: 0.85;
}

#reset-btn {
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.6s var(--transition-ease),
    color 0.2s,
    transform 0.15s;
}

#reset-btn.visible {
  opacity: 1;
  pointer-events: auto;
}

#reset-btn {
  position: relative;
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: "DM Mono", monospace;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  padding: 12px 36px;
  cursor: pointer;
  outline: none;
  transition:
    color 0.2s,
    transform 0.15s;
  overflow: hidden;
}

#reset-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 0;
}

#reset-btn span {
  position: relative;
  z-index: 1;
}

#reset-btn:hover::before {
  transform: scaleX(1);
}

#reset-btn:hover {
  color: var(--bg);
}

#reset-btn:active {
  transform: scale(0.97);
}

/* ── BACKGROUNDS ── */
body.yes-bg {
  background: var(--flake-bg);
}
body.no-bg {
  background: var(--no-flake-bg);
}

/* ── ANIMATIONS ── */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(28px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── CORNERS ── */
.cell--top-left,
.cell--top-right,
.cell--bot-left,
.cell--bot-right {
  position: relative;
}

.cell--top-left::before,
.cell--top-right::before,
.cell--bot-left::before,
.cell--bot-right::before {
  content: "";
  position: absolute;
  width: 60px;
  height: 60px;
  border-color: rgba(154, 112, 32, 0.18);
  border-style: solid;
  pointer-events: none;
}

.cell--top-left::before {
  top: 24px;
  left: 24px;
  border-width: 1px 0 0 1px;
}

.cell--top-right::before {
  top: 24px;
  right: 24px;
  border-width: 1px 1px 0 0;
}

.cell--bot-left::before {
  bottom: 24px;
  left: 24px;
  border-width: 0 0 1px 1px;
}

.cell--bot-right::before {
  bottom: 24px;
  right: 24px;
  border-width: 0 1px 1px 0;
}

.footer-note {
  font-size: 10px;
  letter-spacing: 0.2em;
  color: rgba(30, 26, 20, 0.4);
  text-align: center;
  max-width: calc(100vw - 48px);
}
