:root {
    --bg: #090909;
    --panel: rgba(17, 17, 17, 0.94);
    --panel-hover: #151515;
    --border: rgba(255, 255, 255, 0.09);
    --text: #e5e5e5;
    --muted: #777;
    --dim: #505050;
    --match: #ffffff;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
    user-select: none;
}

canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: none;
}

#wordCursor {
    position: fixed;
    left: 0;
    top: 0;
    width: 18px;
    height: 18px;
    pointer-events: none;
    z-index: 1000;
    transform: translate(-50%, -50%);
    transition: color 80ms linear; /* Transition makes it smoother than displaying color exactly from proximity to a word object per frame */
    color: #777;
}

    #wordCursor svg {
        display: block;
        width: 100%;
        height: 100%;
        fill: currentColor;
    }

/* =========================================================
           SEARCH
========================================================= */

#searchUI {
    position: fixed;
    z-index: 100;
    top: 18px;
    left: 18px;
    width: min(420px, calc(100vw - 36px));
    transform-origin: top left;
}

#searchBox {
    position: relative;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 11px;
    overflow: hidden;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.38), 0 2px 10px rgba(0, 0, 0, 0.22);
}

#searchInput {
    display: block;
    width: 100%;
    height: 46px;
    padding: 0 46px 0 15px;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    font-weight: 400;
    user-select: text;
    -webkit-user-select: text;
}

    #searchInput::placeholder {
        color: #5f5f5f;
    }

#clearSearchButton {
    position: absolute;
    top: 23px;
    right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: #666;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-50%) scale(0.85);
    transition: opacity 160ms ease, color 120ms ease, background 120ms ease, transform 160ms cubic-bezier(.2, .8, .2, 1);
    -webkit-tap-highlight-color: transparent;
}

    #clearSearchButton svg {
        width: 16px;
        height: 16px;
    }

#searchBox:focus-within #clearSearchButton,
#searchInput:not(:placeholder-shown) ~ #clearSearchButton {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(-50%) scale(1);
}

#clearSearchButton:hover {
    color: #aaa;
    background: rgba(255, 255, 255, 0.055);
}

#clearSearchButton:active {
    color: #ccc;
    background: rgba(255, 255, 255, 0.08);
}


/*
 * The results container always exists, but when empty it
 * smoothly collapses upward.
 */
#resultsWrapper {
    display: grid;
    grid-template-rows: 0fr;
    opacity: 0;
    overflow: hidden;
    transition: grid-template-rows 280ms cubic-bezier(.2, .8, .2, 1), opacity 180ms ease;
}

    #resultsWrapper.open {
        grid-template-rows: 1fr;
        opacity: 1;
    }

#results {
    min-height: 0;
    overflow: hidden;
}

#resultsScroll {
    max-height: min(60vh, 500px);
    overflow-y: auto;
    border-top: 1px solid var(--border);
    scrollbar-width: thin;
    scrollbar-color: #333 transparent;
}


/* =========================================================
           SEARCH RESULTS
========================================================= */

.result {
    padding: 11px 15px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.035);
    transition: background 120ms ease;
    -webkit-tap-highlight-color: transparent;
}

    .result:last-child {
        border-bottom: 0;
    }

    .result:hover {
        background: var(--panel-hover);
    }

.resultWord {
    color: #9b9b9b;
    font-size: 14px;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.12s ease;
}

    .result:hover .resultWord {
        color: #b0b0b0;
    }

    /*
    * Only the matching letters become brighter.
    */
    .resultWord .match {
        color: var(--match);
    }

.resultMain {
    min-width: 0;
}

/*
* Duplicate number:
*
* blue #2
*/
.resultNumber {
    display: inline-block;
    margin-left: 5px;
    color: #555;
    font-size: 11px;
    font-style: italic;
    font-weight: 400;
}


/* =========================================================
           RESULT DETAILS
========================================================= */

.resultDetails {
    display: grid;
    grid-template-rows: 0fr;
    opacity: 0;
    transition: grid-template-rows 200ms ease, opacity 160ms ease;
    color: #6e6e6e;
    font-size: 11px;
    line-height: 1.6;
}

.result.expanded .resultDetails {
    grid-template-rows: 1fr;
    opacity: 1;
    margin-top: 7px;
}

.detailsInner {
    min-height: 0;
    overflow: hidden;
}

.detailRow {
    display: flex;
    gap: 10px;
}

.detailLabel {
    width: 50px;
    flex-shrink: 0;
    color: #4e4e4e;
}

.tag {
    margin-right: 6px;
    color: #777;
}

.resultDonors {
    position: relative;
    height: 32px;
    margin-top: 10px;
    overflow: hidden;
}

.donorName {
    position: absolute;
    display: block;
    padding: 2px 4px;
    color: var(--donor-color, #777);
    font-size: 11px;
    font-weight: 400;
    line-height: 1.3;
    white-space: nowrap;
    transform-origin: center;
}

.donorNameColored {
    color: var(--donor-color);
}

.resultActions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 14px;
}

.copyButton,
.trackButton {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 26px;
    margin: 0;
    padding: 0;
    border: 1px solid #333;
    border-radius: 5px;
    background: transparent;
    color: #777;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

    .copyButton:hover,
    .trackButton:hover {
        color: #ccc;
        border-color: #555;
    }

    .trackButton.tracking {
        color: #fff;
        border-color: #777;
    }

    .copyButton:focus,
    .trackButton:focus {
        outline: none;
    }

    .copyButton:focus-visible,
    .trackButton:focus-visible {
        outline: 1px solid #666;
        outline-offset: 2px;
    }

    .copyButton svg,
    .trackButton svg {
        width: 16px;
        height: 16px;
    }

    .copyButton.copied {
        color: #aaa;
        border-color: #555;
    }

        .copyButton.copied svg {
            width: 16px;
            height: 16px;
        }

.noMatches {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 15px;
    color: #555;
    font-size: 12px;
}

.noMatchesHint {
    color: #383838;
    font-size: 10px;
    white-space: nowrap;
}

.searchHintButton {
    padding: 0;
    border: none;
    background: none;
    color: #666;
    font: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

    .searchHintButton:hover {
        color: #aaa;
    }

/* =========================================================
           MUTE BUTTON
*======================================================== */
#muteButton {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #333;
    border-radius: 8px;
    background: rgba(20, 20, 20, 0.85);
    color: #777;
    cursor: pointer;
    backdrop-filter: blur(4px);
    transition: background 0.15s ease, border-color 0.15s ease, color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

    #muteButton:hover {
        background: rgba(35, 35, 35, 0.95);
        border-color: #555;
    }

        #muteButton:hover svg {
            color: #aaa;
        }

    #muteButton:active {
        background: rgba(50, 50, 50, 0.95);
    }

    #muteButton svg {
        width: 24px;
        height: 24px;
        color: #777;
        transition: color 0.2s ease;
    }

    #muteButton:focus {
        outline: none;
    }

    #muteButton:focus-visible {
        outline: 2px solid #666;
        outline-offset: 2px;
    }

/* =========================================================
           SUPPORT / SUBMIT BUTTONS
========================================================= */
#supportButton,
#submitButton {
    position: fixed;
    left: 20px;
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    box-sizing: border-box;
    overflow: hidden;
    border: 1px solid #333;
    border-radius: 8px;
    background: rgba(20, 20, 20, 0.85);
    color: #777;
    cursor: pointer;
    text-decoration: none;
    backdrop-filter: blur(4px);
    transition: width 0.15s ease, background 0.15s ease, border-color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

#submitButton {
    bottom: 20px;
}

#supportButton {
    bottom: 74px;
}

    #supportButton:hover,
    #submitButton:hover,
    #supportButton:focus-visible,
    #submitButton:focus-visible {
        background: rgba(35, 35, 35, 0.95);
        border-color: #555;
    }

    #supportButton:active,
    #submitButton:active {
        background: rgba(50, 50, 50, 0.95);
    }

    #supportButton svg,
    #submitButton svg {
        flex: 0 0 24px;
        width: 24px;
        height: 24px;
        margin-left: 9px;
        color: #777;
        transition: color 0.2s ease;
    }

    #supportButton:hover svg,
    #supportButton:focus-visible svg {
        color: #e8a0b0;
    }

#submitButton:hover svg,
#submitButton:focus-visible svg {
    color: #d8a0e8;
}

#supportButton::after {
    content: "Support";
}

#submitButton::after {
    content: "Add Word";
}

#supportButton::after,
#submitButton::after {
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.1s ease;
}

#supportButton:focus,
#submitButton:focus {
    outline: none;
}

#supportButton:focus-visible,
#submitButton:focus-visible {
    outline: 2px solid #666;
    outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {

    #supportButton:hover {
        width: 116px;
    }

    #submitButton:hover {
        width: 130px;
    }

        #supportButton:hover::after,
        #submitButton:hover::after {
            opacity: 1;
        }
}


/* =========================================================
           HELP
========================================================= */

#hint {
    position: fixed;
    z-index: 5;
    bottom: 17px;
    left: 50%;
    transform: translateX(-50%);
    color: #3f3f3f;
    font-size: 10px;
    pointer-events: none;
    transition: opacity 300ms ease;
}

.desktopHint {
    display: inline;
}

.mobileHint {
    display: none;
}

@media (max-width: 600px) {
    #searchUI {
        top: 10px;
        left: 10px;
        width: calc(100vw - 20px);
    }

    #hint {
        bottom: 10px;
    }

    #supportButton,
    #submitButton {
        left: 10px;
    }

    #submitButton {
        bottom: 10px;
    }

    #supportButton {
        bottom: 64px;
    }

    #muteButton {
        right: 10px;
        bottom: 10px;
    }
}

@media (hover: none) and (pointer: coarse) {
    .desktopHint {
        display: none;
    }

    .mobileHint {
        display: inline;
    }
}


/* =========================================================
           DEBUG INFO
========================================================= */
#debugInfo {
    position: fixed;
    z-index: 1000;
    left: 18px;
    bottom: 18px;
    padding: 10px 12px;
    background: none;
    border: none;
    border-radius: 8px;
    color: #777;
    font-family: monospace;
    font-size: 11px;
    line-height: 1.45;
    white-space: pre;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}