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

body {
    font-family: "Courier New", Courier, monospace;
    background: #0d0d1a;
    background-image:
        radial-gradient(ellipse at top, #1a0a2e 0%, transparent 50%),
        radial-gradient(ellipse at bottom, #0a1a15 0%, transparent 50%);
    color: #c0ffc0;
    min-height: 100vh;
    overflow: hidden;
}

.hidden { display: none !important; }

/* Lobby */
#lobby {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: 2rem;
}

#lobby h1 {
    font-size: 2.5rem;
    color: #00ff88;
    text-shadow: 0 0 20px #00ff8866, 0 0 40px #00ff8833;
    letter-spacing: 4px;
}

.lobby-box {
    background: linear-gradient(135deg, #1a0a2e 0%, #0d1a15 100%);
    padding: 2rem;
    border-radius: 4px;
    border: 2px solid #4a2c7a;
    box-shadow: 0 0 20px #4a2c7a44, inset 0 0 30px #00000066;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 300px;
}

.lobby-box input {
    padding: 0.75rem;
    border: 1px solid #2d6b4f;
    border-radius: 2px;
    font-size: 1rem;
    font-family: "Courier New", Courier, monospace;
    background: #0a0a12;
    color: #00ff88;
}

.lobby-box input::placeholder {
    color: #4a8866;
}

.lobby-box input:focus {
    outline: none;
    border-color: #00ff88;
    box-shadow: 0 0 10px #00ff8844;
}

.lobby-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.join-row {
    display: flex;
    gap: 0.5rem;
}

.join-row input {
    flex: 1;
    text-transform: uppercase;
}

button {
    padding: 0.75rem 1.5rem;
    border: 2px solid #9b4dca;
    border-radius: 2px;
    font-size: 1rem;
    font-family: "Courier New", Courier, monospace;
    background: linear-gradient(180deg, #4a2c7a 0%, #2d1b4e 100%);
    color: #e0b0ff;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

button:hover {
    background: linear-gradient(180deg, #6b3fa0 0%, #4a2c7a 100%);
    border-color: #bf6fff;
    color: #fff;
    box-shadow: 0 0 15px #9b4dca66;
}

/* Game */
#game {
    display: flex;
    flex-direction: column;
    height: 100vh;
    user-select: none;
}

#top-bar {
    display: flex;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    background: linear-gradient(90deg, #1a0a2e 0%, #0d1a15 50%, #1a0a2e 100%);
    border-bottom: 2px solid #4a2c7a;
    align-items: center;
    flex-wrap: nowrap;
    overflow-x: auto;
}

#action-group {
    display: flex;
    gap: 0.25rem;
    margin-left: auto;
    flex-shrink: 0;
}

#action-group button {
    padding: 0.35rem 0.6rem;
    font-size: 0.7rem;
    letter-spacing: 0;
}

#top-bar button {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
}

#room-display {
    font-weight: bold;
    font-size: 1.1rem;
    color: #00ff88;
    text-shadow: 0 0 10px #00ff8844;
}

#players-display {
    color: #9b4dca;
}

#life-total {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: linear-gradient(180deg, #1a0a2e 0%, #0d1a15 100%);
    border: 2px solid #00ff88;
    border-radius: 4px;
    padding: 0.25rem;
}

#life-total button {
    padding: 0.25rem 0.6rem;
    font-size: 1rem;
    font-weight: bold;
    min-width: 28px;
}

#my-life {
    font-size: 1.4rem;
    font-weight: bold;
    color: #00ff88;
    text-shadow: 0 0 10px #00ff8866;
    min-width: 40px;
    text-align: center;
}

.opponent-life {
    font-size: 1.1rem;
    font-weight: bold;
    color: #e0b0ff;
    margin-left: auto;
}

.opponent-counters {
    display: flex;
    gap: 0.5rem;
}

.opponent-counter {
    font-size: 0.75rem;
    color: #bf6fff;
    background: #2d1b4e;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    border: 1px solid #4a2c7a;
}

/* Player Counters */
#player-counters {
    display: flex;
    gap: 0.5rem;
}

.player-counter {
    display: flex;
    align-items: center;
    gap: 0.2rem;
    background: linear-gradient(180deg, #2d1b4e 0%, #1a0a2e 100%);
    border: 1px solid #9b4dca;
    border-radius: 4px;
    padding: 0.2rem 0.4rem;
}

.player-counter .counter-name {
    font-size: 0.7rem;
    color: #e0b0ff;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.player-counter .counter-value {
    font-size: 1rem;
    font-weight: bold;
    color: #bf6fff;
    min-width: 20px;
    text-align: center;
}

.player-counter button {
    padding: 0.1rem 0.4rem;
    font-size: 0.8rem;
    min-width: 22px;
}

.player-counter .remove-counter {
    background: transparent;
    border: 1px solid #4a2c7a;
    color: #9b4dca;
    padding: 0.1rem 0.3rem;
    font-size: 0.7rem;
    margin-left: 0.2rem;
}

.player-counter .remove-counter:hover {
    border-color: #ff6b6b;
    color: #ff6b6b;
}

/* Card Counters */
.card-counters {
    position: absolute;
    bottom: 2px;
    left: 2px;
    right: 2px;
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    pointer-events: none;
}

.card-counter {
    background: rgba(0, 0, 0, 0.85);
    border: 1px solid #9b4dca;
    border-radius: 3px;
    padding: 1px 4px;
    font-size: 0.6rem;
    color: #e0b0ff;
    pointer-events: auto;
    cursor: pointer;
}

.card-counter:hover {
    border-color: #00ff88;
    color: #00ff88;
}

.card-counter .counter-val {
    font-weight: bold;
    color: #bf6fff;
}

/* Counter Modal */
.counter-modal-content {
    min-width: 300px;
}

.counter-modal-content input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #2d6b4f;
    border-radius: 2px;
    background: #0a0a12;
    color: #00ff88;
    font-family: "Courier New", Courier, monospace;
    font-size: 1rem;
    margin-bottom: 1rem;
}

.counter-modal-content input:focus {
    outline: none;
    border-color: #00ff88;
    box-shadow: 0 0 10px #00ff8844;
}

/* Zones */
#zones {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem;
    background: linear-gradient(180deg, #0a0a12 0%, #0d0d1a 100%);
    border-top: 2px solid #2d6b4f;
}

.zone {
    background: linear-gradient(135deg, #0d1a15 0%, #1a0a2e 100%);
    border: 1px solid #2d6b4f;
    border-radius: 4px;
    padding: 0.5rem;
    min-width: 100px;
    min-height: 160px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.zone-label {
    font-size: 0.65rem;
    color: #4a8866;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: absolute;
    top: 4px;
    left: 8px;
}

#hand {
    flex: 1;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-items: flex-end;
    padding-top: 1.5rem;
    gap: 0.25rem;
}

#library, #graveyard, #exile, #command {
    width: 100px;
    overflow: hidden;
    height: 160px;
}

#command {
    border-color: #ffd700;
    background: linear-gradient(135deg, #2a2000 0%, #1a0a2e 100%);
    min-width: 100px;
    overflow: visible;
    position: relative;
}

#command .zone-label {
    color: #ffd700;
}

#command .card {
    position: absolute;
    top: 25px;
    left: 50%;
    transform: translateX(-50%);
}

#command .card:nth-of-type(2) {
    top: 28px;
}

#commander-prompt {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.25rem;
    align-items: center;
    margin-top: 0.25rem;
}

#commander-prompt.hidden {
    display: none;
}

#commander-prompt button {
    font-size: 0.65rem;
    padding: 0.3rem 0.4rem;
    width: 100%;
}

#commander-prompt button.small {
    background: transparent;
    border-color: #4a2c7a;
    color: #9b4dca;
    font-size: 0.55rem;
}

/* Commander Selection Modal */
.commander-modal-content {
    min-width: 500px;
    max-width: 700px;
}

.modal-hint {
    color: #9b4dca;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

#commander-card-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    max-height: 400px;
    overflow-y: auto;
    padding: 0.5rem;
    background: #0a0a12;
    border: 1px solid #2d6b4f;
    border-radius: 4px;
    min-height: 150px;
    margin-top: 0.5rem;
}

.commander-card-option {
    width: 80px;
    height: 112px;
    background-size: cover;
    background-position: center;
    border-radius: 5px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.5);
    border: 2px solid transparent;
}

.commander-card-option:hover {
    transform: scale(1.05);
}

.commander-card-option.selected {
    border-color: #ffd700;
    box-shadow: 0 0 15px #ffd70088;
}

.commander-modal-content input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #2d6b4f;
    border-radius: 2px;
    background: #0a0a12;
    color: #00ff88;
    font-family: "Courier New", Courier, monospace;
}

/* Library Search Modal */
.library-search-modal-content {
    min-width: 600px;
    max-width: 800px;
}

.library-search-modal-content input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #2d6b4f;
    border-radius: 2px;
    background: #0a0a12;
    color: #00ff88;
    font-family: "Courier New", Courier, monospace;
}

#library-card-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    max-height: 400px;
    overflow-y: auto;
    padding: 0.5rem;
    background: #0a0a12;
    border: 1px solid #2d6b4f;
    border-radius: 4px;
    min-height: 150px;
    margin-top: 0.5rem;
}

.library-card-option {
    width: 80px;
    height: 112px;
    background-size: cover;
    background-position: center;
    border-radius: 5px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.5);
    border: 2px solid transparent;
}

.library-card-option:hover {
    transform: scale(1.05);
}

.library-card-option.selected {
    border-color: #00ff88;
    box-shadow: 0 0 15px #00ff8888;
}

.library-search-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: #1a1a2e;
    border: 1px solid #2d6b4f;
    border-radius: 4px;
}

.library-search-actions button {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

#selected-card-name {
    flex: 1;
    color: #00ff88;
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#library .card-in-zone,
#graveyard .card-in-zone,
#exile .card-in-zone {
    display: none;
}

#library .card-in-zone:nth-last-child(-n+3),
#graveyard .card-in-zone:nth-last-child(-n+3),
#exile .card-in-zone:nth-last-child(-n+3),
#command .card-in-zone {
    display: block;
    margin-top: 0;
    position: absolute;
}

#command .card-in-zone:nth-last-child(1) { top: 30px; }
#command .card-in-zone:nth-last-child(2) { top: 27px; }
#command .card-in-zone:nth-last-child(3) { top: 24px; }

#library .card-in-zone:nth-last-child(3),
#graveyard .card-in-zone:nth-last-child(3),
#exile .card-in-zone:nth-last-child(3) { top: 24px; }

#library .card-in-zone:nth-last-child(2),
#graveyard .card-in-zone:nth-last-child(2),
#exile .card-in-zone:nth-last-child(2) { top: 27px; }

#library .card-in-zone:nth-last-child(1),
#graveyard .card-in-zone:nth-last-child(1),
#exile .card-in-zone:nth-last-child(1) { top: 30px; }

.library-count {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: linear-gradient(180deg, #4a2c7a 0%, #2d1b4e 100%);
    border: 1px solid #9b4dca;
    color: #e0b0ff;
    font-size: 0.75rem;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 2px;
    z-index: 100;
}

.card-stack {
    position: relative;
    width: 70px;
    height: 100px;
    margin-top: 1.5rem;
}

/* Table area */
#table-area {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    grid-template-areas: "battlefield";
    min-height: 0;
}

#table-area.has-left {
    grid-template-columns: 160px 1fr;
    grid-template-areas: "opp-left battlefield";
}

#table-area.has-right {
    grid-template-columns: 1fr 160px;
    grid-template-areas: "battlefield opp-right";
}

#table-area.has-left.has-right {
    grid-template-columns: 160px 1fr 160px;
    grid-template-areas: "opp-left battlefield opp-right";
}

#table-area.has-top {
    grid-template-rows: 80px 1fr;
}

#table-area.has-top:not(.has-left):not(.has-right) {
    grid-template-areas: "opp-top" "battlefield";
}

#table-area.has-top.has-left:not(.has-right) {
    grid-template-areas: "opp-top opp-top" "opp-left battlefield";
}

#table-area.has-top.has-right:not(.has-left) {
    grid-template-areas: "opp-top opp-top" "battlefield opp-right";
}

#table-area.has-top.has-left.has-right {
    grid-template-areas:
        "opp-top   opp-top     opp-top"
        "opp-left  battlefield opp-right";
}

/* Opponent strips */
#opp-top {
    grid-area: opp-top;
    display: none;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.3rem 0.5rem;
    background: linear-gradient(to bottom, #1a0a2e, #0d0d1a);
    border-bottom: 1px solid #4a2c7a;
    overflow-x: auto;
    overflow-y: hidden;
}

#opp-left {
    grid-area: opp-left;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem;
    background: linear-gradient(90deg, #1a0a2e, #0d0d1a);
    border-right: 1px solid #4a2c7a;
    overflow-y: auto;
    overflow-x: hidden;
}

#opp-right {
    grid-area: opp-right;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem;
    background: linear-gradient(270deg, #1a0a2e, #0d0d1a);
    border-left: 1px solid #4a2c7a;
    overflow-y: auto;
    overflow-x: hidden;
}

#table-area.has-top    #opp-top   { display: flex; }
#table-area.has-left   #opp-left  { display: flex; }
#table-area.has-right  #opp-right { display: flex; }

/* Compact opponent card */
.opponent-info-compact {
    background: linear-gradient(135deg, #1a0a2e, #0d1a15);
    border: 1px solid #4a2c7a;
    border-radius: 4px;
    padding: 0.4rem 0.3rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    width: 144px;
    overflow: hidden;
    flex-shrink: 0;
}

.opponent-info-compact.active-turn {
    border-color: #00ff88;
    box-shadow: 0 0 10px #00ff8844;
}

.opponent-info-compact .opp-name {
    font-size: 0.72rem;
    color: #e0b0ff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    text-align: center;
    letter-spacing: 0.5px;
}

.opponent-info-compact .opp-life {
    font-size: 1.6rem;
    font-weight: bold;
    color: #00ff88;
    text-shadow: 0 0 12px #00ff8866;
    line-height: 1.1;
}

.opponent-info-compact .opp-stats {
    font-size: 0.58rem;
    color: #4a8866;
    text-align: center;
}

.opponent-info-compact .opp-counters {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    justify-content: center;
}

/* Top strip: horizontal variant */
#opp-top .opponent-info-compact {
    flex-direction: row;
    width: auto;
    min-width: 200px;
    max-width: 340px;
    height: 68px;
    padding: 0.4rem 0.6rem;
    gap: 0.5rem;
    align-items: center;
}

#opp-top .opponent-info-compact .opp-life { font-size: 1.4rem; }
#opp-top .opponent-info-compact .opp-name { text-align: left; min-width: 60px; max-width: 100px; }
#opp-top .opponent-info-compact .opponent-commander { width: 34px; height: 47px; }

/* Battlefield - shared play area */
#battlefield {
    grid-area: battlefield;
    min-height: 0;
    background:
        linear-gradient(to bottom,
            rgba(155, 77, 202, 0.12) 0%,
            rgba(155, 77, 202, 0.04) 45%,
            transparent 50%,
            rgba(0, 255, 136, 0.04) 55%,
            rgba(0, 255, 136, 0.12) 100%),
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 50px,
            rgba(45, 107, 79, 0.03) 50px,
            rgba(45, 107, 79, 0.03) 51px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 50px,
            rgba(74, 44, 122, 0.03) 50px,
            rgba(74, 44, 122, 0.03) 51px
        ),
        radial-gradient(ellipse at center, #0d1a15 0%, #0a0a12 50%, #0d0d1a 100%);
    position: relative;
    overflow: hidden;
    border-left: 2px solid #2d6b4f;
    border-right: 2px solid #2d6b4f;
}

.table-divider {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 2px;
    background: linear-gradient(to right,
        transparent 0%,
        #4a2c7a 10%,
        #00ff88 30%,
        #00ff88 50%,
        #00ff88 70%,
        #4a2c7a 90%,
        transparent 100%);
    pointer-events: none;
    box-shadow: 0 0 15px #00ff8844;
}

.side-label {
    position: absolute;
    left: 10px;
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    pointer-events: none;
}

.side-label.opponent-side {
    top: 8px;
    color: #9b4dca;
}

.side-label.your-side {
    bottom: 8px;
    color: #00ff88;
}

#my-battlefield {
    display: none;
}

/* Cards */
.card {
    width: 70px;
    height: 100px;
    border-radius: 5px;
    background-size: cover;
    background-position: center;
    cursor: grab;
    position: absolute;
    transition: transform 0.1s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

.card:hover {
    z-index: 1000;
    transform: scale(1.1);
}

.card.dragging {
    cursor: grabbing;
    z-index: 1001;
    transform: scale(1.05);
}

.card.tapped {
    transform: rotate(90deg);
}

.card.tapped:hover {
    transform: rotate(90deg) scale(1.1);
}

/* Opponent cards are full size, rotated 180deg, with only one opponent's
   battlefield visible at a time (selected via the #opp-tab-bar). */
.card.opponent-card {
    transform: rotate(180deg);
}

.card.opponent-card:hover {
    transform: rotate(180deg) scale(1.1);
}

.card.opponent-card.tapped {
    transform: rotate(270deg);
}

.card.opponent-card.tapped:hover {
    transform: rotate(270deg) scale(1.1);
}

/* Tab bar above the table: one button per opponent. Click to swap which
   opponent's battlefield is shown. */
#opp-tab-bar {
    display: flex;
    gap: 0.4rem;
    padding: 0.3rem 0.75rem;
    background: linear-gradient(to bottom, #1a0a2e, #0d0d1a);
    border-bottom: 1px solid #4a2c7a;
    flex-shrink: 0;
}

.opp-tab {
    background: #1a0a2e;
    border: 1px solid #4a2c7a;
    color: #c0ffc0;
    padding: 0.3rem 0.8rem;
    font-family: inherit;
    font-size: 0.75rem;
    cursor: pointer;
    border-radius: 3px;
    transition: all 0.15s;
}

.opp-tab:hover { border-color: #9b4dca; }

.opp-tab.active {
    border-color: #00ff88;
    background: #0d1a15;
    box-shadow: 0 0 8px rgba(0, 255, 136, 0.3);
}

.card.face-down {
    background: #0d0d1a !important;
    background-image:
        repeating-linear-gradient(
            45deg,
            #4a2c7a22 0px,
            #4a2c7a22 2px,
            transparent 2px,
            transparent 8px
        ),
        repeating-linear-gradient(
            -45deg,
            #2d6b4f22 0px,
            #2d6b4f22 2px,
            transparent 2px,
            transparent 8px
        ) !important;
    border: 2px solid #4a2c7a;
    box-shadow: inset 0 0 20px #00000088;
}

.card-in-hand {
    position: relative;
}

.card-in-zone {
    position: relative;
    margin-top: -80px;
}

.card-in-zone:first-child {
    margin-top: 1.5rem;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal-content {
    background: linear-gradient(135deg, #1a0a2e 0%, #0d1a15 100%);
    padding: 2rem;
    border: 2px solid #4a2c7a;
    border-radius: 4px;
    box-shadow: 0 0 40px #4a2c7a44, 0 0 80px #00000088;
    min-width: 400px;
    max-width: 600px;
}

.modal-content h2 {
    margin-bottom: 1rem;
    color: #00ff88;
    text-shadow: 0 0 10px #00ff8844;
    letter-spacing: 2px;
}

.modal-content textarea {
    width: 100%;
    height: 200px;
    padding: 1rem;
    border: 1px solid #2d6b4f;
    border-radius: 2px;
    background: #0a0a12;
    color: #00ff88;
    font-family: "Courier New", Courier, monospace;
    resize: vertical;
}

.modal-content textarea:focus {
    outline: none;
    border-color: #00ff88;
    box-shadow: 0 0 10px #00ff8844;
}

.modal-buttons {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.saved-decks-row, .save-deck-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.saved-decks-row select, .save-deck-row input {
    flex: 1;
    padding: 0.4rem;
    background: #1a0a2e;
    border: 1px solid #4a2c7a;
    border-radius: 4px;
    color: #e8e8e8;
}

#load-status {
    margin-top: 1rem;
    color: #9b4dca;
    font-size: 0.9rem;
}

/* Opponent info in top area */
.opponent-info {
    background: linear-gradient(135deg, #1a0a2e 0%, #0d1a15 100%);
    border: 1px solid #4a2c7a;
    border-radius: 4px;
    padding: 0.5rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    overflow: hidden;
}

.opponent-info.active-turn {
    border-color: #00ff88;
    box-shadow: 0 0 12px #00ff8844;
}

.opponent-info .name {
    font-weight: bold;
    font-size: 0.9rem;
    color: #e0b0ff;
}

.opponent-info .stats {
    font-size: 0.75rem;
    color: #4a8866;
}

.opponent-commander {
    width: 40px;
    height: 56px;
    background-size: cover;
    background-position: center;
    border-radius: 3px;
    border: 2px solid #ffd700;
    box-shadow: 0 0 8px #ffd70066;
    cursor: pointer;
    flex-shrink: 0;
}

.opponent-commander:hover {
    box-shadow: 0 0 12px #ffd700aa;
}

.opponent-info-text {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.opponent-cards {
    display: flex;
    gap: 2px;
    margin-left: auto;
}

.opponent-cards .mini-card {
    width: 20px;
    height: 28px;
    background: #2d1b4e;
    border: 1px solid #4a2c7a;
    border-radius: 2px;
}

/* Card Preview */
#card-preview {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 250px;
    height: 350px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    background-color: #0a0a12;
    border: 3px solid #4a2c7a;
    border-radius: 8px;
    box-shadow: 0 0 30px #4a2c7a66, 0 0 60px #00000088;
    z-index: 3000;
    pointer-events: none;
}

/* Zone Viewer Modal */
.zone-viewer {
    max-width: 80vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

#zone-modal-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 1rem;
    overflow-y: auto;
    max-height: 60vh;
    background: #0a0a12;
    border: 1px solid #2d6b4f;
    border-radius: 4px;
}

.zone-card {
    width: 100px;
    height: 140px;
    background-size: cover;
    background-position: center;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

.zone-card:hover {
    transform: scale(1.08);
    box-shadow: 0 0 15px #00ff8866;
}

.zone-empty {
    color: #4a8866;
    font-style: italic;
    padding: 2rem;
    text-align: center;
    width: 100%;
}

.zone-card-actions {
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    background: rgba(10, 10, 18, 0.9);
    padding: 0.25rem;
    border-radius: 3px;
}

.zone-card-wrapper {
    position: relative;
}

.zone-card-wrapper:hover .zone-card-actions {
    opacity: 1;
    pointer-events: auto;
}

.zone-card-actions button {
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
}

.zone.clickable {
    cursor: pointer;
}

.zone.clickable:hover {
    border-color: #00ff88;
    box-shadow: 0 0 10px #00ff8844;
}

/* Context Menu */
#context-menu {
    position: fixed;
    background: linear-gradient(135deg, #1a0a2e 0%, #0d1a15 100%);
    border: 2px solid #4a2c7a;
    border-radius: 4px;
    box-shadow: 0 0 20px #4a2c7a66, 0 0 40px #00000088;
    min-width: 200px;
    max-width: 280px;
    z-index: 5000;
    overflow: hidden;
}

#context-search {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: none;
    border-bottom: 1px solid #4a2c7a;
    background: #0a0a12;
    color: #00ff88;
    font-family: "Courier New", Courier, monospace;
    font-size: 0.85rem;
    outline: none;
}

#context-search::placeholder {
    color: #4a8866;
}

#context-actions {
    max-height: 300px;
    overflow-y: auto;
}

.context-action {
    padding: 0.5rem 0.8rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.1s;
}

.context-action:hover,
.context-action.selected {
    background: linear-gradient(90deg, #4a2c7a44 0%, #2d6b4f44 100%);
}

.context-action .label {
    color: #c0ffc0;
    font-size: 0.85rem;
}

.context-action .shortcut {
    color: #9b4dca;
    font-size: 0.7rem;
    background: #0a0a12;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    border: 1px solid #4a2c7a;
    margin-left: 1rem;
}

.context-action.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.context-divider {
    height: 1px;
    background: #4a2c7a;
    margin: 0.25rem 0;
}

/* Token Cards */
.card.token {
    box-shadow: 0 0 0 3px #ffd700, 0 0 12px #ffd70088, 0 2px 8px rgba(0,0,0,0.5);
}

.card.token::after {
    content: 'TOKEN';
    position: absolute;
    top: 2px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(180deg, #ffd700 0%, #b8960f 100%);
    color: #000;
    font-size: 0.5rem;
    font-weight: bold;
    padding: 1px 4px;
    border-radius: 2px;
    letter-spacing: 1px;
    pointer-events: none;
}

/* Cards you control but don't own (stolen/controlled cards) */
.card.controlled-card {
    box-shadow: 0 0 0 3px #ff4444, 0 0 15px #ff444488, 0 2px 8px rgba(0,0,0,0.5);
}

.card.controlled-card::before {
    content: 'CONTROLLED';
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(180deg, #ff4444 0%, #aa2222 100%);
    color: #fff;
    font-size: 0.45rem;
    font-weight: bold;
    padding: 1px 3px;
    border-radius: 2px;
    letter-spacing: 0.5px;
    pointer-events: none;
    z-index: 5;
}

/* Cards you own but opponent controls */
.card.lost-control {
    opacity: 0.6;
    box-shadow: 0 0 0 2px #888, 0 0 8px #88888888;
}

/* Token Search Modal */
.token-modal-content {
    min-width: 500px;
    max-width: 700px;
}

.token-modal-content input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #2d6b4f;
    border-radius: 2px;
    background: #0a0a12;
    color: #00ff88;
    font-family: "Courier New", Courier, monospace;
    font-size: 1rem;
    margin-bottom: 1rem;
}

.token-modal-content input:focus {
    outline: none;
    border-color: #00ff88;
    box-shadow: 0 0 10px #00ff8844;
}

#token-results {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    max-height: 400px;
    overflow-y: auto;
    padding: 0.5rem;
    background: #0a0a12;
    border: 1px solid #2d6b4f;
    border-radius: 4px;
    min-height: 150px;
}

.token-option {
    width: 100px;
    height: 140px;
    background-size: cover;
    background-position: center;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    position: relative;
}

.token-option:hover {
    transform: scale(1.08);
    box-shadow: 0 0 15px #ffd70066;
}

.token-option .token-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.85);
    color: #ffd700;
    font-size: 0.6rem;
    padding: 2px 4px;
    text-align: center;
    border-radius: 0 0 6px 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#token-status {
    margin-top: 0.5rem;
    color: #9b4dca;
    font-size: 0.85rem;
    min-height: 1.2em;
}

/* Lobby life selector */
.lobby-life-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.lobby-life-row label {
    font-size: 0.85rem;
    color: #9b4dca;
    white-space: nowrap;
}

.lobby-life-row select {
    flex: 1;
    padding: 0.5rem;
    background: #0a0a12;
    border: 1px solid #4a2c7a;
    border-radius: 2px;
    color: #e0b0ff;
    font-family: "Courier New", Courier, monospace;
    font-size: 0.9rem;
}

.lobby-life-row input[type="number"] {
    width: 70px;
    padding: 0.5rem;
    background: #0a0a12;
    border: 1px solid #2d6b4f;
    border-radius: 2px;
    color: #00ff88;
    font-family: "Courier New", Courier, monospace;
    font-size: 0.9rem;
}

/* Turn indicator */
#turn-indicator {
    font-size: 0.8rem;
    font-weight: bold;
    color: #00ff88;
    border: 1px solid #00ff88;
    border-radius: 3px;
    padding: 0.25rem 0.5rem;
    animation: pulse-turn 1.5s ease-in-out infinite;
    white-space: nowrap;
}

@keyframes pulse-turn {
    0%, 100% { opacity: 1; box-shadow: 0 0 8px #00ff8866; }
    50% { opacity: 0.7; box-shadow: none; }
}

#top-bar.my-turn {
    border-bottom-color: #00ff88;
    box-shadow: 0 2px 20px #00ff8833;
}

.turn-badge {
    font-size: 0.65rem;
    background: #00ff88;
    color: #000;
    padding: 1px 4px;
    border-radius: 2px;
    font-weight: bold;
    letter-spacing: 1px;
    vertical-align: middle;
}

/* Life area (life total + commander damage) */
#life-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
}

/* Commander damage chips */
#commander-damage {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
    justify-content: center;
}

.cmd-damage-chip {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: #1a0a2e;
    border: 1px solid #4a2c7a;
    border-radius: 3px;
    padding: 1px 5px;
    cursor: pointer;
    font-size: 0.65rem;
    transition: border-color 0.15s;
}

.cmd-damage-chip:hover {
    border-color: #bf6fff;
}

.cmd-damage-chip.warning {
    border-color: #ff9900;
    box-shadow: 0 0 6px #ff990066;
}

.cmd-damage-chip.lethal {
    border-color: #ff4444;
    box-shadow: 0 0 8px #ff444488;
    animation: pulse-turn 1s ease-in-out infinite;
}

.cmd-dmg-name {
    color: #9b4dca;
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cmd-dmg-val {
    font-weight: bold;
    color: #e0b0ff;
    min-width: 16px;
    text-align: right;
}

/* Opponent stats text truncation in grid */
.opponent-info .stats {
    font-size: 0.72rem;
    color: #4a8866;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.opponent-info .name {
    font-weight: bold;
    font-size: 0.88rem;
    color: #e0b0ff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Chat / Log Panel */
#chat-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 260px;
    height: 100vh;
    background: linear-gradient(180deg, #1a0a2e 0%, #0d1a15 100%);
    border-left: 2px solid #4a2c7a;
    display: flex;
    flex-direction: column;
    z-index: 4000;
    box-shadow: -4px 0 20px #00000088;
}

#chat-panel-header {
    display: flex;
    border-bottom: 1px solid #4a2c7a;
    padding: 0.25rem;
    gap: 0.25rem;
    flex-shrink: 0;
}

.chat-tab {
    flex: 1;
    padding: 0.35rem 0.5rem;
    font-size: 0.75rem;
    background: transparent;
    border: 1px solid #4a2c7a;
    color: #9b4dca;
}

.chat-tab.active {
    background: linear-gradient(180deg, #4a2c7a 0%, #2d1b4e 100%);
    color: #e0b0ff;
    border-color: #9b4dca;
}

#chat-close-btn {
    padding: 0.35rem 0.6rem;
    font-size: 0.75rem;
    background: transparent;
    border: 1px solid #4a2c7a;
    color: #9b4dca;
    flex-shrink: 0;
}

#chat-messages, #log-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.chat-message {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.3rem 0.5rem;
    border-radius: 3px;
    background: #0d0d1a;
    border: 1px solid #2d1b4e;
    word-break: break-word;
}

.chat-message.self {
    background: #1a0a2e;
    border-color: #4a2c7a;
}

.chat-name {
    font-size: 0.7rem;
    color: #9b4dca;
    font-weight: bold;
}

.chat-message.self .chat-name {
    color: #00ff88;
}

.chat-text {
    font-size: 0.8rem;
    color: #c0ffc0;
}

.log-entry {
    font-size: 0.72rem;
    color: #4a8866;
    padding: 0.2rem 0;
    border-bottom: 1px solid #1a1a2e;
}

#chat-input-row {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem;
    border-top: 1px solid #4a2c7a;
    flex-shrink: 0;
}

#chat-input {
    flex: 1;
    padding: 0.4rem;
    background: #0a0a12;
    border: 1px solid #2d6b4f;
    border-radius: 2px;
    color: #00ff88;
    font-family: "Courier New", Courier, monospace;
    font-size: 0.8rem;
}

#chat-input:focus {
    outline: none;
    border-color: #00ff88;
}

#chat-input-row button {
    padding: 0.4rem 0.6rem;
    font-size: 0.75rem;
}

/* Shift card preview when chat panel is open */
body.chat-open #card-preview {
    right: 280px;
}

/* Chat unread notification on toggle button */
#chat-toggle-btn.chat-unread {
    border-color: #00ff88;
    color: #00ff88;
    box-shadow: 0 0 10px #00ff8844;
}

/* Mobile portrait: collapse side strips to life-only */
@media (max-width: 600px) {
    #table-area.has-left,
    #table-area.has-right,
    #table-area.has-left.has-right {
        grid-template-columns: 40px 1fr 40px;
    }
    #table-area.has-left:not(.has-right) {
        grid-template-columns: 40px 1fr;
    }
    #table-area.has-right:not(.has-left) {
        grid-template-columns: 1fr 40px;
    }
    .opponent-info-compact {
        width: 36px;
        padding: 0.2rem;
    }
    .opponent-info-compact .opp-name,
    .opponent-info-compact .opp-stats,
    .opponent-info-compact .opp-counters,
    .opponent-info-compact .opponent-commander { display: none; }
    .opponent-info-compact .opp-life {
        font-size: 0.85rem;
        writing-mode: vertical-rl;
    }
}

/* Dice modal */
.dice-modal-content {
    min-width: 320px;
    max-width: 420px;
}
.dice-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin: 0.5rem 0;
}
.dice-buttons button {
    padding: 0.75rem 0.5rem;
    font-size: 1rem;
    letter-spacing: 1px;
}

/* Sticky notes */
.sticky-note {
    position: absolute;
    width: 170px;
    min-height: 90px;
    background: #fff8b0;
    color: #2a2200;
    border: 1px solid #c9b94a;
    box-shadow: 2px 3px 6px rgba(0,0,0,0.45);
    padding: 18px 6px 6px 6px;
    font-family: "Courier New", Courier, monospace;
    z-index: 50;
    border-radius: 2px;
}
.sticky-handle {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 14px;
    background: #e6d65a;
    border-bottom: 1px solid #c9b94a;
    cursor: grab;
}
.sticky-handle:active { cursor: grabbing; }
.sticky-close {
    position: absolute;
    top: -2px;
    right: 2px;
    width: 18px;
    height: 18px;
    line-height: 14px;
    padding: 0;
    background: transparent;
    color: #2a2200;
    border: none;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
}
.sticky-close:hover { color: #b00; }
.sticky-text {
    width: 100%;
    min-height: 70px;
    background: transparent;
    border: none;
    color: #2a2200;
    font-family: inherit;
    font-size: 0.85rem;
    resize: vertical;
    outline: none;
}
