:root {
    --font-sans: "Avenir Next", "Avenir", "Trebuchet MS", "Candara", sans-serif;
    --font-display: "Bodoni MT", "Didot", "Georgia", serif;
    --bg-1: #f6f1e8;
    --bg-2: #e1ead6;
    --bg-3: #f2dcc6;
    --ink: #1f2a22;
    --ink-muted: #5a6a5f;
    --accent: #D4AF37;
    --accent-strong: #B8962E;
    --accent-cool: #3d9ca5;
    --accent-cool-strong: #2f7d86;
    --accent-forest: #4c8b5e;
    --accent-amber: #E5C76B;
    --surface: rgba(255, 255, 255, 0.88);
    --surface-strong: rgba(255, 255, 255, 0.97);
    --surface-muted: rgba(255, 255, 255, 0.72);
    --surface-dark: #12161b;
    --border: rgba(31, 42, 36, 0.2);
    --border-strong: rgba(31, 42, 36, 0.35);
    --shadow: 0 16px 40px rgba(16, 20, 18, 0.18);
    --radius-lg: 18px;
    --radius-md: 12px;
    --radius-sm: 9px;
    --joystick-size: 130px;
    --joystick-thumb-size: 56px;
    --action-size: 88px;
    --ability-size: 76px;
    --icon-size: 24px;
    --hud-bg: rgba(10, 14, 18, 0.45);
    --hud-border: rgba(255, 255, 255, 0.12);
    --icon-scout: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20d%3D%22M13%202L3%2014h7l-2%208%2012-14h-7l2-6z%22%2F%3E%3C%2Fsvg%3E");
    --icon-ghost: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20d%3D%22M12%203c-3.3%200-6%202.7-6%206v10l2-1%202%201%202-1%202%201%202-1%202%201V9c0-3.3-2.7-6-6-6z%22%2F%3E%3C%2Fsvg%3E");
    --icon-bird: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20d%3D%22M3%2014c5-5%2010-7%2018-7-2%202-3%205-3%208-4-3-8-3-12%200-1%201-2%201-3%200z%22%2F%3E%3C%2Fsvg%3E");
    --icon-mimic: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20d%3D%22M12%203c-3.6%200-6.5%202.5-6.5%205.6%200%202.2%201.4%204.1%203.5%205L8.5%2021h7l-.5-7.4c2.1-.9%203.5-2.8%203.5-5C18.5%205.5%2015.6%203%2012%203z%22%2F%3E%3C%2Fsvg%3E");
    --icon-house: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20d%3D%22M4%2011l8-6%208%206v9h-5v-5H9v5H4z%22%2F%3E%3C%2Fsvg%3E");
    --icon-rescue: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20d%3D%22M11%204h2v6h6v2h-6v6h-2v-6H5v-2h6z%22%2F%3E%3C%2Fsvg%3E");
    --icon-food: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20d%3D%22M12%207c-3.2%200-5.5%202.5-5.5%205.7%200%203.8%202.4%207.3%205.5%207.3s5.5-3.5%205.5-7.3C17.5%209.5%2015.2%207%2012%207z%22%2F%3E%3Cpath%20d%3D%22M12%206c1.3-2%203-3%205-3-1.1%202-2.8%203.2-5%203z%22%2F%3E%3C%2Fsvg%3E");
    --icon-ability: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20d%3D%22M12%202l2.7%205.7%206.3.9-4.5%204.3%201.1%206.4L12%2016.8%206.4%2019.3%207.5%2013%203%208.6l6.3-.9L12%202z%22%2F%3E%3C%2Fsvg%3E");
    --icon-quake: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20d%3D%22M2%2015l4-3%204%203%204-3%204%203%204-3v6H2z%22%2F%3E%3C%2Fsvg%3E");
    --icon-down: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20d%3D%22M7%205l5%205%205-5%202%202-5%205%205%205-2%202-5-5-5%205-2-2%205-5-5-5z%22%2F%3E%3C%2Fsvg%3E");
    --icon-capture: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20d%3D%22M5%204v4H3V3h5v2H5zm14%200h-3V2h5v5h-2V4zM5%2020v-3H3v5h5v-2H5zm14%200h-3v2h5v-5h-2v3zM12%207a5%205%200%20110%2010%205%205%200%20010-10z%22%2F%3E%3C%2Fsvg%3E");
    --icon-knockout: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20d%3D%22M12%202L9%208l-6%201%204%204-1%206%206-3%206%203-1-6%204-4-6-1-3-6zm0%207a3%203%200%20110%206%203%203%200%20010-6z%22%2F%3E%3C%2Fsvg%3E");
    --icon-hammer: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20d%3D%22M2%2019l4%203%208-8-4-4-8%209zm18-12l-6%206-2-2%206-6c1-1%203%200%203%201l-1%201z%22%2F%3E%3C%2Fsvg%3E");
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

html, body {
    height: 100%;
}

body {
    font-family: var(--font-sans);
    background: linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 55%, var(--bg-3) 100%);
    color: var(--ink);
    display: flex;
    justify-content: center;
    align-items: stretch;
    overflow: hidden;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle at 15% 20%, rgba(255, 255, 255, 0.65), transparent 45%),
        radial-gradient(circle at 85% 12%, rgba(255, 255, 255, 0.4), transparent 50%),
        radial-gradient(circle at 70% 80%, rgba(255, 255, 255, 0.35), transparent 50%),
        repeating-linear-gradient(0deg, rgba(31, 42, 36, 0.04) 0 1px, transparent 1px 4px);
    pointer-events: none;
    opacity: 0.85;
}

button, input {
    font-family: inherit;
}

input {
    user-select: text;
    -webkit-user-select: text;
}

.hidden {
    display: none !important;
}

.icon {
    --icon-mask: var(--icon-ability);
    width: var(--icon-size);
    height: var(--icon-size);
    display: inline-block;
    background-color: currentColor;
    mask-image: var(--icon-mask);
    mask-repeat: no-repeat;
    mask-position: center;
    mask-size: contain;
    -webkit-mask-image: var(--icon-mask);
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-position: center;
    -webkit-mask-size: contain;
}

.icon-scout { --icon-mask: var(--icon-scout); }
.icon-ghost { --icon-mask: var(--icon-ghost); }
.icon-bird { --icon-mask: var(--icon-bird); }
.icon-mimic { --icon-mask: var(--icon-mimic); }
.icon-hammer { --icon-mask: var(--icon-hammer); }
.icon-house { --icon-mask: var(--icon-house); }
.icon-rescue { --icon-mask: var(--icon-rescue); }
.icon-food { --icon-mask: var(--icon-food); }
.icon-ability { --icon-mask: var(--icon-ability); }
.icon-quake { --icon-mask: var(--icon-quake); }
.icon-down { --icon-mask: var(--icon-down); }
.icon-capture { --icon-mask: var(--icon-capture); }
.icon-knockout { --icon-mask: var(--icon-knockout); }

.screen {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height - accounts for mobile browser chrome */
    padding: calc(20px + env(safe-area-inset-top)) calc(18px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(18px + env(safe-area-inset-left));
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: left;
    animation: screen-in 420ms ease both;
}

#controller-screen {
    align-items: flex-start;
}

.screen-shell {
    width: min(100%, 460px);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

h1 {
    font-family: var(--font-display);
    font-size: 2.3rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink);
}

#class-select-screen h1 {
    font-size: 1.7rem;
}

.subtitle {
    color: var(--ink-muted);
    font-size: 0.95rem;
    margin-top: 6px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-mark {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.9), rgba(236, 220, 197, 0.8) 40%, rgba(214, 196, 165, 0.9) 100%);
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow);
    position: relative;
}

.brand-mark::after {
    content: "";
    position: absolute;
    inset: 10px;
    border-radius: 10px;
    border: 2px solid rgba(31, 42, 36, 0.25);
}

.panel {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 20px;
    animation: card-rise 420ms ease both;
}

.panel-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--ink-muted);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.form-group input {
    width: 100%;
    padding: 14px;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.9);
    color: var(--ink);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    border-color: var(--accent-strong);
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.2);
}

.input-hint {
    display: block;
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--ink-muted);
    opacity: 0.7;
}

.primary-btn {
    width: 100%;
    padding: 16px;
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.2s ease;
    box-shadow: 0 10px 25px rgba(184, 150, 46, 0.3);
}

.primary-btn:active {
    transform: translateY(1px) scale(0.98);
}

/* Connection mode toggle */
.mode-toggle {
    display: flex;
    gap: 8px;
}

.mode-btn {
    flex: 1;
    padding: 10px 16px;
    font-size: 0.9rem;
    font-weight: 600;
    background: var(--surface-muted);
    color: var(--ink-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
}

.mode-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.mode-btn:hover:not(.active) {
    background: var(--surface);
    border-color: var(--border-strong);
}

/* Quick Join Section */
.quick-join-section {
    margin-bottom: 4px;
}

.quick-join-btn {
    width: 100%;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    box-shadow: 0 10px 25px rgba(184, 150, 46, 0.3);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.quick-join-btn:active {
    transform: translateY(1px) scale(0.98);
    box-shadow: 0 5px 15px rgba(184, 150, 46, 0.2);
}

.quick-join-label {
    font-size: 1.1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.quick-join-details {
    font-size: 0.85rem;
    opacity: 0.9;
    font-weight: 400;
}

.quick-join-divider {
    display: flex;
    align-items: center;
    margin-top: 16px;
    gap: 12px;
}

.quick-join-divider::before,
.quick-join-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--text-muted);
    opacity: 0.3;
}

.quick-join-divider span {
    font-size: 0.75rem;
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.secondary-btn {
    padding: 12px 24px;
    font-size: 0.95rem;
    font-weight: 600;
    background: transparent;
    color: var(--ink-muted);
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    align-self: center;
}

.status {
    padding: 10px 12px;
    border-radius: 999px;
    font-size: 0.85rem;
    color: var(--ink-muted);
    background: var(--surface-muted);
    border: 1px solid rgba(31, 42, 36, 0.12);
    text-align: center;
}

.status.error {
    color: #b64a3d;
    border-color: rgba(182, 74, 61, 0.4);
}

.status.success {
    color: #3d7d53;
    border-color: rgba(61, 125, 83, 0.4);
}

#class-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.class-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 14px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 8px 20px rgba(16, 20, 18, 0.12);
    animation: card-rise 420ms ease both;
}

.class-btn:nth-child(1) { animation-delay: 0.05s; }
.class-btn:nth-child(2) { animation-delay: 0.1s; }
.class-btn:nth-child(3) { animation-delay: 0.15s; }
.class-btn:nth-child(4) { animation-delay: 0.2s; }

.class-btn.selected,
.class-btn:active {
    border-color: var(--accent-strong);
    transform: translateY(1px) scale(0.98);
    box-shadow: 0 10px 20px rgba(184, 150, 46, 0.2);
}

.class-btn[data-class="scout"] { --class-accent: #e07a5f; }
.class-btn[data-class="ghost"] { --class-accent: #6b7786; }
.class-btn[data-class="bird"] { --class-accent: #3d9ca5; }
.class-btn[data-class="mimic"] { --class-accent: #4c8b5e; }
.class-btn[data-class="builder"] { --class-accent: #c4a77d; }

.class-icon {
    --icon-size: 30px;
    color: var(--class-accent);
    margin-bottom: 8px;
}

.class-name {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.class-ability {
    font-size: 0.85rem;
    color: var(--class-accent);
    margin-bottom: 4px;
    font-weight: 600;
}

.class-desc {
    font-size: 0.75rem;
    color: var(--ink-muted);
}

#player-info {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    gap: 4px 8px;
    padding: 14px 16px;
    background: var(--surface-strong);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    align-items: center;
}

/* Inline class icon next to player name */
#player-class-icon {
    grid-column: 1;
    grid-row: 1;
    --icon-size: 14px;
    color: var(--accent);
    flex-shrink: 0;
}

#player-class-icon.hidden {
    display: none;
}

#player-name-display {
    grid-column: 2;
    grid-row: 1;
    font-size: 1.1rem;
    font-weight: 700;
}

#connection-status {
    grid-column: 3;
    grid-row: 1;
    font-size: 0.75rem;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(31, 42, 36, 0.08);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

#player-info #status-effects-bar {
    grid-column: 1 / -1;
    grid-row: 2;
    padding-top: 8px;
}

#connection-status.connected {
    color: #2f7d53;
    background: rgba(61, 125, 83, 0.18);
}

#connection-status.disconnected {
    color: #b64a3d;
    background: rgba(182, 74, 61, 0.18);
}

.status-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
}

/* Standalone class badge is hidden - now integrated into player info */
#class-badge {
    display: none !important;
}

#class-badge-icon {
    --icon-size: 18px;
    color: var(--accent);
}

#class-badge-name {
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

#ability-state {
    padding: 6px 16px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    animation: state-pulse 0.8s ease-in-out infinite;
}

#ability-state.scout-active {
    background: rgba(224, 122, 95, 0.2);
    color: #c65542;
    border: 1px solid rgba(217, 100, 76, 0.4);
}

#ability-state.ghost-active {
    background: rgba(107, 119, 134, 0.2);
    color: #5c6774;
    border: 1px solid rgba(107, 119, 134, 0.4);
}

#ability-state.bird-active {
    background: rgba(61, 156, 165, 0.2);
    color: #2f7d86;
    border: 1px solid rgba(61, 156, 165, 0.4);
}

#ability-state.mimic-active {
    background: rgba(76, 139, 94, 0.2);
    color: #3d7d53;
    border: 1px solid rgba(76, 139, 94, 0.4);
}

#ability-state.builder-active {
    background: rgba(196, 167, 125, 0.2);
    color: #9d8563;
    border: 1px solid rgba(196, 167, 125, 0.4);
}

@keyframes state-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.9; transform: scale(1.02); }
}

#game-view-container {
    display: flex;
    justify-content: center;
}

#game-view {
    position: relative;
    width: min(100%, 320px);
    border-radius: var(--radius-lg);
    background: var(--surface-dark);
    border: 1px solid rgba(255, 255, 255, 0.08);
    overflow: hidden;
    box-shadow: 0 18px 40px rgba(12, 15, 18, 0.45);
}

#game-canvas {
    display: block;
    width: 100%;
    height: auto;
    background: #0b1016;
}

.mini-map-container {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 92px;
    aspect-ratio: 1;
    background: rgba(10, 14, 18, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    overflow: hidden;
}

#mini-map {
    width: 100%;
    height: 100%;
    display: block;
    background: #0b1016;
}

#match-hud {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex;
    gap: 8px;
    font-size: 0.75rem;
    color: #fff;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--hud-bg);
    border: 1px solid var(--hud-border);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

#time-cycle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
}

#time-cycle::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ffd27a;
    box-shadow: 0 0 6px rgba(255, 210, 122, 0.7);
}

#time-cycle.day {
    color: #ffe1a3;
}

#time-cycle.night {
    color: #b8c7ff;
}

#time-cycle.night::before {
    background: #8fa7ff;
    box-shadow: 0 0 6px rgba(143, 167, 255, 0.8);
}

#match-timer {
    font-weight: 700;
}

#match-timer.warning {
    color: #ff7b63;
    animation: timer-pulse 0.5s ease-in-out infinite;
}

#match-timer.urgency {
    color: #ff4444;
    font-size: 1.1em;
    text-shadow: 0 0 8px rgba(255, 68, 68, 0.8);
    animation: urgency-pulse 0.3s ease-in-out infinite;
}

@keyframes timer-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes urgency-pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(1.05);
    }
}

#villager-count {
    color: #7bd19a;
}

#player-hp-display {
    color: #7bd19a;
    font-weight: 700;
    transition: color 0.3s;
}

#player-hp-display.low {
    color: #ff7b63;
    animation: hp-pulse 0.5s ease-in-out infinite;
}

#player-hp-display.medium {
    color: #f2a65a;
}

@keyframes hp-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.ready-btn {
    width: min(100%, 320px);
    align-self: center;
    margin-top: 4px;
}

.ready-active {
    opacity: 0.7;
    pointer-events: none;
}

#status-effects-bar {
    display: none;
    justify-content: flex-start;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    flex-wrap: wrap;
    width: calc(100% - 32px);
    margin: 8px 16px 12px;
}

#status-effects-bar.visible {
    display: flex;
}

.status-effect {
    position: relative;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--surface-strong);
    border: 1px solid var(--border);
    box-shadow: 0 8px 16px rgba(16, 20, 18, 0.15);
}

.status-effect-icon {
    --icon-size: 20px;
    color: var(--ink);
}

.status-effect.buff {
    border-color: rgba(61, 125, 83, 0.5);
}

.status-effect.debuff {
    border-color: rgba(182, 74, 61, 0.5);
    animation: debuff-pulse 0.8s ease-in-out infinite;
}

@keyframes debuff-pulse {
    0%, 100% { box-shadow: 0 0 0 rgba(182, 74, 61, 0.3); }
    50% { box-shadow: 0 0 16px rgba(182, 74, 61, 0.4); }
}

.status-effect::before {
    content: "";
    position: absolute;
    inset: -4px;
    border-radius: 12px;
    background: conic-gradient(
        from 0deg,
        rgba(31, 42, 36, 0.2) var(--progress, 0%),
        transparent var(--progress, 0%)
    );
    z-index: -1;
    pointer-events: none;
}

.status-effect-timer {
    position: absolute;
    bottom: -6px;
    right: -6px;
    font-size: 0.55rem;
    font-weight: 700;
    background: rgba(31, 42, 36, 0.9);
    color: #fff;
    padding: 2px 5px;
    border-radius: 6px;
    z-index: 2;
    min-width: 24px;
    text-align: center;
}

/* Status tooltip (shown on tap) */
#status-tooltip {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(31, 42, 36, 0.95);
    color: #f2f6fb;
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 0.85rem;
    line-height: 1.4;
    text-align: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    max-width: 200px;
}

#status-tooltip.visible {
    opacity: 1;
}

#status-tooltip strong {
    color: #d4a574;
    display: block;
    margin-bottom: 4px;
}

/* === DISTRESSED TEAMMATES ALERT === */
#distressed-teammates {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 16px;
    pointer-events: none;
    z-index: 50;
}

#distressed-teammates:empty {
    display: none;
}

.distressed-entry {
    background: rgba(255, 50, 50, 0.85);
    color: white;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    animation: distress-pulse 0.5s ease-in-out infinite alternate;
    box-shadow: 0 2px 8px rgba(255, 50, 50, 0.4);
}

@keyframes distress-pulse {
    from { opacity: 0.8; transform: scale(1); }
    to { opacity: 1.0; transform: scale(1.02); }
}

#controls-container {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 16px;
    align-items: center;
    padding: 6px 0 0;
}

/* === VIRTUAL JOYSTICK === */
#joystick-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

#joystick-base {
    width: var(--joystick-size);
    height: var(--joystick-size);
    border-radius: 50%;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.15), rgba(0, 0, 0, 0.08));
    border: 3px solid rgba(255, 255, 255, 0.25);
    box-shadow:
        inset 0 4px 12px rgba(0, 0, 0, 0.25),
        0 4px 16px rgba(0, 0, 0, 0.15);
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: none;
}

/* Subtle direction indicators on base */
#joystick-base::before {
    content: "";
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background:
        radial-gradient(circle at 50% 15%, rgba(255,255,255,0.15) 0%, transparent 20%),
        radial-gradient(circle at 50% 85%, rgba(255,255,255,0.15) 0%, transparent 20%),
        radial-gradient(circle at 15% 50%, rgba(255,255,255,0.15) 0%, transparent 20%),
        radial-gradient(circle at 85% 50%, rgba(255,255,255,0.15) 0%, transparent 20%);
    pointer-events: none;
}

#joystick-thumb {
    width: var(--joystick-thumb-size);
    height: var(--joystick-thumb-size);
    border-radius: 50%;
    background: linear-gradient(145deg, #fdfbf7, #e2dacd);
    border: 2px solid rgba(31, 42, 36, 0.25);
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.3),
        inset 0 2px 4px rgba(255, 255, 255, 0.5);
    position: absolute;
    transition: transform 0.05s ease-out;
    will-change: transform;
}

#joystick-thumb.active {
    background: linear-gradient(145deg, var(--accent), var(--accent-strong));
    border-color: rgba(184, 150, 46, 0.5);
    box-shadow:
        0 4px 16px rgba(212, 175, 55, 0.4),
        inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

#joystick-direction-hint {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-muted);
    min-height: 16px;
    opacity: 0.7;
}

#joystick-direction-hint.active {
    color: var(--accent);
    opacity: 1;
}

/* Joystick locked state (when hiding in building/bush) */
#joystick-base.locked {
    opacity: 0.4;
    filter: grayscale(0.5);
    pointer-events: none;
}

#joystick-base.locked #joystick-thumb {
    background: linear-gradient(145deg, #aaa, #888);
}

#buttons-container {
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: center;
}

#action-container,
#ability-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.action-btn {
    width: var(--action-size);
    height: var(--action-size);
    background: linear-gradient(145deg, #fdfbf7, #e2dacd);
    border: 2px solid rgba(31, 42, 36, 0.2);
    border-radius: 24px;
    color: var(--ink);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 6px;
    transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease;
    box-shadow: 0 10px 22px rgba(16, 20, 18, 0.18);
}

.action-btn:disabled {
    background: linear-gradient(145deg, #f0ede6, #d8d1c3);
    color: #9a9488;
    border-color: rgba(31, 42, 36, 0.12);
    cursor: default;
    box-shadow: none;
}

.action-btn:not(:disabled):active {
    transform: translateY(1px) scale(0.97);
}

.action-btn.hiding {
    background: linear-gradient(145deg, #E8D48A, #D4AF37);
    border-color: rgba(184, 150, 46, 0.6);
    color: #fff;
}

.action-btn.rescue {
    background: linear-gradient(145deg, #E8D48A, #D4AF37);
    border-color: rgba(212, 175, 55, 0.7);
    color: #4a351c;
    animation: rescue-pulse 1s ease-in-out infinite;
}

.action-btn.eat {
    background: linear-gradient(145deg, #7acb90, #4c8b5e);
    border-color: rgba(76, 139, 94, 0.6);
    color: #0f2417;
    animation: eat-pulse 1.2s ease-in-out infinite;
}

.action-btn.repair {
    background: linear-gradient(145deg, #c4a77d, #8b6e4e);
    border-color: rgba(139, 110, 78, 0.7);
    color: #2a1f14;
    animation: repair-pulse 1s ease-in-out infinite;
}

@keyframes repair-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.03); }
}

@keyframes eat-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.03); }
}

@keyframes rescue-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.action-icon {
    --icon-size: 28px;
}

.action-text {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

#action-hint {
    font-size: 0.7rem;
    color: var(--ink-muted);
    text-align: center;
    max-width: 120px;
}

.ability-btn {
    width: var(--ability-size);
    height: var(--ability-size);
    background: linear-gradient(145deg, #e7f4f6, #cfe7ea);
    border: 2px solid rgba(61, 156, 165, 0.5);
    border-radius: 22px;
    color: var(--ink);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 6px;
    transition: transform 0.12s ease, box-shadow 0.2s ease;
    box-shadow: 0 10px 20px rgba(16, 20, 18, 0.18);
    position: relative;
}

.ability-btn:disabled {
    background: linear-gradient(145deg, #eae7e2, #d6d1c6);
    border-color: rgba(31, 42, 36, 0.15);
    color: #9a9488;
    cursor: default;
    box-shadow: none;
}

.ability-btn:not(:disabled):active {
    transform: translateY(1px) scale(0.97);
}

.ability-btn.active {
    animation: ability-active-pulse 0.5s ease-in-out infinite;
}

.ability-btn.ready {
    animation: ability-ready-glow 1.5s ease-in-out infinite;
}

@keyframes ability-active-pulse {
    0%, 100% { box-shadow: 0 0 10px rgba(61, 156, 165, 0.4); }
    50% { box-shadow: 0 0 20px rgba(61, 156, 165, 0.8); }
}

@keyframes ability-ready-glow {
    0%, 100% { box-shadow: 0 0 10px rgba(61, 156, 165, 0.3); }
    50% { box-shadow: 0 0 22px rgba(61, 156, 165, 0.6); }
}

.ability-icon {
    --icon-size: 26px;
}

.ability-cooldown {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.ability-cooldown.large {
    font-size: 0.95rem;
}

#ability-name {
    font-size: 0.7rem;
    color: var(--ink-muted);
    text-align: center;
    max-width: 90px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.ability-btn.scout {
    background: linear-gradient(145deg, #f4b19e, #e07a5f);
    border-color: rgba(217, 100, 76, 0.6);
}

.ability-btn.ghost {
    background: linear-gradient(145deg, #c3c8d0, #9da7b3);
    border-color: rgba(107, 119, 134, 0.6);
}

.ability-btn.bird {
    background: linear-gradient(145deg, #b7e3e6, #78c9cf);
    border-color: rgba(61, 156, 165, 0.6);
}

.ability-btn.mimic {
    background: linear-gradient(145deg, #bfe3ca, #7acb90);
    border-color: rgba(76, 139, 94, 0.6);
}

.ability-btn.builder {
    background: linear-gradient(145deg, #e0d4be, #c4a77d);
    border-color: rgba(196, 167, 125, 0.6);
}

.ability-btn.on-cooldown {
    position: relative;
    overflow: hidden;
}

.ability-btn.on-cooldown::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    border-radius: 22px;
    pointer-events: none;
    z-index: 1;
}

.ability-btn.on-cooldown::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 22px;
    background: conic-gradient(
        from 0deg,
        transparent var(--cooldown-progress, 0%),
        rgba(31, 42, 36, 0.55) var(--cooldown-progress, 0%)
    );
    z-index: 2;
    pointer-events: none;
}

.ability-btn.on-cooldown .ability-cooldown,
.ability-btn.on-cooldown .ability-icon {
    position: relative;
    z-index: 3;
}

#upgrade-overlay,
#game-end-overlay,
#settings-overlay {
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at 50% 20%, rgba(22, 30, 40, 0.55), rgba(6, 8, 14, 0.82));
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 900;
    padding: calc(16px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
    overflow: auto;
}

#game-end-overlay {
    z-index: 1000;
}

#upgrade-content,
#game-end-content,
#settings-content {
    text-align: center;
    padding: 22px 20px;
    width: min(92vw, 380px);
    max-height: calc(100vh - 48px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    max-height: calc(100dvh - 48px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    background: rgba(8, 12, 18, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
    color: #f2f6fb;
    display: flex;
    flex-direction: column;
    gap: 12px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

#upgrade-title,
#game-end-title {
    font-family: var(--font-display);
    font-size: 1.6rem;
    margin-bottom: 4px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

#game-end-title.victory {
    color: #2f7d53;
}

#game-end-title.defeat {
    color: #b64a3d;
}

#upgrade-subtitle,
#game-end-subtitle {
    font-size: 0.9rem;
    color: rgba(214, 224, 236, 0.78);
    margin-bottom: 8px;
}

#upgrade-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-right: 2px;
    -webkit-overflow-scrolling: touch;
}

.upgrade-option {
    display: flex;
    flex-direction: column;
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.2s ease;
    text-align: left;
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.upgrade-option:active {
    transform: translateY(1px) scale(0.98);
    box-shadow: 0 8px 16px rgba(16, 20, 18, 0.2);
}

.upgrade-option-name {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 4px;
    color: #f6f8fb;
}

.upgrade-option-desc {
    font-size: 0.85rem;
    color: rgba(214, 224, 236, 0.75);
}

.upgrade-option .upgrade-tree-badge {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 3px 8px;
    border-radius: 999px;
    margin-bottom: 6px;
    align-self: flex-start;
}

.upgrade-option .upgrade-tree-badge.tree-speed {
    background: rgba(224, 122, 95, 0.25);
    color: #ffc1b2;
}

.upgrade-option .upgrade-tree-badge.tree-survival {
    background: rgba(76, 139, 94, 0.25);
    color: #b6f0c7;
}

.upgrade-option .upgrade-tree-badge.tree-teamwork {
    background: rgba(61, 156, 165, 0.25);
    color: #b7f2f7;
}

.upgrade-option .upgrade-tree-badge.tree-ability {
    background: rgba(150, 100, 200, 0.25);
    color: #e0c7ff;
}

.upgrade-option .upgrade-tree-badge.tree-vision {
    background: rgba(242, 166, 90, 0.25);
    color: #ffd9a8;
}

#owned-upgrades-bar {
    display: none;
    justify-content: flex-start;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
    flex-wrap: wrap;
    max-width: 120px;
}

#owned-upgrades-bar.visible {
    display: flex;
}

.owned-upgrade {
    position: relative;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    display: flex;
    cursor: pointer;
    justify-content: center;
    align-items: center;
    background: var(--surface-strong);
    border: 1px solid var(--border);
    box-shadow: 0 4px 10px rgba(16, 20, 18, 0.12);
}

.owned-upgrade.tree-speed {
    border-color: rgba(224, 122, 95, 0.5);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.95), rgba(244, 177, 158, 0.3));
}

.owned-upgrade.tree-survival {
    border-color: rgba(76, 139, 94, 0.5);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.95), rgba(191, 227, 202, 0.3));
}

.owned-upgrade.tree-teamwork {
    border-color: rgba(61, 156, 165, 0.5);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.95), rgba(183, 227, 230, 0.3));
}

.owned-upgrade.tree-ability {
    border-color: rgba(150, 100, 200, 0.5);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.95), rgba(210, 190, 235, 0.3));
}

.owned-upgrade.tree-vision {
    border-color: rgba(242, 166, 90, 0.5);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.95), rgba(245, 212, 138, 0.3));
}

.owned-upgrade-icon {
    --icon-size: 14px;
    color: var(--ink);
}

/* Old hover tooltip removed - using center popup instead */
.owned-upgrade-tooltip {
    display: none;
    color: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.7rem;
    white-space: nowrap;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
}

/* Hover styles removed - tap shows center popup instead */

#game-end-stats {
    margin-bottom: 20px;
    text-align: left;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

#game-end-stats .stat {
    color: rgba(214, 224, 236, 0.85);
    margin: 8px 0;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: var(--radius-sm);
    display: flex;
    justify-content: space-between;
}

.stats-table-container {
    margin-top: 12px;
    overflow-x: auto;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.stats-table th,
.stats-table td {
    padding: 8px 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    text-align: left;
}

.stats-table thead th {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.7rem;
    color: rgba(214, 224, 236, 0.7);
}

.mvp-row {
    background: rgba(212, 175, 55, 0.18);
}

.mvp-badge {
    margin-left: 6px;
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(212, 175, 55, 0.35);
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.dead-icon {
    margin-left: 6px;
    --icon-size: 14px;
    color: #b64a3d;
    vertical-align: middle;
}

#game-end-actions {
    margin-top: 16px;
}

.game-end-btn {
    width: 100%;
    padding: 14px 20px;
    font-size: 0.95rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: transform 0.12s ease;
}

.game-end-btn:active {
    transform: translateY(1px) scale(0.98);
}

.game-end-btn.hidden {
    display: none;
}

/* Round Transition Overlay - shown at start of each round */
#round-transition-overlay {
    position: fixed;
    inset: 0;
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#round-transition-overlay.visible {
    opacity: 1;
    pointer-events: all;
}

#round-transition-overlay.fading {
    opacity: 0;
}

#countdown-text {
    font-family: var(--font-display);
    font-size: 7rem;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 0 40px rgba(255, 255, 255, 0.4);
    animation: countdown-pulse 0.3s ease-out;
}

#countdown-text.go {
    color: #3de08f;
    text-shadow: 0 0 50px rgba(61, 224, 143, 0.6);
}

@keyframes countdown-pulse {
    0% { transform: scale(1.4); opacity: 0.6; }
    100% { transform: scale(1); opacity: 1; }
}

/* --- Manual Pause Overlay --- */

.pause-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1500;
    padding: calc(16px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
}

.pause-content {
    text-align: center;
    padding: 24px 28px;
    width: min(90vw, 340px);
    background: rgba(8, 12, 18, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
    color: #f2f6fb;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.pause-initiator {
    font-family: var(--font-display);
    font-size: 1.5rem;
    color: #D4AF37;
    letter-spacing: 0.1em;
    margin-bottom: 12px;
}

.pause-timer {
    color: #aaa;
    font-size: 0.95rem;
    margin-bottom: 20px;
}

.pause-resume-btn {
    padding: 12px 32px;
    font-size: 1.1rem;
    font-weight: 700;
    background: var(--accent-forest);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

.pause-resume-btn:hover:not(:disabled) {
    background: #5aa670;
}

.pause-resume-btn:disabled {
    background: #444;
    color: #888;
    cursor: not-allowed;
}

/* Pause button in match HUD */
.pause-btn {
    position: absolute;
    top: 6px;
    right: 10px;
    width: 32px;
    height: 28px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 6px;
    color: white;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
}

.pause-btn:hover {
    background: rgba(0, 0, 0, 0.7);
    border-color: rgba(255, 255, 255, 0.4);
}

.pause-btn:active {
    background: rgba(0, 0, 0, 0.85);
}

.pause-icon {
    letter-spacing: -2px;
    font-family: monospace;
}

.game-notification {
    position: fixed;
    top: calc(24px + env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    padding: 10px 18px;
    background: rgba(15, 18, 22, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    font-size: 0.9rem;
    font-weight: 700;
    text-align: center;
    z-index: 1100;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    white-space: nowrap;
    max-width: 90%;
    color: #fff;
}

.game-notification.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.game-notification.danger {
    border-color: rgba(182, 74, 61, 0.6);
    color: #ffb0a4;
}

.game-notification.warning {
    border-color: rgba(212, 175, 55, 0.7);
    color: #E8D48A;
}

.game-notification.success {
    border-color: rgba(61, 125, 83, 0.7);
    color: #b2e1c0;
}

@keyframes screen-in {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes card-rise {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 360px) {
    :root {
        --joystick-size: 100px;
        --joystick-thumb-size: 44px;
        --action-size: 76px;
        --ability-size: 68px;
        --icon-size: 20px;
    }

    .screen {
        padding: 16px;
    }

    h1 {
        font-size: 1.9rem;
    }

    #game-view {
        width: min(100%, 300px);
    }
}

@media (min-width: 480px) {
    :root {
        --joystick-size: 140px;
        --joystick-thumb-size: 60px;
        --action-size: 100px;
        --ability-size: 88px;
        --icon-size: 26px;
    }

    .screen-shell {
        width: min(100%, 520px);
    }

    #game-view {
        width: min(100%, 360px);
    }

    #buttons-container {
        flex-direction: row;
        align-items: flex-start;
    }
}

@media (min-width: 720px) {
    #game-view {
        width: min(100%, 400px);
    }

    .mini-map-container {
        width: 120px;
    }

    #class-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-height: 700px) {
    .screen {
        padding-top: 16px;
    }

    #player-info {
        padding: 10px 12px;
    }

    #controls-container {
        gap: 12px;
    }
}

/* === ROTATION PROMPT === */
#rotation-prompt {
    position: fixed;
    inset: 0;
    background: linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 55%, var(--bg-3) 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

#rotation-prompt.hidden {
    display: none;
}

.rotation-content {
    text-align: center;
    padding: 32px;
}

.rotation-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 24px;
    background: var(--ink-muted);
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7.34 6.41L.86 12.9l6.49 6.48 6.49-6.48-6.5-6.49zM3.69 12.9l3.66-3.66L11 12.9l-3.66 3.66-3.65-3.66zm15.67-6.26A8.95 8.95 0 0013 4V.76L8.76 5 13 9.24V6c1.79 0 3.58.68 4.95 2.05a7.007 7.007 0 010 9.9 6.973 6.973 0 01-7.79 1.44l-1.49 1.49C10.02 21.62 11.51 22 13 22c2.3 0 4.61-.88 6.36-2.64a8.98 8.98 0 000-12.72z'/%3E%3C/svg%3E") center / contain no-repeat;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7.34 6.41L.86 12.9l6.49 6.48 6.49-6.48-6.5-6.49zM3.69 12.9l3.66-3.66L11 12.9l-3.66 3.66-3.65-3.66zm15.67-6.26A8.95 8.95 0 0013 4V.76L8.76 5 13 9.24V6c1.79 0 3.58.68 4.95 2.05a7.007 7.007 0 010 9.9 6.973 6.973 0 01-7.79 1.44l-1.49 1.49C10.02 21.62 11.51 22 13 22c2.3 0 4.61-.88 6.36-2.64a8.98 8.98 0 000-12.72z'/%3E%3C/svg%3E") center / contain no-repeat;
    animation: rotation-hint 2s ease-in-out infinite;
}

@keyframes rotation-hint {
    0%, 100% { transform: rotate(-15deg); }
    50% { transform: rotate(15deg); }
}

.rotation-content p {
    font-size: 1.1rem;
    color: var(--ink);
    max-width: 280px;
    line-height: 1.5;
}

/* === CONTROLLER STAGE === */
#controller-screen {
    display: block;
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
    text-align: left;
    background: #01030b;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
}

#controller-stage {
    position: relative;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    background: radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.08), transparent 45%), #03040f;
    overflow: hidden;
}

#controller-screen #game-view-container {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.04), transparent 50%), #05070f;
    z-index: 1;
    pointer-events: none;
}

#controller-screen #game-view {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    border: none;
    background: #03040a;
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.75);
    overflow: hidden;
}

#controller-screen #game-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#controller-screen #player-info {
    position: absolute;
    top: calc(18px + env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    width: min(88%, 340px);
    padding: 12px 18px;
    background: rgba(5, 8, 14, 0.6);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.6);
    z-index: 5;
    color: #e8eef5;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

#controller-screen #player-name-display {
    color: #f2f6fb;
}

#controller-screen #connection-status {
    color: #d9e4ee;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.16);
}

#controller-screen #connection-status.connected {
    color: #7fe3a2;
    background: rgba(64, 180, 120, 0.2);
}

#controller-screen #connection-status.disconnected {
    color: #ff9e92;
    background: rgba(182, 74, 61, 0.22);
}

#controller-screen .status-row {
    position: absolute;
    top: calc(68px + env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    gap: 10px;
    z-index: 5;
}

#controller-screen #class-badge {
    background: rgba(6, 10, 16, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.16);
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.45);
    color: #e6edf5;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

#controller-screen #ability-state {
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

#controller-screen #ready-btn {
    position: absolute;
    bottom: calc(20px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    min-width: 140px;
    padding: 10px 18px;
    font-size: 0.85rem;
    letter-spacing: 0.14em;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
    z-index: 6;
}

#controller-screen #ready-btn:active {
    transform: translateX(-50%) translateY(1px) scale(0.98);
}

#controller-screen #disconnect-btn {
    position: absolute;
    top: calc(14px + env(safe-area-inset-top));
    right: calc(14px + env(safe-area-inset-right));
    left: auto;
    padding: 8px 14px;
    background: rgba(6, 10, 16, 0.5);
    color: #d9e4ee;
    border: 1px solid rgba(255, 255, 255, 0.16);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 6;
}

#controller-screen #match-hud {
    top: calc(12px + env(safe-area-inset-top));
    left: calc(12px + env(safe-area-inset-left));
    padding: 5px 9px;
    font-size: 0.7rem;
    background: rgba(8, 12, 18, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

#controller-screen .mini-map-container {
    top: calc(56px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
    background: rgba(8, 12, 18, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.16);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

#controller-screen #owned-upgrades-bar {
    position: absolute;
    top: calc(8px + env(safe-area-inset-top));
    left: calc(8px + env(safe-area-inset-left));
    transform: none;
    z-index: 4;
    background: rgba(31, 42, 36, 0.7);
    border-radius: 8px;
}

#controller-screen #status-effects-bar {
    position: relative;
    left: auto;
    transform: none;
    z-index: 4;
}

#controller-screen #controls-container {
    position: absolute;
    bottom: calc(22px + env(safe-area-inset-bottom));
    left: calc(18px + env(safe-area-inset-left));
    right: calc(18px + env(safe-area-inset-right));
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 18px;
    z-index: 5;
}

#controller-screen #joystick-container {
    flex: 0 0 auto;
}

#controller-screen #buttons-container {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
    margin-left: auto;  /* Push to right even when joystick is hidden */
}

#controller-screen #controls-container .action-btn,
#controller-screen #controls-container .ability-btn {
    min-width: 0;
}

@media screen and (orientation: landscape) {
    :root {
        --joystick-size: 120px;
        --joystick-thumb-size: 52px;
        --action-size: 80px;
        --ability-size: 72px;
    }
}

@media screen and (orientation: landscape) and (min-width: 700px) {
    :root {
        --joystick-size: 140px;
        --joystick-thumb-size: 60px;
        --action-size: 90px;
        --ability-size: 80px;
    }
}

@media screen and (orientation: landscape) and (max-width: 900px) {
    #controller-screen #player-info {
        width: min(82%, 320px);
        padding: 10px 16px;
        gap: 8px;
    }

    #controller-screen #player-name-display {
        font-size: 1rem;
    }

    #controller-screen #connection-status {
        font-size: 0.68rem;
        padding: 4px 10px;
    }

    #controller-screen .status-row {
        top: calc(64px + env(safe-area-inset-top));
    }

    #controller-screen #match-hud {
        font-size: 0.66rem;
        padding: 4px 8px;
    }

    #controller-screen .mini-map-container {
        width: 88px;
        top: calc(52px + env(safe-area-inset-top));
    }

    #controller-screen #disconnect-btn {
        padding: 6px 12px;
        font-size: 0.85rem;
    }
}

@media screen and (orientation: landscape) and (max-width: 700px) {
    #controller-screen #player-info {
        width: min(78%, 260px);
        padding: 9px 14px;
    }

    #controller-screen #player-name-display {
        max-width: 65%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #controller-screen .status-row {
        top: calc(60px + env(safe-area-inset-top));
    }

    #controller-screen #match-hud {
        font-size: 0.62rem;
        letter-spacing: 0.06em;
    }

    #controller-screen .mini-map-container {
        width: 72px;
        top: calc(48px + env(safe-area-inset-top));
    }

    #controller-screen #ready-btn {
        min-width: 120px;
        font-size: 0.78rem;
    }
}

@media screen and (orientation: landscape) and (max-height: 420px) {
    #controller-screen #player-info {
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    #controller-screen #ready-btn {
        bottom: calc(12px + env(safe-area-inset-bottom));
        min-width: 120px;
        padding: 8px 14px;
        font-size: 0.78rem;
    }

    #controller-screen #controls-container {
        bottom: calc(12px + env(safe-area-inset-bottom));
        gap: 14px;
    }
}

/* === OBJECTIVE PROGRESS TOASTS === */
#objective-toast-container {
    position: fixed;
    top: calc(70px + env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 1050;
    pointer-events: none;
    max-width: 90%;
}

.objective-toast {
    background: rgba(15, 18, 22, 0.92);
    border-radius: 8px;
    padding: 8px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: #e8e8e8;
    border-left: 3px solid var(--accent-1);
    animation: toast-slide-in 0.3s ease-out, toast-fade-out 0.3s ease-in 2.7s forwards;
    min-width: 180px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.objective-toast.villager {
    border-left-color: #5c9e6b;
}

.objective-toast.god {
    border-left-color: #b47a3e;
}

.objective-toast.actor {
    border-left-color: #7eb8e0;
    background: rgba(20, 28, 35, 0.95);
}

.objective-toast .toast-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.objective-toast .toast-message {
    flex: 1;
    line-height: 1.3;
}

.objective-toast .toast-progress {
    font-weight: 700;
    color: #fff;
    background: rgba(255,255,255,0.1);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
}

@keyframes toast-slide-in {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toast-fade-out {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* === VILLAGER OBJECTIVES PANEL === */
#objectives-panel {
    position: absolute;
    top: calc(50px + env(safe-area-inset-top));
    left: calc(12px + env(safe-area-inset-left));
    background: rgba(8, 12, 18, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    min-width: 140px;
    z-index: 5;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

#objectives-panel.hidden {
    display: none;
}

#objectives-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.7);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    text-transform: uppercase;
}

#objectives-minimize {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    font-size: 1rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    transition: color 0.15s;
}

#objectives-minimize:hover,
#objectives-minimize:active {
    color: rgba(255, 255, 255, 0.9);
}

#objectives-list {
    padding: 6px;
}

#objectives-list.hidden {
    display: none;
}

.objective-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    font-size: 0.75rem;
    color: #d6e4f0;
}

.objective-row .objective-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.objective-row .objective-name {
    flex: 1;
    color: rgba(255, 255, 255, 0.7);
}

.objective-row .objective-value {
    font-weight: 600;
    color: #fff;
}

.objective-row.complete .objective-value {
    color: #7bd19a;
}

.objective-row.partial .objective-value {
    color: rgba(255, 255, 255, 0.5);
}

/* Progress bar for shared objectives */
.objective-bar {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
    min-width: 60px;
}

.objective-fill {
    height: 100%;
    background: var(--accent-gold, #d4a853);
    transition: width 0.3s ease;
    border-radius: 3px;
}

.objective-row.complete .objective-fill {
    background: #7bd19a;
}

.objective-row.complete {
    opacity: 0.7;
}

/* Landscape adjustments */
@media screen and (orientation: landscape) and (max-width: 900px) {
    #objectives-panel {
        top: calc(44px + env(safe-area-inset-top));
        min-width: 120px;
    }

    #objectives-header {
        padding: 4px 8px;
        font-size: 0.6rem;
    }

    .objective-row {
        font-size: 0.7rem;
        padding: 3px 5px;
        gap: 6px;
    }

    .objective-row .objective-icon {
        width: 12px;
        height: 12px;
    }
}

@media screen and (orientation: landscape) and (max-width: 700px) {
    #objectives-panel {
        top: calc(40px + env(safe-area-inset-top));
        min-width: 100px;
    }

    #objectives-header {
        font-size: 0.55rem;
    }

    .objective-row {
        font-size: 0.65rem;
    }
}

/* Settings button and modal */
.top-buttons {
    position: absolute;
    top: calc(8px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
    display: flex;
    gap: 8px;
    align-items: center;
    z-index: 50;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(10, 14, 18, 0.6);
    color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.icon-btn:active {
    transform: scale(0.92);
    background: rgba(30, 40, 50, 0.8);
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

#settings-overlay {
    z-index: 950;
}

#settings-content h2 {
    font-family: var(--font-display);
    font-size: 1.4rem;
    margin-bottom: 16px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.settings-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.settings-section:last-of-type {
    border-bottom: none;
}

.settings-section label {
    font-size: 0.85rem;
    color: rgba(214, 224, 236, 0.78);
    text-align: left;
}

.settings-section input[type="range"] {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    outline: none;
}

.settings-section input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

.settings-actions {
    margin-top: 16px;
    display: flex;
    gap: 10px;
    justify-content: center;
}

#pause-section {
    display: none;
}

#pause-section.visible {
    display: flex;
}

/* === FULLSCREEN PROMPT === */
#fullscreen-prompt {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

#fullscreen-prompt.hidden {
    display: none;
}

#fullscreen-prompt-content {
    text-align: center;
    color: #fff;
    padding: 40px;
}

#fullscreen-prompt-content p {
    font-family: var(--font-display);
    font-size: 1.8rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 12px;
    animation: prompt-pulse 1.5s ease-in-out infinite;
}

#fullscreen-prompt-content .fullscreen-hint {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.6);
}

@keyframes prompt-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.02); }
}

/* Hide fullscreen section on desktop or when not supported */
#fullscreen-section {
    display: flex;
}

@media (hover: hover) and (pointer: fine) {
    /* Desktop - hide fullscreen option */
    #fullscreen-section {
        display: none;
    }
}

/* --- Upgrade Timer Styling --- */

.upgrade-timer {
    text-align: center;
    font-size: 1.2rem;
    font-weight: bold;
    color: #66ff66;
    margin-top: 15px;
    transition: color 0.3s ease;
}

#god-pause-timer {
    color: #ffaa44;
    font-size: 1.1rem;
    text-align: center;
    margin-top: 10px;
    transition: color 0.3s ease;
}
