:root {
    color-scheme: light;
    --background: #ffffff;
    --text: #202124;
    --muted: #777b80;
    --border: #d3d6da;
    --surface: #f5f6f7;
    --keyboard: #e2e4e6;
    --green: #327653;
    --green-hover: #286344;
    --white: #ffffff;
    --error: #c94c4c;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --background: #151515;
    --text: #f2f2f2;
    --muted: #a0a0a0;
    --border: #454545;
    --surface: #222222;
    --keyboard: #404040;
    --green: #327653;
    --green-hover: #408963;
    --error: #ef7777;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--background);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont,
                 "Segoe UI", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

button {
    font: inherit;
    cursor: pointer;
    touch-action: manipulation;
}

button:focus-visible {
    outline: 3px solid var(--green);
    outline-offset: 3px;
}

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

.site-header {
    border-bottom: 1px solid var(--border);
}

.header-inner {
    max-width: 520px;
    height: 64px;
    margin: auto;
    padding: 0 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-size: 34px;
    font-weight: 900;
    letter-spacing: -2px;
    color: inherit;
    text-decoration: none;
}

.icon-button {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: transparent;
    color: var(--text);
    font-size: 20px;
}

.game-container {
    max-width: 520px;
    margin: auto;
    padding: 24px 16px 12px;
}

.challenge-header {
    text-align: center;
    margin-bottom: 24px;
}

.eyebrow {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.8px;
    color: var(--muted);
    text-transform: uppercase;
}

.challenge-header h1 {
    font-size: 23px;
    letter-spacing: -.7px;
    margin: 10px 0;
}

.challenge-header p {
    font-size: 14px;
    margin: 8px 0;
}

.game-board {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 9px;
}

.word-row {
    display: flex;
    justify-content: center;
    gap: 6px;
}

.tile {
    width: clamp(40px, 11vw, 56px);
    height: clamp(40px, 11vw, 56px);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--border);
    border-radius: 5px;
    background: var(--background);
    font-size: 27px;
    font-weight: 800;
    text-transform: uppercase;
    user-select: none;
}

.tile.prefilled,
.tile.locked {
    background: var(--green);
    border-color: var(--green);
    color: var(--white);
}

.tile.filled {
    border-color: var(--muted);
}

.tile.active {
    border-color: var(--green);
}

.word-row.inactive {
    opacity: .55;
}

.message {
    min-height: 22px;
    margin-top: 12px;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--error);
}

.progress {
    text-align: center;
    color: var(--muted);
    font-size: 12px;
    margin: 6px 0 18px;
}

.keyboard {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 4px;
}

.key {
    flex: 1;
    max-width: 44px;
    height: 53px;
    border: none;
    border-radius: 5px;
    background: var(--keyboard);
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
    padding: 0;
    user-select: none;
}

.key:active {
    transform: scale(.95);
    opacity: .8;
}

.key.special {
    flex: 1.5;
    max-width: 66px;
    font-size: 11px;
}

.results {
    margin: 20px auto;
    text-align: center;
}

.results-image {
    padding: 28px 22px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--background);
}

.final-score {
    font-size: 52px;
    font-weight: 900;
    letter-spacing: -2px;
    color: var(--green);
    margin: 10px 0 24px;
}

.score-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 12px 0;
    font-size: 13px;
}

.score-label {
    width: 58px;
    text-align: left;
}

.score-track {
    flex: 1;
    height: 12px;
    background: var(--keyboard);
    border-radius: 6px;
    overflow: hidden;
}

.score-fill {
    height: 100%;
    background: var(--green);
    border-radius: 6px;
}

.score-value {
    width: 28px;
    text-align: right;
    font-weight: 700;
}

.results-tagline {
    font-size: 15px;
    font-weight: 700;
    margin-top: 26px;
}

.results-domain {
    color: var(--muted);
    font-size: 13px;
}

.results-actions {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}

.results-actions button,
#close-help {
    flex: 1;
    padding: 14px 8px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    border: 1px solid var(--green);
}

#download-results {
    background: transparent;
    color: var(--text);
    border-color: var(--border);
}

#share-results,
#close-help {
    background: var(--green);
    color: var(--white);
}

#share-results:hover,
#close-help:hover {
    background: var(--green-hover);
}

dialog {
    width: min(420px, calc(100% - 32px));
    padding: 28px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--background);
    color: var(--text);
}

dialog::backdrop {
    background: rgba(0, 0, 0, .55);
}

dialog h2 {
    margin-top: 0;
}

dialog li {
    margin-bottom: 10px;
    line-height: 1.5;
}

dialog p {
    line-height: 1.5;
}

#close-help {
    width: 100%;
    margin-top: 10px;
}

.site-footer {
    text-align: center;
    padding: 16px;
    font-size: 11px;
    color: var(--muted);
}

@media (max-height: 750px) {
    .game-container {
        padding-top: 12px;
    }

    .challenge-header {
        margin-bottom: 14px;
    }

    .tile {
        width: 44px;
        height: 44px;
        font-size: 24px;
    }

    .key {
        height: 44px;
    }

    .header-inner {
        height: 54px;
    }
}

.header-inner {
    position: relative;
}

.header-inner > .logo {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.dialog-header h2 {
    margin: 0;
    font-size: 22px;
}

.statistics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px 10px;
    text-align: center;
    margin-bottom: 30px;
}

.stat-value {
    font-size: 29px;
    font-weight: 800;
    letter-spacing: -1px;
}

.stat-label {
    font-size: 11px;
    color: var(--muted);
    margin-top: 5px;
}

.distribution-heading {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 16px;
}

.distribution-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.distribution-label {
    width: 60px;
    font-size: 12px;
    color: var(--muted);
}

.distribution-track {
    flex: 1;
}

.distribution-bar {
    background: var(--green);
    color: white;
    border-radius: 3px;
    min-width: 24px;
    height: 23px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 7px;
    font-size: 12px;
    font-weight: 700;
}

.distribution-bar.empty {
    background: var(--keyboard);
    color: var(--muted);
}

.auth-tabs {
    display: flex;
    gap: 5px;
    padding: 4px;
    background: var(--surface);
    border-radius: 8px;
    margin-bottom: 22px;
}

.auth-tab {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-weight: 600;
    font-size: 14px;
}

.auth-tab.selected {
    background: var(--background);
    color: var(--text);
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

#auth-form label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 7px;
}

#auth-form input {
    width: 100%;
    padding: 13px;
    margin-bottom: 17px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--background);
    color: var(--text);
    font: inherit;
    font-size: 16px;
}

#auth-form input:focus {
    outline: 2px solid var(--green);
    outline-offset: 1px;
}

.primary-button {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 8px;
    background: var(--green);
    color: white;
    font-weight: 700;
}

.primary-button:hover {
    background: var(--green-hover);
}

.auth-hint {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.5;
}

#auth-message {
    font-size: 13px;
    color: var(--error);
    text-align: center;
}

#registered-account {
    text-align: center;
}

#account-username {
    font-size: 28px;
    margin: 10px 0;
}

#verification-status {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 24px;
}

@media (max-width: 440px) {
    .header-inner > .logo {
        font-size: 27px;
        position: static;
        transform: none;
    }

    .header-actions {
        gap: 5px;
    }

    .header-inner .icon-button {
        width: 32px;
        height: 32px;
    }
}

#leaderboard-dialog {
    width: min(480px, calc(100% - 32px));
    max-height: 85dvh;
    overflow-y: auto;
}

.leaderboard-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    border-radius: 8px;
    background: var(--surface);
    margin-bottom: 22px;
}

.leaderboard-tab {
    flex: 1;
    padding: 10px 5px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.leaderboard-tab.selected {
    background: var(--background);
    color: var(--text);
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

.leaderboard-locked {
    padding: 30px 10px;
    text-align: center;
}

.leaderboard-locked h3 {
    font-size: 19px;
}

.leaderboard-locked p {
    font-size: 14px;
    color: var(--muted);
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.leaderboard-table th {
    text-align: left;
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    padding: 10px 8px;
}

.leaderboard-table td {
    padding: 15px 8px;
    border-top: 1px solid var(--border);
    overflow-wrap: anywhere;
}

.leaderboard-table th:last-child,
.leaderboard-table td:last-child {
    text-align: right;
}

.leaderboard-table td:last-child {
    font-weight: 700;
}

.leaderboard-table tr.is-you {
    background: var(--surface);
    color: var(--text);
    font-weight: 700;
}

.leaderboard-rank {
    width: 42px;
    color: var(--muted);
}

.personal-ranking {
    padding: 16px;
    background: var(--surface);
    border-radius: 8px;
    margin-top: 18px;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
}

.header-inner {
    max-width: 620px;
}

@media (max-width: 560px) {
    .header-inner > .logo {
        position: static;
        transform: none;
        font-size: 27px;
    }

    .header-actions {
        gap: 5px;
    }

    .header-inner .icon-button {
        width: 30px;
        height: 30px;
    }
}

@media (max-width: 350px) {
    .header-inner {
        padding: 0 8px;
    }

    .header-inner > .logo {
        font-size: 23px;
    }

    .header-actions {
        gap: 3px;
    }
}

#resend-verification {
    width: 100%;
    padding: 12px;
    margin: 8px 0 16px;
    border: 1px solid #327653;
    border-radius: 8px;
    background: transparent;
    color: #327653;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

#resend-verification[hidden] {
    display: none;
}

#resend-verification:disabled {
    opacity: 0.5;
    cursor: default;
}

.forgot-password-button {
    display: block;
    width: 100%;
    padding: 10px;
    margin: 8px 0;
    border: none;
    background: transparent;
    color: #327653;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
}

.forgot-password-button:hover {
    text-decoration: underline;
}

.forgot-password-button:disabled {
    opacity: 0.5;
    cursor: default;
}

.forgot-password-button[hidden] {
    display: none;
}

/* Mobile interaction improvements */

button,
.key,
.icon-button {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

input,
textarea,
select {
    font-size: 16px;
}

dialog {
    max-height: 90dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.keyboard {
    user-select: none;
    -webkit-user-select: none;
}

button:focus-visible,
a:focus-visible {
    outline: 2px solid #327653;
    outline-offset: 3px;
}

/* Responsive layout improvements */

.key {
    min-width: 0;
}

.score-track {
    min-width: 0;
}

dialog {
    max-width: calc(100% - 24px);
    overflow-wrap: anywhere;
}

@media (max-width: 560px) {

    .game-container {
        padding-left: 12px;
        padding-right: 12px;
    }

    .header-inner {
        padding-left: 10px;
        padding-right: 10px;
    }

    .header-inner .icon-button {
        width: 36px;
        height: 36px;
        flex-shrink: 0;
    }

    .tile {
        width: clamp(32px, 12vw, 48px);
        height: clamp(32px, 12vw, 48px);
        font-size: 24px;
    }

    .keyboard-row {
        gap: 4px;
    }

    .key {
        height: 48px;
    }

    dialog {
        padding: 20px;
    }
}

@media (max-width: 360px) {

    .header-inner > .logo {
        font-size: 23px;
    }

    .header-actions {
        gap: 4px;
    }

    .header-inner .icon-button {
        width: 32px;
        height: 32px;
    }

    .word-row {
        gap: 5px;
    }

    .keyboard-row {
        gap: 3px;
    }

    .key {
        font-size: 12px;
    }

    .key.special {
        font-size: 9px;
    }

    .results-image {
        padding: 20px 12px;
    }
}

@media (max-height: 700px) {

    .game-container {
        padding-top: 10px;
    }

    .challenge-header {
        margin-bottom: 12px;
    }

    .game-board {
        gap: 6px;
    }

    .key {
        height: 44px;
    }

    .progress {
        margin-bottom: 10px;
    }
}

.site-footer {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
}

/* Legal and informational pages */

.legal-container {
    max-width: 760px;
    margin: 0 auto;
    padding: 32px 20px 48px;
    font-size: 15px;
    line-height: 1.75;
}

.legal-container h1 {
    font-size: 32px;
    letter-spacing: -1px;
    margin-bottom: 8px;
}

.legal-container h2 {
    font-size: 20px;
    margin-top: 30px;
    margin-bottom: 10px;
}

.legal-container a {
    color: var(--green);
    overflow-wrap: anywhere;
}

.legal-container li {
    margin-bottom: 6px;
}

/* Account deletion */

.danger-link {
    display: block;
    width: 100%;
    margin-top: 18px;
    padding: 10px;
    border: none;
    background: transparent;
    color: var(--error);
    font-size: 13px;
}

#delete-account-form {
    margin-top: 20px;
    padding: 16px;
    border: 1px solid var(--error);
    border-radius: 10px;
}

#delete-account-form h3 {
    font-size: 16px;
    color: var(--error);
    margin-top: 0;
}

#delete-account-form p {
    font-size: 13px;
}

#delete-account-form input {
    width: 100%;
    margin: 8px 0 14px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--background);
    color: var(--text);
}

.danger-button {
    width: 100%;
    padding: 12px;
    background: #b42318;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
}

#cancel-delete-account {
    width: 100%;
    margin-top: 10px;
    padding: 10px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
}

.footer-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 16px;
    margin-bottom: 12px;
}

.footer-links a {
    color: var(--muted);
    text-decoration: none;
    font-size: 12px;
}

.footer-links a:hover {
    color: var(--green);
    text-decoration: underline;
}
