:root {
    --bg-color: #f0f4f8;
    --primary-color: #4a90e2;
    --primary-dark: #357abd;
    --success-color: #48bb78;
    --danger-color: #f56565;
    --accent-color: #667eea;
    --text-color: #2d3748;
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(255, 255, 255, 0.2);
    --shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
    
    --body-dominant: #f0e199;
    --body-recessive: #a0d8ef;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', 'Noto Sans TC', sans-serif;
}

body {
    background: var(--bg-color);
    background-image: 
        radial-gradient(at 0% 0%, rgba(102, 126, 234, 0.1) 0, transparent 50%), 
        radial-gradient(at 100% 100%, rgba(160, 216, 239, 0.1) 0, transparent 50%);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    touch-action: manipulation; /* Prevent double-tap zoom delay */
    -webkit-user-select: none; /* Prevent selection while dragging */
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#app {
    width: 98%;
    max-width: 1400px;
    height: 95vh;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Overlays */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(8px);
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal {
    background: white;
    padding: 2.5rem;
    border-radius: 20px;
    max-width: 550px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}

.modal h2 { margin-bottom: 1rem; color: var(--primary-color); }
.instruction-content { text-align: left; margin-bottom: 1.5rem; }
.instruction-content li { margin-bottom: 0.5rem; display: flex; align-items: center; }
.step { background: var(--primary-color); color: white; width: 20px; height: 20px; border-radius: 50%; display: flex; justify-content: center; align-items: center; margin-right: 10px; font-size: 0.7rem; font-weight: bold; }

/* Header */
header {
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.title-group h1 {
    font-size: 1.4rem;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.stats { display: flex; align-items: center; gap: 1.5rem; }
.stat-item { display: flex; flex-direction: column; align-items: flex-end; }
.stat-item .value { font-size: 1.5rem; font-weight: 600; color: var(--primary-color); }

/* Main Workspace */
main {
    flex: 1;
    padding: 1rem;
    overflow: hidden;
}

.lab-workspace {
    display: grid;
    grid-template-columns: 280px 1fr 320px;
    gap: 1rem;
    height: 100%;
}

.zone {
    background: rgba(255, 255, 255, 0.4);
    border-radius: 20px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(255,255,255,0.6);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

.zone h3 {
    font-size: 1rem;
    color: #4a5568;
    margin: 0;
}

.zone-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    padding-bottom: 5px;
    margin-bottom: 0.8rem;
}

.trait-badge {
    font-size: 0.75rem;
    background: #edf2f7;
    color: #4a5568;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
}

/* Sandbox and Dropzone Containers */
.sandbox, .dropzone {
    position: relative; /* CRITICAL for absolute positioning */
    flex: 1;
    background: #f8fafc;
    border-radius: 12px;
    border: 1px solid #edf2f7;
    overflow: hidden;
    transition: background 0.2s;
}

.dropzone {
    min-height: 120px;
    max-height: 150px;
    border: 2px dashed #cbd5e0;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1rem;
    overflow: visible; /* Allow children to overlap edge during drag if needed */
}

.dropzone.highlight {
    border-color: var(--primary-color);
    background: rgba(74, 144, 226, 0.05);
}

.drop-hint {
    font-size: 0.8rem;
    color: #a0aec0;
    pointer-events: none;
    position: absolute;
}

/* Station Layouts */
.middle-zone {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.repro-station, .offspring-station {
    background: white;
    padding: 1rem;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
}

.offspring-station { flex: 1; }

/* Classification */
.classification-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.genotype-slots {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    flex: 1;
}

.slot {
    background: white;
    border-radius: 12px;
    border: 1px solid #edf2f7;
    display: flex;
    flex-direction: column;
}

.slot-header {
    background: #f7fafc;
    padding: 0.4rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-align: center;
    color: #718096;
    border-bottom: 1px solid #edf2f7;
}

.slot-body {
    min-height: 80px;
    position: relative;
}

/* Blob Sprite - Free Positioning */
.blob-sprite {
    position: absolute;
    width: 44px;
    height: 44px;
    cursor: grab;
    transition: transform 0.2s;
    user-select: none;
    z-index: 10;
    touch-action: none; /* Crucial for touch dragging */
    
    /* Default Trait Variables */
    --blob-main-color: #f0e199;
    --eye-radius: 3;
    --eye-pupil-radius: 1.5;
    --eye-fill: black;
    --mouth-path: "M15 26 Q20 30 25 26";
}

.blob-sprite:active { cursor: grabbing; }
.blob-sprite.dragging { opacity: 0.5; z-index: 100; transform: scale(1.1); }

.blob-svg { width: 100%; height: 100%; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1)); }

.blob-body { 
    fill: var(--blob-main-color); 
    stroke: rgba(0,0,0,0.1); 
    stroke-width: 1; 
}

/* We'll apply traits directly via JS, so these class-based overrides 
   are moved or made more general */

.gene-label {
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.75);
    color: white;
    font-size: 9px;
    padding: 1px 4px;
    border-radius: 4px;
    white-space: nowrap;
    z-index: 11;
}

.hidden { display: none !important; }

/* Buttons */
.action-btn {
    padding: 0.6rem 1rem;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.action-btn.primary { background: var(--primary-color); color: white; }
.action-btn.primary:disabled { background: #cbd5e0; cursor: not-allowed; }
.action-btn.danger { background: #fee2e2; color: var(--danger-color); }
.action-btn.success { background: var(--success-color); color: white; }
.action-btn.small {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    border-radius: 6px;
}

.primary-btn { padding: 1rem 2rem; background: var(--primary-color); color: white; border: none; border-radius: 12px; font-weight: 600; cursor: pointer; }

/* Footer */
footer { padding: 1rem 2rem; border-top: 1px solid rgba(0,0,0,0.05); }
.phenotype-legend { display: flex; gap: 2rem; justify-content: center; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.blob-preview { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.1); }
.blob-preview.dominant { background: var(--body-dominant); }
.blob-preview.recessive { background: var(--body-recessive); }
.stat-value { font-weight: bold; color: var(--primary-color); margin-left: 4px; }

/* Animations */
@keyframes popIn {
    0% { transform: scale(0); opacity: 0; }
    80% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}
.anim-pop { animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); }

@keyframes shake {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(-4px, 0); }
    75% { transform: translate(4px, 0); }
}
.anim-shake { animation: shake 0.2s ease-in-out infinite; }

/* States */
.blob-sprite.correct {
    outline: 3px solid var(--success-color);
    outline-offset: 2px;
    border-radius: 50%;
    filter: drop-shadow(0 0 10px rgba(72, 187, 120, 0.4));
}

/* Pea Mode Styles */
.pea-sprite {
    width: 60px;
    height: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
}

.pea-visual {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.pea-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.allele-sprite {
    width: 30px;
    height: 30px;
    cursor: grab;
    position: absolute;
    z-index: 100;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.allele-sprite:active {
    cursor: grabbing;
}

.allele-sprite:hover {
    transform: scale(1.2);
    filter: drop-shadow(0 0 5px var(--accent-color));
}

.allele-img {
    width: 100%;
    height: 100%;
}

.hidden {
    display: none !important;
}

.repro-station h3 {
    margin-bottom: 0.5rem;
}

