body {
    font-family: Arial, sans-serif;
    background: radial-gradient(circle at 0% 50%, #000000 0%, #374151 100%);

    color: #fff;
    margin: 0
}

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

.container {
    max-width: 900px;
    margin: auto;
    padding: 16px
}

/* ensure positioned container for animations */
.container {
    position: relative;
}

.toolbar {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
    margin-bottom: 10px;
    align-items: center
}

.toolbar>* {
    min-width: 0
}

.toolbar-right {
    display: flex;
    gap: 4px;
    align-items: center;
    margin-left: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
    min-width: 0;
    flex: 0 0 auto
}

.toolbar-right .status,
.toolbar-right .stopwatch {
    min-width: 0;
    flex: 0 1 auto;
    white-space: nowrap
}

.palette {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin: 20px 0
}

.colorBtn {
    min-height: 72px;
    border: none;
    border-radius: 22px;
    box-shadow: 0 12px 25px rgba(0, 0, 0, .28);
    cursor: pointer;
    transition: transform .2s ease, filter .2s ease, box-shadow .2s ease;
    display: flex;
    align-items: center;
    justify-content: center
}

.colorBtn:hover {
    transform: translateY(-2px);
    filter: brightness(1.05);
    box-shadow: 0 16px 30px rgba(0, 0, 0, .32)
}

.current {
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 0;
}

.current-controls {
    display: flex;
    align-items: center;
    gap: 24px;
    margin: 20px 0;
}

.current-controls button {
    min-width: 100px
}

.current-guess {
    justify-content: space-between;
    background: transparent;
    box-shadow: none;
    padding: 0;
    margin-bottom: 20px;
}

.current-guess .pegs {
    display: flex;
    gap: 8px;
    align-items: center;
}

button:disabled {
    opacity: .55;
    cursor: not-allowed
}

.stopwatch {
    padding: 8px 12px;
    background: #0b1420;
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 8px;
    font-weight: 600
}

/* Win animation (confetti) */
.win-animation {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: visible;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 14px;
    border-radius: 2px;
    opacity: 0.95;
    transform-origin: center;
    will-change: transform, opacity;
    animation: confettiFall 4000ms cubic-bezier(.2, .6, .2, 1) forwards;
}

@keyframes confettiFall {
    0% {
        transform: translateY(-20px) rotate(0deg);
        opacity: 1
    }

    80% {
        opacity: 1
    }

    100% {
        transform: translateY(600px) rotate(720deg);
        opacity: 0
    }
}

/* brief text blink for win message */
@keyframes textBlink {

    0%,
    100% {
        opacity: 1
    }

    50% {
        opacity: 0
    }
}

#message.blink,
#lingoMessage.blink {
    animation: textBlink 0.5s linear 0s 8;
}

@media (prefers-reduced-motion: reduce) {

    #message.blink,
    #lingoMessage.blink {
        animation: none;
    }
}

@media(max-width:820px) {
    .toolbar {
        justify-content: flex-start;
        flex-wrap: wrap;
        overflow-x: visible;
    }

    .toolbar-right {
        position: static;
        transform: none;
        width: 100%;
        justify-content: space-between;
        margin-left: 0;
        padding-left: 0;
        border-left: none;
        margin-top: 8px;
    }

    .toolbar-right .status,
    .toolbar-right .stopwatch {
        flex: 0 0 auto;
        min-width: 0;
        margin-left: 0
    }

    .toolbar button,
    .toolbar select {
        flex: 1 1 48%;
        min-width: 96px;
    }
}

.guess {
    display: flex;
    gap: 12px;
    align-items: center;
    margin: 10px 0;
    flex-wrap: nowrap
}

.peg {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 2px solid #666;
    transition: transform .18s ease, box-shadow .18s ease
}

.guess .pegs {
    display: flex;
    gap: 8px;
    align-items: center
}

.peg.placeholder {
    background: #333;
    opacity: 0.5
}

.guess {
    justify-content: space-between;
    padding: 10px 12px;
    background: linear-gradient(145deg, #1f1f24, #16161b);
    border-radius: 14px;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .05)
}

.feedback {
    font-weight: bold
}

button,
select {
    padding: 10px
}

/* Submit / primary button styling */
#submit {
    padding: 10px 18px;
    background: linear-gradient(90deg, #2f2f2f 0%, #0ea5e9 50%, #1f1f1f 100%);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 12px;
    font-weight: 700;
    letter-spacing: 0.3px;
    min-width: 80px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4), inset 0 -2px 0 rgba(0, 0, 0, 0.18);
    cursor: pointer;
    background-size: 200% 100%;
    animation: gradientShift 6s ease infinite;
    will-change: background-position;
    transition: background .22s ease, transform .15s ease, box-shadow .15s ease, filter .15s ease;
}

#submit:hover:not(:disabled) {
    background: linear-gradient(90deg, #0ea5e9 0%, #3b82f6 100%);
    transform: translateY(-3px);
    box-shadow: 0 14px 34px rgba(59, 130, 246, 0.22);
    filter: brightness(1.03);
    animation-play-state: paused;
}

@keyframes gradientShift {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

@media (prefers-reduced-motion: reduce) {
    #submit {
        animation: none !important;
        background-size: auto;
    }
}

#submit:active:not(:disabled) {
    transform: translateY(-1px) scale(.997);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
}

#submit:disabled {
    opacity: .45;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#submit:focus-visible {
    outline: 2px solid rgba(99, 102, 241, 0.22);
    outline-offset: 3px;
}

/* Toolbar buttons (non-primary) */
.toolbar>button:not(#submit) {
    background: linear-gradient(180deg, #2a2d31 0%, #1d2024 100%);
    color: #f8fafc;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    font-weight: 600;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
    transition: transform .14s ease, box-shadow .14s ease, filter .14s ease;
    cursor: pointer;
    min-width: 92px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
}

.toolbar select {
    background: linear-gradient(180deg, #2a2d31 0%, #1d2024 100%);
    color: #f8fafc;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 10px 26px 10px 14px;
    font-weight: 600;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
    transition: transform .14s ease, box-shadow .14s ease, filter .14s ease;
    cursor: pointer;
    min-width: 118px;
    background-image:
        linear-gradient(45deg, transparent 50%, #f8fafc 50%),
        linear-gradient(135deg, #f8fafc 50%, transparent 50%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
    background-position:
        calc(100% - 16px) 50%,
        calc(100% - 10px) 50%,
        calc(100% - 28px) 50%;
    background-size:
        6px 6px,
        6px 6px,
        1px 22px;
    background-repeat: no-repeat;
}

.toolbar>button:not(#submit):hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
    filter: brightness(1.08);
}

.toolbar>button:not(#submit):active {
    transform: translateY(-1px) scale(.998);
}

/* Inline SVG icon rules */
.toolbar>button:not(#submit) svg {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    display: block;
    color: #fff;
}

.toolbar>button:not(#submit):disabled {
    opacity: .5;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.toolbar select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.toolbar select {
    width: 124px;
    max-width: 160px;
}

.toolbar select:focus-visible,
.toolbar>button:not(#submit):focus-visible {
    outline: 2px solid rgba(14, 165, 233, 0.45);
    outline-offset: 3px;
}

/* Improve dropdown option contrast */
.toolbar select option {
    background: #2f2f2f;
    color: #ffffff;
}

.toolbar select option:checked,
.toolbar select option:focus {
    background: #1f6feb;
    color: #fff;
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: rgba(115, 32, 42, 0.72);
    border-radius: 8px;
    border: 1px solid rgba(255, 180, 190, 0.35);
    margin-left: 0;
    white-space: nowrap;
}


.status .label {
    font-weight: 700;
}

.status .sep {
    opacity: 0.7;
    margin: 0 4px;
}

.stopwatch {
    padding: 8px 12px;
    background: #0b1420;
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 8px;
    font-weight: 600
}

.lexis-page .container {
    max-width: 760px;
}

.lexis-page .container>div:first-child,
.lexis-page h1,
.lexis-page .lingo-container {
    width: min(100%, 540px);
    margin-left: auto;
    margin-right: auto;
}

.lexis-page .toolbar {
    width: fit-content;
    max-width: 100%;
    margin: 0 auto 18px;
    justify-content: center;
    flex-wrap: wrap;
    overflow-x: visible;
}

.lexis-page .toolbar-right {
    justify-content: center;
    margin-left: 8px;
}

.lexis-page .lingo-board {
    align-items: center;
}

.lexis-page .lingo-input {
    width: 100%;
}

.back-link {
    margin-bottom: 16px;
}

.back-link a {
    color: #a8b0bc;
    font-size: 14px;
    text-decoration: none;
}

.back-link a:hover {
    color: #ffffff;
}

.cipherchain-page .container {
    max-width: 920px;
}

.cipherchain-page h1,
.cipherchain-page .back-link {
    width: min(100%, 760px);
    margin-left: auto;
    margin-right: auto;
}

.cipherchain-page .toolbar {
    width: fit-content;
    max-width: 100%;
    margin: 0 auto 18px;
    justify-content: center;
    flex-wrap: wrap;
    overflow-x: visible;
}

.cipherchain-page .toolbar-right {
    justify-content: center;
}

.cipher-shell {
    width: min(100%, 760px);
    margin: 0 auto;
    display: grid;
    gap: 14px;
}

.cipher-panel {
    min-width: 0;
    background: linear-gradient(145deg, rgba(23, 27, 33, 0.94), rgba(12, 15, 20, 0.94));
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 10px;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.28);
    padding: 16px;
}

.cipher-meta {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    color: #b9c2cf;
    font-size: 13px;
    margin-bottom: 14px;
}

.cipher-text {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    min-height: 76px;
    align-items: center;
}

.cipher-char,
.cipher-space {
    width: 48px;
    height: 54px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 24px;
    font-weight: 800;
}

.cipher-char {
    background: #111827;
    border: 1px solid rgba(56, 189, 248, 0.35);
    color: #f8fafc;
    box-shadow: inset 0 -2px 0 rgba(14, 165, 233, 0.18);
}

.cipher-space {
    width: 18px;
}

.cipher-wheel {
    min-width: 0;
    display: grid;
    gap: 8px;
    margin-top: 18px;
    padding: 12px;
    background: rgba(2, 6, 23, 0.42);
    border: 1px solid rgba(148, 163, 184, 0.12);
    border-radius: 8px;
    overflow-x: auto;
}

.cipher-chain-track {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 18px;
}

.cipher-chain-node {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: #111827;
    border: 1px solid rgba(148, 163, 184, 0.24);
    color: #dbeafe;
    font-weight: 800;
}

.cipher-chain-node.is-current {
    border-color: rgba(6, 182, 212, 0.85);
    box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.16);
}

.cipher-chain-node.is-solved {
    background: linear-gradient(135deg, #0891b2 0%, #16a34a 100%);
    border-color: rgba(187, 247, 208, 0.35);
    color: #ffffff;
}

.cipher-rail {
    min-width: 560px;
    font-family: Consolas, Monaco, monospace;
    letter-spacing: 4px;
    white-space: nowrap;
    text-align: center;
    color: #dbeafe;
}

.cipher-coded {
    color: #f9a8d4;
}

.cipher-message {
    min-height: 22px;
    margin-bottom: 12px;
    color: #e2e8f0;
    text-align: center;
    font-weight: 700;
}

.cipher-form {
    display: flex;
    gap: 10px;
    min-width: 0;
}

#cipherInput {
    flex: 1;
    min-width: 0;
    padding: 12px;
    background: #14171c;
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 8px;
    color: #ffffff;
    font-size: 16px;
    text-transform: uppercase;
}

#cipherInput::placeholder {
    color: #7b8493;
}

#cipherSubmit {
    min-width: 112px;
    padding: 12px 18px;
    background: linear-gradient(90deg, #0891b2 0%, #2563eb 100%);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    font-weight: 800;
    cursor: pointer;
    transition: transform .14s ease, box-shadow .14s ease, filter .14s ease;
}

#cipherSubmit:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.28);
    filter: brightness(1.05);
}

#cipherSubmit:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.cipher-history {
    display: grid;
    gap: 8px;
    margin-top: 14px;
}

.cipher-history-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    background: rgba(15, 23, 42, 0.68);
    border: 1px solid rgba(148, 163, 184, 0.14);
    border-radius: 8px;
    color: #dbeafe;
}

.cipher-history-row span:first-child {
    min-width: 0;
    overflow-wrap: anywhere;
}

.lexisgrid-page .container {
    max-width: 980px;
}

.lexisgrid-page h1,
.lexisgrid-page .back-link {
    width: min(100%, 860px);
    margin-left: auto;
    margin-right: auto;
}

.lexisgrid-page .toolbar {
    width: fit-content;
    max-width: 100%;
    margin: 0 auto 18px;
    justify-content: center;
    flex-wrap: wrap;
    overflow-x: visible;
}

.lexisgrid-page .toolbar-right {
    justify-content: center;
}

.lexisgrid-shell {
    width: min(100%, 860px);
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 220px;
    gap: 14px;
    align-items: start;
}

.lexisgrid-panel {
    min-width: 0;
    background: linear-gradient(145deg, rgba(23, 27, 33, 0.94), rgba(12, 15, 20, 0.94));
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-radius: 10px;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.28);
    padding: 16px;
}

.lexisgrid-message {
    min-height: 22px;
    margin-bottom: 12px;
    color: #e2e8f0;
    text-align: center;
    font-weight: 700;
}

.lexisgrid-grid {
    --lexisgrid-size: 10;
    display: grid;
    grid-template-columns: repeat(var(--lexisgrid-size), minmax(0, 1fr));
    gap: 4px;
    width: min(100%, 620px);
    margin: 0 auto;
    touch-action: none;
    user-select: none;
}

.lexisgrid-cell {
    aspect-ratio: 1;
    min-width: 0;
    border: 1px solid rgba(56, 189, 248, 0.22);
    border-radius: 6px;
    background: #111827;
    color: #f8fafc;
    font-size: clamp(13px, 2.7vw, 20px);
    font-weight: 800;
    line-height: 1;
    cursor: pointer;
    transition: background .12s ease, border-color .12s ease, transform .12s ease, color .12s ease;
}

.lexisgrid-cell:hover {
    border-color: rgba(56, 189, 248, 0.55);
}

.lexisgrid-cell.is-selected {
    background: #0891b2;
    border-color: rgba(165, 243, 252, 0.75);
    color: #ffffff;
    transform: scale(1.04);
}

.lexisgrid-cell.is-found {
    background: linear-gradient(135deg, #0891b2 0%, #16a34a 100%);
    border-color: rgba(187, 247, 208, 0.45);
    color: #ffffff;
}

.lexisgrid-cell.is-hint {
    background: #f59e0b;
    border-color: rgba(254, 240, 138, 0.85);
    color: #111827;
}

.lexisgrid-list-title {
    color: #b9c2cf;
    font-size: 13px;
    font-weight: 800;
    margin-bottom: 12px;
    text-transform: uppercase;
}

.lexisgrid-words {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.lexisgrid-word {
    padding: 8px 10px;
    background: rgba(15, 23, 42, 0.68);
    border: 1px solid rgba(148, 163, 184, 0.14);
    border-radius: 8px;
    color: #dbeafe;
    font-weight: 800;
    letter-spacing: 0.4px;
}

.lexisgrid-word.is-found {
    color: #bbf7d0;
    border-color: rgba(34, 197, 94, 0.35);
    text-decoration: line-through;
    opacity: 0.75;
}

@media(max-width:820px) {
    .lexis-page .toolbar {
        width: min(100%, 540px);
    }

    .lexis-page .toolbar-right {
        width: 100%;
        justify-content: center;
        margin-left: 0;
    }

    .cipherchain-page .toolbar {
        width: min(100%, 760px);
    }

    .cipherchain-page .toolbar-right {
        width: 100%;
        margin-left: 0;
    }

    .lexisgrid-page .toolbar {
        width: min(100%, 860px);
    }

    .lexisgrid-page .toolbar-right {
        width: 100%;
        margin-left: 0;
    }

    .lexisgrid-shell {
        grid-template-columns: 1fr;
    }

    .lexisgrid-words {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media(max-width:600px) {
    .container {
        padding: 12px;
    }

    .guess {
        gap: 8px;
        padding: 8px;
        max-width: 100%;
    }

    .peg {
        width: clamp(26px, 7.5vw, 34px);
        height: clamp(26px, 7.5vw, 34px);
        flex: 0 0 clamp(26px, 7.5vw, 34px);
    }

    .current-guess {
        justify-content: center;
        gap: 12px;
        flex-wrap: wrap;
        padding: 0;
    }

    .current-guess>.status {
        display: none;
    }

    .current-guess .pegs {
        justify-content: center;
        min-width: 0;
        width: 100%;
        gap: clamp(4px, 1.5vw, 8px);
    }

    #submit {
        max-width: 100%;
        margin-inline: auto;
    }

    #board .guess {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "attempt feedback"
            "pegs pegs";
    }

    #board .guess .status {
        grid-area: attempt;
        width: fit-content;
        max-width: 100%;
        padding: 6px 8px;
        font-size: 12px;
    }

    #board .guess .pegs {
        grid-area: pegs;
        justify-content: center;
        min-width: 0;
        gap: clamp(4px, 1.5vw, 8px);
    }

    #board .guess .feedback {
        grid-area: feedback;
        white-space: nowrap;
        font-size: 14px;
    }

    .lingo-input {
        flex-direction: column;
    }

    #lingoInput,
    #lingoSubmit,
    #cipherInput,
    #cipherSubmit {
        box-sizing: border-box;
        width: 100%;
        min-width: 0 !important;
    }

    .cipher-panel {
        padding: 12px;
    }

    .cipher-char,
    .cipher-space {
        width: clamp(34px, 10vw, 42px);
        height: clamp(42px, 12vw, 48px);
        font-size: clamp(18px, 5vw, 22px);
    }

    .cipher-space {
        width: 10px;
    }

    .cipher-form {
        flex-direction: column;
    }

    .cipher-rail {
        min-width: 500px;
        letter-spacing: 3px;
        font-size: 13px;
    }

    .lexisgrid-panel {
        padding: 12px;
    }

    .lexisgrid-grid {
        gap: 3px;
    }

    .lexisgrid-cell {
        border-radius: 4px;
        padding: 0;
    }

    .lexisgrid-words {
        grid-template-columns: 1fr;
    }
}
