/* =====================================================
   KRZYŻÓWKI GENETYCZNE – KWADRAT PUNNETTA
   ===================================================== */

:root {
    --bg-primary: #f0f4f8;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8eef4;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --accent-primary: #8b5cf6;
    --accent-secondary: #7c3aed;
    --accent-gradient: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.15);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition: all 0.3s ease;
    --canvas-bg: #edf1f7;
    /* Punnett cell colours – light mode */
    --cell-dominant-bg: rgba(139,92,246,0.12);
    --cell-dominant-border: rgba(139,92,246,0.35);
    --cell-dominant-text: #5b21b6;
    --cell-hetero-bg: rgba(99,102,241,0.1);
    --cell-hetero-border: rgba(99,102,241,0.3);
    --cell-hetero-text: #4338ca;
    --cell-recessive-bg: rgba(236,72,153,0.1);
    --cell-recessive-border: rgba(236,72,153,0.3);
    --cell-recessive-text: #be185d;
    --cell-phenotype-color: #6b7280;
    --header-father-bg: rgba(59,130,246,0.12);
    --header-father-border: rgba(59,130,246,0.3);
    --header-father-text: #1d4ed8;
    --header-mother-bg: rgba(236,72,153,0.12);
    --header-mother-border: rgba(236,72,153,0.3);
    --header-mother-text: #be185d;
    --punnett-title-color: #9ca3af;
    --results-bar-bg: rgba(0,0,0,0.04);
    --results-bar-border: rgba(0,0,0,0.08);
    --results-ratio-color: #4b5563;
    --results-ratio-strong: #5b21b6;
}

[data-theme="dark"] {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --text-primary: #f0f6fc;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --border-color: #30363d;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.5);
    --canvas-bg: #060d14;
    /* Punnett cell colours – dark mode */
    --cell-dominant-bg: rgba(139,92,246,0.22);
    --cell-dominant-border: rgba(139,92,246,0.45);
    --cell-dominant-text: #c4b5fd;
    --cell-hetero-bg: rgba(99,102,241,0.2);
    --cell-hetero-border: rgba(99,102,241,0.4);
    --cell-hetero-text: #a5b4fc;
    --cell-recessive-bg: rgba(244,114,182,0.18);
    --cell-recessive-border: rgba(244,114,182,0.38);
    --cell-recessive-text: #f9a8d4;
    --cell-phenotype-color: rgba(255,255,255,0.45);
    --header-father-bg: rgba(96,165,250,0.18);
    --header-father-border: rgba(96,165,250,0.3);
    --header-father-text: #93c5fd;
    --header-mother-bg: rgba(244,114,182,0.18);
    --header-mother-border: rgba(244,114,182,0.3);
    --header-mother-text: #f9a8d4;
    --punnett-title-color: rgba(255,255,255,0.5);
    --results-bar-bg: rgba(255,255,255,0.05);
    --results-bar-border: rgba(255,255,255,0.09);
    --results-ratio-color: rgba(255,255,255,0.55);
    --results-ratio-strong: #c4b5fd;
}

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

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── App Container ─────────────────────────────────── */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
}

/* ── Header ────────────────────────────────────────── */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    z-index: 100;
    flex-shrink: 0;
}

.header h1 {
    font-size: 1.35rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-controls { display: flex; gap: 0.5rem; }

.control-btn {
    width: 40px; height: 40px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: var(--transition);
}
.control-btn:hover { background: var(--accent-primary); color: white; }
.control-btn svg { width: 20px; height: 20px; }

.moon-icon, .compress-icon { display: none; }
[data-theme="dark"] .sun-icon { display: none; }
[data-theme="dark"] .moon-icon { display: block; }
.fullscreen-active .expand-icon { display: none; }
.fullscreen-active .compress-icon { display: block; }

/* ── Main Content Grid ─────────────────────────────── */
.main-content {
    display: grid;
    grid-template-columns: 270px 1fr 310px;
    gap: 1rem;
    padding: 1rem;
    flex: 1;
    overflow: hidden;
    background: var(--bg-primary);
    min-height: 0;
}

/* ── Panels ────────────────────────────────────────── */
.controls-panel, .info-panel {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-md);
    overflow-y: auto;
    border: 1px solid var(--border-color);
}

.controls-panel h2, .info-panel h2 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.control-section {
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border-color);
}
.control-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.control-section h3 {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.parent-label {
    font-weight: 400;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: 2px;
}

/* ── Mode Buttons ──────────────────────────────────── */
.mode-buttons { display: flex; flex-direction: column; gap: 0.4rem; }

.mode-btn {
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
    font-family: 'Inter', sans-serif;
}
.mode-btn:hover { border-color: var(--accent-primary); color: var(--accent-primary); }
.mode-btn.active {
    background: var(--accent-gradient);
    color: white;
    border-color: transparent;
}

/* ── Parent Controls ───────────────────────────────── */
.parent-controls { display: flex; flex-direction: column; gap: 0.5rem; }

.allele-group { display: flex; flex-direction: column; gap: 0.25rem; }
.allele-group-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.allele-selector { display: flex; gap: 0.3rem; flex-wrap: wrap; }

.allele-btn {
    padding: 0.3rem 0.65rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    font-family: 'Courier New', monospace;
    min-width: 38px;
    text-align: center;
}
.allele-btn:hover { border-color: var(--accent-primary); color: var(--accent-primary); }
.allele-btn.active { background: var(--accent-gradient); color: white; border-color: transparent; }

.genotype-display {
    margin-top: 0.5rem;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent-primary);
    font-family: 'Courier New', monospace;
    text-align: center;
    letter-spacing: 0.08em;
    transition: var(--transition);
}

/* ── Preset Buttons ────────────────────────────────── */
.preset-btn {
    width: 100%;
    padding: 0.45rem 0.65rem;
    text-align: left;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-family: 'Inter', sans-serif;
    margin-bottom: 0.3rem;
    display: block;
}
.preset-btn:last-child { margin-bottom: 0; }
.preset-btn:hover { border-color: var(--accent-primary); color: var(--accent-primary); }
.preset-btn.active { background: var(--accent-gradient); color: white; border-color: transparent; }

/* ── Checkbox ──────────────────────────────────────── */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    margin-bottom: 0.5rem;
}
.checkbox-label input { display: none; }
.checkmark {
    width: 18px; height: 18px; flex-shrink: 0;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    position: relative;
    transition: var(--transition);
}
.checkbox-label input:checked + .checkmark { background: var(--accent-primary); border-color: var(--accent-primary); }
.checkbox-label input:checked + .checkmark::after {
    content: '✓';
    position: absolute;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
}

/* ── Action Buttons ────────────────────────────────── */
.action-buttons { display: flex; gap: 0.4rem; }
.action-btn {
    flex: 1; padding: 0.6rem;
    border: none; border-radius: var(--radius-md);
    font-size: 0.78rem; font-weight: 600;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 0.3rem;
    transition: var(--transition);
    font-family: 'Inter', sans-serif;
}
.action-btn.start { background: var(--accent-gradient); color: white; }
.action-btn.start:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(139,92,246,0.4); }
.action-btn.reset { background: var(--bg-tertiary); color: var(--text-secondary); border: 1px solid var(--border-color); }
.action-btn.reset:hover { background: var(--accent-primary); color: white; border-color: var(--accent-primary); }
.btn-icon { font-size: 0.85rem; }

/* ── Simulation Container ──────────────────────────── */
.simulation-container { display: flex; flex-direction: column; min-height: 0; }

.simulation-box {
    flex: 1;
    background: var(--canvas-bg);
    border-radius: var(--radius-lg);
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow-lg);
    min-height: 0;
}

/* ── Zoom Controls ─────────────────────────────────── */
.zoom-controls {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    z-index: 50;
}
.zoom-btn {
    width: 32px; height: 32px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: var(--transition);
    font-size: 0.9rem;
    box-shadow: var(--shadow-sm);
}
.zoom-btn:hover { background: var(--bg-tertiary); color: var(--accent-primary); border-color: var(--accent-primary); }

/* ── Punnett Wrapper ───────────────────────────────── */
.punnett-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 1.5rem;
    gap: 0.85rem;
    transition: transform 0.1s ease-out;
}

.punnett-title {
    color: var(--punnett-title-color);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* ── Punnett Table ─────────────────────────────────── */
.punnett-table {
    display: grid;
    gap: 5px;
}

.punnett-cell {
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    transition: var(--transition);
    cursor: default;
    position: relative;
    min-width: 0;
}

/* Corner / Header cells */
.punnett-cell.corner {
    background: transparent;
}

.punnett-cell.header-mother {
    background: var(--header-mother-bg);
    border: 1px solid var(--header-mother-border);
    color: var(--header-mother-text);
    border-radius: var(--radius-sm);
}

.punnett-cell.header-father {
    background: var(--header-father-bg);
    border: 1px solid var(--header-father-border);
    color: var(--header-father-text);
    border-radius: var(--radius-sm);
}

.header-icon {
    font-size: 0.65rem;
    opacity: 0.7;
    margin-bottom: 1px;
}

.header-gamete {
    font-family: 'Courier New', monospace;
    font-weight: 700;
    letter-spacing: 0.06em;
}

/* Result cells */
.punnett-cell.result {
    animation: cellFadeIn 0.35s ease forwards;
    opacity: 0;
    cursor: pointer;
}

.punnett-cell.dominant {
    background: var(--cell-dominant-bg);
    border: 2px solid var(--cell-dominant-border);
}
.punnett-cell.dominant .cell-genotype { color: var(--cell-dominant-text); }

.punnett-cell.recessive {
    background: var(--cell-recessive-bg);
    border: 2px solid var(--cell-recessive-border);
}
.punnett-cell.recessive .cell-genotype { color: var(--cell-recessive-text); }

.punnett-cell.heterozygous {
    background: var(--cell-hetero-bg);
    border: 2px solid var(--cell-hetero-border);
}
.punnett-cell.heterozygous .cell-genotype { color: var(--cell-hetero-text); }

.punnett-cell.result:hover {
    transform: scale(1.08);
    box-shadow: 0 0 24px rgba(139,92,246,0.5);
    z-index: 10;
}

.cell-genotype {
    font-family: 'Courier New', monospace;
    font-weight: 700;
    letter-spacing: 0.05em;
    line-height: 1;
}

.cell-phenotype {
    font-size: 0.58rem;
    font-weight: 500;
    color: var(--cell-phenotype-color);
    margin-top: 3px;
    text-align: center;
    line-height: 1.2;
    max-width: 90%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.punnett-cell.simple-mode .cell-phenotype { display: none; }

@keyframes cellFadeIn {
    from { opacity: 0; transform: scale(0.65); }
    to   { opacity: 1; transform: scale(1); }
}

/* ── Results Bar ───────────────────────────────────── */
.results-bar {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
    background: var(--results-bar-bg);
    border-radius: var(--radius-md);
    padding: 0.6rem 1.25rem;
    border: 1px solid var(--results-bar-border);
    min-width: 0;
    max-width: 100%;
}

.ratio-item {
    font-size: 0.75rem;
    color: var(--results-ratio-color);
    font-weight: 500;
}
.ratio-item strong { color: var(--results-ratio-strong); font-weight: 700; }

/* ── Info Cards ────────────────────────────────────── */
.info-card {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-bottom: 0.85rem;
}
.info-card:last-child { margin-bottom: 0; }
.info-card h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

.stage-card {
    background: linear-gradient(135deg, rgba(139,92,246,0.1) 0%, rgba(99,102,241,0.1) 100%);
    border: 1px solid rgba(139,92,246,0.25);
}
.stage-card p { font-size: 0.8rem; color: var(--text-secondary); line-height: 1.6; }

/* ── Stats ─────────────────────────────────────────── */
.stats-section { margin-bottom: 0.75rem; }
.stats-section:last-child { margin-bottom: 0; }

.stats-subtitle {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 0.45rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.3rem 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.78rem;
}
.stat-row:last-child { border-bottom: none; }
.stat-label { color: var(--text-secondary); font-family: 'Courier New', monospace; font-weight: 600; }
.stat-value { font-weight: 700; color: var(--accent-primary); }

.stat-bar {
    width: 100%;
    height: 3px;
    background: var(--bg-primary);
    border-radius: 2px;
    margin-top: 3px;
    overflow: hidden;
}
.stat-bar-fill {
    height: 100%;
    background: var(--accent-gradient);
    border-radius: 2px;
    transition: width 0.6s ease;
}

.prob-hidden .stat-bar { display: none; }

/* ── Allele Table ──────────────────────────────────── */
.allele-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.allele-table th {
    text-align: left;
    padding: 0.4rem 0.5rem;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border-color);
}
.allele-table td {
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}
.allele-table tr:last-child td { border-bottom: none; }
.allele-symbol {
    font-weight: 700;
    color: var(--accent-primary);
    font-family: 'Courier New', monospace;
    font-size: 1rem;
}

.physics-info p { font-size: 0.8rem; color: var(--text-secondary); line-height: 1.6; }

/* ── Scrollbar ─────────────────────────────────────── */
.controls-panel::-webkit-scrollbar,
.info-panel::-webkit-scrollbar { width: 5px; }
.controls-panel::-webkit-scrollbar-track,
.info-panel::-webkit-scrollbar-track { background: transparent; }
.controls-panel::-webkit-scrollbar-thumb,
.info-panel::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 1200px) {
    .main-content { grid-template-columns: 240px 1fr 280px; }
}
@media (max-width: 992px) {
    .main-content { grid-template-columns: 1fr; overflow-y: auto; }
    .controls-panel, .info-panel { max-height: 220px; }
    .controls-panel { order: 1; }
    .simulation-container { order: 2; min-height: 400px; }
    .info-panel { order: 3; }
    .header h1 { font-size: 1rem; }
}
