:root {
    --ink: #1b1b1f;
    --muted: #6b6b73;
    --line: #d9d9de;
    --bg: #fbfbfa;
    --accent: #2f4f4f;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0 1.5rem 3rem;
    background: var(--bg);
    color: var(--ink);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.5;
}

/* Title */
header {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2.5rem 0 2rem;
}

/* Lives, top right */
/* Sits in the header's top padding, so it never overlaps the title */
.lives {
    position: absolute;
    top: 0.5rem;
    right: 0;
    display: flex;
    gap: 0.35rem;
}

.life {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

/* Placeholder emoji until img/heart.png and img/heart-broken.png exist */
span.life {
    display: grid;
    place-items: center;
    font-size: 1.5rem;
    line-height: 1;
}

.life.breaking {
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0) scale(1); }
    20% { transform: translateX(-4px) scale(1.2); }
    40% { transform: translateX(4px) scale(1.2); }
    60% { transform: translateX(-3px) scale(1.1); }
    80% { transform: translateX(3px) scale(1.05); }
}

header h1 {
    margin: 0;
    font-size: 2rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

/* Main layout: [ button | image | empty ] then question box, then counter.
   The outer columns are equal, so the image stays truly centered. */
main {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    row-gap: 1.75rem;
    column-gap: 2rem;
    max-width: 720px;
    margin: 0 auto;
}

main br {
    display: none;
}

#guess {
    grid-column: 1;
    grid-row: 1;
    justify-self: end;
}

.npc {
    grid-column: 2;
    grid-row: 1;
    position: relative;
}

.fella {
    width: 200px;
    max-width: 100%;
    height: auto;
}

/* The fella hops when the player wins */
.fella.cheer {
    animation: cheer 0.5s ease-in-out 3;
}

@keyframes cheer {
    0%, 100% { transform: translateY(0); }
    40% { transform: translateY(-24px) rotate(-4deg); }
    60% { transform: translateY(-24px) rotate(4deg); }
}

.confetti {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    pointer-events: none;
}

/* Speech bubble to the right of the fella, with a tail pointing back at him */
.bubble {
    position: absolute;
    top: 1.5rem;
    left: calc(100% + 18px);
    width: max-content;
    min-width: 6rem;
    max-width: min(240px, calc(50vw - 130px));
    margin: 0;
    padding: 0.9rem 1.2rem;
    font-size: 1.15rem;
    text-align: center;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 6px 20px rgba(27, 27, 31, 0.08);
    transform-origin: left center;
}

.bubble::after {
    content: "";
    position: absolute;
    top: 1.1rem;
    right: 100%;
    width: 14px;
    height: 14px;
    background: #fff;
    border-left: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    transform: translateX(8px) rotate(45deg);
}

.bubble.pop {
    animation: pop 0.18s ease-out;
}

@keyframes pop {
    from { transform: scale(0.85); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.ask {
    grid-column: 1 / -1;
    justify-self: center;
    position: relative;
    width: min(100%, 420px);
}

.ask input {
    width: 100%;
}

/* Suggestion menu */
#suggestions {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 10;
    margin: 0;
    padding: 4px;
    list-style: none;
    max-height: 240px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(27, 27, 31, 0.08);
}

#suggestions[hidden] {
    display: none;
}

#suggestions li {
    padding: 0.5rem 0.65rem;
    border-radius: 5px;
    font-size: 0.95rem;
    cursor: pointer;
}

#suggestions li:hover,
#suggestions li.active {
    background: #f0f0ee;
}

/* Log of questions asked so far */
.log {
    grid-column: 1 / -1;
    justify-self: center;
    width: min(100%, 420px);
}

.log h3 {
    margin: 0 0 0.5rem;
    font-size: 0.9rem;
    font-weight: 400;
    text-align: center;
    color: var(--muted);
}

#log {
    margin: 0;
    padding: 0;
    list-style: none;
}

#log li {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: 0.55rem 0.2rem;
    border-bottom: 1px solid var(--line);
    font-size: 0.95rem;
}

#log li:first-child {
    animation: pop 0.18s ease-out;
}

#log .answer {
    flex: none;
    max-width: 50%;
    font-weight: 600;
    text-align: right;
}

/* Controls */
button {
    font: inherit;
    padding: 0.6rem 1.4rem;
    color: var(--ink);
    background: transparent;
    border: 1px solid var(--ink);
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

button:hover {
    background: var(--ink);
    color: var(--bg);
}

button.primary {
    background: var(--ink);
    color: var(--bg);
}

button.primary:hover {
    background: var(--accent);
    border-color: var(--accent);
}

button:disabled,
button:disabled:hover {
    opacity: 0.4;
    cursor: default;
    background: transparent;
    color: var(--ink);
    border-color: var(--ink);
}

input[type="text"]:disabled {
    opacity: 0.5;
}

input[type="text"] {
    font: inherit;
    padding: 0.65rem 0.9rem;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
}

input[type="text"]::placeholder {
    color: var(--muted);
}

button:focus-visible,
input[type="text"]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Guess dialog */
dialog {
    padding: 1.5rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
}

dialog[open] {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: min(90vw, 360px);
}

/* Character picker inside the guess dialog */
.pick input {
    width: 100%;
}

#characterList {
    margin: 0.5rem 0 0;
    padding: 4px;
    list-style: none;
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}

#characterList[hidden] {
    display: none;
}

#characterList li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 0.5rem;
    border-radius: 5px;
    cursor: pointer;
}

#characterList li:hover,
#characterList li.active {
    background: #f0f0ee;
}

#characterList img,
.wrong-guesses img,
.result-card img,
#characterList .initial,
.wrong-guesses .initial,
.result-card .initial {
    flex: none;
    width: 40px;
    height: 40px;
    border-radius: 6px;
    object-fit: cover;
    background: #e8e8e4;
}

#characterList .initial,
.wrong-guesses .initial,
.result-card .initial {
    display: grid;
    place-items: center;
    font-weight: 600;
    color: var(--muted);
}

#characterList .name,
.wrong-guesses .name,
.result-card .name {
    display: block;
    font-size: 0.95rem;
}

#characterList .franchise,
.wrong-guesses .franchise,
.result-card .franchise {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
}

dialog::backdrop {
    background: rgba(27, 27, 31, 0.35);
}

dialog h2 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
}

dialog p {
    margin: 0;
}

.actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
}

.feedback {
    font-size: 0.9rem;
    color: #a3261b;
}

/* Wrong guesses so far, crossed out */
.wrong-guesses {
    margin: 0;
    padding: 0;
    list-style: none;
}

.wrong-guesses:empty {
    display: none;
}

.wrong-guesses li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.3rem 0;
    opacity: 0.6;
}

.wrong-guesses .name {
    text-decoration: line-through;
}

/* The character, revealed at the end */
.result-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    text-align: center;
}

.result-card img,
.result-card .initial {
    width: 120px;
    height: 120px;
    border-radius: 10px;
    font-size: 3rem;
}

.result-card .name {
    font-size: 1.15rem;
    font-weight: 600;
}

.welcome p {
    font-size: 1.05rem;
}

/* Small disclosure link, bottom right */
.about-link {
    position: fixed;
    right: 0.75rem;
    bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    z-index: 5;
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
    color: var(--muted);
    background: rgba(251, 251, 250, 0.9);
    border: 1px solid var(--line);
    border-radius: 999px;
}

.about-link:hover {
    color: var(--ink);
    background: #fff;
}

#about[open] {
    width: min(90vw, 420px);
}

.credits {
    font-size: 0.85rem;
    color: var(--muted);
}

.credits a {
    color: inherit;
}

.next-day {
    text-align: center;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}

.share-status {
    font-size: 0.9rem;
    color: var(--muted);
}

.share-fallback {
    width: 100%;
    min-height: 6rem;
    font: inherit;
    font-size: 0.9rem;
    padding: 0.5rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    resize: vertical;
}

/* Narrow screens: stack everything */
@media (max-width: 560px) {
    main {
        grid-template-columns: 1fr;
    }

    .npc,
    #guess {
        grid-column: 1;
        justify-self: center;
    }

    .npc {
        grid-row: 1;
    }

    #guess {
        grid-row: 2;
    }

    /* No room beside the fella on phones, so the bubble sits above him */
    .npc {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .bubble {
        position: relative;
        top: auto;
        left: auto;
        max-width: 100%;
        margin-bottom: 14px;
        transform-origin: bottom center;
    }

    .bubble::after {
        top: 100%;
        right: auto;
        left: 50%;
        border-left: none;
        border-right: 1px solid var(--line);
        transform: translate(-50%, -7px) rotate(45deg);
    }
}