/* ─── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:         #1a1a2e;
    --surface:    #16213e;
    --surface2:   #0f3460;
    --accent:     #e94560;
    --text:       #eaeaea;
    --text-dim:   #8888aa;
    --border:     #2a2a4a;
    --slot-bg:    #0d0d1f;
    --radius:     6px;

    /* attribute colours */
    --fire:   #c0392b;
    --water:  #2980b9;
    --plant:  #27ae60;
    --light:  #f1c40f;
    --dark:   #8e44ad;
    --neutral:#555577;
}

html, body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    height: 100%;
}

a { color: var(--accent); text-decoration: none; }

/* ─── Header ────────────────────────────────────────────────────────── */
.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.logo { font-size: 1.3rem; font-weight: 700; color: var(--accent); letter-spacing: 1px; text-decoration: none; }
.logo:hover { color: #fff; }
.player-badge { background: var(--surface2); padding: 4px 12px; border-radius: 20px; font-size: 0.85rem; }

/* ─── Flash ─────────────────────────────────────────────────────────── */
.flash {
    margin: 12px 20px;
    padding: 10px 16px;
    background: #5a1a1a;
    border-left: 4px solid var(--accent);
    border-radius: var(--radius);
}

/* ─── Buttons ───────────────────────────────────────────────────────── */
.btn {
    display: inline-block;
    padding: 8px 18px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: opacity 0.15s, transform 0.1s;
}
.btn:hover { opacity: 0.85; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn-primary   { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-action    { background: #1e4d78; color: var(--text); }
.btn-join      { background: #1a6640; color: #fff; padding: 6px 14px; }

/* ─── Lobby ─────────────────────────────────────────────────────────── */
.lobby { max-width: 800px; margin: 30px auto; padding: 0 20px; }
.lobby h1 { margin-bottom: 24px; font-size: 1.8rem; }
.lobby h2 { margin-bottom: 14px; font-size: 1.1rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }

.lobby-actions {
    background: var(--surface);
    padding: 20px;
    border-radius: var(--radius);
    margin-bottom: 30px;
    border: 1px solid var(--border);
}

.host-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.host-form input[type="text"] {
    background: var(--slot-bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    width: 200px;
}
.mode-select { display: flex; gap: 16px; }
.mode-select label { display: flex; align-items: center; gap: 6px; cursor: pointer; }

.open-games {
    background: var(--surface);
    padding: 20px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.empty-msg { color: var(--text-dim); font-style: italic; }

.games-table { width: 100%; border-collapse: collapse; }
.games-table th, .games-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.games-table th { color: var(--text-dim); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }

.join-form { display: flex; gap: 8px; align-items: center; }
.join-form input[type="text"] {
    background: var(--slot-bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 10px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    width: 140px;
}

/* ─── Waiting ───────────────────────────────────────────────────────── */
.waiting { text-align: center; padding: 60px 20px; }
.waiting h1 { margin-bottom: 16px; }
.waiting p { color: var(--text-dim); margin-bottom: 24px; }
.waiting-status { margin-top: 16px; color: var(--text-dim); }

.spinner {
    width: 48px; height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Game Layout ───────────────────────────────────────────────────── */
#game-root {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 47px);
    overflow: hidden;
}

.player-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}
.my-bar { border-top: 1px solid var(--border); border-bottom: none; }

.player-name { font-weight: 700; font-size: 1rem; min-width: 80px; }
.life-display { color: #e74c3c; font-weight: 600; }
.mana-display { color: #3498db; font-weight: 600; }
.phase-display { color: var(--text-dim); font-size: 0.85rem; }
.hand-count { color: var(--text-dim); font-size: 0.85rem; }

/* ─── Board ─────────────────────────────────────────────────────────── */
.board {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
    gap: 6px;
    overflow: hidden;
    min-height: 0;
}

.board-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-height: 0;
}

.row-label {
    width: 36px;
    font-size: 0.72rem;
    color: var(--text-dim);
    text-transform: uppercase;
    writing-mode: vertical-lr;
    text-align: center;
    flex-shrink: 0;
}

.divider {
    height: 2px;
    background: var(--accent);
    margin: 2px 0;
    opacity: 0.3;
    flex-shrink: 0;
}

.slot {
    flex: 1;
    min-width: 0;
    height: 100%;
    background: var(--slot-bg);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: default;
    transition: border-color 0.15s, background 0.15s;
}
.slot.highlight {
    border-color: var(--accent);
    background: rgba(233,69,96,0.08);
    cursor: pointer;
}

/* ─── Cards ─────────────────────────────────────────────────────────── */
.card {
    position: absolute;
    inset: 2px;
    border-radius: var(--radius);
    padding: 4px 5px;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
    border: 2px solid transparent;
    font-size: 0.82rem;
    overflow: hidden;
    user-select: none;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.5); }
.card.selected { border-color: #fff; box-shadow: 0 0 0 3px var(--accent); }
.card.exhausted { opacity: 0.55; }
.card.face-down { background: var(--surface2) !important; }

/* Attribute colours */
.card.attr-fire    { background: linear-gradient(135deg, #3d0a0a, var(--fire)); }
.card.attr-water   { background: linear-gradient(135deg, #0a1a3d, var(--water)); }
.card.attr-plant   { background: linear-gradient(135deg, #0a2a14, var(--plant)); }
.card.attr-light   { background: linear-gradient(135deg, #2a2200, var(--light)); color: #1a1a00; }
.card.attr-dark    { background: linear-gradient(135deg, #1a0a2a, var(--dark)); }
.card.attr-neutral { background: linear-gradient(135deg, #1a1a2a, var(--neutral)); }

/* Card spell / equipment / trap overrides */
.card.type-spell     { border-top: 3px solid #9b59b6; }
.card.type-equipment { border-top: 3px solid #f39c12; }
.card.type-trap      { border-top: 3px solid #e67e22; }

.card-name {
    font-weight: 700;
    font-size: 0.84rem;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-art {
    width: 100%;
    height: 48px;
    background-size: cover;
    background-position: center;
    background-color: rgba(0,0,0,0.3);
    border-radius: 3px;
    margin: 2px 0;
    flex-shrink: 0;
}

.card-type-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    opacity: 0.75;
    white-space: nowrap;
    overflow: hidden;
}
.card-type-label.type-monster   { color: rgba(255,255,255,0.55); }
.card-type-label.type-spell     { color: #9b59b6; }
.card-type-label.type-equipment { color: #f39c12; }
.card-type-label.type-trap      { color: #e67e22; }
.card-type-label.type-fusion    { color: #3498db; }

.card-subtypes {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.45);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card-fusion-req {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 2px;
    margin-top: 2px;
    font-size: 0.62rem;
    line-height: 1;
}
.freq-attr {
    padding: 1px 4px;
    border-radius: 3px;
    background: rgba(0,0,0,0.4);
    font-weight: 600;
    text-transform: capitalize;
}
.freq-attr-fire    { color: var(--fire); }
.freq-attr-water   { color: var(--water); }
.freq-attr-plant   { color: var(--plant); }
.freq-attr-light   { color: var(--light); }
.freq-attr-dark    { color: var(--dark); }
.freq-attr-neutral { color: var(--neutral); }
.freq-name {
    padding: 1px 4px;
    border-radius: 3px;
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.85);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 56px;
}
.freq-plus {
    color: rgba(255,255,255,0.4);
    font-size: 0.6rem;
}

.card-effects {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    margin-top: 2px;
}
.effect-badge {
    font-size: 0.68rem;
    padding: 1px 3px;
    border-radius: 2px;
    background: rgba(0,0,0,0.4);
    white-space: nowrap;
}
.effect-poison  { color: #8bc34a; }
.effect-burn    { color: #ff5722; }
.effect-freeze  { color: #64b5f6; }
.effect-silence { color: #9e9e9e; }

.equipped-badge {
    font-size: 0.6rem;
    color: #f39c12;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Bottom bar holds stats (left) and cost (right) */
.card-bottom-bar {
    margin-top: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 3px;
}
.card-stats-inline {
    display: flex;
    gap: 4px;
    font-size: 0.9rem;
    font-weight: 700;
}
.card-atk { color: #e74c3c; }
.card-hp  { color: #2ecc71; }
.card-cost {
    background: rgba(0,0,0,0.55);
    border-radius: 3px;
    padding: 1px 5px;
    font-size: 0.82rem;
    font-weight: 700;
    color: #3498db;
    flex-shrink: 0;
}

/* ─── Card Hover Tooltip ─────────────────────────────────────────────── */
.card-tooltip-global {
    position: fixed;
    z-index: 500;
    min-width: 200px;
    max-width: 280px;
    background: #09091d;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 10px 12px;
    font-size: 0.78rem;
    pointer-events: none;
    box-shadow: 0 6px 24px rgba(0,0,0,0.85);
    line-height: 1.4;
}
.tip-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 4px;
}
.tip-name { font-weight: 700; font-size: 0.88rem; }
.tip-cost {
    background: rgba(52,152,219,0.25);
    color: #3498db;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.8rem;
    flex-shrink: 0;
}
.tip-meta {
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-bottom: 8px;
}
.tip-atk { color: #e74c3c; font-weight: 700; }
.tip-hp  { color: #2ecc71; font-weight: 700; }
.tip-fusion-req {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 3px;
    font-size: 0.72rem;
    margin-bottom: 8px;
    color: var(--text-dim);
}
.tip-fusion-req .freq-attr  { font-size: 0.72rem; padding: 1px 5px; }
.tip-fusion-req .freq-name  { font-size: 0.72rem; padding: 1px 5px; max-width: none; }
.tip-fusion-req .freq-plus  { font-size: 0.72rem; }
.tip-body { border-top: 1px solid var(--border); padding-top: 7px; }
.tip-line { margin-bottom: 4px; color: var(--text); }
.tip-line:last-child { margin-bottom: 0; }
.tip-empty { color: var(--text-dim); font-style: italic; }
.tip-tag {
    display: inline-block;
    font-size: 0.65rem;
    padding: 1px 4px;
    border-radius: 3px;
    background: rgba(255,255,255,0.1);
    color: var(--text-dim);
    vertical-align: middle;
    margin: 0 2px;
}

/* ─── Hand Zone ─────────────────────────────────────────────────────── */
.hand-zone {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    background: rgba(0,0,0,0.25);
    border-top: 1px solid var(--border);
    overflow-x: auto;
    flex-shrink: 0;
    min-height: 110px;
    align-items: flex-end;
}

.hand-card {
    width: 82px;
    height: 112px;
    flex-shrink: 0;
    border-radius: var(--radius);
    padding: 5px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    border: 2px solid transparent;
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.1s;
    font-size: 0.8rem;
    overflow: hidden;
    position: relative;
}
.hand-card:hover { transform: translateY(-6px); box-shadow: 0 8px 16px rgba(0,0,0,0.5); }
.hand-card.selected { border-color: #fff; transform: translateY(-10px); box-shadow: 0 0 0 3px var(--accent); }
.hand-card.unaffordable { opacity: 0.4; cursor: not-allowed; }

/* ─── Controls ──────────────────────────────────────────────────────── */
.controls {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.selection-hint {
    padding: 4px 12px;
    font-size: 0.8rem;
    color: var(--accent);
    background: var(--surface);
    border-top: 1px solid var(--border);
    min-height: 24px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.hint-skills {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.skill-btn {
    font-size: 0.75rem;
    padding: 2px 8px;
    background: #1e3a5a;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--text);
    line-height: 1.6;
}

.skill-btn:hover:not(:disabled) { background: var(--accent); }

.skill-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    border-color: var(--border);
}

.skill-cost {
    background: var(--surface2);
    padding: 0 4px;
    border-radius: 3px;
    font-size: 0.7rem;
    margin-left: 4px;
}

/* ─── Action Log ────────────────────────────────────────────────────── */
.action-log {
    position: fixed;
    bottom: 160px;
    right: 12px;
    width: 260px;
    max-height: 160px;
    overflow-y: auto;
    background: rgba(0,0,0,0.7);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    font-size: 0.75rem;
    z-index: 50;
}
.log-entry { padding: 2px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
.log-entry.error { color: var(--accent); }

/* ─── Commander Zone ─────────────────────────────────────────────────── */
.commander-zone { font-size: 0.78rem; }
.commander-badge {
    display: inline-flex;
    flex-direction: column;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px 8px;
    cursor: pointer;
    gap: 2px;
}
.commander-badge:hover { border-color: var(--accent); }
.commander-badge.used { opacity: 0.5; cursor: default; }
.commander-name { font-weight: 700; }
.commander-active-label { font-size: 0.68rem; color: #3498db; }

/* ─── Modals ─────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 480px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}
.modal h3 { margin-bottom: 16px; }
.modal p { color: var(--text-dim); margin-bottom: 12px; }

.fuse-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}
.fuse-option .btn { flex-shrink: 0; }

#discardList { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.discard-pick {
    width: 72px;
    height: 100px;
    border-radius: var(--radius);
    padding: 5px;
    cursor: pointer;
    border: 2px solid transparent;
    font-size: 0.7rem;
    overflow: hidden;
    position: relative;
}
.discard-pick.chosen { border-color: var(--accent); }

/* ─── Mulligan Banner ────────────────────────────────────────────────── */
.mulligan-banner {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 12px 20px;
    z-index: 80;
    text-align: center;
    max-width: 500px;
    width: 90%;
}
.mulligan-banner h3 { margin-bottom: 8px; color: var(--accent); }
.mulligan-banner p  { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 12px; }

/* ─── Turn indicator ─────────────────────────────────────────────────── */
.your-turn-badge {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ─── Crystals ───────────────────────────────────────────────────────── */
.crystals {
    display: flex;
    gap: 5px;
    align-items: center;
    flex-shrink: 0;
}
.crystal {
    width: 16px;
    height: 16px;
    background: #f1c40f;
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
    filter: drop-shadow(0 0 5px rgba(241, 196, 15, 0.85));
    flex-shrink: 0;
    transition: background 0.3s, filter 0.3s, opacity 0.3s;
}
.crystal.broken {
    background: #2a2a3a;
    filter: none;
    opacity: 0.35;
}

/* ─── Deck / Zone counters ───────────────────────────────────────────── */
.deck-count {
    font-size: 0.78rem;
    color: var(--text-dim);
    white-space: nowrap;
    flex-shrink: 0;
}

.zone-btn {
    font-size: 0.75rem;
    padding: 2px 7px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-dim);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: border-color 0.15s, color 0.15s;
}
.zone-btn:hover { border-color: var(--accent); color: var(--text); }

/* ─── Zone viewer modal ──────────────────────────────────────────────── */
.zone-modal {
    max-width: 860px;
    width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 12px;
}

.zone-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
.zone-modal-header h3 { margin: 0; font-size: 1rem; }

.zone-card-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    overflow-y: auto;
    padding: 4px 2px;
}

.zone-card {
    width: 82px;
    height: 112px;
    flex-shrink: 0;
    border-radius: var(--radius);
    padding: 5px;
    display: flex;
    flex-direction: column;
    font-size: 0.8rem;
    overflow: hidden;
    position: relative;
    border: 2px solid transparent;
    cursor: default;
    opacity: 0.85;
}
.zone-card:hover { opacity: 1; }

.zone-empty {
    color: var(--text-dim);
    font-size: 0.85rem;
    padding: 12px;
    margin: 0;
}

/* ─── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .row-label  { display: none; }
}
