@font-face {
    font-family: 'DottedSongtiSquare';
    src: url('fonts/DottedSongtiSquareRegular.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
}

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

body {
    font-family: 'DottedSongtiSquare', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #2d2d2d;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    padding: 0;
    margin: 0;
}

.container {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
}

.viewport {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
    cursor: grab;
    /* Prevent text selection during drag */
    user-select: none;
    -webkit-user-select: none;
}

.viewport.dragging {
    cursor: grabbing;
}

.content-wrapper {
    transform-origin: 0 0;
    transition: transform 0.1s ease-out;
    will-change: transform;
}

h1 {
    text-align: center;
    color: white;
    font-size: 2.5rem;
    margin-bottom: 50px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    padding-top: 20px;
}

.section-title {
    text-align: center;
    color: rgba(255, 255, 255, 0.92);
    font-size: 1.6rem;
    margin: 30px 0 18px;
    letter-spacing: 0.5px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.18);
}

.gallery {
    display: flex;
    flex-direction: column;
    gap: 30px; /* vertical gap between rows */
    align-items: center;
    padding: 0 20px;
}

.image-row {
    display: flex;
    gap: 25px; /* horizontal gap between images */
    flex-wrap: nowrap;
}

/* Row A and Row B: Offsets controlled by JavaScript */
.row-a {
    margin-left: 0; /* Default, will be overridden by JavaScript */
}

.row-b {
    margin-left: 162.5px; /* Default, will be overridden by JavaScript */
}

.image-item {
    background: transparent;
    border-radius: 12px;
    overflow: visible;
    box-shadow: none;
    transition: transform 0.3s ease, margin-left 0.1s ease, margin-top 0.1s ease;
    position: relative;
    z-index: 10;
    pointer-events: none; /* Container doesn't capture events */
    flex-shrink: 0;
    width: 300px;
}

.image-item.hover-active {
    transform: translateY(-5px);
    box-shadow: none;
}

.image-item img {
    display: block;
    width: 300px;
    height: auto;
    max-width: 300px;
    /* Create 1px white stroke using optimized drop-shadow (only 4 directions for better performance) */
    /* Format: drop-shadow(x-offset y-offset blur-radius color) */
    filter: drop-shadow(0px 0 0 white)      /* RIGHT: 1px to the right */
            drop-shadow(-0px 0 0 white)      /* LEFT: 1px to the left */
            drop-shadow(0 0px 0 white)       /* DOWN: 1px downward */
            drop-shadow(0 -1px 0 white);     /* UP: 1px upward */
    /* GPU acceleration for better performance */
    transform: translateZ(0);
    backface-visibility: hidden;
    position: relative;
    z-index: 10;
    pointer-events: none; /* Image doesn't capture events - click zone overlay does */
}

/* Clickable zone overlay - used for crosshair hit detection */
.image-item .click-zone-area {
    position: absolute;
    top: var(--click-zone-top, 25%);
    left: var(--click-zone-left, 25%);
    width: var(--click-zone-width, 50%);
    height: var(--click-zone-height, 50%);
    pointer-events: none; /* Crosshair system handles all clicks */
    z-index: 200;
    background: transparent;
}


/* Responsive adjustments */
@media (max-width: 1200px) {
    .image-item {
        width: 250px;
    }
    .image-item img {
        width: 250px;
        max-width: 250px;
    }
}

@media (max-width: 768px) {
    h1 {
        font-size: 2rem;
        margin-bottom: 30px;
    }

    .gallery {
        gap: 20px;
    }
    
    .image-row {
        gap: 15px;
    }

    .image-item {
        width: 250px;
    }
    .image-item img {
        width: 250px;
        max-width: 250px;
    }
}

@media (max-width: 480px) {
    .image-item {
        width: 100%;
        max-width: 100%;
    }
    .image-item img {
        width: 100%;
        max-width: 100%;
    }
}

/* Zoom Controls */
.zoom-controls {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Debug Controls */
.debug-controls {
    position: fixed;
    bottom: 20px;
    left: 90px;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.debug-button {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: background 0.2s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #667eea;
    font-family: 'DottedSongtiSquare', sans-serif;
}

.debug-button:hover {
    background: white;
    transform: scale(1.05);
}

.debug-button:active {
    transform: scale(0.95);
}

.debug-button.active {
    background: #667eea;
    color: white;
}

.debug-panel {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    min-width: 320px;
    max-height: 85vh;
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.3);
    display: none;
    font-family: 'DottedSongtiSquare', sans-serif;
}

.debug-controls.active .debug-panel {
    display: block;
}

.debug-panel .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.debug-panel h3 {
    margin: 0;
    color: #333;
    font-size: 1.1rem;
    font-weight: 600;
}

.zone-section {
    margin-bottom: 15px;
}

.zone-section h4 {
    margin: 0 0 10px 0;
    color: #667eea;
    font-size: 0.95rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.zone-divider {
    height: 1px;
    background: linear-gradient(to right, transparent, #e0e0e0, transparent);
    margin: 20px 0;
}

/* Toggle Switch Styles */
.toggle-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    position: relative;
}

.toggle-label input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    background: #ccc;
    border-radius: 12px;
    transition: background 0.3s ease;
    flex-shrink: 0;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: white;
    top: 3px;
    left: 3px;
    transition: transform 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-label input[type="checkbox"]:checked + .toggle-switch {
    background: #667eea;
}

.toggle-label input[type="checkbox"]:checked + .toggle-switch::after {
    transform: translateX(20px);
}

.toggle-label:hover .toggle-switch {
    background: #bbb;
}

.toggle-label input[type="checkbox"]:checked:hover + .toggle-switch {
    background: #5568d3;
}

/* Detection Boundary Visualization */
.image-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease, top 0.2s ease, left 0.2s ease, width 0.2s ease, height 0.2s ease;
    z-index: 100;
}

.image-item.show-boundaries.show-image-boundary::before {
    opacity: 1;
    border: 3px solid rgba(255, 0, 0, 0.6);
    box-shadow: inset 0 0 0 3px rgba(255, 0, 0, 0.3);
}

.image-item::after {
    content: '';
    position: absolute;
    top: var(--click-zone-top, 25%);
    left: var(--click-zone-left, 25%);
    width: var(--click-zone-width, 50%);
    height: var(--click-zone-height, 50%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease, top 0.2s ease, left 0.2s ease, width 0.2s ease, height 0.2s ease;
    z-index: 101;
}

.image-item.show-boundaries.show-click-zone::after {
    opacity: 1;
    border: 3px solid rgba(0, 255, 0, 0.8);
    background: rgba(0, 255, 0, 0.1);
    box-shadow: 0 0 0 2px rgba(0, 255, 0, 0.4);
}

/* Hover zone overlay */
.image-item .hover-zone-overlay {
    content: '';
    position: absolute;
    top: var(--hover-zone-top, 35%);
    left: var(--hover-zone-left, 35%);
    width: var(--hover-zone-width, 30%);
    height: var(--hover-zone-height, 30%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease, top 0.2s ease, left 0.2s ease, width 0.2s ease, height 0.2s ease;
    z-index: 102;
    border: 3px solid rgba(0, 150, 255, 0.8);
    background: rgba(0, 150, 255, 0.15);
    box-shadow: 0 0 0 2px rgba(0, 150, 255, 0.4);
}

.image-item.show-boundaries.show-hover-zone .hover-zone-overlay {
    opacity: 1;
}

/* Labels for debugging */
.boundary-label {
    position: absolute;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: bold;
    pointer-events: none;
    z-index: 102;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.image-item.show-boundaries.show-zone-labels .boundary-label {
    opacity: 1;
}

.boundary-label.click-zone {
    top: 25%;
    left: 50%;
    transform: translate(-50%, -30px);
    color: #00ff00;
}

.boundary-label.hover-zone {
    top: var(--hover-zone-top, 35%);
    left: 50%;
    transform: translate(-50%, -30px);
    color: #0096ff;
}

@media (max-width: 768px) {
    .debug-controls {
        left: 15px;
        bottom: 90px;
    }
    
    .debug-panel {
        min-width: 240px;
        padding: 15px;
    }
}

.zoom-button {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: none;
    border-radius: 8px;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: background 0.2s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #667eea;
    font-weight: bold;
    font-family: 'DottedSongtiSquare', sans-serif;
}

.zoom-button:hover {
    background: white;
    transform: scale(1.05);
}

.zoom-button:active {
    transform: scale(0.95);
}

.zoom-level {
    width: 50px;
    height: 30px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: #333;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    font-family: 'DottedSongtiSquare', sans-serif;
}

/* Spacing Controls */
.spacing-controls {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}

.control-panel {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    min-width: 250px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    font-family: 'DottedSongtiSquare', sans-serif;
}

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

.control-panel h3 {
    margin: 0;
    color: #333;
    font-size: 1.1rem;
    font-weight: 600;
}

.minimize-button {
    width: 30px;
    height: 30px;
    background: rgba(102, 126, 234, 0.1);
    border: none;
    border-radius: 6px;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: #667eea;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.1s ease;
    font-family: 'DottedSongtiSquare', sans-serif;
}

.minimize-button:hover {
    background: rgba(102, 126, 234, 0.2);
    transform: scale(1.05);
}

.minimize-button:active {
    transform: scale(0.95);
}

.control-panel.minimized .panel-content {
    display: none;
}

.control-panel.minimized .panel-header {
    margin-bottom: 0;
}

.control-group {
    margin-bottom: 20px;
}

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

.control-group label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    color: #555;
    font-size: 0.9rem;
    font-weight: 500;
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.input-wrapper input[type="range"] {
    flex: 1;
}

.input-wrapper input[type="number"] {
    width: 80px;
    padding: 6px 8px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 0.9rem;
    text-align: center;
    outline: none;
    transition: border-color 0.2s ease;
    background: white;
    font-family: 'DottedSongtiSquare', sans-serif;
}

.input-wrapper input[type="number"]:focus {
    border-color: #667eea;
}

.input-wrapper input[type="number"]::-webkit-inner-spin-button,
.input-wrapper input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.input-wrapper input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.input-wrapper .unit {
    color: #666;
    font-size: 0.85rem;
    font-weight: 500;
    min-width: 20px;
}

.control-group input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e0e0e0;
    outline: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: background 0.2s ease;
}

.control-group input[type="range"]::-webkit-slider-thumb:hover {
    background: #5568d3;
}

.control-group input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: background 0.2s ease;
}

.control-group input[type="range"]::-moz-range-thumb:hover {
    background: #5568d3;
}

@media (max-width: 768px) {
    .spacing-controls {
        bottom: 15px;
        right: 15px;
    }

    .control-panel {
        padding: 15px;
        min-width: 220px;
    }

    .control-panel h3 {
        font-size: 1rem;
        margin-bottom: 12px;
    }
}

/* Image Modal/Popup */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.image-modal.active {
    display: flex;
    opacity: 1;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    cursor: pointer;
}

.modal-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    z-index: 2001;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    animation: modalSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    gap: 20px;
}

@keyframes modalSlideUp {
    from {
        transform: translateY(100vh);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    border-radius: 8px;
}

.modal-text-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    max-width: 90%;
    text-align: center;
}

.modal-text-chinese {
    font-size: 1.2rem;
    color: white;
    line-height: 1.6;
    font-weight: normal;
    font-family: 'DottedSongtiSquare', sans-serif;
}

.modal-text-english {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.8);
    line-height: 1.6;
    font-weight: normal;
    font-family: 'DottedSongtiSquare', sans-serif;
}

@media (max-width: 768px) {
    .modal-text-chinese {
        font-size: 1rem;
    }
    
    .modal-text-english {
        font-size: 0.9rem;
    }
    
    .modal-content img {
        max-height: 60vh;
    }
}

.modal-close {
    position: absolute;
    top: -40px;
    right: -40px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.95);
    border: none;
    border-radius: 50%;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 2002;
    font-family: 'DottedSongtiSquare', sans-serif;
}

.modal-close:hover {
    background: white;
    transform: rotate(90deg) scale(1.1);
}

.modal-close:active {
    transform: rotate(90deg) scale(0.95);
}

@media (max-width: 768px) {
    .modal-close {
        top: 10px;
        right: 10px;
        width: 35px;
        height: 35px;
        font-size: 1.5rem;
    }

    .modal-content {
        max-width: 95%;
        max-height: 95%;
    }
}

/* Focus Indicator (elegant targeting reticle) */
.crosshair {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1500;
    pointer-events: none;
    width: 44px;
    height: 44px;
}

/* Central focus ring */
.focus-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    transition: all 0.2s ease;
    box-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
}

/* Center dot */
.focus-dot {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 4px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    transition: all 0.2s ease;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
}

/* Corner brackets container */
.focus-brackets {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.2s ease;
}

/* Individual brackets */
.bracket {
    position: absolute;
    width: 10px;
    height: 10px;
    border: 2px solid #4ade80;
    transition: all 0.2s ease;
}

.bracket.tl {
    top: 0;
    left: 0;
    border-right: none;
    border-bottom: none;
    border-radius: 4px 0 0 0;
}

.bracket.tr {
    top: 0;
    right: 0;
    border-left: none;
    border-bottom: none;
    border-radius: 0 4px 0 0;
}

.bracket.bl {
    bottom: 0;
    left: 0;
    border-right: none;
    border-top: none;
    border-radius: 0 0 0 4px;
}

.bracket.br {
    bottom: 0;
    right: 0;
    border-left: none;
    border-top: none;
    border-radius: 0 0 4px 0;
}

/* Active state - when targeting a clickable zone */
.crosshair.active .focus-ring {
    border-color: #4ade80;
    box-shadow: 0 0 12px rgba(74, 222, 128, 0.4);
    transform: translate(-50%, -50%) scale(1.1);
}

.crosshair.active .focus-dot {
    background: #4ade80;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.6);
    transform: translate(-50%, -50%) scale(1.2);
}

.crosshair.active .focus-brackets {
    opacity: 1;
}

.crosshair.active .bracket {
    animation: bracket-breathe 1.5s ease-in-out infinite;
}

.crosshair.active .bracket.tl { animation-delay: 0s; }
.crosshair.active .bracket.tr { animation-delay: 0.1s; }
.crosshair.active .bracket.br { animation-delay: 0.2s; }
.crosshair.active .bracket.bl { animation-delay: 0.3s; }

@keyframes bracket-breathe {
    0%, 100% { 
        opacity: 1;
        transform: translate(0, 0);
    }
    50% { 
        opacity: 0.6;
        transform: translate(var(--bracket-move-x, 0), var(--bracket-move-y, 0));
    }
}

.bracket.tl { --bracket-move-x: -2px; --bracket-move-y: -2px; }
.bracket.tr { --bracket-move-x: 2px; --bracket-move-y: -2px; }
.bracket.bl { --bracket-move-x: -2px; --bracket-move-y: 2px; }
.bracket.br { --bracket-move-x: 2px; --bracket-move-y: 2px; }

/* Visual hint for dragging */
.viewport.dragging {
    cursor: grabbing;
}

/* Mobile-friendly focus indicator */
@media (max-width: 768px) {
    .crosshair {
        width: 52px;
        height: 52px;
    }
    
    .focus-ring {
        width: 24px;
        height: 24px;
        border-width: 2.5px;
    }
    
    .focus-dot {
        width: 5px;
        height: 5px;
    }
    
    .bracket {
        width: 12px;
        height: 12px;
        border-width: 2.5px;
    }
}

/* Instruction overlay for first-time users */
.instruction-overlay {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.75);
    color: white;
    padding: 12px 20px;
    border-radius: 25px;
    font-size: 0.9rem;
    z-index: 1400;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.5s ease;
    white-space: nowrap;
    font-family: 'DottedSongtiSquare', sans-serif;
}

.instruction-overlay.hidden {
    opacity: 0;
}

@media (max-width: 768px) {
    .instruction-overlay {
        bottom: 140px;
        font-size: 0.85rem;
        padding: 10px 16px;
    }
}
