/* ===== CSS Variables ===== */
:root {
    /* Base colors - nucleotide standard colors */
    --adenine: #22c55e;      /* Green */
    --thymine: #ef4444;      /* Red */
    --guanine: #eab308;      /* Yellow */
    --cytosine: #3b82f6;     /* Blue */
    --uracil: #f97316;       /* Orange */
    --phosphate: #8b5cf6;    /* Purple */
    --sugar-dna: #ec4899;    /* Pink - Deoxyribose */
    --sugar-rna: #14b8a6;    /* Teal - Ribose */

    /* UI colors */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #22c55e;
    --error: #ef4444;
    --warning: #f59e0b;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Touch targets */
    --touch-target: 44px;

    /* Borders */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.4);
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    touch-action: manipulation;
}

/* ===== App Container ===== */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 600px;
    margin: 0 auto;
    position: relative;
}

/* ===== Header ===== */
#mission-header {
    padding: var(--spacing-md);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--bg-tertiary);
    text-align: center;
}

.mission-number {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

#mission-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: var(--spacing-xs);
}

#mission-objective {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-xs);
    position: relative;
}

.peebedu-link {
    font-family: 'Alfa Slab One', serif;
    font-size: 0.9rem;
    color: var(--accent);
    text-decoration: none;
    letter-spacing: 0.02em;
    transition: color 0.2s ease;
}

.peebedu-link:hover {
    color: var(--success);
}

.select-mission-btn {
    font-size: 0.7rem;
    padding: 4px 10px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.select-mission-btn:hover {
    background: var(--accent);
    color: var(--text-primary);
    border-color: var(--accent);
}

/* ===== Build Area ===== */
#build-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md);
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

#canvas {
    width: 100%;
    height: 100%;
    max-width: 400px;
    max-height: 400px;
}

/* Drop zones */
.drop-zone {
    fill: var(--bg-tertiary);
    stroke: var(--text-secondary);
    stroke-width: 2;
    stroke-dasharray: 8 4;
    opacity: 0.6;
    cursor: pointer;
    transition: all 0.2s ease;
}

.drop-zone:hover,
.drop-zone.active {
    opacity: 1;
    stroke: var(--accent);
    fill: rgba(59, 130, 246, 0.1);
}

.drop-zone.filled {
    stroke: var(--success);
    stroke-dasharray: none;
    opacity: 0.8;
}

.drop-zone.error {
    stroke: var(--error);
    animation: shake 0.3s ease-in-out;
}

/* Feedback overlay */
#feedback {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-secondary);
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-weight: 600;
    z-index: 100;
    animation: fadeIn 0.2s ease;
}

#feedback.success {
    border: 2px solid var(--success);
    color: var(--success);
}

#feedback.error {
    border: 2px solid var(--error);
    color: var(--error);
}

/* ===== Toolbox ===== */
#toolbox {
    background: var(--bg-secondary);
    border-top: 1px solid var(--bg-tertiary);
    padding: var(--spacing-sm) 0;
}

#toolbox-scroll {
    display: flex;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

#toolbox-scroll::-webkit-scrollbar {
    display: none;
}

.tool-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm);
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    background: var(--bg-tertiary);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-user-select: none;
    user-select: none;
}

.tool-item:active {
    transform: scale(0.95);
}

.tool-item.selected {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.2);
    box-shadow: var(--shadow-md);
}

.tool-item.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.tool-icon {
    width: 36px;
    height: 36px;
}

.tool-label {
    font-size: 0.5rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    text-align: center;
    white-space: nowrap;
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Tool item colors based on component type */
.tool-item[data-type="adenine"] { border-color: var(--adenine); }
.tool-item[data-type="thymine"] { border-color: var(--thymine); }
.tool-item[data-type="guanine"] { border-color: var(--guanine); }
.tool-item[data-type="cytosine"] { border-color: var(--cytosine); }
.tool-item[data-type="uracil"] { border-color: var(--uracil); }
.tool-item[data-type="phosphate"] { border-color: var(--phosphate); }
.tool-item[data-type="deoxyribose"] { border-color: var(--sugar-dna); }
.tool-item[data-type="ribose"] { border-color: var(--sugar-rna); }

.tool-item[data-type="adenine"].selected { background: rgba(34, 197, 94, 0.2); }
.tool-item[data-type="thymine"].selected { background: rgba(239, 68, 68, 0.2); }
.tool-item[data-type="guanine"].selected { background: rgba(234, 179, 8, 0.2); }
.tool-item[data-type="cytosine"].selected { background: rgba(59, 130, 246, 0.2); }
.tool-item[data-type="uracil"].selected { background: rgba(249, 115, 22, 0.2); }
.tool-item[data-type="phosphate"].selected { background: rgba(139, 92, 246, 0.2); }
.tool-item[data-type="deoxyribose"].selected { background: rgba(236, 72, 153, 0.2); }
.tool-item[data-type="ribose"].selected { background: rgba(20, 184, 166, 0.2); }

/* ===== Action Buttons ===== */
#actions {
    display: flex;
    gap: var(--spacing-sm);
    padding: var(--spacing-md);
    background: var(--bg-secondary);
    border-top: 1px solid var(--bg-tertiary);
}

.action-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    min-height: var(--touch-target);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-tertiary);
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-user-select: none;
    user-select: none;
}

.action-btn:active {
    transform: scale(0.97);
}

.action-btn.primary {
    background: var(--accent);
}

.action-btn.primary:hover {
    background: var(--accent-hover);
}

.action-btn.large {
    padding: var(--spacing-md) var(--spacing-lg);
    font-size: 1rem;
}

.btn-icon {
    font-size: 1.25rem;
    line-height: 1;
}

.btn-label {
    font-size: 0.75rem;
    font-weight: 500;
}

/* ===== Modal ===== */
#modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-lg);
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

#modal {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    max-width: 400px;
    width: 100%;
    text-align: center;
    animation: slideUp 0.3s ease;
}

#modal-title {
    font-size: 1.5rem;
    color: var(--success);
    margin-bottom: var(--spacing-md);
}

#modal-content {
    margin-bottom: var(--spacing-lg);
}

#modal-message {
    font-size: 1rem;
    margin-bottom: var(--spacing-md);
    line-height: 1.5;
}

#modal-info {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    text-align: left;
    font-size: 0.875rem;
    line-height: 1.6;
}

#modal-info h3 {
    color: var(--accent);
    margin-bottom: var(--spacing-sm);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===== Info Panel ===== */
#info-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: var(--spacing-lg);
    max-height: 60%;
    overflow-y: auto;
    z-index: 500;
    animation: slideUp 0.3s ease;
    box-shadow: var(--shadow-lg);
}

#close-info {
    position: absolute;
    top: var(--spacing-md);
    right: var(--spacing-md);
    width: 32px;
    height: 32px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: var(--radius-full);
    color: var(--text-primary);
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#info-title {
    font-size: 1.125rem;
    margin-bottom: var(--spacing-md);
}

#info-content {
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

#info-content strong {
    color: var(--text-primary);
}

/* ===== Start Screen ===== */
#start-screen {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.start-content {
    text-align: center;
    padding: var(--spacing-lg);
}

.start-content h1 {
    font-size: 2rem;
    margin-bottom: var(--spacing-sm);
    background: linear-gradient(135deg, var(--adenine), var(--cytosine));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xl);
}

.dna-icon {
    margin-bottom: var(--spacing-xl);
}

.dna-icon svg {
    animation: rotate 10s linear infinite;
}

#btn-start,
#btn-continue {
    min-width: 200px;
    margin-bottom: var(--spacing-sm);
}

/* ===== Mission Select ===== */
#mission-select {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    padding: var(--spacing-lg);
    z-index: 1500;
    overflow-y: auto;
}

.mission-select-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 400px;
    margin: 0 auto var(--spacing-lg);
}

#mission-select h2 {
    margin: 0;
}

.close-btn {
    width: 36px;
    height: 36px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: var(--radius-full);
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: var(--error);
}

#mission-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    max-width: 400px;
    margin: 0 auto;
}

.mission-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
    border: 2px solid transparent;
}

.mission-item:hover {
    border-color: var(--accent);
}

.mission-item.locked {
    opacity: 0.5;
    pointer-events: none;
}

.mission-item.completed {
    border-color: var(--success);
}

.mission-item .number {
    width: 40px;
    height: 40px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.mission-item.completed .number {
    background: var(--success);
}

.mission-item .details {
    flex: 1;
}

.mission-item .details h3 {
    font-size: 1rem;
    margin-bottom: var(--spacing-xs);
}

.mission-item .details p {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.mission-item.current {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.1);
}

.mission-item.current .number {
    background: var(--accent);
}

/* Mission progress bar */
.mission-progress {
    margin-bottom: var(--spacing-md);
    padding: var(--spacing-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
}

.progress-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-sm);
    text-align: center;
}

.progress-bar {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success), var(--accent));
    border-radius: var(--radius-full);
    transition: width 0.3s ease;
}

/* ===== Utilities ===== */
.hidden {
    display: none !important;
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes wrapDNA {
    to {
        stroke-dashoffset: 0;
    }
}

/* ===== Component SVG Styles ===== */
.component-phosphate { fill: var(--phosphate); }
.component-deoxyribose { fill: var(--sugar-dna); }
.component-ribose { fill: var(--sugar-rna); }
.component-adenine { fill: var(--adenine); }
.component-thymine { fill: var(--thymine); }
.component-guanine { fill: var(--guanine); }
.component-cytosine { fill: var(--cytosine); }
.component-uracil { fill: var(--uracil); }

.component {
    cursor: pointer;
    transition: all 0.15s ease;
}

.component:hover {
    filter: brightness(1.2);
}

.component.placed {
    animation: pulse 0.3s ease;
}

/* Backbone connections */
.backbone {
    stroke: var(--text-secondary);
    stroke-width: 3;
    fill: none;
}

/* Hydrogen bonds */
.h-bond {
    stroke: var(--text-secondary);
    stroke-width: 2;
    stroke-dasharray: 4 2;
    opacity: 0.6;
}

/* ===== Chromosome styles ===== */
.chromosome {
    fill: none;
    stroke: var(--accent);
    stroke-width: 4;
}

.histone {
    fill: var(--warning);
    stroke: var(--bg-primary);
    stroke-width: 1;
}

.plasmid {
    fill: none;
    stroke: var(--success);
    stroke-width: 3;
}

/* ===== Responsive adjustments ===== */
@media (min-width: 480px) {
    #mission-title {
        font-size: 1.5rem;
    }

    .tool-icon {
        width: 44px;
        height: 44px;
    }

    .tool-label {
        font-size: 0.75rem;
    }
}

@media (min-width: 768px) {
    #app {
        max-width: 700px;
    }

    #build-area {
        padding: var(--spacing-lg);
    }

    #canvas {
        max-width: 500px;
        max-height: 500px;
    }
}

/* ===== High contrast mode ===== */
@media (prefers-contrast: high) {
    :root {
        --bg-primary: #000;
        --bg-secondary: #111;
        --bg-tertiary: #222;
        --text-primary: #fff;
        --text-secondary: #ccc;
    }

    .drop-zone {
        stroke-width: 3;
    }
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
