body.initial-load *,
body.initial-load *::before,
body.initial-load *::after {
    transition: none !important;
    animation: none !important;
}

body {
    font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #0a0a0a;
    color: #eee;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    /* Dynamic viewport height for mobile */
    margin: 0;
    padding: 40px 20px;
    box-sizing: border-box;
    overflow-y: auto;
    -webkit-tap-highlight-color: transparent;
}

h2 {
    margin-bottom: 5px;
    font-weight: 300;
    letter-spacing: 1px;
    color: #fff;
    margin-top: 0;
}

p {
    color: #666;
    font-size: 0.8rem;
    margin-bottom: 0;
}

#header {
    margin-bottom: 40px;
    text-align: center;
    width: 90%;
    max-width: 1400px;
    position: relative;
}

#user-display {
    position: absolute;
    top: 0;
    right: 0;
    font-size: 11px;
    color: #888;
    background: #1a1a1a;
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid #333;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
    -webkit-user-select: none;
}

#user-display:hover {
    color: #fff;
    border-color: #3b82f6;
    background: #222;
}

#user-display span {
    color: #3b82f6;
    font-weight: bold;
}

#graph-container {
    position: relative;
    width: 90%;
    max-width: 1400px;
    height: calc(100vh - 250px);
    min-height: 350px;
    border-bottom: 1px solid #666;
    background: linear-gradient(to bottom, #111 0%, #050505 100%);
    margin-bottom: 40px;
    transition: background 3s;
}

/* Y-Axis Indicator */
.y-axis-gradient {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(to top, #ff3d00 0%, #ffea00 50%, #00e676 100%);
    border-radius: 2px;
    opacity: 0.8;
    transition: opacity 3s;
}

/* Axis Labels */
.axis-label {
    position: absolute;
    color: #888;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: opacity 3s;
    user-select: none;
    -webkit-user-select: none;
}

.x-label-left {
    bottom: -40px;
    left: 0;
}

.x-label-right {
    bottom: -40px;
    right: 0;
}

.y-label-top {
    top: -25px;
    left: -10px;
    color: #00e676;
}

.y-label-bottom {
    bottom: 0px;
    left: -80px;
    color: #ff3d00;
    width: 70px;
    text-align: right;
}

/* Top Right Controls Group */
#top-right-controls {
    position: absolute;
    top: -34px;
    right: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 1000;
    pointer-events: none; /* Don't block clicks on graph behind this row */
}

/* Re-enable pointer events for all direct children */
#top-right-controls > * {
    pointer-events: auto;
}

/* Add Button */
#add-item-btn {
    position: relative;
    background: #3b82f6;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    height: 34px;
    line-height: 32px;
    user-select: none;
    -webkit-user-select: none;
    transition: background 0.2s, transform 0.2s;
    border: none;
    padding: 0 16px;
    border-radius: 4px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

#add-item-btn:hover {
    background: #2563eb;
    transform: translateY(-1px);
}

#add-item-btn:active {
    transform: translateY(1px);
}

/* Branch Filter */
#branch-filter-container {
    position: relative;
    z-index: 1001; /* Above other filter items if needed */
}

#branch-filter-btn {
    color: #888;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    height: 34px;
    line-height: 32px; /* Adjusted for border */
    user-select: none;
    -webkit-user-select: none;
    transition: color 0.2s;
    border: 1px solid #333;
    padding: 0 10px;
    border-radius: 4px;
    background: #111;
    box-sizing: border-box;
}

#branch-filter-btn:hover, #branch-filter-btn.active {
    color: #fff;
    border-color: #666;
    background: #222;
}

#branch-filter-dropdown {
    position: absolute;
    top: 30px;
    right: 0;
    background: #1a1a1a;
    border: 1px solid #444;
    border-radius: 6px;
    width: 200px;
    max-height: 300px;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 1);
    padding: 10px;
    display: none;
}

.branch-checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 12px;
    color: #ccc;
    cursor: pointer;
}

.branch-checkbox-item input {
    cursor: pointer;
}

.branch-checkbox-item:hover {
    color: #fff;
}

/* View Mode Button */
#view-mode-btn {
    position: relative;
    color: #888;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    height: 34px;
    line-height: 32px;
    user-select: none;
    -webkit-user-select: none;
    transition: color 0.2s;
    border: 1px solid #333;
    padding: 0 10px;
    border-radius: 4px;
    box-sizing: border-box;
}

#view-mode-btn:hover {
    color: #fff;
    border-color: #666;
}

#view-mode-btn:active {
    background: #333;
}

#view-mode-btn.hint-glow {
    box-shadow: 0 0 15px #3b82f6, 0 0 5px #3b82f6;
    border-color: #3b82f6;
    animation: pulse-glow 2s infinite;
    color: #fff;
}

@keyframes pulse-glow {
    0% {
        box-shadow: 0 0 5px rgba(59, 130, 246, 0.5);
    }

    50% {
        box-shadow: 0 0 20px rgba(59, 130, 246, 0.9);
    }

    100% {
        box-shadow: 0 0 5px rgba(59, 130, 246, 0.5);
    }
}

.mode-hint {
    position: absolute;
    top: -65px;
    right: 30px;
    background: #3b82f6;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: bold;
    white-space: nowrap;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.5s;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

.mode-hint::after {
    content: "";
    position: absolute;
    bottom: -6px;
    right: 20px;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid #3b82f6;
}

.mode-hint.visible {
    opacity: 1;
}

/* Subtle Master Reset Button */
#global-reset-btn {
    display: none;
    position: fixed;
    bottom: 10px;
    left: 10px;
    background: #222;
    color: #666;
    border: 1px solid #333;
    min-height: 28px;
    height: 28px;
    line-height: 26px;
    padding: 0 10px;
    box-sizing: border-box;
    border-radius: 4px;
    cursor: pointer;
    z-index: 1000;
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
    transition: all 0.2s;
}

#global-reset-btn:hover {
    background: #333;
    color: #ccc;
    border-color: #555;
}

/* --- SEARCH BAR --- */
#search-container {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #111;
    border: 1px solid #333;
    padding: 0 10px;
    border-radius: 4px;
    transition: all 0.3s;
    height: 34px;
    box-sizing: border-box;
}

#search-container:focus-within {
    border-color: #3b82f6;
    background: #1a1a1a;
}

#search-input {
    background: transparent;
    border: none;
    color: #eee;
    font-size: 16px;
    padding: 4px 0;
    width: 80px;
    outline: none;
    transition: width 0.3s;
}

#search-input:focus {
    width: 150px;
}

#search-icon {
    font-size: 14px;
    color: #888;
}

/* SEARCH DIMMING */
.searching .dot,
.searching .voter-dot,
.searching .connection-line {
    opacity: 0.1 !important;
}

.searching .dot.search-match,
.searching .voter-dot.search-match {
    opacity: 1 !important;
    z-index: 500;
}

.searching .dot.search-match .dot-label {
    color: #fff;
    opacity: 1 !important;
}

.searching .dot.search-match .voter-username {
    opacity: 1 !important;
}

.grid-line {
    position: absolute;
    background: #222;
    pointer-events: none;
    transition: opacity 3s;
}

.grid-x {
    width: 100%;
    height: 1px;
}

.grid-y {
    height: 100%;
    width: 1px;
}

/* --- SVG LAYER (Lines) --- */
#connections-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

.connection-line {
    stroke: #3b82f6;
    stroke-width: 0.5px;
    stroke-dasharray: 1 1;
    opacity: 0.6;
    vector-effect: non-scaling-stroke;
    transition: opacity 0.5s;
}

/* --- SPLASH ANIMATION --- */
.splash {
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.1);
    transform: translate(-50%, 50%);
    pointer-events: none;
    z-index: 15;
    animation: ripple 0.6s ease-out forwards;
}

.mega-splash {
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 4px solid #fff;
    background: rgba(255, 255, 255, 0.8);
    transform: translate(-50%, 50%);
    pointer-events: none;
    z-index: 200;
    animation: mega-ripple 1.2s ease-out forwards;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

@keyframes ripple {
    0% {
        transform: translate(-50%, 50%) scale(0.2);
        opacity: 1;
        border-width: 4px;
    }

    100% {
        transform: translate(-50%, 50%) scale(2.5);
        opacity: 0;
        border-width: 0px;
    }
}

@keyframes mega-ripple {
    0% {
        transform: translate(-50%, 50%) scale(0.1);
        opacity: 1;
        border-width: 10px;
    }

    50% {
        opacity: 0.8;
    }

    100% {
        transform: translate(-50%, 50%) scale(8);
        opacity: 0;
        border-width: 0px;
    }
}

/* --- CONSENSUS DOT (The Average) --- */
.dot {
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    cursor: grab;
    transform: translate(-50%, 50%);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.8);
    z-index: 10;
    border: 2px solid #fff;
    transition:
        bottom 3s ease-in-out,
        transform 0.2s,
        left 0.2s,
        background-color 3s,
        box-shadow 3s;
    background-color: #fff;
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
}

/* Invisible touch target expansion */
.dot::before {
    content: "";
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
}

.dot:active {
    cursor: grabbing;
}

.dot:hover,
.dot.force-tooltip {
    z-index: 100;
    transform: translate(-50%, 50%) scale(1.2);
    border-color: #fff;
}

.dot.ready-high {
    background-color: #00e676;
    box-shadow: 0 0 10px rgba(0, 230, 118, 0.4);
}

.dot.ready-mid {
    background-color: #ffea00;
    box-shadow: 0 0 10px rgba(255, 234, 0, 0.4);
}

.dot.ready-low {
    background-color: #ff3d00;
    box-shadow: 0 0 10px rgba(255, 61, 0, 0.4);
}

/* --- USER VOTE DOT (Personal) --- */
.user-dot {
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    cursor: grab;
    transform: translate(-50%, 50%);
    background: transparent;
    border: 2px solid #3b82f6;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.5),
        inset 0 0 4px rgba(59, 130, 246, 0.5);
    z-index: 20;
    display: none;
    transition: bottom 3s ease-in-out;
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
}

/* Invisible touch target expansion */
.user-dot::before {
    content: "";
    position: absolute;
    top: -12px;
    left: -12px;
    right: -12px;
    bottom: -12px;
}

.user-dot::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 4px;
    height: 4px;
    background: #3b82f6;
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

.user-dot:hover {
    transform: translate(-50%, 50%) scale(1.2);
    background: rgba(59, 130, 246, 0.1);
}

.user-dot:active {
    cursor: grabbing;
}

/* --- OTHER VOTER DOTS --- */
.voter-dot {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    transform: translate(-50%, 50%);
    background: rgba(59, 130, 246, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.3);
    z-index: 15;
    pointer-events: none;
    opacity: 0;
    transition:
        opacity 2s ease-in-out,
        bottom 3s ease-in-out,
        left 3s ease-in-out;
}

.voter-dot.visible {
    opacity: 1;
}

.voter-username {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 9px;
    color: #3b82f6;
    white-space: nowrap;
    pointer-events: none;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0;
    transition: opacity 2s ease-in-out;
}

.voter-username.visible {
    opacity: 0.8;
}

.user-dot .voter-username {
    color: #fff;
    font-size: 10px;
    font-weight: bold;
    bottom: 18px;
    transition:
        opacity 2s ease-in-out,
        bottom 3s ease-in-out,
        left 3s ease-in-out;
}

.user-dot .voter-username.visible {
    opacity: 1;
}

/* DRAGGING OVERRIDE: Must be very specific to beat the 3s transition */
.dot.dragging,
.user-dot.dragging {
    transition: none !important;
}

/* --- LABELS --- */
.dot-label {
    position: absolute;
    white-space: nowrap;
    font-size: 13px;
    color: #bbb;
    font-weight: 400;
    pointer-events: none;
    letter-spacing: 0.5px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 1);
    z-index: -1;
    /* Transition position smoothly but NOT transform — overlap adjustment
       should be instant so labels don't appear to drift from their dots */
    transition: left 3s ease-in-out, bottom 3s ease-in-out, opacity 0.5s;
    left: 50%;
    top: 50%;
    transform-origin: left center;
    transform: rotate(45deg) translate(10px, 0);
}

.label-below {
    /* default — JS will override with calculated offset */
}

/* label-above kept as no-op for backwards compat */
.label-above {
    /* default — JS will override with calculated offset */
}

/* Tooltip */
.tooltip {
    position: absolute;
    visibility: hidden;
    opacity: 0;
    background: rgba(20, 20, 20, 0.95);
    border: 1px solid #444;
    padding: 12px 16px;
    border-radius: 6px;
    width: 260px;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    color: #ddd;
    font-size: 13px;
    line-height: 1.5;
    pointer-events: none; /* Hidden tooltips must NOT intercept mouse/drag events */
    box-shadow: 0 10px 30px rgba(0, 0, 0, 1);
    transition:
        opacity 0.2s,
        visibility 0.2s;
    z-index: 200;
    text-align: left;
}

.tooltip::after {
    content: "";
    position: absolute;
    bottom: -24px;
    height: 24px;
    left: 0;
    width: 100%;
    background: transparent;
    pointer-events: none; /* Must not block graph interaction below */
}

.tooltip strong {
    display: block;
    color: #fff;
    margin-bottom: 4px;
    font-size: 14px;
}

/* TOOLTIP TRIGGER - Desktop hover */
.dot:hover .tooltip,
.dot.force-tooltip .tooltip {
    visibility: visible;
    opacity: 1;
    pointer-events: auto; /* Allow clicking Edit/Delete buttons when visible */
}

/* TOOLTIP TRIGGER - Mobile tap */
.dot.tooltip-active .tooltip {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}

/* ADMIN TOOLTIP CONTROLS */
.admin-controls {
    margin-top: 10px;
    border-top: 1px solid #444;
    padding-top: 8px;
    display: flex;
    justify-content: space-between;
    gap: 5px;
}

.admin-btn {
    background: #333;
    border: 1px solid #555;
    color: #ccc;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 3px;
    cursor: pointer;
    text-transform: uppercase;
}

.admin-btn:hover {
    background: #555;
    color: white;
}

.admin-btn.delete {
    color: #f87171;
    border-color: #7f1d1d;
}

.admin-btn.delete:hover {
    background: #7f1d1d;
}

/* --- MODAL --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    padding: 20px;
    box-sizing: border-box;
}

.modal-content {
    background: #1a1a1a;
    border: 1px solid #333;
    padding: 30px;
    border-radius: 12px;
    width: 320px;
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 1);
    -webkit-overflow-scrolling: touch;
}

.modal-content h3 {
    margin-top: 0;
    color: #fff;
    font-weight: 300;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    color: #888;
    font-size: 12px;
    margin-bottom: 5px;
}

.form-group input[type="text"] {
    width: 100%;
    box-sizing: border-box;
    padding: 10px;
    background: #222;
    border: 1px solid #444;
    color: #fff;
    border-radius: 4px;
    font-size: 16px;
}

.checkbox-scroll-list {
    max-height: 150px;
    overflow-y: auto;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 10px;
    background: #222;
}

.form-group input[type="range"] {
    width: 100%;
    margin: 10px 0;
    height: 30px;
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: #555;
    text-transform: uppercase;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 20px;
    gap: 10px;
}

button {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background: #333;
    color: #ccc;
    font-size: 14px;
    min-height: 44px;
    min-width: 44px;
}

button:hover {
    background: #444;
}

button:active {
    background: #555;
}

.primary-btn {
    background: #3b82f6;
    color: #fff;
}

.primary-btn:hover {
    background: #2563eb;
}

.primary-btn:active {
    background: #1d4ed8;
}

/* ========================================= */
/*               1D MODE STYLES              */
/* ========================================= */

.mode-1d .y-axis-gradient {
    opacity: 0;
}

.mode-1d .axis-label.y-label-top,
.mode-1d .axis-label.y-label-bottom {
    opacity: 0;
}

.mode-1d .grid-y {
    opacity: 0;
}

.mode-1d .dot,
.mode-1d .user-dot {
    bottom: 50% !important;
    background-color: #888 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.8) !important;
}

.mode-1d .user-dot {
    background-color: transparent !important;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.5),
        inset 0 0 4px rgba(59, 130, 246, 0.5) !important;
}

.mode-1d .connection-line {
    opacity: 0;
}

/* 1D MODE: FORCE ALL LABELS TO POINT DOWN-RIGHT */
.mode-1d .dot-label {
    transform: rotate(45deg) translate(15px, 0) !important;
}

/* ========================================= */
/*           RESPONSIVE / MOBILE            */
/* ========================================= */

/* Tablet */
@media (max-width: 900px) {
    body {
        padding: 20px 10px;
    }

    #graph-container {
        width: 95%;
        height: calc(100vh - 200px);
    }

    .tooltip {
        width: 220px;
        padding: 10px 12px;
    }

    .axis-label {
        font-size: 10px;
    }
}

/* Mobile - NO SCROLL LAYOUT */
@media (max-width: 600px) {

    html,
    body {
        /* Allow scrolling and zooming */
        width: 100%;
        overflow-x: auto;
    }

    body {
        padding: 0;
        margin: 0;
        justify-content: flex-start;
    }

    #header {
        margin: 0;
        padding: 8px 15px;
        width: 100%;
        box-sizing: border-box;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        background: #0a0a0a;
        flex-shrink: 0;
        border-bottom: 1px solid #222;
    }

    #header h2 {
        font-size: 1rem;
        margin: 0;
        white-space: nowrap;
    }

    #header p {
        display: none;
        /* Hide subtitle on mobile */
    }

    #user-display {
        position: relative;
        top: auto;
        right: auto;
        margin: 0;
        font-size: 10px;
        padding: 3px 8px;
    }

    #graph-container {
        width: 100%;
        min-width: 800px;
        height: calc(100dvh - 45px);
        /* Full height minus header */
        height: calc(100vh - 45px);
        /* Fallback */
        margin: 0;
        padding-right: 20px;
        /* buffer for scrolling */
        border: none;
        border-radius: 0;
        flex-grow: 1;
    }

    /* Controls - overlay inside graph container */
    #add-item-btn,
    #view-mode-btn,
    #search-container {
        top: 10px;
        bottom: auto;
        z-index: 100;
    }

    #add-item-btn {
        right: 10px;
        font-size: 24px;
        padding: 8px;
        background: rgba(0, 0, 0, 0.6);
        border-radius: 8px;
    }

    #view-mode-btn {
        right: 55px;
        font-size: 11px;
        padding: 6px 10px;
        line-height: 16px;
        background: rgba(0, 0, 0, 0.6);
    }

    #search-container {
        left: 10px;
        right: auto;
        padding: 4px 8px;
        background: rgba(0, 0, 0, 0.6);
    }

    #search-input {
        width: 60px;
        font-size: 14px;
    }

    #search-input:focus {
        width: 100px;
    }

    /* Axis labels - compact inside graph */
    .axis-label {
        font-size: 7px;
        letter-spacing: 0;
        opacity: 0.5;
    }

    .x-label-left {
        bottom: 8px;
        left: 10px;
    }

    .x-label-right {
        bottom: 8px;
        right: 10px;
    }

    .y-label-top {
        top: 50px;
        /* Below controls */
        left: 8px;
    }

    .y-label-bottom {
        bottom: 25px;
        left: 8px;
        width: auto;
        text-align: left;
    }

    /* Y-axis gradient - inside graph */
    .y-axis-gradient {
        left: 3px;
        top: 45px;
        bottom: 20px;
        width: 2px;
        opacity: 0.4;
    }

    /* Larger touch targets for dots */
    .dot {
        width: 18px;
        height: 18px;
    }

    .dot::before {
        top: -15px;
        left: -15px;
        right: -15px;
        bottom: -15px;
    }

    .user-dot {
        width: 22px;
        height: 22px;
    }

    .user-dot::before {
        top: -15px;
        left: -15px;
        right: -15px;
        bottom: -15px;
    }

    .user-dot::after {
        width: 5px;
        height: 5px;
    }

    /* Labels */
    .dot-label {
        font-size: 10px;
    }

    /* Tooltips - bottom sheet */
    .tooltip {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        width: 100% !important;
        max-width: none !important;
        transform: none !important;
        border-radius: 16px 16px 0 0;
        padding: 16px 20px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        z-index: 500;
        box-sizing: border-box;
        font-size: 13px;
        max-height: 40vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .tooltip::after {
        display: none;
    }

    .tooltip strong {
        font-size: 15px;
        margin-bottom: 6px;
    }

    /* Modals - bottom sheet style */
    .modal-overlay {
        padding: 0;
        align-items: flex-end;
    }

    .modal-content {
        width: 100%;
        max-width: none;
        padding: 20px;
        padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
        max-height: 80vh;
        max-height: 80dvh;
        border-radius: 16px 16px 0 0;
        margin: 0;
    }

    .modal-content h3 {
        font-size: 16px;
    }

    .form-group input[type="text"] {
        padding: 12px;
    }

    .form-group input[type="range"] {
        height: 36px;
    }

    /* Voter dots */
    .voter-dot {
        width: 10px;
        height: 10px;
    }

    .voter-username {
        font-size: 7px;
    }

    .user-dot .voter-username {
        font-size: 8px;
        bottom: 20px;
    }

    /* Admin controls */
    .admin-controls {
        flex-wrap: wrap;
        gap: 6px;
    }

    .admin-btn {
        padding: 8px 12px;
        font-size: 11px;
        flex: 1;
        text-align: center;
        min-height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Global reset button - move to top */
    #global-reset-btn {
        position: absolute;
        top: 10px;
        bottom: auto;
        left: auto;
        right: 100px;
        font-size: 7px;
        padding: 4px 6px;
        min-height: 28px;
        background: rgba(0, 0, 0, 0.6);
    }

    /* Modal buttons */
    .modal-actions {
        flex-direction: column;
        gap: 8px;
    }

    .modal-actions button {
        width: 100%;
        padding: 12px;
        font-size: 15px;
    }

    /* Grid lines */
    .grid-x {
        opacity: 0.3;
    }

    .grid-y {
        opacity: 0.3;
    }
}

/* Very small screens (iPhone SE, etc) */
@media (max-width: 380px) {
    #header h2 {
        font-size: 0.85rem;
    }

    #user-display {
        font-size: 9px;
        padding: 2px 6px;
    }

    .dot-label {
        font-size: 8px;
    }

    .tooltip {
        font-size: 12px;
        padding: 12px 14px;
    }

    .tooltip strong {
        font-size: 14px;
    }

    #search-container {
        display: none;
        /* Hide search on very small screens */
    }

    #view-mode-btn {
        right: 45px;
        font-size: 10px;
        padding: 4px 8px;
    }

    #add-item-btn {
        font-size: 22px;
    }

    #global-reset-btn {
        right: 80px;
        font-size: 6px;
        padding: 3px 5px;
    }

    .axis-label {
        font-size: 6px;
    }
}

/* Landscape mobile - also no scroll */
@media (max-height: 500px) and (orientation: landscape) {

    html,
    body {
        /* Allow scrolling */
        width: 100%;
        overflow-x: auto;
        overflow-y: auto;
    }

    body {
        padding: 0;
    }

    #header {
        padding: 4px 15px;
    }

    #header h2 {
        font-size: 0.85rem;
    }

    #graph-container {
        height: calc(100dvh - 35px);
        height: calc(100vh - 35px);
        min-height: 500px;
        min-width: 800px;
    }

    .tooltip {
        max-height: 50vh;
        max-height: 50dvh;
    }

    .modal-content {
        max-height: 90vh;
        max-height: 90dvh;
    }

    .axis-label {
        font-size: 6px;
    }

    .dot-label {
        font-size: 8px;
    }

    /* Controls even more compact */
    #add-item-btn,
    #view-mode-btn,
    #search-container {
        top: 5px;
    }

    .y-label-top {
        top: 35px;
    }

    .y-axis-gradient {
        top: 30px;
    }
}

/* ========================================= */
/*        TOUCH DEVICE OPTIMIZATIONS        */
/* ========================================= */

@media (hover: none) and (pointer: coarse) {

    /* Remove hover states that don't work on touch */
    .dot:hover {
        transform: translate(-50%, 50%);
        z-index: 10;
    }

    .dot:hover .tooltip {
        visibility: hidden;
        opacity: 0;
    }

    .user-dot:hover {
        transform: translate(-50%, 50%);
        background: transparent;
    }

    /* Add active states instead */
    .dot:active {
        transform: translate(-50%, 50%) scale(1.3);
        z-index: 100;
    }

    .user-dot:active {
        transform: translate(-50%, 50%) scale(1.3);
        background: rgba(59, 130, 246, 0.2);
    }

    /* Tooltip shown via JS class on tap */
    .dot.tooltip-active {
        z-index: 100;
    }

    .dot.tooltip-active .tooltip {
        visibility: visible;
        opacity: 1;
    }

    /* Disable text selection during drag */
    #graph-container {
        -webkit-user-select: none;
        user-select: none;
    }

    /* Remove hover effect on buttons */
    button:hover {
        background: #333;
    }

    .primary-btn:hover {
        background: #3b82f6;
    }

    button:active {
        background: #555;
    }

    .primary-btn:active {
        background: #1d4ed8;
    }
}

/* ========================================= */
/*         SAFE AREA (NOTCHED PHONES)       */
/* ========================================= */

@supports (padding: env(safe-area-inset-bottom)) {
    @media (max-width: 600px) {
        #graph-container {
            padding-bottom: env(safe-area-inset-bottom);
        }

        .y-label-bottom {
            bottom: calc(25px + env(safe-area-inset-bottom));
        }

        .x-label-left,
        .x-label-right {
            bottom: calc(8px + env(safe-area-inset-bottom));
        }
    }
}

/* ========================================= */
/*          REDUCED MOTION SUPPORT          */
/* ========================================= */

@media (prefers-reduced-motion: reduce) {

    .dot,
    .user-dot,
    .voter-dot,
    .tooltip,
    .y-axis-gradient,
    .axis-label,
    .grid-line,
    #graph-container {
        transition: none !important;
    }

    .splash,
    .mega-splash {
        animation: none !important;
        display: none;
    }
}

/* ========================================= */
/*              PRINT STYLES                */
/* ========================================= */

@media print {

    html,
    body {
        overflow: visible !important;
        position: static !important;
        height: auto !important;
    }

    body {
        background: white;
        color: black;
    }

    #graph-container {
        background: white;
        border: 1px solid #ccc;
        height: 80vh;
    }

    .tooltip,
    #add-item-btn,
    #view-mode-btn,
    #search-container,
    #global-reset-btn,
    .modal-overlay {
        display: none !important;
    }

    .dot {
        border-color: #333;
    }

    .dot-label {
        color: #333;
        text-shadow: none;
    }
}

/* --- ADMIN SWITCH --- */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #333;
    transition: .4s;
    border: 1px solid #444;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: #666;
    transition: .4s;
}

input:checked+.slider {
    background-color: #059669;
}

input:focus+.slider {
    box-shadow: 0 0 1px #059669;
}

input:checked+.slider:before {
    transform: translateX(20px);
    background-color: #fff;
}

.slider.round {
    border-radius: 24px;
}

.slider.round:before {
    border-radius: 50%;
}

/* --- TOAST NOTIFICATION --- */
#toast-container {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.toast {
    background: rgba(20, 20, 20, 0.9);
    color: #fff;
    padding: 10px 20px;
    border-radius: 30px;
    font-size: 14px;
    border: 1px solid #444;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    animation: toast-in-out 3s forwards;
    white-space: nowrap;
}

@keyframes toast-in-out {
    0% {
        transform: translateY(20px);
        opacity: 0;
    }

    10% {
        transform: translateY(0);
        opacity: 1;
    }

    90% {
        transform: translateY(0);
        opacity: 1;
    }

    100% {
        transform: translateY(-20px);
        opacity: 0;
    }
}