@font-face { font-family: Mali; font-weight: 500; font-display: swap; src: url(../vendor/fonts/mali-thai-500.woff2) format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: Mali; font-weight: 700; font-display: swap; src: url(../vendor/fonts/mali-thai-700.woff2) format("woff2"); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: Mali; font-weight: 500; font-display: swap; src: url(../vendor/fonts/mali-latin-500.woff2) format("woff2"); }
@font-face { font-family: Mali; font-weight: 700; font-display: swap; src: url(../vendor/fonts/mali-latin-700.woff2) format("woff2"); }

:root {
  --ink: #3a2c4d;
  --paper: #fff8e7;
  --sun: #ffc23d;
  --sun-deep: #e98f12;
  --leaf: #4d9a3a;
  --rose: #e8483f;
  --safe-w: calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  --safe-h: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  --safe-h: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; height: 100dvh; background: linear-gradient(#55c8ff, #b6f0ff 45%, #a6e85a 46%, #5fcf5a); overflow: hidden; overscroll-behavior: none; touch-action: none; }
body { display: grid; place-items: center; font-family: Mali, "Noto Sans Thai", sans-serif; font-weight: 500; color: var(--ink); touch-action: none; user-select: none; -webkit-touch-callout: none; -webkit-user-select: none; }

#stage { position: relative; width: min(var(--safe-w), calc(var(--safe-h) * 16 / 9)); aspect-ratio: 16 / 9; overflow: hidden; container-type: inline-size; background: #8fd3f4; touch-action: none; }
#stage * { touch-action: none; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.tap-item { cursor: pointer; }
[hidden] { display: none !important; }

button { font: inherit; color: inherit; border: 0; cursor: pointer; }
button:focus-visible { outline: 4px solid #fff; outline-offset: 3px; }

#caption { pointer-events: none; position: absolute; left: 2cqw; top: 2.6cqw; right: calc(3 * max(52px, 5.8cqw) + 5cqw); min-height: 8.6cqw; padding: 1.3cqw 2.6cqw; background: var(--paper); border: .4cqw solid var(--ink); border-radius: 2.2cqw; box-shadow: 0 .5cqw 0 rgba(58,44,77,.35); visibility: hidden; }
#caption .who { position: absolute; left: 2cqw; top: -1.9cqw; padding: .2cqw 1.5cqw; border-radius: 99px; border: .3cqw solid var(--ink); font-weight: 700; font-size: 1.9cqw; background: var(--sun); }
#caption .text { margin: .5cqw 0 0; font-size: 2.75cqw; line-height: 1.5; text-align: center; font-weight: 700; }

#controls { position: absolute; top: 1.4cqw; right: 1.4cqw; display: flex; gap: 1cqw; }
.round { width: max(52px, 5.8cqw); height: max(52px, 5.8cqw); border-radius: 50%; background: var(--paper); border: .3cqw solid var(--ink); display: grid; place-items: center; padding: 0; box-shadow: 0 .35cqw 0 rgba(58,44,77,.4); }
.round svg { width: 58%; height: 58%; fill: var(--ink); stroke: var(--ink); }
.round.off .wave { display: none; }
.round:active { transform: translateY(.25cqw); box-shadow: none; }

#wipe { position: absolute; inset: 0; pointer-events: none; --r: 120cqw; background: radial-gradient(circle at 50% 56%, transparent var(--r), #ffd23f calc(var(--r) + 1px)); }

.panel-screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.4cqw; text-align: center; }
.panel-screen.dim { background: radial-gradient(circle, rgba(255,246,176,.95), rgba(255,154,200,.88) 90%); }
.panel-face { font-size: 11cqw; line-height: 1; }
h1, h2 { margin: 0; font-weight: 700; color: var(--paper); -webkit-text-stroke: .9cqw var(--ink); paint-order: stroke fill; line-height: 1.35; }
h1 { font-size: 8cqw; }
h2 { font-size: 7.5cqw; }
.sub { margin: 0; font-size: 3cqw; font-weight: 700; color: var(--paper); -webkit-text-stroke: .5cqw var(--ink); paint-order: stroke fill; }
.note { margin: 0; font-size: 2.2cqw; font-weight: 700; color: var(--ink); }

.big { display: inline-flex; align-items: center; gap: 1.2cqw; min-height: 56px; padding: 1.2cqw 4.4cqw; font-size: 4.4cqw; font-weight: 700; color: var(--ink); background: var(--sun); border: .45cqw solid var(--ink); border-radius: 99px; box-shadow: 0 .8cqw 0 var(--sun-deep), 0 1.1cqw 0 var(--ink); }
.big svg { width: 4cqw; height: 4cqw; fill: var(--ink); }
.big:active { transform: translateY(.6cqw); box-shadow: 0 .2cqw 0 var(--sun-deep), 0 .5cqw 0 var(--ink); }
.soft { display: inline-flex; align-items: center; gap: 1cqw; min-height: 44px; padding: .6cqw 3cqw; font-size: 2.6cqw; font-weight: 700; background: var(--paper); border: .3cqw solid var(--ink); border-radius: 99px; }

#stage.in-game #caption { top: 9.8cqw; }
#game-hud { position: absolute; top: 1.4cqw; left: 1.4cqw; pointer-events: none; }
#hud-track { display: flex; align-items: center; gap: 1.6cqw; }
#hud-pips { display: flex; gap: .5cqw; padding: .5cqw 1.2cqw; background: var(--paper); border: .3cqw solid var(--ink); border-radius: 99px; }
#hud-pips svg { width: 4.6cqw; height: 4.6cqw; overflow: visible; opacity: .28; filter: grayscale(1); }
#hud-pips svg.on { opacity: 1; filter: none; }
.hud-count { display: flex; align-items: center; gap: .6cqw; padding: .3cqw 1.8cqw .3cqw .8cqw; background: var(--paper); border: .3cqw solid var(--ink); border-radius: 99px; font-size: 3.2cqw; font-weight: 700; }
.hud-count svg { width: 3.8cqw; height: 3.8cqw; }
.track-bar { position: relative; width: 36cqw; height: 2.4cqw; background: var(--paper); border: .3cqw solid var(--ink); border-radius: 99px; overflow: visible; }
.track-bar i { position: absolute; inset: 0; right: auto; width: 100%; background: #8fd05b; border-radius: 99px; transform-origin: left center; transform: scaleX(0); }
.track-flag { position: absolute; right: -2cqw; top: -1.4cqw; font-size: 3.4cqw; line-height: 1; }

#tap-hint { position: absolute; transform: translateX(-34%); display: flex; flex-direction: column; align-items: center; gap: .4cqw; font-size: 5cqw; font-weight: 700; color: var(--sun); -webkit-text-stroke: .7cqw var(--ink); paint-order: stroke fill; pointer-events: none; }
#tap-hint.no-label span, #tap-hint.swipe span { display: none; }
#tap-hint.swipe svg { animation: swipe 1.1s ease-in-out infinite alternate; }
@keyframes swipe { from { transform: translateX(-16cqw) rotate(-8deg); } to { transform: translateX(16cqw) rotate(8deg); } }
#tap-hint svg { width: 11cqw; height: 11cqw; filter: drop-shadow(0 .5cqw 0 rgba(58,44,77,.35)); }
#tap-hint:not(.swipe) svg { animation: press .55s ease-in-out infinite alternate; }
@keyframes press { to { transform: translateY(1.8cqw) scale(.9); } }

#big-word { position: absolute; left: 0; right: 0; top: 30%; text-align: center; font-size: 12cqw; font-weight: 700; color: var(--sun); -webkit-text-stroke: 1cqw var(--ink); paint-order: stroke fill; pointer-events: none; visibility: hidden; }

.soft svg { width: 3cqw; height: 3cqw; fill: var(--ink); }

#stars { display: flex; gap: 1.5cqw; }
#stars svg { width: 12cqw; height: 12cqw; }

@media (prefers-reduced-motion: reduce) { #tap-hint svg { animation: none; } }

/* Phones held upright: turn the 16:9 stage a quarter turn so it fills the screen (pointer maths goes through the SVG matrix, so rotation is safe). */
@media (orientation: portrait) and (pointer: coarse) {
  #stage {
    position: fixed;
    left: calc(50% + (env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)) / 2);
    top: calc(50% + (env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) / 2);
    width: min(var(--safe-h), calc(var(--safe-w) * 16 / 9));
    transform: translate(-50%, -50%) rotate(90deg);
  }
}
/* Tiny screens: keep text and buttons tappable. */
@media (max-width: 700px), (max-height: 420px) {
  #caption .text { font-size: max(2.75cqw, 14px); }
  #caption .who { font-size: max(1.9cqw, 11px); }
  .soft { min-height: 44px; font-size: max(2.6cqw, 14px); }
}

#rotate { background: #ffd23f; }
#rotate svg { width: 26cqw; height: 26cqw; }
#rotate .phone { transform-origin: 60px 60px; animation: turn 1.6s ease-in-out infinite; }
/* The stage itself is drawn a quarter turn clockwise, so -90deg here is an upright phone to the viewer. */
@keyframes turn { 0%, 20% { transform: rotate(-90deg); } 60%, 100% { transform: rotate(-180deg); } }

/* --- Home: upright on every screen, scrolls with a thumb. --- */
#home { position: fixed; inset: 0; overflow: hidden auto; overscroll-behavior: contain; touch-action: pan-y; -webkit-overflow-scrolling: touch; padding: calc(14px + env(safe-area-inset-top, 0px)) calc(18px + env(safe-area-inset-right, 0px)) calc(90px + env(safe-area-inset-bottom, 0px)) calc(18px + env(safe-area-inset-left, 0px)); text-align: center; }
.sky { position: fixed; inset: 0; z-index: -1; overflow: hidden; background: linear-gradient(#38bdff, #9be7ff 50%, #fff6c9); }
.sky > * { position: absolute; }
.sunburst { width: clamp(96px, 22vmin, 200px); left: -14px; top: -14px; overflow: visible; }
.sunburst .rays { animation: spin 26s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.rainbow { width: min(1100px, 130vw); left: 50%; top: 40%; transform: translateX(-50%); opacity: .55; }
.hills { left: 0; bottom: 0; width: 100%; height: 30%; }
.cloud { width: 120px; height: 38px; border-radius: 40px; background: #fff; opacity: .95; animation: drift 46s linear infinite; }
.cloud::before, .cloud::after { content: ""; position: absolute; border-radius: 50%; background: #fff; }
.cloud::before { width: 54px; height: 54px; left: 18px; top: -26px; }
.cloud::after { width: 68px; height: 68px; left: 46px; top: -34px; }
.c1 { top: 12%; } .c2 { top: 30%; animation-duration: 64s; animation-delay: -30s; scale: .7; } .c3 { top: 56%; animation-duration: 78s; animation-delay: -55s; scale: 1.2; }
@keyframes drift { from { transform: translateX(-200px); } to { transform: translateX(calc(100vw + 200px)); } }
#home-sound { position: absolute; z-index: 2; top: calc(12px + env(safe-area-inset-top, 0px)); right: calc(12px + env(safe-area-inset-right, 0px)); width: 56px; height: 56px; border-width: 3px; box-shadow: 0 4px 0 rgba(58,44,77,.4); }
#logo { position: relative; margin: 10px 70px 14px 84px; white-space: nowrap; font-size: clamp(30px, 8.6vmin, 88px); line-height: 1.5; -webkit-text-stroke: 0; }
#logo span { display: inline-block; text-shadow: 0 0 0 #fff, 3px 3px 0 #fff, -3px 3px 0 #fff, 3px -3px 0 #fff, -3px -3px 0 #fff, 0 4px 0 #fff, 0 -4px 0 #fff, 4px 0 0 #fff, -4px 0 0 #fff, 0 8px 0 rgba(58,44,77,.28); animation: bob 1.6s ease-in-out infinite alternate; animation-delay: calc(var(--i) * -.22s); }
@keyframes bob { from { transform: translateY(4px) rotate(-2deg); } to { transform: translateY(-6px) rotate(2deg); } }
#story-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: 22px; max-width: 1080px; margin: 0 auto; }
.story-card { container-type: inline-size; position: relative; padding: 0; background: var(--c); border: 6px solid #fff; border-radius: 30px; overflow: hidden; box-shadow: 0 8px 0 rgba(58,44,77,.28); display: flex; flex-direction: column; transition: transform .12s; touch-action: pan-y; }
.story-card > svg { display: block; width: 100%; aspect-ratio: 16 / 11; }
.story-card .name { padding: 8px 10px 10px; font-size: clamp(20px, 2.4vw, 26px); font-weight: 700; line-height: 1.35; color: #fff; text-shadow: 0 2px 0 rgba(58,44,77,.45); }
.story-card .go { position: absolute; right: 12px; bottom: calc(100% - 100cqw * 11 / 16 + 8px); width: clamp(48px, 18cqw, 72px); aspect-ratio: 1; border-radius: 50%; background: var(--sun); border: 5px solid #fff; display: grid; place-items: center; box-shadow: 0 4px 0 rgba(58,44,77,.3); animation: pulse 1s ease-in-out infinite alternate; }
.story-card .go svg { width: 34px; height: 34px; fill: #fff; }
@keyframes pulse { to { transform: scale(1.1); } }
.story-card .got { position: absolute; left: 10px; top: 8px; display: flex; gap: 2px; }
.story-card .got svg { width: 34px; height: 34px; }
.story-card:active, .game-card:active { transform: scale(.95); }
.games-title { margin: 30px 0 12px; font-size: clamp(28px, 6vmin, 48px); color: #fff; -webkit-text-stroke: 8px #e0459b; }
#game-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(126px, 1fr)); gap: 16px; max-width: 1080px; margin: 0 auto; }
.game-card { position: relative; padding: 12px 6px 10px; min-height: 140px; background: #fff; border: 5px solid var(--c); border-radius: 26px; box-shadow: 0 6px 0 var(--c); display: flex; flex-direction: column; align-items: center; gap: 6px; transition: transform .12s; touch-action: pan-y; }
.game-card svg { width: 84px; height: 84px; overflow: visible; }
.game-card .name { font-size: 16px; font-weight: 700; line-height: 1.3; color: var(--ink); }
/* Short landscape phones: whole cards fit one screen height, three across. */
@media (max-height: 500px) and (orientation: landscape) {
  #story-list { grid-template-columns: repeat(3, 1fr); gap: 16px; }
  #logo { margin-top: 0; margin-bottom: 6px; line-height: 1.4; }
}
@media (prefers-reduced-motion: reduce) { #logo span, .cloud, .sunburst .rays, .story-card .go { animation: none; } }
@media (min-width: 900px) { #story-list { grid-template-columns: repeat(3, 1fr); } }
