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

/* Theme variables */
body {
    /* Dark theme (default) */
    --bg-gradient-start: #1e1e2e;
    --bg-gradient-end: #2d2d44;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-heading: #ffffff;
    --panel-bg: rgba(255, 255, 255, 0.05);
    --panel-border: rgba(255, 255, 255, 0.1);
    --control-bg: rgba(255, 255, 255, 0.1);
    --control-hover-bg: rgba(255, 255, 255, 0.15);
    --control-border: rgba(255, 255, 255, 0.2);
    --control-border-hover: rgba(255, 255, 255, 0.3);
    --accent-color: #4a9eff;
    --accent-color-dim: rgba(74, 158, 255, 0.3);
    --canvas-bg: rgba(0, 0, 0, 0.2);
    --canvas-border: none;
    --info-panel-bg: rgba(0, 0, 0, 0.2);
    --pad-label-fill: #ffffff;
    --pin-stroke: rgba(255, 255, 255, 0.3);
    --pin-selected-bg: #000000;
    --shadow-color: rgba(0, 0, 0, 0.5);
    --tooltip-bg: rgba(20, 20, 30, 0.95);
    --tooltip-border: rgba(74, 158, 255, 0.5);
    --segmented-bg: rgba(255, 255, 255, 0.05);
    --segmented-label: rgba(255, 255, 255, 0.7);
    --segmented-label-hover: rgba(255, 255, 255, 0.9);
    --segmented-separator: rgba(255, 255, 255, 0.1);
    --credits-bg: rgba(255, 255, 255, 0.03);
    --credits-hover-bg: rgba(255, 255, 255, 0.05);
    --clear-button-bg: rgba(255, 100, 100, 0.2);
    --row-col-label: #4a9eff;
    --status-ok-color: #00ff00;
    --status-fail-color: #ff0000;
}

body.light-theme {
    /* Light theme */
    --bg-gradient-start: #e8eef7;
    --bg-gradient-end: #c9d6e8;
    --text-primary: #2d3748;
    --text-secondary: #4a5568;
    --text-heading: #1a202c;
    --panel-bg: rgba(255, 255, 255, 0.8);
    --panel-border: rgba(0, 0, 0, 0.1);
    --control-bg: rgba(255, 255, 255, 0.9);
    --control-hover-bg: rgba(240, 244, 248, 1);
    --control-border: rgba(0, 0, 0, 0.15);
    --control-border-hover: rgba(0, 0, 0, 0.25);
    --accent-color: #2563eb;
    --accent-color-dim: rgba(37, 99, 235, 0.2);
    --canvas-bg: rgba(255, 255, 255, 0.5);
    --canvas-border: 2px solid rgba(0, 0, 0, 0.3);
    --info-panel-bg: rgba(0, 0, 0, 0.03);
    --pad-label-fill: #ffffff;
    --pin-stroke: rgba(0, 0, 0, 0.3);
    --pin-selected-bg: #ffffff;
    --shadow-color: rgba(0, 0, 0, 0.15);
    --tooltip-bg: rgba(255, 255, 255, 0.98);
    --tooltip-border: rgba(37, 99, 235, 0.4);
    --segmented-bg: rgba(0, 0, 0, 0.03);
    --segmented-label: rgba(0, 0, 0, 0.6);
    --segmented-label-hover: rgba(0, 0, 0, 0.8);
    --segmented-separator: rgba(0, 0, 0, 0.15);
    --credits-bg: rgba(0, 0, 0, 0.03);
    --credits-hover-bg: rgba(0, 0, 0, 0.05);
    --clear-button-bg: rgba(239, 68, 68, 0.15);
    --row-col-label: #2563eb;
    --status-ok-color: #008000;
    --status-fail-color: #cc0000;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    color: var(--text-primary);
    padding: 15px;
    min-height: 100vh;
    height: 100vh;
    overflow: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1750px;
    margin: 0 auto;
    height: calc(100vh - 30px);
    display: flex;
    flex-direction: column;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-shrink: 0;
}

.header-center {
    flex: 1;
    text-align: center;
}

.credits {
    width: 280px;
    display: flex;
    align-items: center;
}

.credits-link {
    display: flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.9em;
    transition: color 0.3s ease, background 0.3s ease;
    padding: 6px 10px;
    border-radius: 5px;
    background: var(--credits-bg);
}

.credits-link:hover {
    color: #ff0000;
    background: var(--credits-hover-bg);
}

.credits-link svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.feedback {
    width: 320px;
    display: flex;
    justify-content: flex-end;
    text-align: right;
    font-size: 0.8em;
    color: var(--text-secondary);
}

.feedback a {
    color: var(--accent-color);
    text-decoration: none;
    transition: color 0.3s ease;
}

.feedback a:hover {
    color: var(--text-primary);
    text-decoration: underline;
}

h1 {
    color: var(--text-heading);
    font-size: 2em;
    margin-bottom: 5px;
    text-shadow: 2px 2px 4px var(--shadow-color);
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95em;
}

.controls {
    background: var(--panel-bg);
    padding: 20px;
    border-radius: 10px;
    backdrop-filter: blur(10px);
    border: 1px solid var(--panel-border);
    overflow-y: auto;
    max-height: 100%;
}

.control-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 20px;
}

.control-group:last-child {
    margin-bottom: 0;
}

label {
    font-weight: 600;
    color: var(--text-heading);
    margin-bottom: 8px;
    display: block;
}

.control-section-title {
    color: var(--accent-color);
    margin-bottom: 10px;
    font-size: 1.05em;
    border-bottom: 2px solid var(--accent-color-dim);
    padding-bottom: 6px;
    font-weight: 600;
}

.checkbox-container {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
}

.checkbox-container input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--accent-color);
}

.checkbox-container label {
    margin: 0;
    cursor: pointer;
    font-size: 0.95em;
    user-select: none;
}

select {
    padding: 10px 15px;
    font-size: 1em;
    border-radius: 5px;
    border: 1px solid var(--control-border);
    background: var(--control-bg);
    color: var(--text-heading);
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
}

select:hover {
    background: var(--control-hover-bg);
    border-color: var(--control-border-hover);
}

select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px var(--accent-color-dim);
}

/* Segmented control for view mode */
.view-mode-control {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.segmented-control {
    display: flex;
    border-radius: 5px;
    overflow: hidden;
    border: 1px solid var(--control-border);
    background: var(--segmented-bg);
    width: 100%;
}

.segmented-control input[type="radio"] {
    display: none;
}

.segmented-control label {
    padding: 10px 15px;
    font-size: 0.95em;
    font-weight: normal;
    color: var(--segmented-label);
    background: var(--segmented-bg);
    cursor: pointer;
    transition: all 0.3s ease;
    border-right: 1px solid var(--panel-border);
    margin: 0;
    user-select: none;
    flex: 1;
    text-align: center;
}

.segmented-control label:last-child {
    border-right: none;
}

.segmented-control label:hover {
    background: var(--control-hover-bg);
    color: var(--segmented-label-hover);
}

.segmented-control input[type="radio"]:checked + label {
    background: var(--accent-color-dim);
    color: var(--text-heading);
    font-weight: 600;
}

/* Grid layout specific overrides for Filter Pins (2-column grid) */
/* Remove all right borders first */
#pad-filter-control label {
    border-right: none;
}

/* Add right border only to column 1 labels (positions 2, 6, 10, 14, 18) */
/* These are labels at 4n+2 positions */
#pad-filter-control label:nth-child(4n+2) {
    border-right: 1px solid var(--panel-border);
}

.main-content {
    display: grid;
    grid-template-columns: 280px 1fr 320px;
    gap: 15px;
    align-items: stretch;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.viewer-panel {
    background: var(--panel-bg);
    padding: 20px;
    border-radius: 10px;
    backdrop-filter: blur(10px);
    border: 1px solid var(--panel-border);
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    overflow: hidden;
    position: relative;
}

.ic-type-label {
    position: absolute;
    top: 10px;
    left: 10px;
    font-size: 0.9em;
    font-weight: 600;
    color: var(--accent-color);
    background: var(--info-panel-bg);
    padding: 6px 12px;
    border-radius: 5px;
    border: 1px solid var(--accent-color-dim);
    z-index: 5;
}

.rotate-button {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    border: 1px solid var(--control-border);
    background: var(--control-bg);
    color: var(--text-heading);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 10;
}

.rotate-button:hover {
    background: var(--control-hover-bg);
    border-color: var(--control-border-hover);
    transform: scale(1.05);
}

.rotate-button svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

#pinout-canvas {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    display: block;
    background: var(--canvas-bg);
    border: var(--canvas-border);
    border-radius: 8px;
    transition: transform 0.6s ease;
}

.info-panel {
    background: var(--panel-bg);
    padding: 20px;
    border-radius: 10px;
    backdrop-filter: blur(10px);
    border: 1px solid var(--panel-border);
    overflow-y: auto;
    max-height: 100%;
}

.info-section {
    margin-bottom: 20px;
}

.info-section:last-child {
    margin-bottom: 0;
}

.info-section h3 {
    color: var(--accent-color);
    margin-bottom: 10px;
    font-size: 1.05em;
    border-bottom: 2px solid var(--accent-color-dim);
    padding-bottom: 6px;
}

.legend {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.legend-circle {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid var(--pin-stroke);
    flex-shrink: 0;
}

.legend-label {
    font-size: 0.9em;
}

.hint-block {
    font-size: 0.8em;
    line-height: 1.4;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.hint-block strong {
    color: var(--text-secondary);
}

.pin-info {
    background: var(--info-panel-bg);
    padding: 12px;
    border-radius: 8px;
    border-left: 3px solid var(--accent-color);
    font-size: 1.5em;
}

.pin-info-empty {
    color: var(--text-secondary);
    font-style: italic;
    text-align: center;
    padding: 20px;
}

.pin-detail {
    margin-bottom: 8px;
    line-height: 1.5;
    font-size: 0.9em;
}

.pin-detail:last-child {
    margin-bottom: 0;
}

.pin-detail strong {
    color: var(--accent-color);
    display: inline-block;
    min-width: 90px;
}

.selected-count {
    background: var(--accent-color-dim);
    padding: 10px;
    border-radius: 5px;
    text-align: center;
    font-weight: 600;
    margin-top: 15px;
}

.clear-button {
    padding: 6px 12px;
    border-radius: 4px;
    border: 1px solid var(--control-border);
    background: var(--clear-button-bg);
    color: var(--text-heading);
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    transition: all 0.3s ease;
}

.clear-button:hover {
    background: rgba(239, 68, 68, 0.3);
    border-color: var(--control-border-hover);
}

/* SVG Styles */
.pad-circle {
    cursor: pointer;
    transition: all 0.2s ease;
    stroke-width: 2;
}

.pad-circle:hover {
    stroke-width: 3;
    filter: brightness(1.3);
}

.pad-circle.selected {
    fill: var(--pin-selected-bg) !important;
    stroke: #ff0000;
    stroke-width: 1;
}

.pad-label.selected {
    fill: #808080;
}

.pad-circle.filtered-out {
    opacity: 0.15;
    filter: grayscale(100%);
}

.pad-circle.filtered-out:hover {
    opacity: 0.25;
}

.pad-label {
    font-size: 8px;
    font-weight: 600;
    fill: var(--pad-label-fill);
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
    text-shadow: 1px 1px 2px var(--shadow-color);
    transition: opacity 0.2s ease;
}

.pad-label.filtered-out {
    opacity: 0.15;
}

/* Smooth transitions for SVG text elements */
text {
    transition: transform 0.6s ease;
}

.column-label, .row-label {
    font-size: 12px;
    font-weight: 700;
    fill: var(--row-col-label);
    text-anchor: middle;
    dominant-baseline: central;
}

.pad1-indicator {
    filter: drop-shadow(0 0 3px rgba(255, 215, 0, 0.6));
}

/* Tooltip */
.tooltip {
    position: absolute;
    background: var(--tooltip-bg);
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.9em;
    pointer-events: none;
    z-index: 1000;
    border: 1px solid var(--tooltip-border);
    box-shadow: 0 4px 12px var(--shadow-color);
    max-width: 300px;
    display: none;
}

.tooltip.visible {
    display: block;
}

.tooltip-row {
    margin-bottom: 5px;
}

.tooltip-row:last-child {
    margin-bottom: 0;
}

.tooltip-label {
    color: var(--accent-color);
    font-weight: 600;
}

/* Hamburger menu button */
.menu-toggle {
    display: none;
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 1002;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    border: 1px solid var(--control-border);
    background: var(--control-bg);
    color: var(--text-heading);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.menu-toggle:hover {
    background: var(--control-hover-bg);
    border-color: var(--control-border-hover);
}

.menu-toggle svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* Drawer overlay */
.drawer-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.drawer-overlay.active {
    display: block;
    opacity: 1;
}

/* Drawer close button */
.drawer-close {
    display: none;
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    border: 1px solid var(--control-border);
    background: var(--control-bg);
    color: var(--text-heading);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 10;
}

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

.drawer-close svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

@media (max-width: 1400px) {
    .menu-toggle {
        display: flex;
    }
    
    .drawer-close {
        display: flex;
    }
    
    /* Allow scrolling on mobile */
    body {
        height: auto;
        min-height: 100vh;
        overflow: auto;
    }
    
    .container {
        height: auto;
        min-height: calc(100vh - 30px);
    }
    
    .main-content {
        grid-template-columns: 1fr 320px;
        height: auto;
        min-height: 0;
    }
    
    .viewer-panel {
        height: auto;
        min-height: 300px;
        max-height: calc(100vh - 150px); /* Fallback for browsers without dvh support */
        max-height: calc(100dvh - 150px); /* Account for header, margins, and mobile browser bars */
        overflow: auto;
    }
    
    #pinout-canvas {
        max-height: calc(100vh - 200px);
        max-height: calc(100dvh - 200px);
    }
    
    .info-panel {
        height: auto;
        max-height: none;
        overflow-y: visible;
    }
    
    .controls {
        position: fixed;
        top: 0;
        left: -320px;
        width: 300px;
        height: 100vh;
        height: 100dvh; /* Use dynamic viewport height for better mobile support */
        z-index: 1000;
        transition: left 0.3s ease;
        margin: 0;
        border-radius: 0;
        padding-top: 55px;
    }
    
    .controls.open {
        left: 0;
    }
    
    /* Hide email feedback section on mobile */
    .feedback {
        display: none;
    }

    header h1 {
        font-size: 1.3em;
    }

    header .subtitle {
        display: none;
    }

    header {
        flex-direction: column;
        gap: 10px;
    }

    header .credits {
        display: none;
    }

    .tooltip {
        display: none !important;
    }
}

@media (max-width: 1000px) {
    .main-content {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .info-panel {
        margin-bottom: 20px;
    }

    #damaged-connections-section {
        margin-bottom: 0;
    }

    #damaged-connections-section .hint-block {
        display: none;
    }

    #damaged-connections-section .pin-info-empty {
        padding: 5px;
    }

    #damaged-connections-section .selected-count {
        padding: 5px;
    }

    #legend-section {
        display: none;
    }
}
