:root {
    --bg-dark: #0a0e1a;
    --bg-panel: #151925;
    --text-primary: #e8eaed;
    --text-secondary: #9195a0;
    --accent-gold: #d4af37;
    --accent-blue: #4a90e2;
    --accent-purple: #8b5cf6;
    --accent-red: #ef4444;
    --accent-green: #10b981;
    --border: #2a2f3e;
}

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

body {
    font-family: Arial, sans-serif;
    font-size: 14px;
    background: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 80px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 40px;
    backdrop-filter: blur(10px);
}

.header h1 {
    font-size: 1.8em;
    font-weight: 300;
    letter-spacing: 2px;
    color: var(--accent-gold);
}

.header-stats {
    display: flex;
    gap: 30px;
    font-family: Arial, sans-serif;
    font-size: 0.85em;
    color: var(--text-secondary);
}

.stat-item strong {
    color: var(--text-primary);
    margin-left: 5px;
}

.control-panel {
    position: fixed;
    top: 80px;
    left: 0;
    width: 320px;
    height: calc(100vh - 80px);
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    padding: 30px;
    overflow-y: auto;
    z-index: 50;
}

.control-section {
    margin-bottom: 30px;
}

.control-section h3 {
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--accent-gold);
    margin-bottom: 15px;
    font-weight: 600;
}

.control-section label {
    display: block;
    font-size: 0.9em;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

input[type="range"] {
    width: 100%;
    height: 2px;
    background: var(--border);
    outline: none;
    opacity: 0.8;
    transition: opacity 0.2s;
    -webkit-appearance: none;
}

input[type="range"]:hover {
    opacity: 1;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent-gold);
    cursor: pointer;
    border-radius: 50%;
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--accent-gold);
    cursor: pointer;
    border-radius: 50%;
    border: none;
}

.filter-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn {
    padding: 12px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s;
    font-family: Arial, sans-serif;
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn:hover {
    background: var(--accent-gold);
    color: var(--bg-dark);
    border-color: var(--accent-gold);
}

.btn.active {
    background: var(--accent-gold);
    color: var(--bg-dark);
    border-color: var(--accent-gold);
}

.btn-export {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: white;
}

.btn-export:hover {
    background: #3a7bc8;
}

.slider-value {
    font-family: Arial, sans-serif;
    font-size: 0.85em;
    color: var(--accent-gold);
    margin-top: 5px;
}

#network-container {
    position: fixed;
    top: 80px;
    left: 320px;
    right: 0;
    height: calc(100vh - 80px);
    background: radial-gradient(circle at 50% 50%, #0f1420 0%, var(--bg-dark) 100%);
}

.tooltip {
    position: fixed;
    background: rgba(21, 25, 37, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--accent-gold);
    padding: 15px;
    border-radius: 4px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 1000;
    min-width: 260px;
    max-width: 400px;
    font-size: 0.9em;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.tooltip-title {
    font-size: 1.1em;
    font-weight: 600;
    color: var(--accent-gold);
    margin-bottom: 8px;
}

.tooltip-vampire-marker {
    display: inline-block;
    margin-bottom: 10px;
    padding: 3px 10px;
    border-radius: 12px;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid var(--accent-red);
    color: var(--accent-red);
    font-size: 0.78em;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.tooltip-stat {
    display: flex;
    justify-content: space-between;
    margin: 4px 0;
    font-size: 0.85em;
}

.tooltip-stat-label {
    color: var(--text-secondary);
}

.tooltip-stat-value {
    color: var(--text-primary);
    font-family: Arial, sans-serif;
}

.legend {
    position: fixed;
    bottom: 30px;
    left: 340px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    padding: 20px;
    border-radius: 4px;
    font-size: 0.85em;
}

.legend-title {
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--accent-gold);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.legend-item {
    display: flex;
    align-items: center;
    margin: 8px 0;
}

.legend-line {
    width: 40px;
    height: 2px;
    margin-right: 10px;
}

.legend-direct {
    background: var(--accent-blue);
}

.legend-copresence {
    background: var(--accent-purple);
    opacity: 0.5;
}

.node {
    cursor: pointer;
    transition: all 0.3s;
}

.node:hover {
    stroke-width: 3px !important;
}

.node-label {
    font-family: Arial, sans-serif;
    font-size: 11px;
    font-weight: 400;
    pointer-events: none;
    text-shadow: 0 0 3px var(--bg-dark), 0 0 3px var(--bg-dark);
}

.link {
    transition: all 0.3s;
}

.link-direct {
    stroke: var(--accent-blue);
}

.link-copresence {
    stroke: var(--accent-purple);
    opacity: 0.4;
}

.link.highlighted {
    opacity: 1 !important;
    stroke-width: 3px !important;
}

.link.dimmed {
    opacity: 0.1 !important;
}

.node.highlighted {
    stroke-width: 3px !important;
}

.node.dimmed {
    opacity: 0.3 !important;
}

.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5em;
    color: var(--accent-gold);
    font-family: Arial, sans-serif;
}

.drawer {
    position: fixed;
    top: 80px;
    right: -675px;
    width: 675px;
    height: calc(100vh - 80px);
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    box-shadow: -5px 0 20px rgba(0, 0, 0, 0.3);
    transition: right 0.3s ease-out;
    z-index: 200;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.drawer.open {
    right: 0;
}

.drawer-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.drawer-title {
    font-size: 1.3em;
    font-weight: 300;
    color: var(--accent-gold);
    letter-spacing: 1px;
}

.drawer-close {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
    width: 32px;
    height: 32px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 1.2em;
}

.drawer-close:hover {
    background: var(--accent-gold);
    color: var(--bg-dark);
    border-color: var(--accent-gold);
}

.drawer-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.2);
    overflow-x: auto;
}

.drawer-tab {
    flex-shrink: 0;
    padding: 12px 14px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.3s;
    font-family: Arial, sans-serif;
    font-size: 0.75em;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.drawer-tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.drawer-tab.active {
    color: var(--accent-gold);
    border-bottom-color: var(--accent-gold);
    background: rgba(212, 175, 55, 0.1);
}

.drawer-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.character-profile {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.profile-header {
    text-align: center;
    padding: 20px;
    background: rgba(212, 175, 55, 0.1);
    border-radius: 8px;
    border: 1px solid var(--accent-gold);
}

.profile-name {
    font-size: 1.5em;
    font-weight: 600;
    color: var(--accent-gold);
    margin-bottom: 8px;
}

.profile-gender {
    font-size: 1.1em;
    color: var(--text-secondary);
}

.profile-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.stat-box {
    background: rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.stat-label {
    font-size: 0.85em;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
}

.stat-value {
    font-size: 1.8em;
    font-weight: 600;
    color: var(--accent-gold);
    font-family: Arial, sans-serif;
}

.chart-container {
    background: rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 6px;
    border: 1px solid var(--border);
    overflow: hidden;
}

.chart-container svg {
    max-width: 100%;
    height: auto;
}

.chart-title {
    font-size: 0.9em;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 15px;
}

.connections-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.search-box,
.filter-select {
    padding: 8px 12px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 4px;
    font-size: 0.9em;
}

.search-box {
    flex: 1;
    min-width: 150px;
}

.search-box:focus,
.filter-select:focus {
    outline: none;
    border-color: var(--accent-gold);
}

.partners-table {
    overflow-x: auto;
}

.partners-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
}

.partners-table th {
    background: rgba(255, 255, 255, 0.1);
    padding: 10px 8px;
    text-align: left;
    font-weight: 600;
    color: var(--accent-gold);
    border-bottom: 2px solid var(--border);
    cursor: pointer;
    user-select: none;
    font-family: Arial, sans-serif;
    font-size: 0.75em;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.partners-table th:hover {
    background: rgba(255, 255, 255, 0.15);
}

.partners-table td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.partners-table tr {
    transition: background 0.2s;
    cursor: pointer;
}

.partners-table tr:hover {
    background: rgba(212, 175, 55, 0.1);
}

.partner-name {
    font-weight: 600;
    color: var(--text-primary);
}

.gender-icon {
    display: inline-block;
    width: 20px;
    text-align: center;
    margin-right: 5px;
}

.gender-M {
    color: var(--accent-blue);
}

.gender-F {
    color: #ec4899;
}

.gender-C {
    color: var(--accent-purple);
}

.metric-cell {
    font-family: Arial, sans-serif;
    color: var(--text-secondary);
    font-size: 0.85em;
}

.metric-bar {
    height: 4px;
    background: var(--accent-gold);
    border-radius: 2px;
    margin-top: 4px;
}

.vocab-section {
    margin-bottom: 24px;
}

.vocab-section-title {
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--accent-gold);
    margin-bottom: 12px;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    padding-bottom: 6px;
}

.reliability-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-family: Arial, sans-serif;
    font-size: 0.75em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.reliability-high {
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
    border: 1px solid #10b981;
}

.reliability-medium {
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
    border: 1px solid #f59e0b;
}

.reliability-low {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    border: 1px solid #ef4444;
}

.reliability-none {
    background: rgba(107, 114, 128, 0.2);
    color: #6b7280;
    border: 1px solid #6b7280;
}

.vocab-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.vocab-stat-box {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 16px;
}

.vocab-stat-label {
    font-size: 0.75em;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
}

.vocab-stat-value {
    font-size: 1.7em;
    font-weight: 600;
    color: var(--accent-gold);
    font-family: Arial, sans-serif;
}

.vocab-stat-sub {
    font-size: 0.78em;
    color: var(--text-secondary);
    margin-top: 4px;
}

.word-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 0;
}

.word-chip {
    background: rgba(212, 175, 55, 0.10);
    border: 1px solid rgba(212, 175, 55, 0.25);
    border-radius: 14px;
    padding: 5px 12px;
    font-size: 0.85em;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 7px;
    opacity: 1 !important;
}

.word-chip-count {
    font-family: Arial, sans-serif;
    font-size: 0.72em;
    color: var(--accent-gold);
    background: rgba(212, 175, 55, 0.15);
    border-radius: 8px;
    padding: 1px 5px;
}

.pos-bar-row {
    display: flex;
    align-items: center;
    margin-bottom: 9px;
    gap: 10px;
}

.pos-bar-label {
    font-size: 0.78em;
    color: var(--text-secondary);
    width: 58px;
    text-align: right;
    flex-shrink: 0;
    letter-spacing: 0.5px;
}

.pos-bar-track {
    flex: 1;
    height: 10px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 5px;
    overflow: hidden;
}

.pos-bar-fill {
    height: 100%;
    border-radius: 5px;
}

.pos-bar-pct {
    font-family: Arial, sans-serif;
    font-size: 0.78em;
    color: var(--text-primary);
    width: 46px;
    text-align: right;
    flex-shrink: 0;
}

.overlap-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(139, 92, 246, 0.15);
    border: 1px solid rgba(139, 92, 246, 0.4);
    border-radius: 10px;
    padding: 3px 8px;
    font-family: Arial, sans-serif;
    font-size: 0.75em;
    color: #a78bfa;
}

.exclusive-tag {
    display: inline-block;
    background: rgba(74, 144, 226, 0.15);
    border: 1px solid rgba(74, 144, 226, 0.35);
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 0.75em;
    color: #7db3e8;
    margin: 2px;
}

.rel-vocab-accordion {
    margin-top: 8px;
}

.rel-vocab-partner {
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 8px;
    overflow: hidden;
}

.rel-vocab-header {
    padding: 12px 14px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.03);
    transition: background 0.2s;
    user-select: none;
}

.rel-vocab-header:hover {
    background: rgba(212, 175, 55, 0.08);
}

.rel-vocab-header-name {
    font-size: 1em;
    color: var(--text-primary);
    font-weight: 600;
    letter-spacing: 0.2px;
}

.rel-vocab-header-meta {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-shrink: 0;
    margin-left: 12px;
}

.rel-vocab-body {
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    display: none;
}

.rel-vocab-body.open {
    display: block;
}

.rel-vocab-arrow {
    font-size: 0.75em;
    color: var(--text-secondary);
    transition: transform 0.2s;
}

.rel-vocab-arrow.open {
    transform: rotate(180deg);
}

.vampire-avatar {
    filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.6));
    animation: vampirePulse 2s ease-in-out infinite;
}

.vampire-true-form {
    filter: drop-shadow(0 0 12px rgba(139, 92, 246, 0.8));
    animation: trueFormPulse 3s ease-in-out infinite;
}

@keyframes vampirePulse {

    0%,
    100% {
        filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.6));
    }

    50% {
        filter: drop-shadow(0 0 15px rgba(239, 68, 68, 0.9));
    }
}

@keyframes trueFormPulse {

    0%,
    100% {
        filter: drop-shadow(0 0 12px rgba(139, 92, 246, 0.8));
    }

    50% {
        filter: drop-shadow(0 0 20px rgba(139, 92, 246, 1));
    }
}

.vampire-merged {
    filter: drop-shadow(0 0 20px rgba(139, 92, 246, 1));
}

.btn-vampire-toggle {
    background: linear-gradient(135deg, #ef4444 0%, #8b5cf6 100%);
    border: none;
    color: white;
    font-weight: bold;
    position: relative;
    overflow: hidden;
}

.btn-vampire-toggle.active {
    background: linear-gradient(135deg, #8b5cf6 0%, #ef4444 100%);
}

.identity-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 15px 0;
}

.identity-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    transition: all 0.3s;
    cursor: pointer;
}

.identity-card:hover {
    background: rgba(139, 92, 246, 0.2);
    border-color: #8b5cf6;
}

.identity-card.true-form {
    grid-column: 1 / -1;
    background: rgba(139, 92, 246, 0.15);
    border-color: #8b5cf6;
}

.identity-name {
    font-weight: 600;
    color: var(--accent-gold);
    margin-bottom: 5px;
}

.identity-stat {
    font-size: 0.85em;
    color: var(--text-secondary);
}

.merged-stats-box {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(139, 92, 246, 0.1));
    border: 1px solid #8b5cf6;
    border-radius: 8px;
    padding: 15px;
    margin: 15px 0;
}

.btn-community-toggle {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.btn-community-toggle.active {
    background: var(--accent-gold);
    color: var(--bg-dark);
    border-color: var(--accent-gold);
}

.comm-node {
    cursor: pointer;
}

.comm-label {
    font-family: Arial, sans-serif;
    font-size: 11px;
    pointer-events: none;
    text-shadow: 0 0 4px var(--bg-dark), 0 0 4px var(--bg-dark);
}

.comm-link {
    stroke: rgba(255, 255, 255, 0.15);
    fill: none;
}

.comm-link.highlighted {
    stroke: var(--accent-gold);
    opacity: 1 !important;
}

.comm-link.dimmed {
    opacity: 0.05 !important;
}

.comm-node.dimmed {
    opacity: 0.25 !important;
}

.comm-section {
    margin-bottom: 22px;
}

.comm-section-title {
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--accent-gold);
    margin-bottom: 12px;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    padding-bottom: 6px;
}

.comm-stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.comm-stat-box {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 14px;
}

.comm-stat-label {
    font-size: 0.75em;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
}

.comm-stat-value {
    font-size: 1.6em;
    font-weight: 600;
    color: var(--accent-gold);
    font-family: Arial, sans-serif;
}

.comm-stat-sub {
    font-size: 0.75em;
    color: var(--text-secondary);
    margin-top: 3px;
}

.comm-member-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
}

.comm-member-row:hover {
    background: rgba(212, 175, 55, 0.06);
}

.comm-member-name {
    font-size: 0.95em;
    color: var(--text-primary);
    font-weight: 600;
}

.comm-member-meta {
    font-family: Arial, sans-serif;
    font-size: 0.75em;
    color: var(--text-secondary);
}

.comm-inter-row {
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-bottom: 8px;
    overflow: hidden;
}

.comm-inter-header {
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.03);
    transition: background 0.2s;
    user-select: none;
}

.comm-inter-header:hover {
    background: rgba(212, 175, 55, 0.08);
}

.comm-inter-body {
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    display: none;
}

.comm-inter-body.open {
    display: block;
}

.comm-inter-arrow {
    font-size: 0.75em;
    color: var(--text-secondary);
    transition: transform 0.2s;
}

.comm-inter-arrow.open {
    transform: rotate(180deg);
}

.comm-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 2px;
    margin-right: 8px;
    flex-shrink: 0;
    vertical-align: middle;
}

.cohesion-bar-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.cohesion-bar-label {
    font-size: 0.8em;
    color: var(--text-secondary);
    width: 140px;
    flex-shrink: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cohesion-bar-track {
    flex: 1;
    height: 8px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 4px;
    overflow: hidden;
}

.cohesion-bar-fill {
    height: 100%;
    border-radius: 4px;
}

.cohesion-bar-pct {
    font-family: Arial, sans-serif;
    font-size: 0.72em;
    color: var(--text-secondary);
    width: 38px;
    text-align: right;
    flex-shrink: 0;
}

/* =====================================================================
   MOBILE LAYOUT (≤ 768px)
   The network fills the whole screen. The top bar and the control
   panel are hidden and slide in together when the user taps
   "Controls" (body.mobile-controls-open, toggled in the HTML).
   Desktop layout above is unchanged.
   ===================================================================== */

/* Toggle button and backdrop exist only on mobile */
.mobile-controls-toggle,
.mobile-controls-close,
.mobile-backdrop {
    display: none;
}

@media (max-width: 768px) {

    body {
        height: 100dvh;
    }

    /* ---- Top bar: hidden until Controls is opened ---- */
    .header {
        height: auto;
        min-height: 56px;
        padding: 10px 64px 10px 16px;
        flex-direction: column;
        align-items: flex-start;
        justify-content: center;
        gap: 6px;
        transform: translateY(-100%);
        transition: transform 0.3s ease-out;
        z-index: 120;
    }

    .header h1 {
        font-size: 1.1em;
        letter-spacing: 1px;
        line-height: 1.3;
    }

    .header-stats {
        gap: 14px;
        flex-wrap: wrap;
        font-size: 0.8em;
    }

    /* ---- Control panel: off-canvas drawer from the left ---- */
    .control-panel {
        top: 0;
        width: min(85vw, 320px);
        height: 100dvh;
        padding: 96px 20px 24px;
        transform: translateX(-100%);
        transition: transform 0.3s ease-out;
        z-index: 110;
        box-shadow: 5px 0 20px rgba(0, 0, 0, 0.4);
    }

    body.mobile-controls-open .header,
    body.mobile-controls-open .control-panel {
        transform: none;
    }

    .control-section {
        margin-bottom: 24px;
    }

    /* Larger touch targets */
    .btn {
        padding: 12px;
        min-height: 44px;
    }

    input[type="range"] {
        height: 24px;
        background: transparent;
    }

    input[type="range"]::-webkit-slider-runnable-track {
        height: 2px;
        background: var(--border);
    }

    input[type="range"]::-webkit-slider-thumb {
        width: 22px;
        height: 22px;
        margin-top: -10px;
    }

    input[type="range"]::-moz-range-track {
        height: 2px;
        background: var(--border);
    }

    input[type="range"]::-moz-range-thumb {
        width: 22px;
        height: 22px;
    }

    /* ---- Network: full screen ---- */
    #network-container {
        top: 0;
        left: 0;
        right: 0;
        height: 100dvh;
        touch-action: none;
    }

    /* ---- Floating Controls button ---- */
    .mobile-controls-toggle {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 105;
        padding: 10px 14px;
        min-height: 44px;
        background: rgba(21, 25, 37, 0.85);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border: 1px solid var(--border);
        border-radius: 6px;
        color: var(--accent-gold);
        font-family: Arial, sans-serif;
        font-size: 0.8em;
        text-transform: uppercase;
        letter-spacing: 1px;
        cursor: pointer;
    }

    /* Close button sits in the top bar's right corner */
    .mobile-controls-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 10px;
        right: 12px;
        z-index: 130;
        width: 44px;
        height: 44px;
        background: transparent;
        border: 1px solid var(--border);
        border-radius: 6px;
        color: var(--text-primary);
        font-size: 1.2em;
        cursor: pointer;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s;
    }

    body.mobile-controls-open .mobile-controls-close {
        opacity: 1;
        pointer-events: auto;
    }

    /* Dark overlay behind the panel; tapping it closes the panel */
    .mobile-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 108;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
    }

    body.mobile-controls-open .mobile-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    /* ---- Legend: small, bottom-left ---- */
    .legend {
        left: 12px;
        bottom: 12px;
        padding: 10px 12px;
        font-size: 0.75em;
    }

    .legend-title {
        margin-bottom: 6px;
    }

    .legend-item {
        margin: 4px 0;
    }

    .legend-line {
        width: 24px;
        margin-right: 8px;
    }

    /* ---- Character / community drawer: full screen ---- */
    .drawer {
        top: 0;
        right: -100vw;
        width: 100vw;
        height: 100dvh;
        z-index: 200;
    }

    .drawer.open {
        right: 0;
    }

    .drawer-header {
        padding: 14px 16px;
    }

    .drawer-close {
        width: 44px;
        height: 44px;
    }

    .drawer-tab {
        padding: 14px 12px;
    }

    .drawer-content {
        padding: 16px;
    }

    .profile-stats,
    .vocab-stats-grid,
    .comm-stat-grid {
        gap: 10px;
    }

    .cohesion-bar-label {
        width: 100px;
    }

    /* Hover tooltip is not useful on touch screens */
    .tooltip {
        display: none;
    }
}