/**
 * trace-app styles.
 *
 * Three UI layers:
 *   .trace-upload-screen  — fullscreen prompt on first load
 *   .trace-preview-screen — fullscreen threshold preview before drawing starts
 *   .trace-ref-panel      — corner reference during drawing
 *   .trace-top-bar        — top bar controls during drawing
 */

/* ===== SHARED OVERLAY BASE ===== */

.trace-upload-screen,
.trace-preview-screen {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(17, 24, 39, 0.96);
    backdrop-filter: blur(6px);
    overflow-y: auto;
}

/* ===== UPLOAD SCREEN ===== */

.trace-upload-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 40px 24px;
    text-align: center;
}

.trace-upload-title {
    font-size: 30px;
    font-weight: bold;
    color: #fff;
    letter-spacing: 0.02em;
}

.trace-upload-sub {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.55);
}

.trace-upload-btn {
    width: auto;
    height: auto;
    padding: 12px 36px;
    font-size: 15px;
    font-family: inherit;
    font-weight: bold;
}

/* ===== PREVIEW SCREEN ===== */

.trace-preview-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    padding: 32px 24px;
    max-width: 90vw;
    width: 100%;
}

.trace-preview-title {
    font-size: 20px;
    font-weight: bold;
    color: #fff;
}

.trace-preview-canvas {
    display: block;
    max-width: min(82vw, 960px);
    max-height: 52vh;
    width: auto;
    height: auto;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    image-rendering: auto;
    background: #fff;
}

.trace-preview-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(440px, 82vw);
}

.trace-preview-label {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.75);
}

.trace-preview-range {
    width: 100%;
    accent-color: #3b82f6;
    cursor: pointer;
}

.trace-preview-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 4px;
}

.trace-preview-btn-primary,
.trace-preview-btn-secondary {
    width: auto;
    height: auto;
    padding: 10px 28px;
    font-size: 14px;
    font-family: inherit;
    font-weight: bold;
}

.trace-preview-btn-primary {
    background: rgba(59, 130, 246, 0.55);
    border-color: rgba(59, 130, 246, 0.8);
}

.trace-preview-btn-primary:hover {
    background: rgba(59, 130, 246, 0.75);
    border-color: rgba(59, 130, 246, 1);
}

/* ===== CORNER REFERENCE PANEL ===== */

.trace-ref-panel {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    padding: 10px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    width: 200px;
    overflow: visible;
}

.trace-ref-label {
    font-size: 11px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    text-align: center;
    cursor: grab;
    user-select: none;
    padding: 2px 0;
}

.trace-ref-canvas {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: #fff;
    image-rendering: auto;
    /* prevent canvas from triggering drag */
    pointer-events: none;
}

.trace-ref-toggle {
    width: 100%;
    height: auto;
    min-height: 34px;
    padding: 0 10px;
    font-size: 12px;
    font-family: inherit;
    font-weight: 600;
    white-space: nowrap;
    min-width: 0;
}

.trace-ref-panel {
    min-width: min-content;
}

.trace-ref-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 28px;
    height: 28px;
    cursor: nwse-resize;
    opacity: 0.4;
    /* two diagonal tick marks, scaled to fill the larger hit area */
    background:
        linear-gradient(135deg, transparent 55%, rgba(255,255,255,0.9) 55%, rgba(255,255,255,0.9) 65%, transparent 65%),
        linear-gradient(135deg, transparent 70%, rgba(255,255,255,0.9) 70%, rgba(255,255,255,0.9) 80%, transparent 80%);
}

.trace-ref-panel:hover .trace-ref-resize-handle { opacity: 0.75; }

/* Edge tab on the right side of the ref panel — visible on hover */
.trace-ref-edge-tab {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, background 0.15s, color 0.15s;
}

.trace-ref-panel:hover .trace-ref-edge-tab {
    opacity: 1;
    pointer-events: auto;
}

/* Edge tab on the right side of the ref panel */
.trace-ref-edge-tab {
    position: absolute;
    right: -13px;
    top: 50%;
    transform: translateY(-50%);
    width: 13px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-left: none;
    border-radius: 0 8px 8px 0;
    cursor: pointer;
    font-size: 8px;
    color: rgba(255, 255, 255, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
}

.trace-ref-edge-tab:hover {
    background: rgba(255, 255, 255, 0.22);
    color: rgba(255, 255, 255, 0.9);
}

/* Restore dot — top-left corner */
.trace-ref-dot {
    position: fixed;
    top: 12px;
    left: 12px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.5);
    cursor: pointer;
    z-index: 10;
    transition: background 0.15s, transform 0.15s;
    padding: 0;
}

.trace-ref-dot:hover {
    background: rgba(255, 255, 255, 0.65);
    transform: scale(1.4);
}

/* ===== TOP BAR (draw phase) ===== */

.trace-top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    margin: 0 auto;
    z-index: 11;
    box-sizing: border-box;
    width: max-content;
    max-width: calc(100vw - 24px);
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    padding: 6px 8px;
    border-radius: 0 0 10px 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-top: none;
    transition: transform 0.2s ease;
}

.trace-top-bar {
    transition: transform 0.2s ease, opacity 0.15s ease;
    overflow: visible;
}

.trace-top-bar.trace-top-bar-collapsed {
    transform: translateY(calc(-100% - 2px));
    opacity: 0;
    pointer-events: none;
}

/* Tab on the bottom edge of the top bar — visible on hover */
.trace-top-bar-edge-tab {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, background 0.15s, color 0.15s;
}

.trace-top-bar:hover .trace-top-bar-edge-tab {
    opacity: 1;
    pointer-events: auto;
}

/* Tab on the bottom edge of the top bar */
.trace-top-bar-edge-tab {
    position: absolute;
    bottom: -13px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 13px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-top: none;
    border-radius: 0 0 8px 8px;
    cursor: pointer;
    font-size: 8px;
    color: rgba(255, 255, 255, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
    z-index: 12;
}

.trace-top-bar-edge-tab:hover {
    background: rgba(255, 255, 255, 0.22);
    color: rgba(255, 255, 255, 0.9);
}

/* Restore dot — appears at top-right when bar is hidden */
.trace-top-bar-restore-tab {
    display: none;
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 12;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
    padding: 0;
    font-size: 0;
}

.trace-top-bar-restore-tab:hover {
    background: rgba(255, 255, 255, 0.65);
    transform: scale(1.4);
}

@media (max-width: 768px) {
    .trace-top-bar {
        left: 216px; /* just past the reference panel edge */
        right: 0;
        margin: 0 auto;
        max-width: calc(100vw - 216px);
    }
}

.trace-top-bar-inner {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 4px;
    overflow: visible;
}


.trace-top-bar .trace-top-bar-btn {
    width: auto;
    min-width: 0;
    height: 28px;
    padding: 0 10px;
    font-size: 11px;
    font-family: inherit;
    font-weight: 600;
    white-space: nowrap;
    border-radius: 6px;
}

/* Active/pressed state (top bar toggles and ref panel toggle) */
.trace-btn-active {
    background: rgba(255, 255, 255, 0.35);
    border-color: rgba(255, 255, 255, 0.5);
}

/* ===== ACCURACY CHECK MODAL ===== */

#traceCheckModal .modal-content {
    max-width: min(92vw, 700px);
}

.trace-accuracy-pct {
    font-size: 56px;
    font-weight: bold;
    color: #111827;
    text-align: center;
    letter-spacing: -0.02em;
    margin: 4px 0 8px;
}

#checkResultCanvas {
    display: block;
    max-width: min(96vw, 760px);
    max-height: 55vh;
    margin: 12px auto;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.trace-check-stats {
    font-size: 14px;
    line-height: 1.6;
    color: #e5e7eb;
    margin-top: 8px;
}

.trace-check-stats strong { color: #fff; }
