/* Pukytoon: a full-screen feed of games you swipe through like videos. */

:root {
    --bar: calc(52px + env(safe-area-inset-top));
    --bg: #0b0a12;
    --panel: #17151f;
    --line: rgba(255, 255, 255, 0.12);
    --fg: #ffffff;
    --muted: rgba(255, 255, 255, 0.72);
    --pink: #ff5fa2;
    --violet: #7b5cff;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--fg);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
}
body { overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }

/* --- Top bar: logo and + in the feed; back, title and restart while playing --- */

.topbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 20;
    height: var(--bar); padding-top: env(safe-area-inset-top);
    background: var(--bg);
}
.feed-bar, .play-bar {
    height: 52px; padding: 0 12px;
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.play-bar { display: none; }
body.playing .feed-bar { display: none; }
body.playing .play-bar { display: flex; }
.logo { font-weight: 900; font-size: 23px; letter-spacing: -0.5px; }
.logo span {
    background: linear-gradient(90deg, var(--pink), var(--violet));
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.play-title {
    flex: 1; text-align: center; font-weight: 700; font-size: 16px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
    width: 40px; height: 40px; flex: none; border: 0; border-radius: 50%;
    background: rgba(255, 255, 255, 0.1); font-size: 24px; line-height: 1;
    display: grid; place-items: center;
}

/* --- The feed: one game per screen, snapping like a video feed --- */

.feed {
    position: fixed; inset: 0;
    overflow-y: auto; scroll-snap-type: y mandatory;
    overscroll-behavior: contain; scrollbar-width: none;
}
.feed::-webkit-scrollbar { display: none; }
body.playing .feed { overflow: hidden; }

.slide {
    position: relative; height: 100%; overflow: hidden;
    scroll-snap-align: start; scroll-snap-stop: always;
}
/* The game always sits under the top bar, so it never resizes between the feed and playing */
.stage {
    position: absolute; top: var(--bar); left: 0; right: 0; bottom: 0;
    background: #000;
}
.stage iframe { display: block; width: 100%; height: 100%; border: 0; background: #fff; }

/* The cover lets you swipe past a game; tapping it starts playing */
.cover {
    position: absolute; top: var(--bar); left: 0; right: 0; bottom: 0;
    border: 0; padding: 0; margin: 0;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0) 45%, rgba(0, 0, 0, 0.78));
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
}
.play-btn {
    padding: 14px 30px; border-radius: 999px;
    background: rgba(255, 255, 255, 0.96); color: #111;
    font-weight: 800; font-size: 18px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.play-note { font-size: 13px; color: var(--muted); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); }
body.playing .slide.active .cover,
body.playing .caption,
body.playing .rail { display: none; }

.caption {
    position: absolute; left: 16px; right: 84px; bottom: calc(22px + env(safe-area-inset-bottom));
    pointer-events: none; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
}
.caption h2 { margin: 8px 0 4px; font-size: 21px; line-height: 1.2; }
.caption p { margin: 0; font-size: 14px; color: var(--muted); line-height: 1.35; }
.caption .chip {
    display: inline-block; min-height: 0; padding: 3px 10px; border: 0; border-radius: 999px;
    font-size: 12px; font-weight: 700; text-shadow: none;
    background: linear-gradient(90deg, var(--c1), var(--c2));
}
.caption .by { margin-top: 3px; font-size: 13px; font-weight: 700; color: var(--fg); }
.caption .by-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 3px; }
.caption .by-line .by { margin-top: 0; }
.caption .follow {
    pointer-events: auto; min-height: 30px; padding: 4px 12px;
    border: 1px solid rgba(255, 255, 255, 0.75); border-radius: 999px; background: rgba(0, 0, 0, 0.35);
    font-size: 12px; font-weight: 800; text-shadow: none;
}
.caption .follow.on { border-color: transparent; background: rgba(255, 255, 255, 0.16); color: var(--muted); }
.caption .follow:focus-visible { outline: 2px solid var(--pink); outline-offset: 2px; }

.rail {
    position: absolute; right: 10px; bottom: calc(26px + env(safe-area-inset-bottom));
    display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.rail button {
    width: 48px; height: 48px; border: 0; border-radius: 50%;
    background: rgba(0, 0, 0, 0.45); font-size: 22px; line-height: 1;
    display: grid; place-items: center;
}
.rail button.liked { color: #ff3b6b; }
.rail button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.rail button.saved { color: #ffd23f; }
.rail button.saved svg { fill: currentColor; }
.rail-item { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.rail .count { font-size: 12px; font-weight: 700; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8); }

.swipe-hint {
    position: absolute; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%);
    pointer-events: none; font-size: 13px; font-weight: 600; color: var(--muted);
    animation: nudge 1.6s ease-in-out infinite;
}
@keyframes nudge { 50% { transform: translate(-50%, -8px); } }
body.playing .swipe-hint { display: none; }

/* Link games that can't play inside the feed get a poster instead */
.poster {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
    background: radial-gradient(circle at 30% 20%, var(--c2), var(--c1) 55%, var(--bg));
}
.poster-emoji { font-size: 104px; line-height: 1; filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.35)); margin-bottom: 190px; }
.poster-host { position: absolute; top: 18px; font-size: 13px; color: rgba(255, 255, 255, 0.85); }

/* The last screen of the feed */
.add-slide .stage {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
    padding: 24px; text-align: center;
    background: radial-gradient(circle at 50% 35%, rgba(123, 92, 255, 0.35), var(--bg) 65%);
}
.add-slide h2 { margin: 18px 0 4px; font-size: 24px; }
.add-slide p { margin: 0; max-width: 320px; color: var(--muted); line-height: 1.45; }
.big-add {
    width: 96px; height: 96px; border: 0; border-radius: 30px;
    background: linear-gradient(135deg, var(--pink), var(--violet));
    font-size: 52px; font-weight: 300; line-height: 1;
    box-shadow: 0 16px 40px rgba(123, 92, 255, 0.45);
}

/* --- Add-a-game sheet --- */

.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.6); }
.sheet-card {
    position: relative; width: 100%; max-width: 560px; max-height: 94%; overflow-y: auto;
    background: var(--panel); border-radius: 22px 22px 0 0;
    padding: 8px 16px calc(18px + env(safe-area-inset-bottom));
    animation: rise 0.22s ease-out;
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet-card h2 { margin: 0 0 4px; font-size: 20px; }
.hint { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.sheet-card textarea, .sheet-card .name {
    width: 100%; border: 1px solid var(--line); border-radius: 12px;
    background: #0f0e16; color: var(--fg); padding: 12px;
    font: 14px/1.45 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}
.sheet-card textarea { min-height: 120px; max-height: 40vh; resize: vertical; }
.sheet-card .name { font-family: inherit; font-size: 15px; margin-top: 10px; }
.sheet-card textarea:focus, .sheet-card .name:focus { outline: 2px solid var(--violet); outline-offset: 0; }
.detect { min-height: 20px; margin-top: 8px; font-size: 13px; font-weight: 600; color: #a7f3d0; }
.made-with { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.made-with[hidden] { display: none; }
.made-with label input { position: absolute; opacity: 0; pointer-events: none; }
.made-with label span {
    display: inline-block; padding: 6px 12px; border-radius: 999px;
    border: 1px solid var(--line); color: var(--fg); cursor: pointer;
}
.made-with label input:checked + span { background: var(--violet); border-color: var(--violet); }
.made-with label input:focus-visible + span { outline: 2px solid var(--pink); }
.sheet-actions { display: flex; gap: 10px; margin-top: 14px; }
.file-btn, .primary {
    flex: 1; min-height: 48px; border-radius: 14px; border: 0;
    display: grid; place-items: center; font-weight: 700; font-size: 15px;
}
.file-btn { background: rgba(255, 255, 255, 0.08); cursor: pointer; }
.primary { flex: 1.4; background: linear-gradient(90deg, var(--pink), var(--violet)); }
.primary:disabled { opacity: 0.4; cursor: default; }
.how { margin-top: 14px; font-size: 13px; color: var(--muted); line-height: 1.45; }
.how summary { cursor: pointer; font-weight: 600; color: var(--fg); }
.how p { margin: 8px 0 0; }

.toast {
    position: fixed; left: 50%; top: calc(var(--bar) + 12px); z-index: 60;
    transform: translate(-50%, -20px); opacity: 0; pointer-events: none;
    background: rgba(255, 255, 255, 0.95); color: #111;
    padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
    transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
    .swipe-hint, .sheet-card { animation: none; }
    .toast { transition: none; }
}

/* --- Create button, links, and the "not responding" cover --- */

.bar-actions { display: flex; align-items: center; gap: 8px; }
.create-btn {
    height: 36px; padding: 0 14px; border: 0; border-radius: 999px;
    font-weight: 800; font-size: 14px;
    background: linear-gradient(90deg, var(--pink), var(--violet));
}
.link-btn {
    display: block; margin-top: 8px; padding: 0; border: 0; background: none;
    color: #c4b5ff; font-weight: 700; font-size: 14px; text-align: left;
    text-decoration: underline; text-underline-offset: 3px;
}
.add-slide .studio-cta {
    margin-top: 16px; min-height: 46px; padding: 0 20px; border: 0; border-radius: 14px;
    background: rgba(255, 255, 255, 0.1); font-weight: 700; font-size: 15px;
}
.stuck {
    position: absolute; top: var(--bar); left: 0; right: 0; bottom: 0; z-index: 5;
    display: grid; place-content: center; gap: 12px; padding: 24px; text-align: center;
    background: rgba(11, 10, 18, 0.88);
}
.stuck h3 { margin: 0; font-size: 20px; }
.stuck p { margin: 0; color: var(--muted); }
.stuck .row { display: flex; gap: 10px; justify-content: center; margin-top: 6px; }
.stuck button { min-height: 44px; padding: 0 18px; border: 0; border-radius: 12px; background: rgba(255, 255, 255, 0.12); font-weight: 700; }
.stuck button.go { background: linear-gradient(90deg, var(--pink), var(--violet)); }

/* --- Creator Studio --- */

.studio { position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; background: var(--bg); }
.studio[hidden] { display: none; }
.studio-bar {
    flex: none; height: var(--bar); padding: env(safe-area-inset-top) 12px 0;
    display: flex; align-items: center; gap: 10px;
}
.studio-name { flex: 1; font-weight: 800; font-size: 17px; }
.studio-publish { flex: none; min-height: 38px; padding: 0 20px; border-radius: 999px; font-size: 15px; }
.studio-preview { flex: none; height: 42%; min-height: 220px; background: #000; }
.studio-preview iframe { display: block; width: 100%; height: 100%; border: 0; }
.studio-panel {
    position: relative; flex: 1; overflow-y: auto; margin-top: -10px;
    padding: 4px 16px calc(28px + env(safe-area-inset-bottom));
    background: var(--panel); border-radius: 18px 18px 0 0;
}
.studio-panel section { padding: 12px 0 16px; border-bottom: 1px solid var(--line); }
.studio-panel section:last-child { border-bottom: 0; }
.studio-panel h3 { margin: 8px 0 10px; font-size: 12.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.studio-note { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.studio-panel .name {
    width: 100%; border: 1px solid var(--line); border-radius: 12px;
    background: #0f0e16; color: var(--fg); padding: 12px; font: inherit; font-size: 15px;
}

.cards { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.cards::-webkit-scrollbar { display: none; }
.card {
    flex: none; width: 150px; padding: 12px; border: 2px solid var(--line); border-radius: 16px;
    background: rgba(255, 255, 255, 0.04); text-align: left;
    display: flex; flex-direction: column; gap: 4px;
}
.card.selected { border-color: var(--violet); background: rgba(123, 92, 255, 0.18); }
.card-emoji { font-size: 26px; line-height: 1.1; }
.card-name { font-weight: 800; font-size: 15px; }
.card-text { font-size: 12.5px; color: var(--muted); line-height: 1.35; }
.card.theme { width: 132px; align-items: center; text-align: center; background: linear-gradient(160deg, var(--sw), var(--sw2)); }
.card.theme.selected { border-color: var(--violet); box-shadow: 0 0 0 2px var(--violet) inset; }
.card.theme .card-name { padding: 2px 10px; border-radius: 999px; background: rgba(11, 10, 18, 0.72); color: #fff; font-size: 13px; }
.theme-art { display: flex; justify-content: center; padding: 4px 0; }
.theme-art .thumb { width: 38px; height: 38px; margin: 0 -3px; }
.thumb { width: 34px; height: 34px; object-fit: contain; }

.slots { display: grid; gap: 8px; margin-top: 12px; }
.slot-head {
    width: 100%; min-height: 52px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 12px;
    background: rgba(255, 255, 255, 0.04); display: flex; align-items: center; gap: 10px;
}
.slot-name { flex: none; min-width: 90px; font-weight: 700; text-align: left; }
.slot-art { flex: 1; display: flex; gap: 2px; overflow: hidden; }
.slot-change { color: #c4b5ff; font-weight: 700; font-size: 13px; }
.picker { display: grid; gap: 8px; padding: 10px 2px 4px; }
.picker[hidden] { display: none; }
.picker .chip { justify-self: start; }
.set-pick { display: flex; gap: 2px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, 0.04); }
.pic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; }
.pic { aspect-ratio: 1; padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255, 255, 255, 0.05); display: grid; place-items: center; }
.pic .thumb { width: 100%; height: 100%; }

.params { display: grid; gap: 16px; }
.param-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.param-name { font-weight: 600; font-size: 14px; }
.param-value { font-weight: 800; font-variant-numeric: tabular-nums; color: #c4b5ff; }
.param input[type=range] { width: 100%; height: 28px; margin: 6px 0 0; accent-color: var(--violet); }
.param-bool { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.toggle {
    appearance: none; -webkit-appearance: none; position: relative; flex: none; margin: 0;
    width: 48px; height: 28px; border-radius: 999px; background: rgba(255, 255, 255, 0.18);
    cursor: pointer; transition: background 0.15s;
}
.toggle::after {
    content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
    border-radius: 50%; background: #fff; transition: transform 0.15s;
}
.toggle:checked { background: var(--violet); }
.toggle:checked::after { transform: translateX(20px); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    min-height: 36px; padding: 6px 14px; border: 1px solid var(--line); border-radius: 999px;
    background: rgba(255, 255, 255, 0.05); font-weight: 600; font-size: 14px;
}
.chip.selected { background: var(--violet); border-color: var(--violet); }
.rule { margin-bottom: 12px; }
.rule-input {
    width: 100%; margin-top: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px;
    background: #0f0e16; color: var(--fg); font: 14px ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}
.rule-input[hidden] { display: none; }
.rule-note { min-height: 18px; margin-top: 6px; font-size: 13px; color: var(--muted); }
.rule-note.bad { color: #ffb4b4; }

.card:focus-visible, .chip:focus-visible, .slot-head:focus-visible, .pic:focus-visible, .set-pick:focus-visible,
.toggle:focus-visible, .create-btn:focus-visible, .link-btn:focus-visible { outline: 2px solid var(--pink); outline-offset: 2px; }

@media (min-width: 900px) {
    .studio { display: grid; grid-template-columns: minmax(340px, 40%) 1fr; grid-template-rows: var(--bar) 1fr; }
    .studio[hidden] { display: none; }
    .studio-bar { grid-column: 1 / -1; }
    .studio-preview { height: auto; min-height: 0; }
    .studio-panel { margin-top: 0; border-radius: 0; }
}

/* --- Account, and the menu of choices --- */

.account-btn { font-size: 20px; font-weight: 800; }
.account-btn.signed-in { background: linear-gradient(135deg, var(--pink), var(--violet)); font-size: 17px; }
.primary.wide { width: 100%; flex: none; margin-top: 12px; }
.fine { margin: 10px 0 0; font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.sheet-card .code-input {
    font: 700 24px/1.2 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    letter-spacing: 8px; text-align: center;
}
.handle-field {
    display: flex; align-items: center; gap: 2px; margin-top: 10px; padding: 0 12px;
    border: 1px solid var(--line); border-radius: 12px; background: #0f0e16;
}
.handle-field:focus-within { outline: 2px solid var(--violet); }
.handle-field span { color: var(--muted); font-weight: 700; }
.handle-field input {
    flex: 1; min-width: 0; padding: 12px 0; border: 0; outline: 0;
    background: transparent; color: var(--fg); font: inherit; font-size: 15px;
}
.acct-actions { display: flex; gap: 10px; margin-top: 4px; }
.acct-actions button, .menu-options button {
    flex: 1; min-height: 48px; border: 0; border-radius: 14px;
    background: rgba(255, 255, 255, 0.08); font-weight: 700; font-size: 15px;
}
.acct-error { margin: 12px 0 0; color: #ffb4b4; font-size: 14px; line-height: 1.4; }
.acct-error:empty { display: none; }
.link-btn.danger, .menu-options button.danger { color: #ff8f8f; }
.fine .link-btn { display: inline; margin: 0; font-size: 13px; }
.menu-options { display: grid; gap: 8px; max-height: 56vh; overflow-y: auto; }   /* a long list scrolls */
.acct-lists { margin-bottom: 10px; }
.menu-options button { text-align: left; padding: 0 16px; }
.menu-cancel {
    width: 100%; min-height: 44px; margin-top: 8px; border: 0; border-radius: 14px;
    background: transparent; color: var(--muted); font-weight: 700; font-size: 15px;
}
.menu-options button:focus-visible, .menu-cancel:focus-visible, .acct-actions button:focus-visible,
.account-btn:focus-visible { outline: 2px solid var(--pink); outline-offset: 2px; }
