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

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: #0a0a0f;
    color: #e8e0d0;
    min-height: 100vh;
}

/* ─── Home Page ─── */
.home-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 40px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 32px;
}

.title-block { text-align: center; }

.game-title {
    font-size: clamp(2rem, 8vw, 3rem);
    font-weight: 900;
    color: #f5a623;
    text-shadow: 0 0 20px #f5a62360, 0 2px 8px #000;
    letter-spacing: 2px;
    text-align: center;
}

.subtitle {
    color: #a09080;
    font-size: 1rem;
    margin-top: 8px;
}

.error-banner {
    background: #7f1d1d;
    border: 1px solid #ef4444;
    color: #fca5a5;
    padding: 12px 24px;
    border-radius: 8px;
    width: 100%;
    text-align: center;
}

.panels {
    display: flex;
    gap: 24px;
    align-items: flex-start;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
}

.panel {
    background: #1a1a2e;
    border: 1px solid #2a2a4a;
    border-radius: 12px;
    padding: 28px;
    flex: 1;
    min-width: 260px;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.panel h2 {
    font-size: 1.2rem;
    color: #f5a623;
    margin-bottom: 4px;
}

.panel label {
    font-size: 0.85rem;
    color: #a09080;
    margin-bottom: 2px;
}

.panel input {
    width: 100%;
    padding: 10px 12px;
    background: #0d0d1a;
    border: 1px solid #333355;
    border-radius: 6px;
    color: #e8e0d0;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.panel input:focus { border-color: #f5a623; }

.divider {
    color: #555;
    font-size: 0.9rem;
    align-self: center;
    padding-top: 32px;
}

/* ─── Toggle switch ─── */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0;
}

.toggle-label { color: #a09080; font-size: 0.85rem; }

.toggle-switch {
    position: relative;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
    position: absolute;
    inset: 0;
    background: #333355;
    border-radius: 22px;
    cursor: pointer;
    transition: background 0.2s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider { background: #f5a623; }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ─── Section blocks (room browser, leaderboard) ─── */
.section-block {
    width: 100%;
    background: #111122;
    border: 1px solid #2a2a4a;
    border-radius: 10px;
    padding: 20px 24px;
}

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

.section-title {
    color: #f5a623;
    font-size: 1.1rem;
}

.empty-msg {
    color: #a09080;
    font-style: italic;
    text-align: center;
    padding: 12px;
}

/* ─── Room Browser table ─── */
.room-browser {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.room-browser th {
    text-align: left;
    color: #a09080;
    font-weight: 600;
    padding: 6px 10px;
    border-bottom: 1px solid #2a2a4a;
}

.room-browser td {
    padding: 8px 10px;
    border-bottom: 1px solid #1a1a30;
    color: #e8e0d0;
}

.room-browser tr:hover td { background: #1a1a2e; }

.room-code-badge {
    font-family: monospace;
    font-size: 1rem;
    font-weight: 700;
    color: #f5a623;
    letter-spacing: 2px;
}

/* ─── Leaderboard table ─── */
.leaderboard {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.leaderboard th {
    text-align: left;
    color: #a09080;
    font-weight: 600;
    padding: 6px 10px;
    border-bottom: 1px solid #2a2a4a;
}

.leaderboard td {
    padding: 8px 10px;
    border-bottom: 1px solid #1a1a30;
    color: #e8e0d0;
}

.leaderboard tr:hover td { background: #1a1a2e; }

.lb-victory td { border-left: 3px solid #22c55e; }
.lb-defeat  td { border-left: 3px solid #ef4444; }

.lb-score {
    font-weight: 700;
    color: #f5a623;
    font-size: 1rem;
}

.player-name-tag {
    display: inline-block;
    background: #1a1a2e;
    border: 1px solid #333355;
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 0.8rem;
    margin: 1px;
}

/* ─── Badges ─── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
}

.badge-win  { background: #166534; color: #86efac; }
.badge-loss { background: #7f1d1d; color: #fca5a5; }
.badge-full { background: #3b1f00; color: #f59e0b; }

/* ─── Instructions ─── */
.instructions {
    background: #111122;
    border: 1px solid #2a2a4a;
    border-radius: 10px;
    padding: 20px 28px;
    width: 100%;
}

.instructions h3 { color: #f5a623; margin-bottom: 10px; }

.instructions ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.instructions li { color: #a09080; }

kbd {
    background: #2a2a4a;
    border: 1px solid #555;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 0.85rem;
    color: #e8e0d0;
}

/* ─── Buttons ─── */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    transition: all 0.15s;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none !important;
}

.btn-primary { background: #f5a623; color: #0a0a0f; }
.btn-primary:hover:not(:disabled) { background: #fbbf24; transform: translateY(-1px); }

.btn-secondary { background: #3498db; color: #fff; }
.btn-secondary:hover:not(:disabled) { background: #60a5fa; transform: translateY(-1px); }

.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #f87171; transform: translateY(-1px); }

.btn-large  { padding: 14px 40px; font-size: 1.1rem; border-radius: 8px; }
.btn-sm     { padding: 4px 10px; font-size: 0.8rem; }

/* ─── Lobby Page ─── */
.lobby-container {
    max-width: 520px;
    margin: 0 auto;
    padding: 40px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

.room-code-display {
    background: #1a1a2e;
    border: 2px solid #f5a623;
    border-radius: 10px;
    padding: 16px 32px;
    font-size: 1.2rem;
    text-align: center;
}

.room-code-display .code {
    font-size: 2rem;
    font-weight: 900;
    letter-spacing: 6px;
    color: #f5a623;
    font-family: monospace;
}

.share-hint { color: #a09080; font-size: 0.9rem; }

.player-list-section { width: 100%; }
.player-list-section h2 { color: #f5a623; margin-bottom: 12px; }

.player-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.player-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #1a1a2e;
    padding: 10px 16px;
    border-radius: 8px;
    border: 1px solid #2a2a4a;
}

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

.host-badge {
    margin-left: auto;
    background: #f5a623;
    color: #0a0a0f;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
}

.waiting-msg {
    color: #a09080;
    font-style: italic;
    text-align: center;
    padding: 20px;
}

.start-hint { color: #666; font-size: 0.85rem; }

/* ─── Game HUD ─── */
#game-ui {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

#hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 1100px;
    padding: 6px 20px;
    background: #111122;
    border-bottom: 1px solid #2a2a4a;
}

.hud-label { color: #a09080; font-size: 0.85rem; margin-right: 4px; }
.hud-value { color: #f5a623; font-weight: 700; font-size: 1rem; }
.hud-center { display: flex; align-items: center; }

.phase-badge {
    background: #7c3aed;
    color: #e8e0d0;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 10px;
    border-radius: 12px;
    margin-left: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#canvas-wrapper {
    position: relative;
    display: inline-block;
}

#game-canvas {
    display: block;
    background: #111;
    cursor: crosshair;
}

/* ─── Game Overlay ─── */
#overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    z-index: 50;
}

#overlay.hidden { display: none; }

#overlay-content {
    text-align: center;
    background: #1a1a2e;
    border: 2px solid #f5a623;
    border-radius: 14px;
    padding: 40px 56px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

#overlay-title { font-size: 2.2rem; color: #f5a623; }
#overlay-msg   { color: #a09080; font-size: 0.95rem; }

/* ─── Class Overlay ─── */
#class-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 60;
    overflow-y: auto;
}

#class-overlay.hidden { display: none; }

#class-panel {
    background: #12121f;
    border: 2px solid #7c3aed;
    border-radius: 16px;
    padding: 32px 36px;
    max-width: 680px;
    width: 95%;
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-height: 90vh;
    overflow-y: auto;
}

.class-ui-title {
    font-size: 1.5rem;
    color: #a78bfa;
    text-align: center;
}

.class-ui-subtitle {
    color: #a09080;
    font-size: 0.9rem;
    text-align: center;
}

.class-select-header { text-align: center; }

/* ─── Class cards ─── */
.class-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
}

.class-card {
    background: #1a1a2e;
    border: 2px solid #333355;
    border-radius: 10px;
    padding: 14px 10px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    transition: border-color 0.15s, transform 0.15s, background 0.15s;
}

.class-card:hover {
    border-color: var(--class-color, #f5a623);
    background: #1f1f38;
    transform: translateY(-2px);
}

.class-card.selected {
    border-color: var(--class-color, #f5a623);
    background: #22224a;
    box-shadow: 0 0 12px var(--class-color, #f5a62340);
}

.class-card-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 900;
    color: #0a0a0f;
    flex-shrink: 0;
}

.class-card-name {
    font-size: 0.85rem;
    font-weight: 700;
    color: #e8e0d0;
    text-align: center;
}

.class-card-desc {
    font-size: 0.72rem;
    color: #a09080;
    text-align: center;
    line-height: 1.4;
}

/* ─── Skill tree ─── */
.skill-tree-container {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.skill-row {
    background: #1a1a2e;
    border: 1px solid #2a2a4a;
    border-radius: 8px;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.skill-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    min-width: 140px;
}

.skill-name {
    font-weight: 700;
    color: #c4b5fd;
    font-size: 0.9rem;
}

.skill-desc {
    color: #a09080;
    font-size: 0.78rem;
    line-height: 1.4;
}

.skill-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.skill-rank-pips {
    display: flex;
    gap: 4px;
}

.skill-rank-pip {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #2a2a4a;
    border: 1px solid #444;
    transition: background 0.15s;
}

.skill-rank-pip.filled {
    background: #7c3aed;
    border-color: #a78bfa;
}

.skill-rank-text {
    font-size: 0.78rem;
    color: #888;
    min-width: 28px;
}

.skill-btn {
    padding: 5px 12px;
    font-size: 0.8rem;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.15s;
}

.skill-spend {
    background: #7c3aed;
    color: #e8e0d0;
}

.skill-spend:hover:not(:disabled) { background: #8b5cf6; }
.skill-spend:disabled { opacity: 0.4; cursor: not-allowed; }

/* ─── Points badge ─── */
.points-badge {
    background: #7c3aed;
    color: #e8e0d0;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 700;
}

/* ─── Class UI actions ─── */
.class-ui-actions {
    display: flex;
    justify-content: center;
}

/* ─── Ready status ─── */
.ready-status-section {
    border-top: 1px solid #2a2a4a;
    padding-top: 14px;
}

.ready-status-label {
    color: #a09080;
    font-size: 0.8rem;
    margin-bottom: 8px;
}

.ready-status-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ready-status-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    border-radius: 6px;
    background: #1a1a2e;
}

.ready-status-item.ready  { border-left: 3px solid #22c55e; }
.ready-status-item.waiting { border-left: 3px solid #f59e0b; }

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

.ready-name {
    font-size: 0.85rem;
    flex: 1;
}

.ready-badge {
    font-size: 0.75rem;
    font-weight: 600;
    color: #888;
}

.ready-status-item.ready .ready-badge  { color: #22c55e; }
.ready-status-item.waiting .ready-badge { color: #f59e0b; }

/* ─── Health bars ─── */
#health-bars {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
    padding: 8px 20px;
    max-width: 1100px;
    width: 100%;
}

.health-entry {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    padding: 3px 6px;
    border-radius: 5px;
    background: rgba(0,0,0,0.3);
}

.health-entry.downed-entry {
    opacity: 0.65;
    border: 1px solid #ef4444;
}

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

.health-bar-bg {
    width: 80px;
    height: 8px;
    background: #333;
    border-radius: 4px;
    overflow: hidden;
}

.health-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.12s;
}

#controls-hint {
    color: #555;
    font-size: 0.76rem;
    padding: 6px;
    letter-spacing: 0.4px;
}

/* ─── Toast ─── */
.game-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: #1a1a2e;
    border: 1px solid #f5a623;
    color: #f5a623;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 0.88rem;
    z-index: 999;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s, transform 0.25s;
}

.game-toast.toast-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ─── Downed visual cue in HUD ─── */
.downed-label {
    color: #ef4444;
    font-size: 0.7rem;
    font-weight: 700;
    margin-left: 4px;
    text-transform: uppercase;
}

/* ─── Mana bars (under health bars) ─── */
.bars-stack {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mana-bar-bg {
    width: 80px;
    height: 4px;
    background: #1a2030;
    border-radius: 3px;
    overflow: hidden;
}

.mana-bar-fill {
    height: 100%;
    border-radius: 3px;
    background: #3b82f6;
    transition: width 0.12s;
}

/* ─── Menu button + inventory panel ─── */
#menu-btn {
    margin-left: 14px;
    background: #2d2d44;
    color: #f5a623;
    border: 1px solid #f5a623;
    border-radius: 6px;
    font-size: 1.05rem;
    line-height: 1;
    padding: 4px 10px;
    cursor: pointer;
    transition: background 0.15s;
}
#menu-btn:hover { background: #3d3d5c; }

#inventory-panel {
    position: fixed;
    top: 48px;
    right: 12px;
    width: 280px;
    background: #12121f;
    border: 2px solid #f5a623;
    border-radius: 12px;
    z-index: 200;
    box-shadow: 0 8px 30px rgba(0,0,0,0.6);
    overflow: hidden;
}
#inventory-panel.hidden { display: none; }

.inv-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #1a1a2e;
    border-bottom: 1px solid #2a2a4a;
    font-weight: 700;
    color: #f5a623;
}

.inv-header button {
    background: none;
    border: none;
    color: #a09080;
    font-size: 1rem;
    cursor: pointer;
}
.inv-header button:hover { color: #fff; }

#inventory-body { padding: 12px 14px; }

.inv-stats {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.inv-stat {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: #a09080;
}

.inv-stat .gold { color: #fbbf24; }

.inv-bar-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    color: #a09080;
}
.inv-bar-row span { min-width: 34px; }
.inv-bar-row small { min-width: 46px; text-align: right; color: #888; }

.inv-bar {
    flex: 1;
    height: 7px;
    background: #1a2030;
    border-radius: 4px;
    overflow: hidden;
}
.inv-bar-fill { height: 100%; border-radius: 4px; }
.inv-bar-fill.hp { background: #22c55e; }
.inv-bar-fill.mana { background: #3b82f6; }

.inv-section-title {
    color: #f5a623;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-top: 1px solid #2a2a4a;
    padding-top: 10px;
    margin-bottom: 8px;
}

.inv-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
}

.inv-item-info { display: flex; flex-direction: column; }
.inv-item-name { color: #e8e0d0; font-size: 0.85rem; }
.inv-item-count { color: #888; font-size: 0.72rem; }
.inv-empty { color: #a09080; font-style: italic; font-size: 0.8rem; }

.inv-use { background: #22c55e; color: #04210f; }
.inv-use:hover:not(:disabled) { background: #34d97a; }

/* ─── NPC dialog overlay ─── */
#npc-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.82);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 70;
}
#npc-overlay.hidden { display: none; }

#npc-panel {
    background: #14110c;
    border: 2px solid #b9822f;
    border-radius: 16px;
    padding: 26px 30px;
    max-width: 460px;
    width: 92%;
    max-height: 88vh;
    overflow-y: auto;
}

.npc-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.npc-title { color: #fbbf24; font-size: 1.4rem; }

.npc-close {
    background: none;
    border: none;
    color: #a09080;
    font-size: 1.1rem;
    cursor: pointer;
}
.npc-close:hover { color: #fff; }

.npc-subtitle { color: #b6a489; font-size: 0.88rem; margin: 6px 0 4px; }
.npc-share { color: #a09080; font-size: 0.85rem; margin-bottom: 14px; }
.npc-share .gold { color: #fbbf24; }
.npc-dealer-text {
    color: #cbb98f;
    font-style: italic;
    line-height: 1.6;
    margin: 12px 0 18px;
}

.shop-list { display: flex; flex-direction: column; gap: 10px; }

.shop-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: #1d1810;
    border: 1px solid #3a2e1c;
    border-radius: 8px;
    padding: 10px 12px;
}

.shop-item-info { display: flex; flex-direction: column; gap: 2px; }
.shop-item-name { color: #f0e2c4; font-weight: 700; font-size: 0.9rem; }
.shop-item-desc { color: #a39072; font-size: 0.76rem; line-height: 1.4; }

.shop-item-effect {
    font-size: 0.66rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 6px;
    vertical-align: middle;
}
.shop-item-effect.heal { background: #14532d; color: #86efac; }
.shop-item-effect.mana { background: #1e3a8a; color: #93c5fd; }

.shop-buy { background: #fbbf24; color: #1a1206; min-width: 52px; }
.shop-buy:hover:not(:disabled) { background: #fcd34d; }

/* ─── Tavern banner ─── */
#tavern-banner {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 16px;
    background: rgba(20,17,12,0.94);
    border: 1px solid #b9822f;
    border-radius: 10px;
    padding: 8px 16px;
    z-index: 40;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
#tavern-banner.hidden { display: none; }

.tb-info { color: #e8d6b0; font-size: 0.82rem; }
.tb-info kbd { padding: 1px 5px; font-size: 0.75rem; }

.tb-ready { display: flex; align-items: center; gap: 5px; }
.tb-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    opacity: 0.4;
    border: 1px solid #000;
}
.tb-dot.ready { opacity: 1; box-shadow: 0 0 6px currentColor; }
.tb-count { color: #a09080; font-size: 0.76rem; margin-left: 4px; }

.tb-host-hint { color: #f59e0b; font-size: 0.72rem; margin-top: 3px; }

/* ─── Kick confirmation ─── */
.kick-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

/* ─── Mobile / touch controls ───────────────────────────────────────────────── */
#mobile-controls {
    position: absolute;
    inset: 0;
    z-index: 10;
    pointer-events: none;
}
#mobile-controls.hidden { display: none; }

#touch-layer {
    position: absolute;
    inset: 0;
    pointer-events: auto;
    touch-action: none;
}

/* Joysticks: anchored and always visible in the bottom corners while playing */
.joystick {
    position: absolute;
    bottom: max(26px, env(safe-area-inset-bottom));
    width: 116px;
    height: 116px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
    border: 2px solid rgba(255, 255, 255, 0.22);
    pointer-events: none;
    z-index: 11;
}
#joy-move { left: max(24px, env(safe-area-inset-left)); }
#joy-aim  { right: max(24px, env(safe-area-inset-right)); }
.joystick.hidden { display: none; }

.joy-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 54px;
    height: 54px;
    margin: -27px 0 0 -27px;
    border-radius: 50%;
    background: rgba(245, 166, 35, 0.6);
    border: 2px solid rgba(245, 166, 35, 0.9);
}
#joy-aim .joy-knob {
    background: rgba(239, 68, 68, 0.55);
    border-color: rgba(239, 68, 68, 0.9);
}

.joy-label {
    position: absolute;
    bottom: -16px;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: rgba(232, 224, 208, 0.55);
    pointer-events: none;
}

/* Contextual ability buttons */
#mobile-buttons {
    position: absolute;
    right: 16px;
    bottom: 168px;  /* clears the anchored aim joystick */
    display: flex;
    flex-direction: column;
    gap: 14px;
    pointer-events: none;
}

.mobile-btn {
    pointer-events: auto;
    touch-action: none;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    border: 2px solid rgba(245, 166, 35, 0.7);
    background: rgba(20, 18, 12, 0.72);
    color: #f5e3c0;
    font-size: 1.7rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
}
.mobile-btn.hidden { display: none; }
.mobile-btn.held { background: rgba(245, 166, 35, 0.4); transform: scale(0.94); }

/* Touch-device layout: fill the screen, overlay the HUD, hide clutter. */
.touch-device #game-ui {
    height: 100vh;
    height: 100dvh;
}
.touch-device #hud {
    flex-wrap: nowrap;
    padding: 5px 10px;
    gap: 4px;
}
.touch-device #hud .hud-label { font-size: 0.68rem; margin-right: 2px; }
.touch-device #hud .hud-value { font-size: 0.82rem; }
.touch-device #menu-btn { padding: 3px 9px; }

.touch-device #canvas-wrapper {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.touch-device #game-canvas { touch-action: none; }

/* Player health/mana bars become a compact, non-blocking overlay. */
.touch-device #health-bars {
    position: fixed;
    top: 40px;
    left: 4px;
    width: auto;
    max-width: 64vw;
    padding: 2px;
    gap: 3px;
    flex-direction: column;
    align-items: flex-start;
    pointer-events: none;
    z-index: 30;
}
.touch-device .health-entry {
    background: rgba(0, 0, 0, 0.45);
    font-size: 0.72rem;
    padding: 2px 5px;
}
.touch-device .health-bar-bg, .touch-device .mana-bar-bg { width: 56px; }

.touch-device #controls-hint { display: none; }

/* Keep the ?debug panel clear of the bottom-corner joysticks on phones. */
.touch-device #debug-panel {
    top: 78px !important;
    bottom: auto !important;
    right: 8px !important;
    left: auto !important;
}

/* Very small phones: drop the room code block to save HUD width. */
@media (max-width: 560px) {
    .touch-device #hud .hud-left { display: none; }
    .touch-device #tavern-banner {
        flex-direction: column;
        gap: 6px;
        padding: 6px 10px;
        max-width: 94vw;
    }
    .touch-device .tb-info { font-size: 0.74rem; }
}

/* ─── Responsive: home & lobby on phones/tablets ────────────────────────────── */
@media (max-width: 720px) {
    .home-container { padding: 22px 14px; gap: 22px; }
    .lobby-container { padding: 24px 14px; gap: 20px; }

    /* Stack the Create / Join panels full width */
    .panels { flex-direction: column; gap: 14px; }
    .panel { max-width: 100%; width: 100%; min-width: 0; }
    .panel form .btn { width: 100%; }
    .divider { padding-top: 0; }

    /* Forms: full-width, comfortable tap targets, 16px inputs (no iOS zoom) */
    .panel input { padding: 13px 14px; font-size: 16px; }
    .btn { padding: 13px 20px; }
    .btn-sm { padding: 9px 14px; font-size: 0.85rem; }
    .btn-large { width: 100%; padding: 16px; }

    /* Tables scroll horizontally instead of overflowing the screen */
    .section-block { padding: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .room-browser, .leaderboard { font-size: 0.8rem; }
    .room-browser th, .room-browser td,
    .leaderboard th, .leaderboard td { padding: 7px 8px; }

    .room-code-display { width: 100%; padding: 14px 16px; }
    .room-code-display .code { font-size: 1.5rem; letter-spacing: 4px; }
    .instructions { padding: 16px 18px; }
}

/* Tiny phones: trim the leaderboard to its most important columns */
@media (max-width: 520px) {
    .leaderboard th:nth-child(5), .leaderboard td:nth-child(5),  /* Gold */
    .leaderboard th:nth-child(6), .leaderboard td:nth-child(6) { /* Enemies */
        display: none;
    }
    .subtitle { font-size: 0.9rem; }
}

/* ─── Class UI hint ─── */
.class-ui-hint {
    color: #a09080;
    font-size: 0.78rem;
    text-align: center;
    font-style: italic;
}
