:root {
    --site-header-height: 44px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --header-total: calc(var(--site-header-height) + var(--safe-top));
    --controls-bottom: calc(16px + var(--safe-bottom));
}
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}
body {
    margin: 0;
    overflow: hidden;
    background-color: #222;
    font-family: 'Microsoft YaHei', 'PingFang SC', sans-serif;
    touch-action: none;
    overscroll-behavior: none;
    max-width: 100%;
}
body.modal-open {
    overflow: hidden;
}
body.layout-mobile { --site-header-height: 48px; }
#site-header {
    position: fixed; top: 0; left: 0; right: 0; z-index: 10050;
    height: var(--header-total);
    min-height: var(--header-total);
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--safe-top) calc(12px + var(--safe-right)) 0 calc(12px + var(--safe-left));
    box-sizing: border-box;
    background: #222; border-bottom: 1px solid #3a3a3a;
    color: #f0f0f0;
}
#site-header a { text-decoration: none; }
#site-header a:hover { opacity: 0.85; }
.site-header-brand { font-size: 15px; font-weight: 600; color: #fff; }
.site-header-brand em { font-style: normal; font-weight: 400; color: #bbb; font-size: 13px; margin-left: 6px; }
.site-header-home { font-size: 13px; color: #ffcc00; white-space: nowrap; }
#steering-wheel-container {
    position: fixed;
    top: calc(var(--header-total) + 12px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}
#steering-wheel {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(23, 162, 184, 0.85);
    border: 3px solid rgba(255, 255, 255, 0.9);
    cursor: grab;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
    position: relative;
    pointer-events: auto;
    backdrop-filter: blur(4px);
    touch-action: none;
}
.steering-wheel-icon {
    color: white;
    font-size: 18px;
    pointer-events: none;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}
#steering-wheel-knob {
    position: absolute;
    top: -3px;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    height: 9px;
    background: #ffcc00;
    border-radius: 3px;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.8);
}
#steering-reset-btn {
    background: #dc3545;
    padding: 4px 12px;
    border: none;
    border-radius: 12px;
    color: white;
    cursor: pointer;
    font-size: 13px;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
    min-height: 32px;
    touch-action: manipulation;
}
#mobile-gallery-tip {
    display: none;
    position: fixed;
    right: calc(10px + var(--safe-right));
    top: calc(var(--header-total) + 8px) !important;
    z-index: 10100 !important;
    cursor: pointer;
    pointer-events: auto !important;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    background: rgba(40, 167, 69, 0.9);
    color: white;
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 12px;
    font-weight: bold;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
body.compare-open #compare-modal {
    display: flex !important;
}
#canvas-container {
    position: fixed;
    top: var(--header-total);
    left: 0;
    z-index: 1;
    width: 100%;
    width: 100vw;
    height: calc(100vh - var(--header-total));
    height: calc(100dvh - var(--header-total));
}

#ui-panel {
    position: fixed;
    top: calc(8px + var(--header-total));
    left: calc(12px + var(--safe-left));
    width: min(220px, calc(100vw - 24px - var(--safe-left) - var(--safe-right)));
    max-width: 220px;
    background: rgba(0, 0, 0, 0.8); padding: 14px 18px;
    border-radius: 8px; color: white; border-left: 4px solid #ffcc00; z-index: 10;
}
#ui-panel h2 { margin: 0 0 10px 0; font-size: 16px; }
.cut-count-label { font-size: 16px; color: #ddd; margin: 0; }
.highlight { color: #ffcc00; font-weight: bold; font-size: 30px; }

        
#controls-container { 
    position: fixed; 
    bottom: var(--controls-bottom); 
    left: calc(12px + var(--safe-left)); 
    right: calc(12px + var(--safe-right));
    z-index: 9999; 
    display: flex; 
    gap: 8px;
    flex-wrap: wrap;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: 42vh;
    padding-bottom: 4px; 
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
}
@media (min-width: 1025px) {
    #controls-container { right: calc(270px + var(--safe-right)); }
}
#controls-container::-webkit-scrollbar { height: 6px; }
#controls-container::-webkit-scrollbar-thumb { background-color: rgba(255,255,255,0.3); border-radius: 3px; }
#controls-container button { 
    padding: 12px 16px; 
    color: white; border: none; border-radius: 8px; 
    cursor: pointer; font-size: 15px; 
    font-weight: bold; transition: all 0.2s; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.3); 
    white-space: nowrap;
    flex: 0 1 auto;
    min-height: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
#controls-container button.active-mode {
    color: black !important;
    background-color: #ffffff !important;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.5);
    transform: translateY(2px);
}
#undo-btn { background-color: #ff9800; } #undo-btn:hover { background-color: #e68a00; } #undo-btn:disabled { background-color: #555; color: #888; cursor: not-allowed; box-shadow: none; }
#redo-btn { background-color: #17a2b8; } #redo-btn:hover { background-color: #138496; } #redo-btn:disabled { background-color: #555; color: #888; cursor: not-allowed; box-shadow: none; }
#reset-btn { background-color: #007bff; } #reset-btn:hover { background-color: #0056b3; }
#snapshot-btn { background-color: #28a745; } #snapshot-btn:hover { background-color: #218838; }

.tool-btn { background: #444; color: #fff; padding: 6px 12px; border: 1px solid #666; font-size: 13px; border-radius: 4px; cursor: pointer; outline: none; }
.tool-btn.active { background: #e83e8c; border-color: #e83e8c; font-weight: bold; }
.tool-btn:hover { background: #555; }
.tool-btn.active:hover { background: #d3337b; }

#gallery-panel { 
    position: absolute; 
    top: 80px; 
    right: 20px; 
    bottom: 100px; 
    width: 220px; 
    background: rgba(0, 0, 0, 0.7); 
    padding: 12px; 
    border-radius: 12px; 
    border-top: 4px solid #28a745; 
    overflow-y: auto; 
    display: flex; 
    flex-direction: column; 
    gap: 10px; 
    z-index: 10; 
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
@media (max-width: 1024px) {
    #gallery-panel {
        width: min(180px, 28vw);
        top: calc(var(--header-total) + 72px);
        bottom: calc(110px + var(--safe-bottom));
        right: calc(10px + var(--safe-right));
    }
    #ui-panel { width: min(180px, 42vw); padding: 10px; }
    #ui-panel h2 { font-size: 14px; }
    .highlight { font-size: 24px; }
}

/* 平板竖屏 */
@media (max-width: 768px) {
    .site-header-brand {
        font-size: 13px;
        line-height: 1.25;
        max-width: 58vw;
        white-space: normal;
    }
    .site-header-brand em {
        display: inline;
        font-size: 11px;
        margin-left: 5px;
        color: #bbb;
    }
    .site-header-home { font-size: 12px; flex-shrink: 0; }
    #gallery-panel { display: none; }
    #controls-container {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 6px;
        max-height: none;
    }
    #controls-container button {
        width: 100%;
        padding: 10px 6px;
        font-size: 12px;
        min-height: 42px;
        white-space: normal;
        line-height: 1.2;
        text-align: center;
    }
    #mobile-gallery-tip {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        top: calc(var(--header-total) + 8px) !important;
        white-space: nowrap;
        z-index: 10100 !important;
        pointer-events: auto !important;
    }
    #compare-grid {
        grid-template-columns: 1fr !important;
        max-width: 92vw;
        padding: 10px;
        gap: 12px;
    }
    .compare-cell img {
        max-width: 100%;
    }
    #steering-wheel-container {
        top: calc(var(--header-total) + 6px);
        right: calc(10px + var(--safe-right));
        left: auto;
        transform: none;
    }
    #steering-wheel { width: 38px; height: 38px; }
    #ui-panel {
        width: min(150px, 46vw);
        padding: 8px 10px;
    }
    #compare-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 10px;
    }
    .help-content {
        width: min(92vw, 420px);
        max-height: 85dvh;
        overflow-y: auto;
        padding: 18px 16px;
        margin: 12px;
        box-sizing: border-box;
    }
    #image-modal {
        padding: calc(12px + var(--safe-top)) calc(10px + var(--safe-right))
            calc(12px + var(--safe-bottom)) calc(10px + var(--safe-left));
        overflow-y: auto;
        align-items: center;
    }
    .modal-preview-sheet {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: min(88vw, 100%);
        height: auto;
        max-height: min(88dvh, 100%);
        position: relative;
        padding: 10px 10px 12px;
        border-radius: 12px;
        background: rgba(28, 28, 28, 0.98);
        box-sizing: border-box;
        overflow: hidden;
        flex-shrink: 0;
    }
    #image-modal img {
        display: block;
        max-width: 100%;
        width: auto;
        height: auto;
        max-height: min(58dvh, calc(88dvh - 110px));
        border-width: 3px;
        box-sizing: border-box;
        flex: 0 0 auto;
    }
    #modal-controls {
        gap: 6px;
        padding: 8px 0 0;
        margin-top: 0;
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
        flex-shrink: 0;
    }
    #modal-controls button, #modal-controls select {
        font-size: 12px;
        min-height: 38px;
        padding: 8px 10px;
        flex: 0 1 auto;
    }
}

/* 手机 */
@media (max-width: 480px) {
    #ui-panel {
        width: min(132px, 40vw);
        padding: 6px 8px;
        border-left-width: 3px;
    }
    #ui-panel h2 { font-size: 11px; margin-bottom: 2px; }
    .cut-count-label { font-size: 11px; }
    .highlight { font-size: 18px; }
    #controls-container {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        --controls-bottom: calc(8px + var(--safe-bottom));
    }
    #controls-container button {
        font-size: 11px;
        padding: 8px 4px;
        min-height: 40px;
    }
    .site-header-brand { font-size: 12px; max-width: 52vw; }
    .site-header-brand em { font-size: 10px; margin-left: 4px; }
    .site-header-home { font-size: 11px; }
    #alarm-text {
        font-size: 16px;
        padding: 10px 16px;
        width: min(90vw, 320px);
        text-align: center;
        box-sizing: border-box;
    }
    #compare-modal h2 { font-size: 16px; }
    #compare-close { width: min(90vw, 280px); }
}

/* 超小屏 */
@media (max-width: 360px) {
    #controls-container {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* 手机横屏 */
@media (max-height: 500px) and (orientation: landscape) {
    #ui-panel { display: none; }
    #controls-container {
        grid-template-columns: repeat(7, minmax(0, 1fr));
        bottom: calc(4px + var(--safe-bottom));
    }
    #controls-container button {
        font-size: 10px;
        min-height: 36px;
        padding: 6px 4px;
    }
    #steering-wheel-container {
        top: calc(var(--header-total) + 4px);
        right: calc(8px + var(--safe-right));
    }
    #steering-wheel { width: 32px; height: 32px; }
    #steering-reset-btn { font-size: 11px; padding: 2px 8px; min-height: 28px; }
}
#gallery-panel h3 { margin: 0; color: white; font-size: 18px; text-align: center; letter-spacing: 1px; }
.snapshot-item { 
    position: relative; 
    width: 100%; 
    border: 3px solid #444; 
    border-radius: 8px; 
    cursor: grab; 
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); 
    background: #111; 
    margin-bottom: 8px; 
    overflow: hidden; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}
.snapshot-item:hover { 
    border-color: #28a745; 
    transform: scale(1.02);
    box-shadow: 0 6px 20px rgba(40, 167, 69, 0.3);
}
.snapshot-item img { 
    width: 100%; 
    display: block; 
    transition: transform 0.5s ease;
}
.snapshot-item:hover img {
    transform: scale(1.05);
}
.snapshot-index {
    position: absolute;
    bottom: 8px;
    left: 8px;
    background: rgba(40, 167, 69, 0.9);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    z-index: 5;
}

.item-tools { position: absolute; top: 5px; right: 5px; display: flex; flex-direction: column; gap: 5px; z-index: 100; }
.item-btn { background: rgba(0, 0, 0, 0.7); color: white; border: 1px solid rgba(255,255,255,0.3); border-radius: 4px; width: 28px; height: 28px; font-size: 14px; cursor: pointer; display: flex; justify-content: center; align-items: center; transition: all 0.2s; }
.item-btn:hover { background: #28a745; }
.delete-btn-new { background: rgba(220, 53, 69, 0.8); }
.delete-btn-new:hover { background: rgba(220, 53, 69, 1); }

#scissors-cursor { position: fixed; pointer-events: none; font-size: 32px; z-index: 9999; display: none; transform: translate(-50%, -50%); text-shadow: 0 0 5px rgba(0,0,0,0.5); }
@keyframes snip-anim { 0% { transform: translate(-50%, -50%) rotate(0deg) scale(1); } 50% { transform: translate(-50%, -50%) rotate(-30deg) scale(0.8); } 100% { transform: translate(-50%, -50%) rotate(0deg) scale(1); } }
.snipping { animation: snip-anim 0.3s ease-in-out; }

/* 报警遮罩 */
#alarm-overlay {
    display: none;
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    border: 8px solid #ff3300; box-sizing: border-box;
    pointer-events: none; z-index: 9998;
    animation: alarm-flash 0.4s ease-in-out;
}
@keyframes alarm-flash {
    0%   { border-color: #ff3300; box-shadow: inset 0 0 60px rgba(255,50,0,0.5); }
    50%  { border-color: #ffcc00; box-shadow: inset 0 0 80px rgba(255,200,0,0.6); }
    100% { border-color: #ff3300; box-shadow: inset 0 0 60px rgba(255,50,0,0.5); }
}
#alarm-text {
    display: none;
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
    background: rgba(200, 0, 0, 0.85); color: white;
    font-size: 28px; font-weight: bold; padding: 16px 32px;
    border-radius: 12px; z-index: 9999; pointer-events: none;
    text-shadow: 1px 1px 3px black;
    animation: alarm-text-pop 0.4s ease;
}
@keyframes alarm-text-pop {
    0%   { transform: translate(-50%,-50%) scale(0.7); opacity: 0; }
    60%  { transform: translate(-50%,-50%) scale(1.1); opacity: 1; }
    100% { transform: translate(-50%,-50%) scale(1); opacity: 1; }
}

#help-modal {
    display: none;
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 10005;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    box-sizing: border-box;
}
.help-content { background: #333; color: #fff; padding: 25px 35px; border-radius: 8px; max-width: 450px; line-height: 1.8; border-top: 4px solid #17a2b8; box-shadow: 0 5px 20px rgba(0,0,0,0.6); }
.help-content h3 { margin-top: 0; color: #17a2b8; text-align: center; font-size: 20px;}
.help-content ul { padding-left: 20px; font-size: 15px;}
.help-content li { margin-bottom: 12px; }
.modal-preview-sheet {
    display: contents;
}
#image-modal {
    display: none;
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    overflow: hidden;
    overflow-x: hidden;
    box-sizing: border-box;
    padding: 12px;
}
#image-modal img {
    max-width: 90%;
    max-height: 75%;
    width: auto;
    height: auto;
    object-fit: contain;
    border: 4px solid #fff;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
    box-sizing: border-box;
}
#modal-controls {
    margin-top: 16px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    max-width: 100%;
    box-sizing: border-box;
}
#modal-close { background-color: #dc3545; } #modal-close:hover { background-color: #c82333; }
#modal-download { background-color: #28a745; } #modal-download:hover { background-color: #218838; }
#modal-draw-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    pointer-events: none;
    z-index: 10001;
}
.modal-drawing-active #modal-draw-canvas { pointer-events: auto; cursor: crosshair; }
#modal-controls { position: relative; z-index: 10002; flex-shrink: 0; }
#modal-controls button,
#modal-controls select {
    max-width: 100%;
    box-sizing: border-box;
}
#modal-draw-btn { background-color: #e83e8c; } #modal-draw-btn:hover { background-color: #d3337b; }
#modal-clear-btn { background-color: #6c757d; } #modal-clear-btn:hover { background-color: #5a6268; }

/* 对比模态窗 */
#compare-modal {
    display: none;
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.92);
    z-index: 10200;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 20px;
    box-sizing: border-box;
}
#compare-modal h2 { color: #ffcc00; margin: 0 0 16px 0; font-size: 20px; }
#compare-grid {
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 24px;
    width: 100%;
    max-width: 1400px;
    padding: 20px;
}
.compare-cell {
    background: #1a1a1a; 
    border: 3px solid #333; 
    border-radius: 12px;
    padding: 16px; 
    display: flex; 
    flex-direction: column; 
    align-items: center;
    transition: all 0.3s ease;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.compare-cell:hover {
    border-color: #ffcc00;
    transform: translateY(-5px);
    background: #222;
}
.compare-cell img { 
    width: 100%; 
    height: auto;
    border-radius: 8px; 
    border: 1px solid #444;
    margin-bottom: 15px;
}
.compare-cell span { 
    color: #ffffff; 
    font-size: 18px; 
    font-weight: bold;
    background: #28a745;
    padding: 6px 20px;
    border-radius: 25px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    letter-spacing: 1px;
}
#compare-close { background: #dc3545; margin-top: 16px; margin-bottom: 20px; padding: 10px 36px; }
@keyframes edge-glow {
    0% { opacity: 0.6; transform: scaleY(1); }
    50% { opacity: 1; transform: scaleY(1.05); }
    100% { opacity: 0.6; transform: scaleY(1); }
}
.edge-hover-effect {
    animation: edge-glow 0.8s infinite ease-in-out;
}
