/* Unscripted playable. Mirrors the Euphoria game page: full-bleed scene art,
   bottom-anchored character sprite, a 90%-opaque surface text box with an
   uppercase speaker line, the choice card with text field + suggestion chips,
   and the floating variable-effect pill. Colors and type from the app's dark
   scheme (Palanquin Dark / Cabin). The welcome carousel is ad-only. */
:root {
  --surface: #201a19;
  --surface-90: rgba(32, 26, 25, 0.9);
  --surface-40: rgba(32, 26, 25, 0.4);
  --on-surface: #ede0de;
  --on-surface-variant: #d8c2bf;
  --outline: #a08c8a;
  --primary: #ffb3ac;
  --on-primary: #5f1413;
  --ground: #331817;
  --up: #65b25c;
  --down: #ef534a;
  --neutral: #f2be44;
  --keyboard-h: 176px;
  --font-display: "Palanquin Dark", "Avenir Next Condensed", "Arial Narrow", system-ui, sans-serif;
  --font-body: "Cabin", "Helvetica Neue", Arial, sans-serif;
  --ease-out: cubic-bezier(.22, .61, .36, 1);
  --ease-in: cubic-bezier(.32, 0, .67, 0);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--surface); color: var(--on-surface); font-family: var(--font-body); -webkit-text-size-adjust: 100%; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; margin: 0; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:focus-visible, .field:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---- stage: full bleed; a centred 4:7 canvas on wide viewports, like the app */
.stage { position: relative; width: 100%; height: 100%; min-height: 480px; overflow: hidden; background: #000; isolation: isolate; user-select: none; -webkit-user-select: none; }
@media (min-width: 560px) and (min-height: 700px) {
  body { display: grid; place-items: center; background: var(--ground); }
  .stage { width: min(100vw, calc(100vh * 4 / 7)); height: min(100vh, calc(100vw * 7 / 4)); }
}

/* ---- background: two layers cross-fading */
.bg { position: absolute; inset: 0; background-size: cover; background-position: center; opacity: 0; transition: opacity 1.2s ease; }
.bg.show { opacity: 1; }

/* ---- character sprite: bottom centre, 90% of the height, fade + slide in */
.sprite { position: absolute; left: 0; right: 0; bottom: 0; height: 90%; display: flex; justify-content: center; align-items: flex-end; pointer-events: none;
  opacity: 0; transform: translateY(3.3%); transition: opacity .3s ease-in-out, transform .3s ease-in-out; }
.sprite.show { opacity: 1; transform: none; transition: opacity .65s var(--ease-out), transform .65s var(--ease-out); }
.sprite img { max-height: 100%; max-width: 100%; object-fit: contain; object-position: bottom center; display: block; }

/* ---- variable effect pill */
.effect { position: absolute; top: 130px; left: 42px; right: 42px; z-index: 4; display: flex; justify-content: center; pointer-events: none; }
.effect-pill { display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; border-radius: 20px; background: var(--surface-40);
  font-family: var(--font-display); font-weight: 700; font-size: 20px; line-height: 1.2;
  text-shadow: 1px 1px 3px var(--surface-40), -1px -1px 3px var(--surface-40); }
.effect.up { color: var(--up); } .effect.down { color: var(--down); } .effect.neutral { color: var(--neutral); }
.effect.up .effect-pill { --drift: 10px; } .effect.down .effect-pill { --drift: -10px; }
.effect.show .effect-pill { animation: pop .45s cubic-bezier(.34, 1.56, .64, 1) both, drift 1.5s var(--ease-out) .2s both; }
.effect.hide .effect-pill { animation: unpop .3s ease-in both; }
@keyframes pop { from { transform: scale(0); } }
@keyframes unpop { to { transform: scale(0); opacity: 0; } }
@keyframes drift { from { translate: 0 var(--drift, 0); } to { translate: 0 0; } }

/* ---- controls layer */
.controls { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.topline { position: absolute; top: 14px; right: 12px; pointer-events: auto; display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px 0 6px; border-radius: 16px;
  background: rgba(0, 0, 0, .4); border: 1px solid rgba(255, 255, 255, .1); font-size: 12px; font-weight: 600; letter-spacing: .02em; color: var(--on-surface); }
.topline-mark { display: block; width: 20px; height: 20px; border-radius: 6px; object-fit: cover; }
.autoplay { position: absolute; top: 14px; right: 118px; pointer-events: auto; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(0, 0, 0, .4); border: 1px solid rgba(255, 255, 255, .1); color: var(--on-surface); }
.autoplay .ring { position: absolute; inset: -1px; width: 32px; height: 32px; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: rgba(255, 255, 255, .12); stroke-width: 2.5; }
.ring-fill { fill: none; stroke: var(--primary); stroke-width: 2.5; stroke-linecap: round; stroke-dasharray: 100.53; stroke-dashoffset: 100.53; }
.autoplay .glyph { width: 16px; height: 16px; position: relative; }
.autoplay .glyph-play { display: none; }
.autoplay.off .glyph-play { display: block; } .autoplay.off .glyph-pause { display: none; }
.autoplay.off .ring-fill { visibility: hidden; }
.tap { position: absolute; left: 0; right: 0; bottom: 14px; display: flex; flex-direction: column; align-items: center; gap: 6px; opacity: .6; animation: fadein .4s ease both; }
.tap-ring { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--on-surface); position: relative; }
.tap-ring::after { content: ""; position: absolute; inset: -8px; border-radius: 50%; border: 2px solid var(--on-surface); animation: ripple 1.6s ease-out infinite; }
@keyframes ripple { from { transform: scale(.5); opacity: .8; } to { transform: scale(1.3); opacity: 0; } }
.tap-label { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }

/* ---- welcome + character carousel (ad-only screen) */
.eyebrow { margin: 0; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--primary); font-weight: 700; }
.welcome { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; gap: 10px; padding: 18px 0 20px;
  background: linear-gradient(180deg, rgba(32, 26, 25, .55) 0%, rgba(32, 26, 25, .25) 30%, rgba(32, 26, 25, .85) 70%, var(--surface) 100%); }
.welcome.leave { animation: fadeout .4s ease both; }
@keyframes fadeout { to { opacity: 0; } }
.welcome-head { padding: 0 20px; display: flex; flex-direction: column; gap: 4px; }
.welcome-title { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 30px; line-height: 1; text-wrap: balance; text-shadow: 0 2px 16px rgba(0, 0, 0, .5); }
.welcome-title em { font-style: normal; color: var(--primary); }
.welcome-sub { margin: 4px 0 0; font-family: var(--font-display); font-weight: 700; font-size: 20px; line-height: 1.1; color: var(--primary); text-shadow: 0 1px 8px rgba(0, 0, 0, .6); }
.carousel-wrap { flex: 1; min-height: 0; position: relative; display: flex; }
.carousel { flex: 1; min-height: 0; display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; padding: 0 calc(50% - 120px); scrollbar-width: none; -webkit-overflow-scrolling: touch; cursor: grab; }
.carousel.dragging { scroll-snap-type: none; cursor: grabbing; }
.carousel::-webkit-scrollbar { display: none; }
.card { flex: none; width: 240px; scroll-snap-align: center; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; padding-bottom: 6px;
  opacity: .55; transform: scale(.88); transition: opacity .35s ease, transform .35s var(--ease-out); }
.card.active { opacity: 1; transform: none; }
.card-art { flex: 1; min-height: 0; width: 100%; display: flex; justify-content: center; align-items: flex-end; }
.card-art img { max-height: 100%; max-width: 100%; object-fit: contain; object-position: bottom center; display: block; filter: drop-shadow(0 12px 18px rgba(0, 0, 0, .5)); pointer-events: none; }
.card-text { text-align: center; padding: 0 12px; text-shadow: 0 2px 12px rgba(0, 0, 0, .8); }
.card-name { font-family: var(--font-display); font-weight: 700; font-size: 24px; line-height: 1; }
.card-tag { margin: 4px 0 0; font-size: 13px; line-height: 1.35; color: var(--on-surface); }
.arrow { position: absolute; top: 40%; z-index: 2; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: rgba(32, 26, 25, .55); border: 1px solid rgba(255, 255, 255, .12); color: var(--on-surface); transition: transform .12s ease, opacity .2s ease; }
.arrow:active { transform: scale(.94); }
.arrow-left { left: 8px; } .arrow-right { right: 8px; }
.arrow[disabled] { opacity: .25; cursor: default; }
.dots { display: flex; justify-content: center; gap: 6px; }
.dot { width: 6px; height: 6px; border-radius: 3px; background: rgba(237, 224, 222, .3); transition: width .3s ease, background .3s ease; }
.dot.active { width: 18px; background: var(--primary); }
.welcome-cta { align-self: center; }

/* ---- text box layer */
.boxlayer { position: absolute; inset: 0; z-index: 2; padding: 0 12px; display: flex; flex-direction: column; justify-content: flex-end; pointer-events: none; transition: padding-bottom .3s var(--ease-out); }
.stage[data-box="middle"] .boxlayer { justify-content: center; }
.stage[data-box="bottom"] .boxlayer { padding-bottom: 56px; }
.stage[data-keyboard="on"] .boxlayer { padding-bottom: var(--keyboard-h); }
.boxlayer > * { pointer-events: auto; }

.textbox { width: 100%; max-height: 55%; padding: 24px; border-radius: 4px; background: var(--surface-90); overflow-y: auto; transform-origin: center bottom; }
.textbox.anim-out { animation: boxOut .2s var(--ease-in) both; }
.textbox.anim-in { animation: boxIn .3s var(--ease-out) both; }
@keyframes boxOut { to { opacity: 0; transform: translateY(24px) scale(.94); } }
@keyframes boxIn { from { opacity: 0; transform: translateY(24px) scale(.94); } }
.stage[data-keyboard="on"] .textbox { display: none; }
.speaker { font-size: 13px; font-weight: 700; letter-spacing: -0.2px; text-transform: uppercase; }
.speaker.tutorial { color: var(--primary); letter-spacing: .08em; }
.story { position: relative; font-size: 16px; font-weight: 500; letter-spacing: .5px; line-height: 1.5; }
.story-full { visibility: hidden; }
.story-typed { position: absolute; inset: 0; }
.story.blocked { color: var(--on-surface-variant); font-style: italic; }

/* ---- choice card: text field + suggestion chips. Revealed by growing its
   max-height so the text box glides up instead of jumping. */
.choices { max-height: 0; overflow: hidden; opacity: 0; transform: translateY(12px); margin: 0;
  transition: max-height .5s var(--ease-out), opacity .5s ease, transform .5s var(--ease-out), margin .5s var(--ease-out); }
.choices.show { max-height: 260px; opacity: 1; transform: none; margin: 16px 0 0; }
.stage[data-keyboard="on"] .choices { margin: 0; }
.choice-card { margin: 8px; border-radius: 12px; background: var(--surface); box-shadow: 0 4px 8px rgba(0, 0, 0, .15); position: relative; }
.choice-card.generating::before { content: ""; position: absolute; inset: 0; border-radius: 12px; padding: 1px; pointer-events: none;
  background: conic-gradient(from var(--angle, 0deg), transparent 0 65%, var(--primary) 85%, transparent 100%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude; animation: trace 1.8s linear infinite; }
@property --angle { syntax: "<angle>"; initial-value: 0deg; inherits: false; }
@keyframes trace { to { --angle: 360deg; } }
.field { position: relative; min-height: 72px; max-height: 120px; overflow: hidden; padding: 14px 52px 14px 16px; border-radius: 12px; border: 2px solid transparent; font-size: 16px; line-height: 1.5; letter-spacing: .5px; cursor: text; }
.field.focused { border-color: var(--primary); }
.field-text { white-space: pre-wrap; word-break: break-word; }
.caret { display: none; width: 2px; height: 1.1em; background: var(--primary); vertical-align: text-bottom; margin-left: 1px; animation: caret 1s steps(1) infinite; }
.field.focused .caret { display: inline-block; }
@keyframes caret { 50% { opacity: 0; } }
.placeholder { position: absolute; left: 16px; top: 14px; right: 52px; color: rgba(237, 224, 222, .6); pointer-events: none; }
.field.has-text .placeholder { display: none; }
.send { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: rgba(237, 224, 222, .4); transition: color .2s ease; }
.send:not(:disabled) { color: var(--primary); }
.send:disabled { cursor: default; }
.choice-card.generating .field { padding-right: 104px; }
.generating-label { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); font-size: 12px; font-weight: 500; color: var(--primary); animation: pulse 1s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: .66; } to { opacity: .91; } }
.chips { display: flex; gap: 8px; padding: 6px 8px 14px 14px; overflow-x: auto; scrollbar-width: none; cursor: grab;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent); }
.chips.at-end { -webkit-mask-image: none; mask-image: none; }
.chips.dragging { cursor: grabbing; scroll-snap-type: none; }
.chips::-webkit-scrollbar { display: none; }
.stage[data-keyboard="on"] .chips { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px 0 10px; border-radius: 18px; background: rgba(83, 67, 66, .5); border: 1px solid rgba(160, 140, 138, .2);
  font-size: 12px; color: rgba(237, 224, 222, .75); white-space: nowrap; transition: background .2s ease, border-color .2s ease, transform .12s ease, color .2s ease; }
.chip svg { width: 16px; height: 16px; flex: none; opacity: .8; }
.chip:active, .chip.pressed { background: rgba(255, 179, 172, .22); border-color: var(--primary); color: var(--on-surface); transform: scale(.96); }
.chip.pressed svg { animation: spin .5s ease; }
@keyframes spin { to { transform: rotate(360deg); } }
.chip.pulse { animation: chippulse 1.4s ease-in-out infinite; border-color: var(--primary); color: var(--on-surface); }
@keyframes chippulse { 50% { box-shadow: 0 0 0 5px rgba(255, 179, 172, .18); } }

/* ---- custom keyboard (the OS keyboard is unreliable inside ad webviews).
   The composer moves up above it; the story box hides while typing. */
.keyboard { position: absolute; left: 0; right: 0; bottom: 0; z-index: 6; height: var(--keyboard-h); padding: 8px 6px 10px; background: var(--surface); border-top: 1px solid rgba(255, 255, 255, .08); display: flex; flex-direction: column; justify-content: space-between; animation: slideup .25s var(--ease-out); }
@keyframes slideup { from { transform: translateY(100%); } }
.krow { display: flex; justify-content: center; gap: 4px; }
.key { flex: 1; max-width: 34px; height: 36px; border-radius: 6px; background: rgba(83, 67, 66, .5); font-size: 16px; font-weight: 500; display: grid; place-items: center; }
.key:active { background: var(--primary); color: var(--on-primary); }
.key-wide { max-width: none; flex: 1.6; font-size: 12px; font-weight: 700; letter-spacing: .04em; }
.key-space { flex: 5; max-width: none; }
.key-done { background: var(--primary); color: var(--on-primary); }

/* ---- buttons + end card */
.cta { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 28px; border-radius: 999px; background: var(--primary); color: var(--on-primary); font-size: 16px; font-weight: 700; box-shadow: 0 8px 24px rgba(255, 179, 172, .22); transition: transform .12s ease; }
.cta:active { transform: scale(.97); }
.end { position: absolute; inset: 0; z-index: 7; display: flex; flex-direction: column; background: var(--surface); animation: fadein .6s ease both; }
@keyframes fadein { from { opacity: 0; } }
.end-art { flex: 1; min-height: 0; position: relative; }
.end-art img { width: 100%; height: 100%; object-fit: cover; object-position: top center; display: block; }
.end-art::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(32, 26, 25, 0) 40%, var(--surface) 100%); }
.end-body { padding: 0 24px 30px; display: flex; flex-direction: column; gap: 14px; margin-top: -24px; position: relative; }
.end-title { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 28px; line-height: 1.05; text-wrap: balance; }
.end-text { margin: 0; font-size: 15px; line-height: 1.45; color: var(--on-surface-variant); max-width: 34ch; }
.end-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; margin-top: 8px; }
.ghost { min-height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid rgba(237, 224, 222, .3); color: var(--on-surface); font-size: 14px; font-weight: 600; transition: background .2s ease; }
.ghost:active { background: rgba(255, 255, 255, .08); }
.end-fine { margin: 8px 0 0; font-size: 11.5px; line-height: 1.4; color: rgba(237, 224, 222, .6); }

/* Short viewports (the 320x480 ad slot): smaller welcome text so the
   character art keeps as much height as possible. */
@media (max-height: 560px) {
  .welcome { padding-top: 12px; gap: 6px; }
  .welcome-head { gap: 2px; }
  .welcome-title { font-size: 22px; }
  .welcome-sub { margin-top: 2px; font-size: 16px; }
  .card-name { font-size: 20px; }
  .card-tag { font-size: 12px; line-height: 1.3; }
}

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