/*
 * RIFT game mode screens (docs/rift-game-mode.md): the shared screen (story/rift.html) and the
 * phone (story/rift-play.html). The stage part is a port of rift-demo/css/style.css — same
 * layout, shapes and highlighter — generalized from exactly 3 players + 1 NPC to 1-6 players and
 * any number of NPCs, and mapped onto the app's whiteboard tokens from app.css (--iost-*), so
 * light/dark mode and the six marker colors come from one place.
 *
 * Demo variable -> app token: --bg/--ink/--muted -> --iost-bg/-ink/-muted, --p0..p2 ->
 * --iost-marker-1..6, --npc -> --iost-ai, --hl -> --iost-highlight, --marker/--hand -> the
 * Caveat/Patrick Hand font stacks.
 */

.rift {
    --bg: var(--iost-bg);
    --ink: var(--iost-ink);
    --muted: var(--iost-muted);
    --npc: var(--iost-ai);
    --hl: var(--iost-highlight);
    --marker: var(--iost-marker-font);
    --hand: var(--iost-hand-font);
    --c: var(--ink);
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--hand);
    font-size: 1.1rem;
    line-height: 1.4;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
.rift *, .rift *::before, .rift *::after { box-sizing: border-box; }

/* Marker color of an element: player seat 1..6, AI purple, or board ink for the narrator. */
.rift .p1 { --c: var(--iost-marker-1); }
.rift .p2 { --c: var(--iost-marker-2); }
.rift .p3 { --c: var(--iost-marker-3); }
.rift .p4 { --c: var(--iost-marker-4); }
.rift .p5 { --c: var(--iost-marker-5); }
.rift .p6 { --c: var(--iost-marker-6); }
.rift .ai, .rift .npc { --c: var(--npc); }
.rift .nar { --c: var(--ink); }

.rift-wrap { max-width: 1280px; margin: 0 auto; padding: 16px 16px 40px; }
.rift h1 { font-family: var(--marker); font-weight: 700; font-size: clamp(1.8rem, 5vw, 2.8rem); line-height: 1; margin: 0; }
.rift a { color: inherit; }

/* Header row: title, round + timer, host controls */
.rift-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 18px; }
.rift-head .grow { flex: 1; min-width: 0; }
.rift-head .title-small { font-family: var(--marker); font-size: 1rem; opacity: .7; }
/* Join QR: always black on white, also in dark mode — inverted codes don't scan reliably. */
.rift-qr { width: 92px; height: 92px; flex: none; background: #fff; padding: 4px; border-radius: 6px; }
.rift-qr:empty { display: none; }
.rift-qr svg { width: 100%; height: 100%; display: block; }
.rift-round { font-family: var(--marker); font-size: 1.4rem; white-space: nowrap; }
.rift-join { font-size: .95rem; opacity: .85; }
.rift-join b { font-family: var(--marker); font-size: 1.3rem; letter-spacing: .08em; }

/* Every .sk element gets its own Rough.js drawing under its content (demo pattern). */
.rift .sk { position: relative; }
.rift .sk > .sk-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; z-index: 0; }
.rift .sk > :not(.sk-svg) { position: relative; z-index: 1; }

/* ---------- Stage (shared screen) ---------- */
.stage { position: relative; display: grid; row-gap: 70px; }
.wires { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; z-index: 2; }

.players { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; }
.players:empty::before { content: "Czekamy na graczy — dołączcie kodem powyżej."; opacity: .6; }
.middle { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; align-items: start; }
.narrator { grid-column: 2; justify-self: center; width: 84%; padding: 26px 26px 24px; text-align: center; }
.npcs { grid-column: 3; display: flex; flex-direction: column; gap: 16px; margin-top: 44px; }

.phone, .npc-card { padding: 14px 14px 12px; min-height: 186px; display: flex; flex-direction: column; gap: 6px; opacity: .4; transition: opacity .35s, transform .35s; }
.npc-card { min-height: 150px; }
.phone.joined, .npc-card.joined { opacity: 1; }
.phone.active, .npc-card.active { transform: rotate(-1deg) translateY(-3px); }
.phone-head { font-family: var(--marker); font-weight: 700; font-size: 1.5rem; line-height: 1; color: var(--c); overflow-wrap: anywhere; }
.hero { font-size: .95rem; opacity: .75; }
.screen { flex: 1; font-size: 1.05rem; min-height: 50px; overflow-wrap: anywhere; }
.screen .state { opacity: .7; }
.caret { display: inline-block; width: 2px; height: 1em; background: var(--c); vertical-align: -2px; opacity: 0; }
.active .caret { opacity: 1; animation: rift-blink 1s steps(1) infinite; }
.send { align-self: flex-end; padding: 2px 14px; font-size: 1rem; }
.phone.sent .send { color: var(--bg); }

.narrator b { display: block; font-family: var(--marker); font-size: 1.9rem; line-height: 1; }
.inbox { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 10px 0 4px; }
.slot { width: 28px; height: 14px; display: inline-block; }
.status { font-size: .95rem; opacity: .75; }

.shared { padding: 20px 22px 24px; min-height: 220px; cursor: default; }
.shared-head { font-family: var(--marker); font-size: 1.6rem; line-height: 1; margin-bottom: 12px; }
.story { font-size: clamp(1.15rem, 2.8vw, 1.4rem); line-height: 1.65; margin: 0; max-width: 70ch; }
/* Highlighter in the color of the action's author (demo ".story span"). Narration spans have no color class. */
.story span[class] { background: linear-gradient(transparent 58%, color-mix(in srgb, var(--c) var(--hl), transparent) 58%, color-mix(in srgb, var(--c) var(--hl), transparent) 92%, transparent 92%); }
.story:empty::before { content: "Tu pojawi się wspólna scena."; opacity: .5; }

.caption { min-height: 1.4em; margin: 28px 0 12px; font-size: 1.2rem; }
.controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.rift button, .rift .btn-sketch {
    font: inherit; font-size: 1.15rem; padding: 8px 18px; cursor: pointer; color: var(--ink); background: transparent; text-decoration: none;
    border: 2px solid var(--ink); border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
    min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.rift button.primary, .rift .btn-sketch.primary { border-width: 3px; }
.rift button:disabled { opacity: .35; cursor: default; }
.rift button:focus-visible, .rift .btn-sketch:focus-visible { outline: 3px dashed var(--iost-marker-2); outline-offset: 3px; }
.rift [hidden] { display: none !important; }
.fallback { display: none; border: 2px dashed var(--iost-marker-1); padding: 10px 14px; margin-bottom: 16px; }
.rift-error { border: 2px dashed var(--iost-marker-1); padding: 8px 12px; margin: 12px 0; }
.rift-notice { border: 2px dashed var(--muted); padding: 8px 12px; margin: 12px 0; }

/* Earlier scenes, each keeps its highlights */
.history { margin-top: 28px; }
.history summary { font-family: var(--marker); font-size: 1.3rem; cursor: pointer; }
.history .story { font-size: 1.05rem; margin: 12px 0; padding-bottom: 12px; border-bottom: 1px dashed var(--muted); }

@keyframes rift-blink { 50% { opacity: 0; } }

@media (max-width: 640px) {
    .stage { row-gap: 52px; }
    .players { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .middle { grid-template-columns: 3fr 2fr; gap: 10px; }
    .narrator { grid-column: 1; width: 86%; padding: 24px 18px 22px; }
    .npcs { grid-column: 2; margin-top: 36px; }
    .narrator b { font-size: 1.55rem; }
    .phone, .npc-card { padding: 10px 9px; }
    .phone { min-height: 170px; }
    .phone-head { font-size: 1.25rem; }
    .screen { font-size: .92rem; }
}

/* ---------- Phone (rift-play.html) ---------- */
.play-wrap { max-width: 560px; margin: 0 auto; padding: 12px 16px 32px; }
.play-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.play-top .grow { flex: 1; min-width: 0; font-family: var(--marker); font-size: 1.3rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-narrator { padding: 6px 16px; font-size: .95rem; text-align: center; white-space: nowrap; }
.play-card { padding: 16px 16px 14px; display: flex; flex-direction: column; gap: 10px; }
.play-card .phone-head { font-size: 1.8rem; }
.play-card textarea {
    font: inherit; font-size: 1.15rem; color: var(--ink); background: transparent; width: 100%; min-height: 110px; resize: vertical;
    border: 2px dashed var(--muted); border-radius: 10px; padding: 10px;
}
.play-card textarea:focus { outline: none; border-color: var(--c); }
.play-card textarea:disabled { opacity: .55; }
.play-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; align-items: center; }
.play-actions .hint { margin-right: auto; font-size: .95rem; opacity: .75; }
.send-btn.sent { background: var(--c) !important; color: var(--bg) !important; border-color: var(--c) !important; }
.last-scene { font-size: 1.05rem; line-height: 1.55; }
.last-scene .label, .own-action .label { font-family: var(--marker); font-size: 1.1rem; opacity: .7; display: block; }
.own-action { font-size: 1rem; opacity: .85; border-left: 3px solid var(--c); padding-left: 8px; }
.divider { border: 0; border-top: 1px dashed var(--muted); margin: 4px 0; width: 100%; }
.play-inbox { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 16px 0 6px; }
.play-inbox .slot { border: 2px solid var(--muted); border-radius: 3px; }
.play-inbox .slot.full { border-color: var(--c); background: repeating-linear-gradient(-45deg, var(--c) 0 2px, transparent 2px 5px); }
/* Player chips with ✓ / ⏳ m:ss (docs/rift-player-wait.md): one row, horizontal scroll when crowded. */
.play-inbox { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; }
.play-inbox .slot.chip {
    width: auto; height: auto; flex: 0 0 auto; padding: 2px 8px; font-size: .95rem; line-height: 1.3; white-space: nowrap;
    border-color: var(--c); border-radius: 12px;
}
.play-inbox .slot.chip.full { background: none; border-style: solid; }
.rift-timer-warn { color: #c0392b; font-weight: 700; }
.phone.standin .state { opacity: 1; }
.standin-note { display: block; opacity: .7; margin-top: 4px; }
.seat-list { display: grid; gap: 12px; }
.seat { padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.seat.taken { opacity: .55; }
.seat .who { font-size: .95rem; opacity: .8; }
.seat .personality { font-size: .95rem; opacity: .75; }
.play-menu { margin-top: 22px; display: flex; flex-wrap: wrap; gap: 10px; }
.wobble { animation: rift-wobble .45s ease-in-out infinite alternate; }
@keyframes rift-wobble { from { transform: rotate(-1.2deg); } to { transform: rotate(1.2deg); } }

@media (prefers-reduced-motion: reduce) {
    .phone, .npc-card { transition: none; }
    .phone.active, .npc-card.active { transform: none; }
    .active .caret { animation: none; }
    .wobble { animation: none; }
}
