/* ════════════════════════════════════════════════════════
   Party Hat Games — Controller
   "Confetti": sticker-comic party aesthetic on warm paper.
   ════════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    width: 100%;
    overflow-x: hidden;
    overscroll-behavior-x: none;
}

:root {
    /* Paper & ink */
    --paper:   #FFF4E6;
    --paper-2: #FBE8D0;
    --card:    #FFFFFF;
    --ink:     #2E1248;
    --ink-2:   #7A6A88;
    --ink-3:   #BAACC6;
    --ink-soft: rgba(46, 18, 72, 0.14);
    --on-overlay: #FFF4E6;

    /* Confetti palette */
    --pink:   #FF3D8B;  --pink-deep:   #C9165F;
    --yellow: #FFC42E;  --yellow-deep: #E2A400;
    --cyan:   #18C6DE;  --cyan-deep:   #0C93A6;
    --purple: #9B57F0;  --purple-deep: #6E2BCB;
    --lime:   #57CF3C;  --lime-deep:   #3A9E26;
    --tang:   #FF6B2C;  --tang-deep:   #D84E12;

    /* Roles */
    --action: var(--pink);   --action-deep: var(--pink-deep);
    --accent: var(--cyan);   --accent-deep: var(--cyan-deep);
    --celebrate: var(--yellow); --celebrate-deep: var(--yellow-deep);

    /* Lines & corners */
    --line: 2.5px;
    --r-sm:  12px;
    --r:     20px;
    --r-lg:  28px;
    --r-pill: 999px;
    --press: 5px;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    --ease: cubic-bezier(.34, 1.32, .5, 1);
    --ease-out: cubic-bezier(.16, 1, .3, 1);
}

/* #game owns the paper + confetti — self-contained no matter what's behind it. */
#game {
    height: 100dvh;
    display: flex; flex-direction: column;
    width: 100%; max-width: 440px;
    margin-inline: auto;
    position: relative;
    padding-top: var(--safe-top);
    overflow: hidden;
    color: var(--ink);
    background-color: var(--paper);
    background-image:
        radial-gradient(circle, rgba(255, 61, 139, .09) 2.4px, transparent 3px),
        radial-gradient(circle, rgba(24, 198, 222, .09) 2.4px, transparent 3px),
        radial-gradient(circle, rgba(255, 196, 46, .12) 2.4px, transparent 3px);
    background-size: 72px 72px, 72px 72px, 72px 72px;
    background-position: 0 0, 26px 38px, 50px 14px;
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
    user-select: none; -webkit-user-select: none;
}
#game input, #game textarea { user-select: text; -webkit-user-select: text; }
#game *::-webkit-scrollbar { display: none; }
#game * { scrollbar-width: none; }

/* Fredoka carries anything that should feel like a party */
#game .title, #game .title--xl, #game .btn, #game .field__label, #game .field__suggest,
#game .sheet__title, #game .eyebrow, #game .highlight__winnerBadge, #game .highlight__name,
#game .highlight__share {
    font-family: "Fredoka", "Inter", system-ui, sans-serif;
}

/* ---------- Stage ---------- */
#game .stage {
    flex: 1;
    display: flex; flex-direction: column;
    padding: 26px 22px 22px;
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    min-height: 0;
    animation: stageIn .32s var(--ease-out) both;
}
#game .stage--center { justify-content: center; align-items: center; text-align: center; }
#game .stage--gif { padding: 0; overflow: hidden; }
@keyframes stageIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: none; }
}

#game .eyebrow {
    font-size: 12px; font-weight: 600;
    letter-spacing: 0.14em; text-transform: uppercase;
    color: var(--ink-2);
    margin: 0 0 10px;
}

#game .title {
    font-size: 34px; font-weight: 600;
    line-height: 1.07; letter-spacing: -0.005em;
    color: var(--ink);
    margin: 0;
}
#game .title--xl { font-size: 44px; font-weight: 700; line-height: 1.0; }

#game .title--mark {
    background:
        linear-gradient(104deg, transparent 0.4%, var(--yellow) 1.6%, var(--yellow) 97%, transparent 99%);
    background-size: 100% 58%;
    background-repeat: no-repeat;
    background-position: 0 80%;
    padding: 0 .1em;
    box-decoration-break: clone; -webkit-box-decoration-break: clone;
}

#game .subtitle {
    margin: 12px 0 0;
    color: var(--ink-2);
    font-size: 16px; line-height: 1.4; font-weight: 500;
}

/* ---------- Buttons ---------- */
#game .btn {
    -webkit-appearance: none; appearance: none;
    font-size: 18px; font-weight: 600; letter-spacing: 0.01em;
    border: var(--line) solid var(--ink);
    border-radius: var(--r);
    padding: 15px 26px;
    cursor: pointer; touch-action: manipulation;
    color: var(--ink);
    background: var(--card);
    box-shadow: 0 var(--press) 0 var(--ink);
    transition: transform .07s ease, box-shadow .07s ease, background-color .15s, opacity .2s;
    position: relative;
}
#game .btn:active { transform: translateY(var(--press)); box-shadow: 0 0 0 var(--ink); }
#game .btn:disabled {
    cursor: not-allowed;
    background: var(--paper-2); color: var(--ink-3);
    border-color: var(--ink-3); box-shadow: 0 var(--press) 0 var(--ink-3);
}
#game .btn:disabled:active { transform: none; box-shadow: 0 var(--press) 0 var(--ink-3); }
#game .btn--primary { background: var(--action); color: var(--ink); }
#game .btn--ghost   { background: var(--card); color: var(--ink); }
#game .btn--full    { width: 100%; }

/* ---------- Bottom CTA ---------- */
#game .cta {
    position: sticky; bottom: 0;
    margin-top: auto;
    padding: 16px 0 calc(var(--safe-bottom) + 4px);
    background: linear-gradient(to top, var(--paper) 62%, transparent);
}

/* ---------- Form ---------- */
#game .form { display: grid; gap: 16px; margin-top: 18px; }
#game .subtitle + .form { margin-top: 24px; }
#game .form__row { display: grid; grid-template-columns: 1fr 92px; gap: 12px; }

#game .field { display: block; }
#game .field__label {
    display: block;
    font-size: 13px; font-weight: 600;
    letter-spacing: 0.1em; text-transform: uppercase;
    color: var(--ink-2);
    margin: 0 0 7px;
}
#game .field__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 7px; }
#game .field__head .field__label { margin: 0; }

#game .field__suggest {
    -webkit-appearance: none; appearance: none;
    font-size: 12px; font-weight: 700;
    color: var(--ink);
    background: var(--yellow);
    border: var(--line) solid var(--ink);
    border-radius: 999px;
    box-shadow: 0 3px 0 var(--ink);
    padding: 4px 12px;
    cursor: pointer; touch-action: manipulation;
    transition: transform .07s, box-shadow .07s, background-color .15s;
}
#game .field__suggest:active {
    transform: translateY(3px);
    box-shadow: 0 0 0 var(--ink);
}

#game .input {
    width: 100%;
    padding: 15px 16px;
    background: var(--card);
    border: var(--line) solid var(--ink);
    border-radius: var(--r);
    color: var(--ink);
    font-size: 17px; font-weight: 600;
    outline: none;
    box-shadow: 0 4px 0 var(--ink-soft);
    transition: box-shadow .12s, border-color .12s;
    font-family: inherit;
    -webkit-appearance: none; appearance: none;
}
#game .input::placeholder { color: var(--ink-3); font-weight: 500; }
#game .input:focus { border-color: var(--accent); box-shadow: 0 4px 0 var(--accent); }
#game .input--center { text-align: center; }
#game .input--upper  { text-transform: uppercase; letter-spacing: 0.08em; }
#game .input--mono   { font-variant-numeric: tabular-nums; letter-spacing: 0.3em; font-size: 22px; font-weight: 700; }
#game .input--hero   { font-size: 27px; font-weight: 700; padding: 17px 16px; letter-spacing: 0.34em; text-indent: 0.34em; text-transform: uppercase; text-align: center; }
#game textarea.input { resize: none; min-height: 60px; line-height: 1.4; overflow: hidden; }

/* ---------- Emoji trigger ---------- */
#game .field--emoji { text-align: center; }
#game .field--emoji .field__label { text-align: center; }
#game .emojiTrigger {
    width: 88px; height: 88px;
    padding: 0;
    background: var(--card);
    border: var(--line) solid var(--ink);
    border-radius: 50%;
    box-shadow: 0 var(--press) 0 var(--ink);
    color: var(--ink);
    font-size: 42px; font-family: inherit;
    line-height: 1;
    cursor: pointer;
    display: inline-grid; place-items: center;
    touch-action: manipulation;
    -webkit-appearance: none; appearance: none;
    transition: transform .08s, box-shadow .08s;
}
#game .emojiTrigger:active { transform: translateY(var(--press)); box-shadow: 0 0 0 var(--ink); }
#game .emojiTrigger__display { display: inline-flex; align-items: center; justify-content: center; line-height: 1; }
#game .emojiTrigger__display:empty::before {
    content: "+";
    font-family: "Fredoka", "Inter", sans-serif;
    font-weight: 500;
    color: var(--ink-3);
    font-size: 36px;
    line-height: 1;
}

/* ---------- Bottom sheet ---------- */
#game .sheet {
    position: absolute; inset: 0; z-index: 100;
    display: flex; align-items: flex-end; justify-content: center;
    pointer-events: none; opacity: 0;
    transition: opacity .2s;
}
#game .sheet.open { pointer-events: auto; opacity: 1; }
#game .sheet__backdrop {
    position: absolute; inset: 0;
    background: rgba(46, 18, 72, .42);
    backdrop-filter: blur(20px) saturate(120%);
    -webkit-backdrop-filter: blur(20px) saturate(120%);
}
#game .sheet__panel {
    position: relative;
    background: var(--paper);
    border: var(--line) solid var(--ink);
    border-bottom: 0;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding: 10px 18px calc(var(--safe-bottom) + 20px);
    width: 100%; max-width: 440px;
    transform: translateY(100%);
    transition: transform .32s var(--ease-out);
    max-height: 78dvh; height: 78dvh;
    display: flex; flex-direction: column;
}
#game .sheet.open .sheet__panel { transform: translateY(0); }
#game .sheet__handle { width: 44px; height: 5px; background: var(--ink-3); border-radius: 3px; margin: 4px auto 14px; }
#game .sheet__title { text-align: center; font-size: 16px; font-weight: 600; color: var(--ink); margin: 0 0 16px; }

#game .emojiSearch { position: relative; margin: 0 0 12px; flex-shrink: 0; }
#game .emojiSearch__input {
    width: 100%;
    background: var(--card);
    border: var(--line) solid var(--ink);
    border-radius: var(--r-pill);
    padding: 11px 16px;
    color: var(--ink); font-size: 15px; font-family: inherit; font-weight: 500;
    outline: none;
    -webkit-appearance: none; appearance: none;
    transition: box-shadow .12s, border-color .12s;
}
#game .emojiSearch__input::placeholder { color: var(--ink-3); }
#game .emojiSearch__input:focus { border-color: var(--accent); box-shadow: 0 3px 0 var(--accent); }

#game .emojiGridScroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; min-height: 0; }
#game .emojiGrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding-bottom: 6px; }
#game .emojiOption {
    -webkit-appearance: none; appearance: none;
    border: 0; background: transparent;
    border-radius: 12px;
    font-size: 26px; cursor: pointer; font-family: inherit;
    touch-action: manipulation;
    aspect-ratio: 1; display: grid; place-items: center; line-height: 1; padding: 0;
    transition: background .1s, transform .1s;
}
#game .emojiOption:active { transform: scale(.78); background: var(--accent); }
#game .emojiOption.selected { background: var(--yellow); box-shadow: inset 0 0 0 var(--line) var(--ink); }
#game .emojiEmpty { text-align: center; padding: 48px 20px; color: var(--ink-3); font-size: 14px; grid-column: 1 / -1; }

/* ---------- Waiting screen ---------- */
#game .waiting {
    flex: 1;
    display: flex; flex-direction: column;
    justify-content: center; align-items: center; text-align: center;
    gap: 26px; padding: 36px 0;
}
#game .halo { position: relative; width: 132px; height: 132px; display: grid; place-items: center; }
#game .halo__inner {
    width: 116px; height: 116px;
    border-radius: 50%;
    background: var(--card);
    border: var(--line) solid var(--ink);
    box-shadow: 0 6px 0 var(--ink);
    display: grid; place-items: center;
    font-size: 50px; line-height: 1;
    animation: bob 2.4s ease-in-out infinite;
}
#game .halo__inner--blank { background: var(--paper-2); }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }

#game .waiting__helper { margin: 0 auto; max-width: 290px; color: var(--ink-2); font-size: 15px; line-height: 1.4; font-weight: 500; }

#game .dots { display: inline-flex; gap: 9px; align-items: center; }
#game .dots span {
    width: 11px; height: 11px; border-radius: 50%;
    border: 2px solid var(--ink);
    animation: dotPop 1.4s ease-in-out infinite;
}
#game .dots span:nth-child(1) { background: var(--pink); }
#game .dots span:nth-child(2) { background: var(--yellow); animation-delay: .18s; }
#game .dots span:nth-child(3) { background: var(--cyan);   animation-delay: .36s; }
@keyframes dotPop { 0%, 70%, 100% { transform: translateY(0) scale(1); } 35% { transform: translateY(-8px) scale(1.12); } }

/* ---------- GIF picker ---------- */
#game .gifPrompt { padding: 24px 22px 18px; text-align: center; flex-shrink: 0; }
#game .gifPicker {
    flex: 1; display: flex; flex-direction: column;
    background: var(--paper-2);
    border-top: var(--line) solid var(--ink);
    min-height: 0;
}
#game .search { position: relative; flex-shrink: 0; }
#game .search--inPicker { margin: 14px 14px 10px; position: relative; }
#game .search .input {
    padding: 12px 18px;
    font-size: 15px; font-weight: 500; letter-spacing: 0; text-transform: none;
    border-radius: var(--r-pill);
    box-shadow: 0 3px 0 var(--ink-soft);
}
#game .search .input:focus { box-shadow: 0 3px 0 var(--accent); }
#game .search--inPicker .input { padding-left: 44px; }
#game .search__icon {
    position: absolute;
    top: 50%; left: 16px;
    transform: translateY(-50%);
    display: inline-flex;
    color: var(--ink-2);
    pointer-events: none;
    line-height: 0;
}
#game .searchScroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 0 14px 14px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; min-height: 0; }
/* JS-balanced masonry (see gifGame_gif_picker): two independent columns so
   appending more pages never reflows or reorders the gifs already on screen,
   unlike CSS multi-column which re-balances every tile on each append. */
#game .searchResults { display: flex; align-items: flex-start; gap: 8px; }
#game .masonryCol { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
#game .gifResult {
    width: 100%; height: auto; display: block;
    border-radius: var(--r-sm);
    border: var(--line) solid var(--ink);
    cursor: pointer;
    background: var(--card);
    touch-action: manipulation;
    object-fit: cover;
    box-shadow: 0 3px 0 var(--ink-soft);
    transition: transform .12s, box-shadow .12s, border-color .15s;
}
#game .gifResult:active { transform: translateY(3px) rotate(-1deg); box-shadow: 0 0 0 var(--ink-soft); border-color: var(--accent); }
#game .searchEmpty { text-align: center; padding: 48px 20px; color: var(--ink-3); font-size: 14px; column-span: all; display: flex; justify-content: center; }
#game .searchSentinel { height: 1px; display: flex; align-items: center; justify-content: center; }
#game .searchSentinel .dots { display: none; }
#game .searchSentinel.is-loading { height: 60px; padding: 14px 0 4px; }
#game .searchSentinel.is-loading .dots { display: flex; }

/* ---------- GIF preview / vote confirm sheet ---------- */
#game .gifPreview {
    position: absolute; inset: 0; z-index: 100;
    display: flex; align-items: center; justify-content: center;
    pointer-events: none; opacity: 0;
    transition: opacity .22s;
}
#game .gifPreview.open { opacity: 1; pointer-events: auto; }
#game .gifPreview__backdrop {
    position: absolute; inset: 0;
    background: rgba(38, 14, 60, .66);
    backdrop-filter: blur(24px) saturate(120%);
    -webkit-backdrop-filter: blur(24px) saturate(120%);
}
#game .gifPreview .title { color: var(--on-overlay); }
#game .gifPreview__panel {
    position: relative; width: 100%; max-width: 440px;
    max-height: 100%; min-height: 0; box-sizing: border-box;
    padding: calc(var(--safe-top) + 60px) 22px calc(var(--safe-bottom) + 22px);
    display: flex; flex-direction: column; align-items: stretch; gap: 16px;
    transform: scale(.94);
    transition: transform .3s var(--ease-out);
}
#game .gifPreview.open .gifPreview__panel { transform: scale(1); }
#game .gifPreview__close {
    position: absolute; top: calc(var(--safe-top) + 14px); right: 22px;
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--card); border: var(--line) solid var(--ink);
    box-shadow: 0 4px 0 var(--ink);
    color: var(--ink); cursor: pointer;
    display: grid; place-items: center;
    font-size: 22px; line-height: 1;
    -webkit-appearance: none; appearance: none; touch-action: manipulation;
    transition: transform .07s, box-shadow .07s;
}
#game .gifPreview__close:active { transform: translateY(4px); box-shadow: 0 0 0 var(--ink); }
#game .gifPreview__img {
    width: 100%; max-height: 54vh; min-height: 0; flex: 0 1 auto;
    object-fit: contain;
    border-radius: var(--r);
    border: var(--line) solid var(--ink);
    box-shadow: 0 6px 0 var(--ink);
    background: var(--card);
}
#game .gifPreview__attribution {
    align-self: center;
    width: 140px; height: auto;
    flex-shrink: 0;
    opacity: 0.85;
}
#game .gifPreview .btn { flex-shrink: 0; }

/* ---------- Vote ---------- */
#game .voteCards { display: grid; grid-template-columns: 1fr 1fr; align-items: start; gap: 12px; margin-top: 22px; width: 100%; }
#game .voteButton {
    -webkit-appearance: none; appearance: none;
    border: var(--line) solid var(--ink);
    background: var(--card);
    border-radius: var(--r);
    padding: 0; overflow: hidden;
    cursor: pointer; position: relative;
    display: block; width: 100%; touch-action: manipulation;
    box-shadow: 0 var(--press) 0 var(--ink);
    transition: transform .14s var(--ease), box-shadow .12s, opacity .2s, filter .2s, border-color .2s;
}
#game .voteButton:nth-child(1) { transform: rotate(-1.6deg); }
#game .voteButton:nth-child(2) { transform: rotate(1.6deg); }
#game .voteButton img { width: 100%; display: block; height: auto; object-fit: contain; background: var(--card); }
#game .voteButton:active { transform: translateY(var(--press)) rotate(0deg); box-shadow: 0 0 0 var(--ink); }
#game .voteButton.disabled { opacity: .42; filter: saturate(.65); }
#game .voteButton.voteButton--picked {
    border-color: var(--pink);
    box-shadow: 0 var(--press) 0 var(--pink);
    transform: rotate(0deg) scale(1.03);
    opacity: 1 !important; filter: none !important;
    z-index: 1;
}
#game .voteButton.voteButton--picked::after {
    content: "✓";
    position: absolute; top: 8px; right: 8px;
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--pink); color: #fff;
    border: var(--line) solid var(--ink);
    display: grid; place-items: center;
    font-family: "Fredoka", sans-serif; font-weight: 700; font-size: 16px;
}

/* ---------- Highlights ---------- */
#game .highlightsFeed { display: flex; flex-direction: column; gap: 20px; margin-top: 20px; }
#game .highlight {
    background: var(--card);
    border: var(--line) solid var(--ink);
    border-radius: var(--r-lg);
    box-shadow: 0 6px 0 var(--ink);
    padding: 18px;
    display: flex; flex-direction: column; gap: 14px;
}
#game .highlight:nth-child(odd)  { transform: rotate(-.5deg); }
#game .highlight:nth-child(even) { transform: rotate(.5deg); }
#game .highlight__prompt { font-size: 18px; line-height: 1.3; font-weight: 600; color: var(--ink); margin: 0; }
#game .highlight__battle { display: grid; grid-template-columns: 1fr 1fr; align-items: start; gap: 10px; }
#game .highlight__side { display: flex; flex-direction: column; gap: 8px; position: relative; }
#game .highlight__side:not(.highlight__side--winner) { opacity: .5; }
#game .highlight__gif {
    width: 100%; height: auto; object-fit: contain;
    border-radius: var(--r-sm);
    border: var(--line) solid var(--ink);
    display: block; background: var(--card);
}
#game .highlight__side--winner .highlight__gif { border-color: var(--celebrate); box-shadow: 0 4px 0 var(--celebrate-deep); }
#game .highlight__player { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--ink-2); min-height: 18px; }
#game .highlight__emoji { font-size: 14px; line-height: 1; }
#game .highlight__name { letter-spacing: 0.04em; text-transform: uppercase; font-size: 11px; color: var(--ink); font-weight: 600; }
#game .highlight__winnerBadge {
    position: absolute; top: -9px; left: -9px;
    font-size: 11px; font-weight: 700;
    letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--ink);
    background: var(--celebrate);
    border: var(--line) solid var(--ink);
    padding: 4px 10px; border-radius: var(--r-pill);
    transform: rotate(-9deg);
    box-shadow: 0 3px 0 var(--ink);
}
#game .highlight__share {
    -webkit-appearance: none; appearance: none;
    font-size: 15px; font-weight: 600;
    color: var(--ink);
    background: var(--yellow);
    border: var(--line) solid var(--ink);
    border-radius: var(--r);
    box-shadow: 0 4px 0 var(--ink);
    padding: 11px 16px;
    cursor: pointer; touch-action: manipulation;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%;
    transition: transform .07s, box-shadow .07s, background-color .15s;
}
#game .highlight__share:active { transform: translateY(4px); box-shadow: 0 0 0 var(--ink); }
#game .highlight__share.copied { background: var(--lime); }

#game .highlight__gifWrap { position: relative; }
#game .klipyBadge {
    position: absolute;
    bottom: 6px;
    left: 6px;
    width: 52px; height: auto;
    aspect-ratio: auto;
    object-fit: contain;
    opacity: 0.85;
    pointer-events: none;
    z-index: 1;
}
#game .voteButton .klipyBadge {
    width: 52px;
    bottom: 8px;
    left: 8px;
    aspect-ratio: auto;
    object-fit: contain;
    background: transparent;
}

#game .hidden { display: none !important; }
