.header-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    min-height: 3rem;
    gap: 0.5rem;
}

h1 {
    text-align: center;
    grid-column: 2;
    white-space: nowrap;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-right {
    grid-column: 3;
    justify-self: end;
    display: flex;
    align-items: center;
}

.phase-label {
    font-size: var(--font-sm);
    font-weight: 600;
    letter-spacing: 0.1em;
    color: var(--color-yellow);
}

.sidebar-right {
    position: fixed;
    top: 4.5rem;
    right: 0.75rem;
    width: 145px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    z-index: 5;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
}

.player-icon {
    width: 16px;
    height: 16px;
    vertical-align: middle;
}

.username-group {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    width: 100%;
}

.sidebar-label {
    font-size: var(--font-xs);
    font-weight: 600;
    color: var(--color-border-hover);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    width: 100%;
    text-align: center;
}

.sidebar-right .connected-count {
    font-size: var(--font-sm);
    font-weight: 600;
    transition: color 0.2s;
}

.sidebar-right .connected-count.alone {
    color: var(--color-border-hover);
}

.sidebar-right .connected-count.together {
    color: var(--color-green);
}

.phase {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.phase.hidden {
    display: none;
}

.menu-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    padding: 3rem 1rem;
}

.menu-desc {
    font-size: var(--font-body);
    color: var(--color-text-muted);
    text-align: center;
    line-height: 1.6;
}

.username-input {
    flex: 1;
    min-width: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    color: var(--color-text);
    font-size: var(--font-xs);
    font-family: inherit;
    padding: 0.2rem 0.5rem;
    outline: none;
    transition: border-color 0.15s;
    text-overflow: ellipsis;
}

.username-input::placeholder {
    color: var(--color-border-hover);
}

.username-input:focus {
    border-color: var(--color-yellow);
}

.icon-btn {
    background: var(--color-green);
    border: none;
    border-radius: 3px;
    color: var(--color-text);
    font-size: 0.75rem;
    width: 22px;
    height: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    font-family: inherit;
    line-height: 1;
}

.icon-btn:hover {
    background: var(--color-green-hover);
}

.icon-btn:active {
    transform: scale(0.95);
}

.queue-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    padding: 3rem 1rem;
}

.queue-message {
    font-size: var(--font-lg);
    color: var(--color-text);
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--color-border);
    border-top-color: var(--color-yellow);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.game-area {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
    justify-content: center;
}

.player-board-section,
.opponent-board-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.board-label {
    font-size: var(--font-sm);
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.opponent-board .tile {
    width: 48px;
    height: 48px;
    font-size: 1.4rem;
    border-width: 1px;
}

.opponent-board .tile.opponent {
    background: transparent;
    border-color: var(--color-border);
}

.opponent-board .tile.opponent.green {
    background: var(--color-green);
    border-color: var(--color-green);
}

.opponent-board .tile.opponent.yellow {
    background: var(--color-yellow);
    border-color: var(--color-yellow);
}

.opponent-board .tile.opponent.gray {
    background: var(--color-border);
    border-color: var(--color-border);
}

#back-btn {
    font-size: var(--font-pill);
    padding: 0.4rem 0.8rem;
}

.hamburger-menu {
    position: relative;
    display: flex;
    align-items: center;
}

.hamburger-btn {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    color: var(--color-text-muted);
    font-size: 1.3rem;
    padding: 0.3rem 0.55rem;
    cursor: pointer;
    font-family: inherit;
    transition: color 0.15s, border-color 0.15s;
    line-height: 1;
}

.hamburger-btn:hover {
    color: var(--color-text);
    border-color: var(--color-border-hover);
}

.hamburger-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    min-width: 130px;
    z-index: 50;
    overflow: hidden;
}

.hamburger-dropdown.open {
    display: block;
}

.hamburger-dropdown button {
    display: block;
    width: 100%;
    padding: 0.6rem 1rem;
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: var(--font-sm);
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: background 0.1s, color 0.1s;
}

.hamburger-dropdown button:hover {
    background: rgba(255,255,255,0.04);
    color: var(--color-text);
}

.hamburger-dropdown button.active {
    color: var(--color-green);
    font-weight: 600;
}

.result-comparison {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin: 0.5rem 0;
}

.result-player {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
}

.result-player-label {
    font-size: var(--font-sm);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.result-attempt-count {
    font-size: var(--font-xl);
    font-weight: 700;
}

.result-attempt-sub {
    font-size: var(--font-xs);
    color: var(--color-text-muted);
    text-transform: uppercase;
}

.result-vs {
    font-size: var(--font-lg);
    font-weight: 700;
    color: var(--color-yellow);
}

.give-up-btn {
    background: var(--color-red);
    border: none;
    border-radius: 6px;
    color: var(--color-text);
    font-size: var(--font-pill);
    font-weight: 700;
    padding: 0.5rem 1.5rem;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
    margin-top: 0.5rem;
}

.give-up-btn:hover {
    background: var(--color-red-hover);
}

.give-up-btn:active {
    transform: scale(0.95);
}

.rematch-status {
    font-size: var(--font-sm);
    color: var(--color-yellow);
    min-height: 1.2rem;
    margin: 0.25rem 0;
}

.rematch-status.hidden {
    display: none;
}

@media (max-width: 900px) {
    .header-row {
        grid-template-columns: 1fr;
        gap: 0.3rem;
    }

    .header-row > * {
        grid-column: 1;
    }

    .header-row > h1 {
        order: -1;
    }

    .header-row > * {
        justify-self: center;
    }

    .sidebar-right {
        position: static;
        width: 100%;
        max-width: 300px;
        margin: 0 auto 0.75rem;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        top: auto;
        right: auto;
        padding: 0.5rem 0.75rem;
    }

    .sidebar-right .sidebar-label {
        width: auto;
    }

    .sidebar-right .username-group {
        width: auto;
        max-width: 180px;
    }
}

@media (max-width: 800px) {
    .game-area {
        flex-direction: column;
        align-items: center;
        gap: 1rem;
    }

    .result-comparison {
        gap: 0.75rem;
    }

    .result-attempt-count {
        font-size: var(--font-lg);
    }
}

@media (max-height: 750px) {
    :root {
        --tile-size: 60px;
        --tile-font: 2rem;
        --key-size: 42px;
        --key-wide-size: 66px;
        --key-enter-size: 82px;
        --key-font: 1rem;
        --key-wide-font: 0.85rem;
        --board-gap: 4px;
        --tile-gap: 4px;
        --keyboard-gap: 5px;
        --key-gap: 4px;
        --spacer-row1: 28px;
        --spacer-row2: 54px;
    }

    .sidebar-right {
        top: 3.5rem;
        padding: 0.4rem 0.6rem;
    }

    main {
        gap: 0.5rem;
        padding: 0.5rem;
    }
}

@media (max-height: 650px) {
    .opponent-board-section {
        display: none;
    }

    .sidebar-right {
        display: none;
    }
}
