/* AIpocalypse: a cinematic, illustration-first interactive story. Mobile first; the picture dominates. */
html, body { margin: 0; background: #05070d; }
.ap { --bg: #05070d; --ink: #eef2fb; --dim: #a9b4cc; --acc: #6aa2ff; --card: #0b101c; --line: #1c2740;
  position: fixed; inset: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 40dvh) minmax(0, 1fr); background: var(--bg); color: var(--ink);
  font: 400 clamp(16px, 2.3vw, 18px)/1.55 Georgia, 'Iowan Old Style', 'Palatino Linotype', serif; overflow: hidden; -webkit-tap-highlight-color: transparent; }
.ap *, .ap *::before, .ap *::after { box-sizing: border-box; }
:where(.ap) button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; }
.ap button:focus-visible { outline: 3px solid var(--acc); outline-offset: 2px; }

.ap[data-view=title] { grid-template-rows: auto minmax(0, 56dvh) minmax(0, 1fr); }
.ap-hud { position: relative; z-index: 4; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left)); background: #05070d; font: 600 12px/1.2 system-ui, sans-serif; letter-spacing: .14em; }
.ap-wk { display: flex; flex-direction: column; gap: 2px; min-width: 0; } .ap-wk b { font-size: 15px; letter-spacing: .2em; } .ap-wk span { color: var(--dim); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ap-ctl { display: flex; gap: 6px; }
.ap-ctl button { min-height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 18px; color: var(--dim); font: 600 11px/1 system-ui, sans-serif; letter-spacing: .08em; text-transform: uppercase; }
.ap-ctl button.on { color: #fff; border-color: var(--acc); background: #12203c; }

.ap-stage { position: relative; overflow: hidden; background: #000; }
.ap-pic { position: absolute; inset: 0; opacity: 0; transition: opacity .9s ease; }
.ap-pic.in { opacity: 1; } .ap-pic.out { opacity: 0; }
.ap-svg { display: block; width: 100%; height: 100%; transform-origin: 50% 70%; animation: ap-kb 26s ease-in-out infinite alternate; }
.ap-l1 { animation: ap-par1 14s ease-in-out infinite alternate; } .ap-l2 { animation: ap-par2 11s ease-in-out infinite alternate; } .ap-l3 { animation: ap-par3 9s ease-in-out infinite alternate; }
.ap-cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 36px 16px 12px; pointer-events: none; background: linear-gradient(transparent, rgba(3, 5, 10, .88)); }
.ap-cap h1 { margin: 0; font: 800 clamp(20px, 5.2vw, 30px)/1.1 system-ui, 'Segoe UI', sans-serif; letter-spacing: .08em; text-shadow: 0 2px 12px #000; text-transform: uppercase; }
.ap-cap.pop h1 { animation: ap-rise .8s .15s both; }

.ap-card { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); background: var(--card); border-top: 1px solid var(--line); }
.ap-card.swap > * { animation: ap-rise .55s both; } .ap-card.swap > :nth-child(2) { animation-delay: .08s; } .ap-card.swap > :nth-child(3) { animation-delay: .16s; }
.ap-tx { margin: 0 0 12px; max-width: 62ch; } .ap-tx b { font-weight: 700; color: #fff; }
.ap-echo { color: #e8c98a; font-style: italic; }
.ap-question { margin: 0 0 12px; max-width: 62ch; color: #fff; font-weight: 700; }
.ap-kind { margin: 0 0 8px; font: 700 11px/1.3 system-ui, sans-serif; letter-spacing: .16em; color: var(--acc); } .ap-kind.bad { color: #ff8470; } .ap-kind.secret { color: #e8c98a; } .ap-kind.good { color: #7fe3a7; }
.ap-leg { margin: 4px 0 14px; padding: 10px 0 0; border-top: 1px solid var(--line); max-width: 62ch; } .ap-leg h3 { margin: 0 0 6px; font: 700 11px/1.3 system-ui, sans-serif; letter-spacing: .16em; color: var(--dim); text-transform: uppercase; } .ap-leg ul { margin: 0; padding: 0 0 0 18px; color: #cfd8ec; font-size: .94em; } .ap-leg li { margin: 0 0 3px; }

.ap-ch { display: grid; gap: 10px; max-width: 760px; }
.ap-b { position: relative; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; width: 100%; min-height: 58px; padding: 12px 16px 12px 52px; text-align: left; border: 1px solid #2a3a5e; border-radius: 12px; background: #101a2e; font: 600 16px/1.3 system-ui, 'Segoe UI', sans-serif; transition: background .15s, border-color .15s, transform .1s; }
.ap-b:hover { background: #172644; border-color: var(--acc); } .ap-b:active { transform: scale(.985); }
.ap-b i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: #1f3156; color: #bcd0f5; font: 700 13px/1 system-ui, sans-serif; font-style: normal; }
.ap-b small { color: var(--dim); font: 500 12px/1.2 system-ui, sans-serif; }
.ap-b.main { padding-left: 18px; background: #1b3a78; border-color: var(--acc); } .ap-b.main:hover { background: #24499a; }
.ap-view-title .ap-b { padding-left: 18px; }
.ap[data-view=title] .ap-b, .ap[data-view=end] .ap-b { padding-left: 18px; }

.ap-sheet { position: absolute; inset: 0; z-index: 10; display: none; flex-direction: column; background: #05070d; }
.ap-sheet.open { display: flex; }
.ap-sh { display: flex; align-items: center; justify-content: space-between; padding: max(12px, env(safe-area-inset-top)) 16px 10px; } .ap-sh h2 { margin: 0; font: 800 16px/1 system-ui, sans-serif; letter-spacing: .16em; text-transform: uppercase; } .ap-sh h2 span { color: var(--acc); margin-left: 8px; }
.ap-sh button { min-height: 40px; padding: 0 16px; border: 1px solid var(--line); border-radius: 20px; font: 600 12px/1 system-ui, sans-serif; letter-spacing: .1em; text-transform: uppercase; }
.ap-grid { flex: 1; min-height: 0; overflow-y: auto; display: grid; grid-auto-rows: max-content; grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr)); gap: 12px; padding: 4px 16px max(18px, env(safe-area-inset-bottom)); align-content: start; }
.ap-end { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #0b101c; } .ap-end h3 { margin: 10px 12px 2px; font: 700 14px/1.25 system-ui, sans-serif; } .ap-end p { margin: 0 12px 12px; color: var(--dim); font-size: 13px; line-height: 1.4; }
.ap-end.secret { border-color: #6a5420; } .ap-end.good { border-color: #1f5a3a; } .ap-end.bad { border-color: #5a2a24; }
.ap-th { width: 100%; aspect-ratio: 16 / 9; background: #0e1424; overflow: hidden; } .ap-th .ap-svg { animation: none; } .ap-end.locked .ap-th { background: repeating-linear-gradient(135deg, #0e1424 0 10px, #111a30 10px 20px); } .ap-end.locked { opacity: .75; }

/* svg motion */
.ap-pulse { animation: ap-pulse 3.2s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.ap-flick { animation: ap-flick 2.4s steps(1) infinite; } .ap-twk { animation: ap-twk 3.5s ease-in-out infinite; } .ap-blink { animation: ap-blink 5s steps(1) infinite; }
.ap-scan { animation: ap-scan 4.5s linear infinite; } .ap-drift { animation: ap-drift 9s ease-in-out infinite alternate; } .ap-sway { animation: ap-sway 2.6s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: bottom; }
.ap-rise { animation: ap-up 6s linear infinite; } .ap-rain { animation: ap-rain .9s linear infinite; } .ap-glitch { animation: ap-glitch 3s steps(1) infinite; }
.ap-spin { animation: ap-spin 5s linear infinite; transform-box: fill-box; transform-origin: center; } .ap-bolt { opacity: 0; animation: ap-bolt 2.7s steps(1) infinite; } .ap-flash { animation: ap-flashy 3.6s steps(1) infinite; }
.ap-ring { transform-box: fill-box; transform-origin: center; animation: ap-ring 2.4s ease-out infinite; } .ap-burst { transform-box: fill-box; transform-origin: center; animation: ap-burst 3.3s ease-out infinite; opacity: 0; }
@keyframes ap-spin { to { transform: rotate(360deg); } } @keyframes ap-bolt { 0%, 10%, 100% { opacity: 0; } 2% { opacity: 1; } 5% { opacity: .2; } 7% { opacity: .9; } }
@keyframes ap-flashy { 0%, 100% { opacity: 0; } 2% { opacity: .55; } 5% { opacity: 0; } 7% { opacity: .25; } }
@keyframes ap-ring { from { transform: scale(.2); opacity: 1; } to { transform: scale(7); opacity: 0; } } @keyframes ap-burst { 0% { transform: scale(.1); opacity: 1; } 70% { opacity: 1; } 100% { transform: scale(1.6); opacity: 0; } }
/* ending montage */
.ap-fin { position: absolute; inset: 0; z-index: 3; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 16px 20px 56px; pointer-events: none; text-align: center; }
.ap-fin p { position: absolute; left: 12px; right: 12px; top: 22%; margin: 0; opacity: 0; font: 800 clamp(16px, 4.4vw, 26px)/1.2 system-ui, sans-serif; letter-spacing: .06em; text-transform: uppercase; text-shadow: 0 2px 14px #000, 0 0 24px rgba(106, 162, 255, .6); animation: ap-beat 1.9s both; }
.ap-fin.bad p { text-shadow: 0 2px 14px #000, 0 0 26px rgba(255, 90, 50, .8); } .ap-fin.good p, .ap-fin.secret p { text-shadow: 0 2px 14px #000, 0 0 26px rgba(255, 220, 130, .8); }
.ap-fin .ap-fl { position: absolute; inset: 0; background: #fff; opacity: 0; animation: ap-fl 1.4s .1s ease-out both; } .ap-fin.good .ap-fl, .ap-fin.secret .ap-fl { background: #ffeeb5; }
.ap-fin .ap-rg { position: absolute; left: 50%; top: 60%; width: 40px; height: 40px; margin: -20px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .9); opacity: 0; animation: ap-shock 1.8s .15s ease-out both; } .ap-fin .ap-rg.b { animation-delay: .5s; border-color: rgba(255, 150, 80, .8); }
.ap-fin.good .ap-rg, .ap-fin.secret .ap-rg { border-color: rgba(255, 224, 140, .9); } .ap-fin.good .ap-rg.b, .ap-fin.secret .ap-rg.b { border-color: rgba(122, 224, 255, .8); }
.ap-stage.shake .ap-svg { animation: ap-kb 26s ease-in-out infinite alternate, ap-shake 1.4s .1s both; } .ap-stage.glow { animation: ap-glow 2.4s ease-out; }
.ap-card.late > * { animation: ap-rise .7s 4.6s both !important; }
@keyframes ap-beat { 0% { opacity: 0; transform: scale(1.5); } 12% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-10px); } }
@keyframes ap-fl { 0% { opacity: .95; } 100% { opacity: 0; } } @keyframes ap-shock { 0% { opacity: .9; transform: scale(.2); } 100% { opacity: 0; transform: scale(14); } }
@keyframes ap-shake { 0%, 100% { translate: 0 0; } 10% { translate: -7px 4px; } 20% { translate: 6px -5px; } 30% { translate: -5px -3px; } 45% { translate: 4px 4px; } 60% { translate: -3px 2px; } 80% { translate: 2px -1px; } }
@keyframes ap-glow { 0% { filter: brightness(2.4) saturate(1.5); } 100% { filter: none; } }
@keyframes ap-kb { to { transform: scale(1.07) translateX(-1%); } }
@keyframes ap-par1 { to { transform: translateX(-4px); } } @keyframes ap-par2 { to { transform: translateX(5px); } } @keyframes ap-par3 { to { transform: translateX(-9px); } }
@keyframes ap-pulse { 50% { opacity: .35; } } @keyframes ap-flick { 0%, 38%, 42%, 100% { opacity: 1; } 40% { opacity: .15; } 70% { opacity: .6; } }
@keyframes ap-twk { 50% { opacity: .15; } } @keyframes ap-blink { 0%, 90%, 100% { opacity: 0; } 92% { opacity: .5; } 95% { opacity: .1; } }
@keyframes ap-scan { from { transform: translateY(-10px); } to { transform: translateY(260px); } } @keyframes ap-drift { to { transform: translateX(22px); } }
@keyframes ap-sway { to { transform: rotate(5deg); } } @keyframes ap-up { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-120px); opacity: 0; } }
@keyframes ap-rain { from { transform: translateY(-20px); } to { transform: translateY(40px); } } @keyframes ap-glitch { 0%, 80%, 100% { transform: translateX(0); opacity: .35; } 82% { transform: translateX(-18px); opacity: .7; } 86% { transform: translateX(12px); } }
@keyframes ap-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* wide screens: picture left, story right */
@media (min-width: 900px) and (min-height: 520px) {
  .ap { grid-template-columns: minmax(0, 1.55fr) minmax(360px, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .ap-hud { grid-column: 1 / -1; } .ap-stage { grid-row: 2; grid-column: 1; align-self: center; aspect-ratio: 16 / 10; max-height: 100%; } .ap-card { grid-row: 2; grid-column: 2; border-top: 0; border-left: 1px solid var(--line); padding: 24px 28px; display: flex; flex-direction: column; justify-content: center; }
  .ap-cap h1 { font-size: clamp(24px, 2.8vw, 40px); }
}
@media (max-height: 560px) and (orientation: landscape) and (max-width: 899px) {
  .ap { grid-template-columns: minmax(0, 1fr) minmax(300px, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .ap-hud { grid-column: 1 / -1; padding-bottom: 2px; } .ap-stage { grid-row: 2; grid-column: 1; align-self: center; aspect-ratio: 16 / 10; max-height: 100%; } .ap-card { grid-row: 2; grid-column: 2; border-top: 0; border-left: 1px solid var(--line); }
  .ap-b { min-height: 48px; padding-top: 8px; padding-bottom: 8px; }
}
@media (prefers-reduced-motion: reduce) { .ap *, .ap *::before, .ap *::after { animation: none !important; transition: none !important; } }
