* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: linear-gradient(135deg, #1a0a2e 0%, #0a0a1a 50%, #0e1a2e 100%);
    color: #eee;
    font-family: 'Nunito', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-user-select: none;
    user-select: none;
}

.view {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 24px;
    width: 100%;
    max-width: 340px;
    margin-top: 8vh;
}

.view.active {
    display: flex;
}

.lobby-form {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    width: 100%;
    margin-top: 48px;
}

.logo {
    max-width: 640px;
    width: 150%;
    height: auto;
    margin-bottom: 8px;
    filter: drop-shadow(0 4px 16px rgba(255, 136, 0, 0.4));
}

.logo-game {
    max-width: 162px;
    width: 45%;
    margin-bottom: 0;
}

h2 {
    font-size: 1.4em;
    margin-bottom: 6px;
    color: #ffcc00;
    text-shadow: 1px 1px 0 #ff8800;
}

.form-group {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-size: 0.85em;
    color: #ccaaee;
}

input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #4a3a6e;
    border-radius: 16px;
    background: rgba(20, 10, 40, 0.8);
    color: #eee;
    font-size: 1em;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus {
    border-color: #ff8833;
    box-shadow: 0 0 12px rgba(255, 136, 51, 0.4);
}

.btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 16px;
    font-size: 1em;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.15s;
}

@media (hover: hover) {
    .btn:hover {
        transform: scale(1.03);
    }

    .btn-primary:hover {
        box-shadow: 0 4px 0 #cc4400, 0 8px 24px rgba(255, 102, 34, 0.4);
    }

    .btn-secondary:hover {
        background: linear-gradient(180deg, #555 0%, #3a3a4a 100%);
    }

    .btn-accent:hover {
        box-shadow: 0 4px 0 #5522aa, 0 8px 24px rgba(119, 51, 204, 0.4);
    }
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: linear-gradient(180deg, #ff9944 0%, #ff6622 100%);
    color: #fff;
    box-shadow: 0 4px 0 #cc4400, 0 6px 16px rgba(255, 102, 34, 0.3);
    text-shadow: 1px 1px 0 rgba(0,0,0,0.2);
}

.btn-primary:active {
    box-shadow: 0 2px 0 #cc4400;
    transform: scale(0.97) translateY(2px);
}

.btn-primary:disabled {
    background: linear-gradient(180deg, #666 0%, #444 100%);
    box-shadow: 0 4px 0 #333;
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-secondary {
    background: linear-gradient(180deg, #444 0%, #2a2a3a 100%);
    color: #ccc;
    box-shadow: 0 3px 0 #1a1a2a;
}

.btn-ready {
    background: linear-gradient(180deg, #33bb55 0%, #1a9940 100%);
    color: #fff;
    box-shadow: 0 4px 0 #0e7733, 0 6px 16px rgba(26, 153, 64, 0.3);
    text-shadow: 1px 1px 0 rgba(0,0,0,0.2);
    animation: pulse-ready 1.5s ease-in-out infinite;
}

@keyframes pulse-ready {
    0%, 100% { box-shadow: 0 4px 0 #0e7733, 0 6px 16px rgba(26, 153, 64, 0.3); }
    50% { box-shadow: 0 4px 0 #0e7733, 0 6px 24px rgba(26, 153, 64, 0.6), 0 0 40px rgba(34, 187, 85, 0.3); }
}

.btn-ready.is-ready {
    background: linear-gradient(180deg, #dd4444 0%, #aa2222 100%);
    box-shadow: 0 4px 0 #881111, 0 6px 16px rgba(170, 34, 34, 0.3);
    animation: none;
}

.btn-accent {
    background: linear-gradient(180deg, #aa66ff 0%, #7733cc 100%);
    color: #fff;
    box-shadow: 0 4px 0 #5522aa, 0 6px 16px rgba(119, 51, 204, 0.3);
    text-shadow: 1px 1px 0 rgba(0,0,0,0.2);
}

.room-actions {
    display: flex;
    gap: 12px;
    width: 100%;
}

.room-actions .btn {
    flex: 1;
}

.divider {
    color: #7766aa;
    font-size: 0.9em;
    text-align: center;
}

.error-msg {
    color: #ff4466;
    font-size: 0.85em;
    min-height: 1.5em;
    text-shadow: 0 0 8px rgba(255, 68, 102, 0.3);
}

/* Power-up selector */
#powerup-selector {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.powerup-label {
    font-size: 0.8em;
    color: #ccaaee;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.powerup-icons {
    display: flex;
    gap: 4px;
    justify-content: center;
    width: 100%;
}

.powerup-icon {
    width: 36px;
    height: auto;
    aspect-ratio: 1 / 1;
    flex: 1 1 0;
    max-width: 52px;
    border-radius: 8px;
    border: 2px solid #555;
    background: rgba(20, 10, 40, 0.6);
    padding: 2px;
    opacity: 0.3;
    filter: grayscale(1);
    transition: opacity 0.2s, filter 0.2s, box-shadow 0.2s, border-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.powerup-icon img {
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.powerup-icon.is-host {
    cursor: pointer;
}

.powerup-icon.is-host:hover {
    opacity: 0.6;
    filter: grayscale(0.5);
}

.powerup-icon.active {
    opacity: 1;
    filter: none;
}

.powerup-icon.active.cat-green {
    border-color: #22CC55;
    box-shadow: 0 0 10px rgba(51, 255, 102, 0.4);
}

.powerup-icon.active.cat-red {
    border-color: #FF3344;
    box-shadow: 0 0 10px rgba(255, 51, 68, 0.4);
}

.powerup-icon.active.cat-blue {
    border-color: #4488FF;
    box-shadow: 0 0 10px rgba(68, 136, 255, 0.4);
}

.powerup-icon.pu-game {
    width: 100%;
    max-width: 42px;
    cursor: default;
}

#game-header-right {
    display: grid;
    grid-template-rows: repeat(3, auto);
    grid-auto-flow: column;
    grid-auto-columns: 32px;
    gap: 6px;
    justify-content: end;
    align-content: center;
}

/* Room view */
#view-room {
    -webkit-user-select: none;
    user-select: none;
}

#room-code {
    -webkit-user-select: text;
    user-select: text;
    margin-left: 0.4em;
    color: #ffcc00;
    letter-spacing: 5px;
    font-size: 1.3em;
    text-shadow: 0 0 10px rgba(255, 204, 0, 0.4);
}

#player-list {
    list-style: none;
    width: 100%;
    margin: 8px 0;
}

#player-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    margin-bottom: 6px;
    font-size: 0.95em;
    transition: background 0.15s;
    position: relative;
    border: 1px solid transparent;
}

#player-list li:hover {
    background: rgba(255, 255, 255, 0.1);
}

#player-list li.is-me::before {
    content: "";
    position: absolute;
    left: -22px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    background: url("public/arrow-sm-right-svgrepo-com.svg") center / contain no-repeat;
    filter: invert(80%) sepia(90%) saturate(500%) hue-rotate(360deg) brightness(1.05);
}

#player-list.grid li.is-me:nth-child(even)::before {
    background-image: url("public/arrow-sm-left-svgrepo-com.svg");
    left: auto;
    right: -22px;
}

/* Crown for host — left column */
#player-list li.is-host::after {
    content: "";
    position: absolute;
    left: -22px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    background: url("public/crown-svgrepo-com.svg") center / contain no-repeat;
    filter: invert(80%) sepia(90%) saturate(500%) hue-rotate(360deg) brightness(1.05);
}

/* When both host and current player: side by side on left */
#player-list li.is-me.is-host::before {
    left: -42px;
}

/* Grid even column: flip crown to right side */
#player-list.grid li.is-host:nth-child(even)::after {
    left: auto;
    right: -22px;
}

/* Grid even column: both icons side by side on right */
#player-list.grid li.is-me.is-host:nth-child(even)::before {
    left: auto;
    right: -42px;
}

.color-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex-shrink: 0;
}

.player-name {
    flex: 1;
}

.player-score {
    color: #ffcc00;
    font-size: 0.85em;
    text-shadow: 0 0 6px rgba(255, 204, 0, 0.3);
}

#player-list li.is-ready {
    background: rgba(34, 204, 85, 0.12);
    border-color: rgba(34, 204, 85, 0.3);
}


#player-list.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

#player-list.grid li {
    padding: 6px 8px;
    font-size: 0.8em;
    margin-bottom: 0;
    min-width: 0;
}

#player-list li.empty-slot {
    border: 1px dashed rgba(255, 255, 255, 0.15);
    background: transparent;
}

#player-list.grid {
    grid-template-rows: repeat(3, 1fr);
}

#player-list.grid .player-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Game view */
#view-game {
    max-width: none;
    padding: 10px;
    gap: 8px;
    margin-top: 52px;
    user-select: none;
    -webkit-user-select: none;
}

#game-header {
    display: flex;
    align-items: center;
    width: min(calc(100vw - 20px), 600px);
    max-width: 600px;
    height: 110px;
    margin: 4px 0;
}

#game-header > * {
    flex: 1;
    min-width: 0;
}

#game-header .logo-game {
    flex: 0 0 auto;
    width: auto;
}

#scoreboard {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-end;
    align-self: stretch;
    gap: 2px;
    font-size: 13px;
    font-weight: bold;
    white-space: nowrap;
}

#scoreboard .sb-entry {
    display: flex;
    align-items: center;
    gap: 5px;
    width: 100%;
}

#scoreboard .sb-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

#scoreboard .sb-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#scoreboard .sb-score {
    flex-shrink: 0;
    min-width: 20px;
    text-align: right;
}

#canvas-wrap {
    position: relative;
    width: min(calc(100vw - 20px), 600px);
    height: min(calc(100vw - 20px), 600px);
    max-width: 600px;
    max-height: 600px;
    overflow: hidden;
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
    background: #0a0a1a;
    box-shadow: 0 0 30px rgba(100, 50, 180, 0.4), 0 0 60px rgba(100, 50, 180, 0.15);
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.45);
    font-size: 3em;
    font-weight: 700;
    font-family: 'Nunito', sans-serif;
    color: #ffcc00;
    text-shadow: 1px 1px 0 #ff8800, 0 0 30px rgba(255, 204, 0, 0.5);
    pointer-events: none;
    z-index: 10;
}

.overlay.show {
    display: flex;
}

#controls {
    display: flex;
    gap: 10px;
    width: min(calc(100vw - 20px), 600px);
    max-width: 600px;
}

.ctrl-btn {
    flex: 1;
    padding: 32px 18px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(180deg, #3a2a5e 0%, #2a1a4e 100%);
    color: #eee;
    font-size: 1.1em;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    box-shadow: 0 4px 0 #1a0a3e, 0 6px 16px rgba(40, 20, 80, 0.4);
    transition: transform 0.1s, box-shadow 0.1s;
}

/* App header */
#app-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 1000;
    background: rgba(10, 5, 20, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    user-select: none;
    -webkit-user-select: none;
}

.app-title {
    font-size: 1.1em;
    font-weight: 800;
    color: #ffcc00;
    text-shadow: 1px 1px 0 #ff8800;
}

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

#btn-lang,
#btn-guide {
    width: 38px;
    height: 38px;
    background: rgba(40, 20, 80, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    padding: 6px;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
    line-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#btn-lang:hover,
#btn-guide:hover {
    background: rgba(60, 30, 110, 0.6);
    box-shadow: 0 0 12px rgba(100, 50, 180, 0.3);
}

#btn-lang:active,
#btn-guide:active {
    background: rgba(80, 40, 140, 0.7);
}

#btn-lang img,
#btn-guide img {
    display: block;
    border-radius: 3px;
}

/* Guide sidebar */
.guide-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.guide-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.guide-sidebar {
    -webkit-user-select: none;
    user-select: none;
    position: fixed;
    top: 0;
    right: 0;
    width: 420px;
    max-width: 100%;
    height: 100%;
    z-index: 1200;
    background: linear-gradient(180deg, #1a0a2e 0%, #0e1020 100%);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.guide-sidebar.open {
    transform: translateX(0);
}

.guide-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.guide-header h2 {
    margin: 0;
    font-size: 1.3em;
    color: #ffcc00;
    text-shadow: 1px 1px 0 #ff8800;
}

.guide-close {
    background: none;
    border: none;
    color: #aaa;
    font-size: 1.8em;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 8px;
    transition: color 0.15s, background 0.15s;
}

.guide-close:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.guide-body {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    overflow-y: auto;
    flex: 1;
}

.guide-body section h3 {
    font-size: 1em;
    color: #aa66ff;
    margin-bottom: 8px;
}

.guide-body section p {
    font-size: 0.9em;
    color: #ccc;
    line-height: 1.6;
    white-space: pre-line;
}

/* Guide powerup grid */
.guide-powerups-intro {
    margin-bottom: 10px;
}

.guide-powerups-note {
    margin-top: 10px;
    font-style: italic;
    opacity: 0.7;
}

.guide-powerup-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.guide-powerup-cat-label {
    width: 100%;
    font-size: 0.8em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 4px;
}

.guide-powerup-card {
    flex: 0 0 calc(33.33% - 6px);
    border-radius: 10px;
    border: 2px solid;
    background: rgba(20, 10, 40, 0.6);
    padding: 10px 6px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.guide-powerup-card img {
    width: 32px;
    height: 32px;
}

.guide-powerup-card .name {
    color: #fff;
    font-weight: 700;
    font-size: 0.8em;
}

.guide-powerup-card .desc {
    color: #999;
    font-size: 0.72em;
    line-height: 1.3;
}

/* Custom lobby powerup tooltips */
.powerup-tooltip {
    position: absolute;
    z-index: 999;
    background: rgba(15, 8, 30, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 8px 12px;
    pointer-events: none;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.15s;
}

.powerup-tooltip.visible {
    opacity: 1;
}

.powerup-tooltip .tt-name {
    color: #fff;
    font-weight: 700;
    font-size: 0.85em;
}

.powerup-tooltip .tt-desc {
    color: #999;
    font-size: 0.75em;
}

.footer {
    position: fixed;
    bottom: 8px;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 0.7em;
    color: rgba(255, 255, 255, 0.25);
    pointer-events: none;
    -webkit-user-select: none;
    user-select: none;
}

.ctrl-btn:active {
    background: linear-gradient(180deg, #ff9944 0%, #ff6622 100%);
    box-shadow: 0 2px 0 #cc4400;
    transform: translateY(2px);
}

/* Mobile responsiveness */
@media (max-width: 480px) {
    .logo {
        width: 100%;
    }

    .view {
        padding: 14px 10px;
        gap: 10px;
        margin-top: 10vh;
    }

    h2 {
        font-size: 1.15em;
    }

    input {
        padding: 10px 12px;
        font-size: 0.9em;
        border-radius: 12px;
    }

    .btn {
        padding: 11px;
        font-size: 0.9em;
        border-radius: 12px;
    }

    #room-code {
        font-size: 1.1em;
        letter-spacing: 3px;
    }

    #player-list li {
        padding: 8px 10px;
        font-size: 0.85em;
        border-radius: 10px;
    }

    .overlay {
        font-size: 2em;
    }

    .ctrl-btn {
        padding: 24px 14px;
        font-size: 1em;
        border-radius: 10px;
    }

    #canvas-wrap {
        width: min(calc(100vw - 16px), 600px);
        height: min(calc(100vw - 16px), 600px);
    }

    #controls {
        width: min(calc(100vw - 16px), 600px);
    }

    #game-header {
        width: min(calc(100vw - 16px), 600px);
    }

    #scoreboard {
        font-size: 11px;
    }

    .guide-sidebar {
        width: 100%;
    }

    .guide-powerup-card {
        flex: 0 0 calc(33.33% - 6px);
        padding: 8px 4px;
    }

    .guide-powerup-card img {
        width: 28px;
        height: 28px;
    }

    .guide-powerup-card .name {
        font-size: 0.72em;
    }

    .guide-powerup-card .desc {
        font-size: 0.65em;
    }

    .powerup-label {
        display: none;
    }
}

@media (max-width: 360px) {
    .view {
        padding: 10px 8px;
        gap: 8px;
    }

    h2 {
        font-size: 1em;
    }

    .btn {
        padding: 10px;
        font-size: 0.85em;
    }

    .ctrl-btn {
        padding: 20px 12px;
        font-size: 0.9em;
    }

    .overlay {
        font-size: 1.6em;
    }

    #player-list li {
        padding: 6px 8px;
        font-size: 0.8em;
    }

}
