@import url('https://fonts.googleapis.com/css2?family=Source+Code+Pro:ital,wght@0,200..900;1,200..900&display=swap');

:root {
    color-scheme: light;
    --bg: #ffffff;
    --fg: #111111;
    --bubble: rgb(245, 245, 245);
    --btn-border: #cccccc;
    --img-filter: none;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #111111;
    --fg: #e8e8e8;
    --bubble: #1e1e1e;
    --btn-border: #3a3a3a;
    /* white bg -> #111 so it matches the page */
    --img-filter: invert(0.933);
}

body{
    background-color: var(--bg);
    color: var(--fg);
    font-family: 'Source Code Pro', monospace;
    font-size: 19px;
    display: grid;
    gap: 2em;
    justify-items: center;
}

header{
    margin: 1.25em 0;
    
    h2{
        margin: 0;
    }

    small{
        opacity: 0.4;
        font-weight: bold;
    }
}

main{
    display: grid;
    gap: 1em;
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
}


input, textarea, button{
    font: inherit;
}

button{
    padding-left: 1em;
    padding-right: 1em;
}

textarea{
    flex: 1;
    font-size: 0.9em;
    resize: vertical;
}

.play-area{
    width: 100%;
    display: grid;
    gap: 0.5em;

    .top{
        display: flex;
        justify-items: stretch;
        align-items: flex-end;

        img.odile{
            user-select: none;
            pointer-events: none;
            display: block;
            width: 35%;
            filter: var(--img-filter);
        }
    }

    .msg{
        position: relative;
        background-color: var(--bubble);
        padding: 1em;
        line-height: 1.5;
        width: 100%;
        box-sizing: border-box;
        user-select: none;
        white-space: pre-wrap;
        word-break: break-word;

        &::before{
            content: '';
            position: absolute;
            display: block;

            /* triangle */
            top: -15px;
            left: 20%;
            width: 0;
            height: 0;
            border-left: 15px solid transparent;
            border-right: 15px solid transparent;
            border-bottom: 15px solid var(--bubble);
        }
    }

    .msg.hint::after{
        display: block;
        margin-top: 0.5em;
        content: 'Click to continue...';
        font-size: 0.8em;
        opacity: 0.5;
    }

    .level{
        font-size: 0.9em;
        cursor: pointer;
        opacity: 0.5;
        margin-right: 0.5em;
        margin-left: auto;
        user-select: none;
    }

    .action{
        display: flex;
        gap: 0.5em;
    }
}

.out{
    animation: out 0.2s forwards;
}

@keyframes out {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

.in{
    animation: in 0.2s forwards;
}

@keyframes in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* theme toggle, top-right */
.theme-toggle{
    position: fixed;
    top: 1em;
    right: 1em;
    z-index: 10;
    background: none;
    border: none;
    padding: 0.25em;
    cursor: pointer;
    color: var(--fg);
    opacity: 0.4;
    line-height: 0;
}
.theme-toggle:hover{ opacity: 0.8; }
.theme-toggle svg{ width: 1.4em; height: 1.4em; }

/* svg sprite */
.svg-sprite{ position: absolute; width: 0; height: 0; overflow: hidden; }

/* leave overlay */
.leave-overlay{
    position: fixed;
    inset: 0;
    z-index: 1000;
    background-color: var(--bg);
    color: var(--fg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5em;
    padding: 2em;
    text-align: center;
    font-family: 'Source Code Pro', monospace;
    transition: opacity 1s ease;
}
.leave-overlay .leave-text{
    font-size: 1.3em;
    line-height: 1.5;
    max-width: 600px;
    white-space: pre-wrap;
}
.leave-overlay .leave-hint{
    font-size: 0.8em;
    opacity: 0;
    transition: opacity 0.6s ease;
}
.leave-overlay .leave-hint.show{ opacity: 0.4; }

/* fixed-ish height so the controls don't jump around */
.play-area .msg-box{
    min-height: 14em;
}

/* best stacked over level, right side */
.play-area .top .level-box{
    margin-left: auto;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.3;
}
.play-area .top .level-box .level,
.play-area .top .level-box .max-level{
    margin: 0;
}

/* best marker */
.play-area .max-level{
    font-size: 0.8em;
    cursor: pointer;
    opacity: 0.4;
    user-select: none;
}

/* narration: italic, no tail */
.play-area .msg.narration{
    font-style: italic;
}
.play-area .msg.narration::before{
    display: none;
}

/* buttons: flat, stable look (no native hover) */
.play-area button{
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--bubble);
    color: var(--fg);
    border: 1px solid var(--btn-border);
    border-radius: 4px;
    padding: 0.4em 1em;
    cursor: pointer;
}
.play-area button:disabled{
    opacity: 0.5;
    cursor: default;
}
/* press feedback */
.play-area button:active:not(:disabled){
    transform: scale(0.96);
}

/* control line */
.play-area .controls{
    display: flex;
    align-items: center;
    gap: 0.5em;
    width: 100%;
}
.play-area .controls .leave{
    flex-shrink: 0; /* Leave keeps its size */
}

/* one-shot pop so a changed button gets noticed */
@keyframes attn{
    0%   { transform: scale(1);    box-shadow: 0 0 0 0 rgba(128, 128, 128, 0.55); }
    15%  { transform: scale(1.04); }
    100% { transform: scale(1);    box-shadow: 0 0 0 10px rgba(128, 128, 128, 0); }
}
.play-area .attn{
    animation: attn 0.5s ease;
}
.play-area .controls .stay-group{
    margin-left: auto;
    min-width: 0;   /* allow the group to shrink so a long Stay label wraps instead of overflowing */
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5em;
}
.play-area .controls .stay{
    min-width: 10em; /* keep Stay comfortably wide (esp. the short "Stay" label); still wraps down to this floor if the label is long */
}
.play-area .controls .counter{
    opacity: 0.6;
    font-variant-numeric: tabular-nums;
    white-space: nowrap; /* keep "10 / 2000000" on one line */
    flex-shrink: 0;
    text-align: right;
}
.play-area .extra{
    display: flex;
    gap: 0.5em;
    width: 100%;
    margin-bottom: 0.5em;
}
.play-area .extra textarea{
    width: 100%;
}
.play-area .extra .choice{
    flex: 1;
}

/* secret/ code generator */
.play-area .extra input{
    width: 100%;
    font: inherit;
    padding: 0.4em;
    box-sizing: border-box;
}
.play-area .code-output{
    font-size: 1.2em;
    margin-top: 0.5em;
    min-height: 1.4em;
    font-variant-numeric: tabular-nums;
}
