:root {
    --bg-color: #0f172a;
    --text-color: #f8fafc;
    --border-color: #334155;
    --correct-bg: rgba(34, 197, 94, 0.2);
    --correct-border: #22c55e;
    --absent-bg: rgba(0, 0, 0, 0.2);
    --wire-color: #64748b;
    --gate-bg: #3b82f6;
    --cx-color: #eab308;
    --panel-bg: #1e293b;
}

/* --- iOS Centering & Mobile Fixes --- */
html, body {
    overflow-x: hidden;
    width: 100%;
    position: relative;
    box-sizing: border-box;
    /* Respect iPhone notch / Dynamic Island / home-bar */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    /* Prevent rubber-band overscroll showing white background */
    background-color: var(--bg-color);
    /* Disable tap flash on all interactive elements */
    -webkit-tap-highlight-color: transparent;
    /* Prevent text resize on orientation change */
    -webkit-text-size-adjust: 100%;
}

*, *:before, *:after {
    box-sizing: inherit;
}

/* Ensure the board scrolls internally on small screens without breaking the page layout */
#board, #history-board {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* Enables buttery-smooth momentum scrolling on iPhones */
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0;
    padding: 20px;
    overflow-x: hidden;
}

/* Logo Styles */
.app-logo {
    display: block;
    margin: 0 auto;
}


#game-view { display: none; width: 100%; flex-direction: column; align-items: center;}

.instructions { font-size: 0.95rem; color: #94a3b8; margin-bottom: 20px; text-align: center; max-width: 800px; line-height: 1.4;}
.stage-breadcrumb { font-size: 1rem; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 4px; font-weight: 600; }
.stage-level-title { font-size: 1.55rem; font-weight: 700; color: #e2e8f0; margin-bottom: 4px; }
.stage-subtitle { font-size: 0.88rem; color: #94a3b8; margin-top: 2px; }
#stage-nav { display: flex; justify-content: center; gap: 12px; margin-bottom: 16px; }
#stage-nav.hidden { display: none; }
.stage-nav-btn { background: transparent; border: 1px solid #334155; color: #94a3b8; border-radius: 6px; padding: 5px 14px; font-size: 0.85rem; cursor: pointer; transition: border-color 0.15s, color 0.15s; }
.stage-nav-btn:hover:not(:disabled) { border-color: #7c3aed; color: #c4b5fd; }
.stage-nav-btn:disabled { opacity: 0.25; cursor: default; }

/* Hint/Lesson Button Styles */
.hint-btn {
    background: #475569; color: white; border: none; padding: 6px 12px; 
    border-radius: 4px; cursor: pointer; font-size: 0.8rem; margin-top: 10px; margin-right: 5px;
    transition: background 0.2s;
}
.hint-btn:hover { filter: brightness(1.1); }
.hint-text { margin-top: 10px; font-style: italic; color: #eab308; }
.lesson-text { margin-top: 10px; color: #cbd5e1; font-size: 0.9rem; text-align: left; background: rgba(0,0,0,0.2); padding: 12px; border-radius: 6px; border-left: 3px solid #38bdf8; line-height: 1.5; max-height: 55vh; overflow-y: auto; }
.lesson-text b { color: #38bdf8; }

.main-layout {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 30px;
    width: 100%;
    max-width: 1200px;
}

.left-col { display: flex; flex-direction: column; flex: 1; min-width: 320px; max-width: 700px; order: 1; }
.right-col {
    display: flex; flex-direction: column; width: 250px; background: var(--panel-bg);
    border: 1px solid var(--border-color); border-radius: 8px; padding: 15px; height: fit-content;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3); order: 2; margin: 0 auto;
}

.state-container {
    background-color: var(--panel-bg); border: 1px solid var(--border-color);
    border-radius: 8px; padding: 15px; margin-bottom: 20px; text-align: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}
.state-amplitudes { font-size: 1.1rem; font-family: monospace; font-weight: bold; color: #38bdf8; word-wrap: break-word;}
.state-label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1px; color: #94a3b8; margin-bottom: 5px; }

#live-state-container { border-color: #eab308; }
#live-state-container .state-amplitudes { color: #eab308; }

#board { display: flex; flex-direction: column; gap: 12px; margin-bottom: 25px; width: 100%; }
.row-wrapper { 
    display: flex; flex-direction: column; background: var(--panel-bg); 
    border-radius: 6px; overflow: hidden; border: 2px solid transparent; transition: border-color 0.2s; width: 100%;
}
.row-wrapper.active { border-color: #94a3b8; box-shadow: 0 0 8px rgba(148, 163, 184, 0.3); }

.circuit-row { display: flex; position: relative; width: 100%; }

.qubit-labels {
    display: flex; flex-direction: column; justify-content: space-around; width: 30px; 
    background: #0f172a; font-family: monospace; font-size: 0.7rem; color: #94a3b8; 
    padding-left: 5px; border-right: 1px solid var(--border-color); flex-shrink: 0;
}

.slot {
    flex: 1; min-width: 35px; position: relative; border-right: 1px dashed var(--border-color); transition: background 0.2s;
}
.slot:last-child { border-right: none; }
.slot.drag-over { background: rgba(255, 255, 255, 0.1); }

.wire { position: absolute; left: 0; right: 0; height: 2px; background: var(--wire-color); z-index: 1; pointer-events: none;}

/* Base Gate Styles */
.gate-box {
    position: absolute; width: 30px; height: 30px; background: var(--gate-bg); color: white; 
    text-align: center; font-weight: bold; line-height: 30px; font-size: 14px; z-index: 2; 
    left: 50%; transform: translate(-50%, -50%); border-radius: 4px; box-shadow: 0 2px 4px rgba(0,0,0,0.5); pointer-events: none;
}
.rz-gate { display: flex; flex-direction: column; justify-content: center; align-items: center; line-height: 1.1; }
.cp-gate { background: #8b5cf6 !important; }

.ctrl-dot { position: absolute; width: 12px; height: 12px; background: var(--cx-color); border-radius: 50%; z-index: 2; left: 50%; transform: translate(-50%, -50%); pointer-events: none; }
.tgt-cross { position: absolute; width: 20px; height: 20px; color: var(--cx-color); z-index: 2; left: 50%; transform: translate(-50%, -50%); font-size: 26px; line-height: 20px; text-align: center; pointer-events: none; }
.ctrl-line { position: absolute; left: 50%; width: 2px; background: var(--cx-color); transform: translateX(-50%); z-index: 1; pointer-events: none;}

/* Evaluated Feedback Styles */
.eval-correct { background-color: #059669 !important; border-color: #34d399 !important; color: white !important; }
.eval-absent { background-color: #334155 !important; color: #94a3b8 !important; border-color: #1e293b !important; opacity: 0.8; }
.eval-correct.ctrl-dot, .eval-correct.ctrl-line { background-color: #059669 !important; border:none !important;}
.eval-correct.tgt-cross { color: #059669 !important; }
.eval-absent.ctrl-dot, .eval-absent.ctrl-line { background-color: #475569 !important; border:none !important;}
.eval-absent.tgt-cross { color: #475569 !important; opacity: 0.7;}

#board.hard-mode .gate-box { width: 22px; height: 22px; line-height: 22px; font-size: 11px; }
#board.hard-mode .tgt-cross { width: 16px; height: 16px; font-size: 20px; line-height: 16px; }
#board.hard-mode .ctrl-dot { width: 8px; height: 8px; }
#board.hard-mode .qubit-labels { width: 22px; font-size: 0.6rem; }

.amplitudes-result { font-family: monospace; font-size: 0.95rem; background-color: rgba(0,0,0,0.3); padding: 8px; text-align: center; color: #cbd5e1; border-top: 1px solid var(--border-color); }
.original-label { font-size: 0.8rem; color: #f8fafc; background: rgba(0,0,0,0.4); padding: 4px; text-align: center; text-transform: uppercase;}

#palette-container { margin-bottom: 20px; width: 100%;}
.palette-label { font-size: 0.8rem; color: #94a3b8; margin-bottom: 10px; text-align: center; text-transform: uppercase;}
#palette { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; background: var(--panel-bg); padding: 15px; border-radius: 8px; border: 1px solid var(--border-color); }
.palette-item { width: 45px; background: #0f172a; border: 1px solid var(--border-color); border-radius: 6px; position: relative; cursor: grab; transition: transform 0.1s;}
.palette-item:active { cursor: grabbing; transform: scale(0.95); }
.palette-item:hover { border-color: #64748b; }

.controls { display: flex; gap: 10px; margin-bottom: 20px; width: 100%;}
.btn { flex: 1; padding: 12px; font-size: 0.9rem; font-weight: bold; border: none; border-radius: 6px; cursor: pointer; color: white; text-transform: uppercase; }
#submit-btn { background-color: var(--gate-bg); }
#submit-btn:hover { background-color: #2563eb; }
#submit-btn:disabled { background-color: #475569; cursor: not-allowed; color: #94a3b8; }
#menu-btn { background: #475569; }
#menu-btn:hover { background: #334155; }
#game-menu-btn { background: #1e3a5f; }
#game-menu-btn:hover { background: #1e40af; }
#modal-menu-btn { background: #1e3a5f !important; }
#modal-menu-btn:hover { background: #1e40af !important; }
.btn-green { background-color: #059669 !important; }
.btn-green:hover { background-color: #047857 !important; }
.btn-yellow { background-color: #eab308 !important; color: #000 !important; }
.btn-yellow:hover { background-color: #ca8a04 !important; }
.btn-red { background-color: #ef4444 !important; }
.btn-red:hover { background-color: #dc2626 !important; }

#message { font-size: 1.2rem; font-weight: bold; height: 1.5rem; text-align: center; margin-bottom: 20px; padding: 0 10px;}

#gate-guide { 
    background-color: var(--panel-bg); border: 1px solid var(--border-color); border-radius: 8px; 
    padding: 15px; width: 100%; max-width: 980px; box-sizing: border-box; order: 3; margin: 0 auto 20px auto;
}
.guide-title { font-size: 0.9rem; color: #94a3b8; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 12px; text-align: center; }
.guide-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.guide-card { background: rgba(0,0,0,0.2); padding: 12px; border-radius: 6px; border: 1px solid var(--border-color); font-size: 0.85rem; color: #cbd5e1; }
.guide-card b { color: #f8fafc; font-size: 0.95rem; display: block; margin-bottom: 6px; }
.math-expr { font-family: monospace; color: #eab308; display: block; line-height: 1.5; }

.bloch-title { text-align: center; font-size: 0.9rem; color: #cbd5e1; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 15px;}
.canvas-container { display: flex; flex-direction: column; align-items: center; gap: 20px;}
canvas { border-radius: 8px; background: #0f172a; border: 1px solid var(--border-color); }
.bloch-note { font-size: 0.75rem; color: #94a3b8; text-align: center; margin-top: 15px;}

/* Main Menu Overlay & Accordion Styles */
#main-menu { width: 100%; max-width: 900px; display: flex; flex-direction: column; gap: 20px; animation: fadeIn 0.3s ease-out; }

/* Home screen */
body:has(#menu-home:not(.hidden)) {
    padding: 0;
}
#menu-home {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 52px;
    min-height: 100svh;
    padding: 32px 20px;
    text-align: center;
    background: radial-gradient(ellipse 60% 40% at 50% 38%, rgba(59,130,246,0.22) 0%, rgba(139,92,246,0.14) 40%, transparent 65%);
}
#menu-welcome-sub { margin: 0; font-size: 1.1rem; color: #64748b; }

/* ── Login screen ───────────────────────────────────────────────── */
#login-screen {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 6px;
    min-height: 100dvh; padding: 24px 16px; box-sizing: border-box;
    animation: fadeIn 0.4s ease-out;
}
.login-logo {
    width: clamp(220px, 48vw, 380px); height: auto; margin: 0 auto;
    animation: logoFadeIn 0.9s ease-out both, logoPulse 3.5s 1s ease-in-out infinite;
}
@keyframes logoPulse {
    0%, 100% { filter: drop-shadow(0 0 8px rgba(56,189,248,0.25)); }
    50%       { filter: drop-shadow(0 0 22px rgba(56,189,248,0.55)); }
}
.login-subtitle { margin: 4px 0 20px; font-size: 1rem; color: #64748b; }
.login-form {
    display: flex; flex-direction: column; gap: 12px;
    width: min(340px, 92vw);
}
#login-title { margin: 0 0 4px; font-size: 1.35rem; color: #f8fafc; text-align: center; }

/* ── Auth inputs (shared between login screen and any future forms) */
.auth-input {
    width: 100%; box-sizing: border-box;
    background: #1e293b; border: 1px solid #334155; border-radius: 8px;
    padding: 11px 13px; color: #f8fafc; font-size: 0.95rem;
}
.auth-input:focus { outline: none; border-color: #38bdf8; }
#auth-submit-btn { width: 100%; padding: 12px; font-size: 1rem; }
.auth-toggle-btn { background: none; border: none; color: #64748b; font-size: 0.85rem; cursor: pointer; text-align: center; text-decoration: underline; }
.auth-toggle-btn:hover { color: #94a3b8; }
.auth-error { font-size: 0.85rem; text-align: center; }

/* ── Auth status bar on home screen ────────────────────────────── */
#auth-status-bar { margin-top: 18px; display: flex; align-items: center; justify-content: center; gap: 10px; }
#auth-email-display { font-size: 0.85rem; color: #64748b; }
.auth-link-btn { background: none; border: none; color: #64748b; font-size: 0.85rem; cursor: pointer; text-decoration: underline; padding: 2px 4px; }
.auth-link-btn:hover { color: #94a3b8; }

/* ── Home screen logo (static, no animation) ────────────────────── */
.home-logo {
    width: clamp(160px, 32vw, 320px);
    height: auto; margin: 0 auto;
}
@keyframes logoFadeIn {
    from { opacity: 0; transform: translateY(-10px) scale(0.93); }
    to   { opacity: 1; transform: translateY(0)     scale(1); }
}
#home-btns { display: flex; gap: 12px; }
.home-btn {
    padding: 16px 56px;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.15s, filter 0.15s;
}
.home-btn:hover { transform: translateY(-2px); filter: brightness(1.12); }
.home-btn:active { transform: none; filter: brightness(0.93); }
#btn-go-learn { background: #3b82f6; color: #fff; box-shadow: 0 4px 28px rgba(59,130,246,0.45); }
#btn-go-play  { background: #8b5cf6; color: #fff; box-shadow: 0 4px 28px rgba(139,92,246,0.45); }

@media (max-width: 520px) {
    #menu-home { gap: 28px; }
    .home-logo { width: clamp(260px, 74vw, 340px); }
    #home-btns { gap: 10px; }
    .home-btn { padding: 16px 36px; }
}

/* Stages & play pages */
#menu-stages, #menu-play-page { display: flex; flex-direction: column; gap: 14px; animation: fadeIn 0.2s ease-out; }

#mode-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.mode-card { background: var(--panel-bg); border: 1px solid var(--border-color); border-radius: 12px; padding: 22px 20px; cursor: pointer; transition: border-color 0.18s, transform 0.15s, box-shadow 0.18s; }
.mode-card:hover { border-color: #38bdf8; transform: translateY(-3px); box-shadow: 0 8px 24px rgba(56,189,248,0.12); }
.mode-card-wide { grid-column: 1 / -1; }
.mode-card-icon { font-size: 2rem; margin-bottom: 10px; }
.mode-card-title { font-size: 1.1rem; font-weight: 700; color: #e2e8f0; margin-bottom: 6px; }
.mode-card-desc { font-size: 0.85rem; color: #64748b; line-height: 1.45; }

.mode-panel { background: var(--panel-bg); border: 1px solid var(--border-color); border-radius: 12px; padding: 24px; animation: fadeIn 0.2s ease-out; }
.mode-panel.hidden { display: none; }
.panel-back-btn { background: none; border: 1px solid #334155; color: #94a3b8; border-radius: 6px; padding: 5px 14px; font-size: 0.85rem; cursor: pointer; margin-bottom: 20px; transition: border-color 0.15s, color 0.15s; }
.panel-back-btn:hover { border-color: #38bdf8; color: #38bdf8; }
.panel-desc { font-size: 0.9rem; color: #94a3b8; margin: 0 0 20px 0; line-height: 1.5; }

.menu-row { display: flex; flex-wrap: wrap; gap: 10px; }
.menu-btn { background: var(--gate-bg); color: white; border: none; padding: 10px 16px; border-radius: 6px; cursor: pointer; font-weight: bold; font-size: 0.95rem; }
.menu-btn:hover { filter: brightness(1.1); }
.menu-btn.completed { background-color: #059669; border: 1px solid #047857; color: white; }

.stage-box { background: rgba(0,0,0,0.2); border: 1px solid #475569; border-radius: 8px; padding: 15px; margin-bottom: 15px;}
.stage-box h3 { margin: 0 0 5px 0; color: #f8fafc; font-size: 1.1rem;}
.stage-box p { margin: 0 0 10px 0; font-size: 0.85rem; color: #94a3b8;}

/* Learning Map — winding path */
.learn-map { position: relative; width: 100%; overflow-x: hidden; }

/* Section Overview Cards */
.section-overview-card {
    width: 100%; display: flex; align-items: center; justify-content: space-between;
    padding: 16px 18px; border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.07);
    background: rgba(15,23,42,0.5);
    cursor: pointer; font-family: inherit; color: inherit; text-align: left;
    transition: background 0.15s, transform 0.12s;
}
.section-overview-card:not([disabled]):hover { background: rgba(255,255,255,0.06); transform: translateY(-1px); }
.section-overview-card.locked { opacity: 0.45; cursor: not-allowed; }

.soc-left { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 0; }
.soc-icon { font-size: 1.6rem; flex-shrink: 0; }
.soc-info { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.soc-name { font-size: 1rem; font-weight: 700; color: #e2e8f0; }
.soc-bar { height: 5px; border-radius: 3px; background: rgba(255,255,255,0.1); overflow: hidden; }
.soc-fill { height: 100%; border-radius: 3px; transition: width 0.4s ease; }
.soc-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; margin-left: 12px; }
.soc-count { font-size: 0.82rem; color: #64748b; font-weight: 600; }
.soc-arrow { color: #475569; font-size: 1rem; }

/* Section Detail Header */
#section-detail-header { padding: 4px 0 20px; }
.sd-title { font-size: 1.3rem; font-weight: 800; margin-bottom: 10px; }
.sd-progress-wrap { display: flex; flex-direction: column; gap: 6px; }
.sd-bar { height: 8px; border-radius: 4px; background: rgba(255,255,255,0.1); overflow: hidden; }
.sd-fill { height: 100%; border-radius: 4px; transition: width 0.4s ease; }
.sd-count { font-size: 0.82rem; color: #64748b; font-weight: 600; }

.map-node-dot {
    position: absolute;
    width: 44px; height: 44px; border-radius: 50%;
    transform: translate(-50%, -50%);
    background: var(--nc, #475569);
    border: 3px solid #0f172a;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5), 0 0 0 3px rgba(255,255,255,0.06);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; color: white; font-weight: bold;
    z-index: 3;
    transition: transform 0.12s, filter 0.12s;
}
.map-node-dot:hover { transform: translate(-50%, -50%) scale(1.14); filter: brightness(1.3); }
.map-node-dot.done { background: #059669; box-shadow: 0 0 0 3px rgba(5,150,105,0.35); }

.map-node-label {
    position: absolute;
    font-size: 0.78rem; color: #94a3b8;
    transform: translateX(-50%);
    cursor: pointer; z-index: 3;
    line-height: 1.3; width: min(96px, 29vw);
    text-align: center;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.map-node-label.done { color: #34d399; }
.map-node-label:hover { color: #e2e8f0; }
.map-node-dot.locked { cursor: not-allowed; opacity: 0.55; box-shadow: none; font-size: 13px; }
.map-node-dot.locked:hover { transform: translate(-50%, -50%); filter: none; }
.map-node-label.locked { color: #334155; cursor: default; opacity: 0.5; }

/* Gate Selection Pills */
.gate-checkbox { display: none; }
.gate-label {
    background: #1e293b; border: 1px solid var(--border-color); color: #94a3b8;
    padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 0.85rem; font-weight: bold;
    transition: all 0.2s; user-select: none;
}
.gate-checkbox:checked + .gate-label {
    background: rgba(56, 189, 248, 0.15); border-color: #38bdf8; color: #38bdf8;
}

@keyframes fadeIn { from {opacity: 0;} to {opacity: 1;} }
.hidden { display: none !important; }

/* --- Quantum Confetti --- */
.quantum-confetti {
    position: fixed;
    width: 26px;
    height: 26px;
    line-height: 26px;
    text-align: center;
    font-weight: bold;
    font-size: 13px;
    z-index: 9999;
    pointer-events: none; /* Prevents them from blocking your mouse clicks */
    user-select: none;
}
.confetti-cx { background: var(--cx-color); color: #000; border-radius: 50%; }
.confetti-cp { background: #8b5cf6; color: white; border-radius: 4px; }

/* --- Cinematic Victory Modal --- */
.victory-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.7); /* Darkens the screen */
    backdrop-filter: blur(5px);        /* Blurs the game board */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}
.victory-overlay.show {
    opacity: 1;
    pointer-events: auto;
}
.victory-banner {
    width: 100%;
    max-height: 90dvh;
    overflow-y: auto;
    background: rgba(15, 23, 42, 0.95);
    border-top: 2px solid #22c55e;
    border-bottom: 2px solid #22c55e;
    box-shadow: 0 0 40px rgba(34, 197, 94, 0.2);
    text-align: center;
    padding: 50px 20px;
    transform: translateX(-100vw);
    transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
.victory-overlay.show .victory-banner {
    transform: translateX(0);
}
.victory-banner h1 {
    margin: 0 0 10px 0;
    font-size: 3.5rem;
    color: #22c55e;
    text-transform: uppercase;
    letter-spacing: 4px;
    text-shadow: 0 0 20px rgba(34, 197, 94, 0.4);
}
.victory-banner p {
    font-size: 1.2rem;
    color: #cbd5e1;
    margin: 0 0 30px 0;
    font-weight: bold;
}
.victory-controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    max-width: 600px;
    margin: 0 auto;
}
.victory-controls .btn { flex: 1; }

.modal-view-solution-btn {
    display: block;
    width: 100%;
    max-width: 600px;
    margin: 10px auto 0;
    background: transparent;
    border: 1px solid #334155;
    border-radius: 6px;
    color: #94a3b8;
    font-size: 0.9rem;
    font-weight: bold;
    text-transform: uppercase;
    padding: 12px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.modal-view-solution-btn:hover { border-color: #7c3aed; color: #c4b5fd; }

/* Collapsible optimization note */
.opt-note {
    margin-top: 12px;
    padding: 10px 14px;
    background: rgba(56,189,248,0.06);
    border: 1px solid #334155;
    border-radius: 8px;
    font-size: 0.82rem;
    color: #94a3b8;
    text-align: left;
    width: 100%;
}
.opt-note summary {
    color: #38bdf8;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
    padding: 2px 0;
}
.opt-note summary::after { content: ' ▸'; font-size: 0.7rem; }
.opt-note[open] summary::after { content: ' ▾'; }
.opt-note summary::-webkit-details-marker { display: none; }
.opt-note-body { margin-top: 10px; line-height: 1.55; }
.opt-note-body strong { color: #cbd5e1; }

/* Compact victory modal on small phones */
@media (max-height: 700px) {
    .victory-banner { padding: 24px 16px; }
    .victory-banner h1 { font-size: 2.2rem; letter-spacing: 2px; }
    .victory-banner p { font-size: 1rem; margin-bottom: 16px; }
}

/* ── Section Complete Overlay ──────────────────────────────────────────────── */
.sco-overlay {
    position: fixed; inset: 0; z-index: 900;
    display: flex; align-items: center; justify-content: center;
    background: rgba(2, 6, 23, 0.94);
    animation: scoFadeIn 0.35s ease-out both;
}
@keyframes scoFadeIn { from { opacity: 0; } to { opacity: 1; } }

.sco-banner {
    position: relative; max-width: 400px; width: 90%;
    text-align: center; padding: 44px 32px 36px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.1);
    background: radial-gradient(ellipse 80% 60% at 50% 20%, var(--sco-bg, rgba(59,130,246,0.18)) 0%, transparent 70%),
                #0f172a;
    animation: scoBannerIn 0.45s cubic-bezier(0.34,1.56,0.64,1) both;
}
@keyframes scoBannerIn { from { opacity: 0; transform: scale(0.88) translateY(20px); } to { opacity: 1; transform: none; } }

.sco-label {
    font-size: 0.7rem; font-weight: 800; letter-spacing: 0.18em;
    text-transform: uppercase; color: #94a3b8; margin-bottom: 20px;
}

.sco-done-icon { font-size: 3.6rem; line-height: 1; margin-bottom: 8px; animation: scoIconPop 0.5s 0.2s cubic-bezier(0.34,1.56,0.64,1) both; }
@keyframes scoIconPop { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.sco-done-name {
    font-size: 1.5rem; font-weight: 800; letter-spacing: 0.01em; margin-bottom: 0;
    animation: scoSlideUp 0.4s 0.3s ease-out both;
}
@keyframes scoSlideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.sco-divider {
    height: 1px; background: rgba(255,255,255,0.08); margin: 24px 0;
    animation: scoSlideUp 0.4s 0.35s ease-out both;
}

.sco-unlock-wrap { animation: scoSlideUp 0.4s 0.45s ease-out both; }
.sco-unlock-label {
    font-size: 0.72rem; font-weight: 700; letter-spacing: 0.14em;
    text-transform: uppercase; color: #fbbf24; margin-bottom: 12px;
}
.sco-next-icon { font-size: 2.4rem; line-height: 1; margin-bottom: 6px; }
.sco-next-name { font-size: 1.1rem; font-weight: 700; }

.sco-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 28px; animation: scoSlideUp 0.4s 0.55s ease-out both; }

.sco-btn-primary {
    padding: 14px 24px; border: none; border-radius: 10px;
    font-size: 1rem; font-weight: 700; cursor: pointer; font-family: inherit;
    color: #fff; transition: filter 0.15s, transform 0.12s;
    box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}
.sco-btn-primary:hover { filter: brightness(1.15); transform: translateY(-1px); }

.sco-btn-secondary {
    padding: 12px 24px; border: 1px solid rgba(255,255,255,0.12); border-radius: 10px;
    font-size: 0.9rem; font-weight: 600; cursor: pointer; font-family: inherit;
    background: transparent; color: #64748b; transition: color 0.15s, border-color 0.15s;
}
.sco-btn-secondary:hover { color: #94a3b8; border-color: rgba(255,255,255,0.22); }

/* --- Tap-to-Place Grid UI --- */
.palette-item.selected {
    border-color: #22c55e;
    box-shadow: 0 0 12px rgba(34, 197, 94, 0.4);
    transform: scale(1.05);
    background: rgba(34, 197, 94, 0.1);
}
.slot-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    border-right: 1px dashed var(--border-color);
}
.slot-column:last-child { border-right: none; }
.cell-zone {
    flex: 1;
    z-index: 10; /* Sits above the drawn wires and gates */
    cursor: pointer;
    transition: background 0.1s;
}
.cell-zone:hover { background: rgba(255, 255, 255, 0.05); }
.cell-zone.pending {
    background: rgba(234, 179, 8, 0.2);
    border: 1px dashed #eab308;
}

/* --- Tooltip System --- */
.tt { position: relative; }
.tt::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #0f172a;
    color: #cbd5e1;
    border: 1px solid #475569;
    border-radius: 6px;
    padding: 7px 11px;
    font-size: 0.76rem;
    line-height: 1.45;
    width: max-content;
    max-width: 230px;
    text-align: center;
    white-space: normal;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 8000;
    font-weight: normal;
}
.tt:hover::after { opacity: 1; }
.bloch-wrap { display: inline-block; }

/* --- Tutorial & Ghost Hand Animations --- */
.tutorial-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.85);
    z-index: 10000; display: none;
}
.tutorial-overlay.show { display: block; }
.tutorial-tooltip {
    position: absolute; background: #1e293b; border: 2px solid #38bdf8;
    padding: 20px; border-radius: 8px; color: white; width: 320px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5); z-index: 10002;
    transition: top 0.3s ease; display: none;
    left: 50%; transform: translateX(-50%);
}
.tutorial-tooltip.show { display: block; }
.tutorial-spotlight {
    position: relative; z-index: 10001 !important;
    box-shadow: 0 0 0 4px #38bdf8, 0 0 20px rgba(56, 189, 248, 0.6) !important;
    background: var(--panel-bg); border-radius: 6px; pointer-events: auto;
}

/* The In-Game Pointer */
.ghost-pulse {
    animation: pulse-ring 1.5s infinite;
    position: relative; z-index: 100;
    border-radius: 4px;
}
@keyframes pulse-ring {
    0% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.7); }
    70% { box-shadow: 0 0 0 15px rgba(56, 189, 248, 0); }
    100% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0); }
}
.ghost-text {
    position: absolute; top: -45px; left: 50%; transform: translateX(-50%);
    background: #38bdf8; color: #000; padding: 6px 12px; border-radius: 6px;
    font-weight: bold; white-space: nowrap; pointer-events: none;
    animation: float-up-down 2s infinite ease-in-out; z-index: 101;
}
.ghost-text::after {
    content: ''; position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%);
    border-width: 6px 6px 0; border-style: solid; border-color: #38bdf8 transparent transparent transparent;
}
@keyframes float-up-down {
    0%, 100% { transform: translate(-50%, 0); }
    50% { transform: translate(-50%, -5px); }
}

/* --- Column Command Gates --- */
.gate-box.qft-gate {
    background: linear-gradient(135deg, #eab308 0%, #ca8a04 100%);
    border-color: #fef08a; color: #451a03; font-weight: 900;
    box-shadow: 0 0 15px rgba(234, 179, 8, 0.4); z-index: 50;
}
.gate-box.iqft-gate {
    background: linear-gradient(135deg, #d946ef 0%, #a21caf 100%);
    border-color: #f0abfc; color: #4a044e; font-weight: 900;
    box-shadow: 0 0 15px rgba(217, 70, 239, 0.4); z-index: 50;
}

/* --- Timed Mode --- */
.timer-warning {
    animation: timer-pulse 0.8s ease-in-out infinite;
}
@keyframes timer-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}
.wrong-attempt {
    animation: wrong-shake 0.45s ease-out;
    outline: 2px solid #ef4444;
    border-radius: 8px;
}
@keyframes wrong-shake {
    0%   { transform: translateX(0);    background: rgba(239,68,68,0.15); }
    15%  { transform: translateX(-8px); background: rgba(239,68,68,0.2); }
    35%  { transform: translateX(7px);  background: rgba(239,68,68,0.2); }
    55%  { transform: translateX(-5px); background: rgba(239,68,68,0.1); }
    75%  { transform: translateX(3px);  background: rgba(239,68,68,0.05); }
    100% { transform: translateX(0);    background: transparent; }
}

/* === Achievement Toast === */
.achievement-toast {
    position: fixed;
    top: -90px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #1e293b, #0f172a);
    border: 2px solid #eab308;
    border-radius: 12px;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 10001;
    transition: top 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 4px 24px rgba(234,179,8,0.35);
    max-width: 340px;
    width: 90%;
    pointer-events: none;
}
.achievement-toast.show { top: 16px; }
.ach-toast-icon { font-size: 1.8rem; line-height: 1; }
.ach-toast-label { font-size: 0.7rem; color: #eab308; font-weight: bold; text-transform: uppercase; letter-spacing: 0.06em; }
.ach-toast-name { font-size: 0.95rem; color: #f8fafc; font-weight: bold; }

/* === Achievements Panel === */
.ach-header { margin-bottom: 20px; }
.ach-header-count { font-size: 1.05rem; color: #eab308; font-weight: bold; }
.ach-total-bar { height: 6px; background: #1e293b; border-radius: 3px; margin-top: 8px; overflow: hidden; }
.ach-total-fill { height: 100%; background: linear-gradient(90deg, #eab308, #f59e0b); border-radius: 3px; transition: width 0.5s ease; }

.ach-category { margin-bottom: 24px; }
.ach-category-title {
    font-size: 0.75rem; color: #64748b; font-weight: bold;
    text-transform: uppercase; letter-spacing: 0.1em;
    margin-bottom: 10px; border-bottom: 1px solid #1e293b; padding-bottom: 6px;
}
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.ach-card {
    background: #0f172a; border: 1px solid #1e293b; border-radius: 10px;
    padding: 12px 14px; display: flex; align-items: flex-start; gap: 12px;
    transition: border-color 0.2s;
}
.ach-card.unlocked { border-color: #eab308; background: #1a1500; }
.ach-card.locked { opacity: 0.65; }
.ach-icon { font-size: 1.5rem; min-width: 1.8rem; text-align: center; padding-top: 2px; }
.ach-info { flex: 1; min-width: 0; }
.ach-name { font-weight: bold; color: #f8fafc; font-size: 0.9rem; }
.ach-desc { font-size: 0.78rem; color: #94a3b8; margin-top: 2px; line-height: 1.4; }
.ach-badge { font-size: 0.72rem; color: #eab308; font-weight: bold; margin-top: 5px; }
.ach-progress { margin-top: 6px; }
.ach-progress-text { font-size: 0.72rem; color: #64748b; }
.ach-progress-bar { height: 4px; background: #1e293b; border-radius: 2px; margin-top: 3px; overflow: hidden; }
.ach-progress-fill { height: 100%; background: #3b82f6; border-radius: 2px; transition: width 0.4s; }

/* ── Quiz Map Nodes ─────────────────────────────────────────────────────── */
.map-node-dot.quiz-node {
    background: transparent;
    border: 3px solid var(--nc, #f59e0b);
    color: var(--nc, #f59e0b);
    font-size: 1rem;
}
.map-node-dot.quiz-node.done {
    background: #f59e0b;
    color: #0f172a;
    box-shadow: 0 0 0 3px rgba(245,158,11,0.35);
}
.map-node-label.quiz-label { color: #f59e0b; font-weight: 700; font-size: 0.72rem; }
.map-node-label.quiz-label.done { color: #fbbf24; }

/* ── Quiz In-Game UI ────────────────────────────────────────────────────── */
.quiz-header {
    display: flex; align-items: center; gap: 12px; margin: 6px 0 4px;
    flex-wrap: wrap;
}
.quiz-lives { font-size: 1.05rem; line-height: 1; flex-shrink: 0; }
.quiz-progress-dots {
    display: flex; gap: 8px;
}
.quiz-dot {
    width: 12px; height: 12px; border-radius: 50%;
    background: #1e293b; border: 2px solid #334155;
    transition: background 0.2s, border-color 0.2s;
}
.quiz-dot.current { border-color: #f59e0b; background: rgba(245,158,11,0.2); }
.quiz-dot.correct { background: #22c55e; border-color: #22c55e; }
.quiz-dot.missed  { background: #ef4444; border-color: #ef4444; }

.quiz-skip-btn { margin-top: 4px !important; background: #334155 !important; color: #94a3b8 !important; }
.quiz-skip-btn:hover { background: #475569 !important; color: #cbd5e1 !important; }

/* ── Quiz Result Overlay ────────────────────────────────────────────────── */
.qr-overlay {
    position: fixed; inset: 0; z-index: 1100;
    background: rgba(0,0,0,0.82);
    display: flex; align-items: center; justify-content: center;
    animation: scoFadeIn 0.3s ease-out both;
}
.qr-banner {
    background: #0f172a;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 20px;
    padding: 36px 32px;
    max-width: 360px; width: 90%;
    text-align: center;
    box-shadow: 0 24px 60px rgba(0,0,0,0.6);
    animation: scoBannerIn 0.4s cubic-bezier(0.34,1.56,0.64,1) both;
}
.qr-label {
    font-size: 0.8rem; font-weight: 700; letter-spacing: 0.12em;
    text-transform: uppercase; color: #64748b; margin-bottom: 16px;
}
.qr-emoji { font-size: 3rem; line-height: 1; margin-bottom: 6px; animation: scoIconPop 0.5s 0.15s cubic-bezier(0.34,1.56,0.64,1) both; }
.qr-score { font-size: 2.4rem; font-weight: 900; color: #f8fafc; letter-spacing: -1px; animation: scoSlideUp 0.4s 0.2s ease-out both; }
.qr-dots { display: flex; gap: 8px; justify-content: center; margin: 12px 0; animation: scoSlideUp 0.4s 0.28s ease-out both; }
.qr-message {
    font-size: 0.95rem; color: #94a3b8; line-height: 1.5;
    margin: 4px 0 24px; animation: scoSlideUp 0.4s 0.34s ease-out both;
}
.qr-buttons { display: flex; flex-direction: column; gap: 10px; animation: scoSlideUp 0.4s 0.44s ease-out both; }
.qr-btn-primary {
    padding: 13px 24px; border: none; border-radius: 10px;
    font-size: 1rem; font-weight: 700; cursor: pointer;
    background: #f59e0b; color: #0f172a;
    transition: filter 0.15s, transform 0.1s;
}
.qr-btn-primary:hover { filter: brightness(1.15); transform: translateY(-1px); }
.qr-btn-secondary {
    padding: 11px 24px; border: 1px solid rgba(255,255,255,0.15);
    border-radius: 10px; font-size: 0.95rem; font-weight: 600;
    cursor: pointer; background: transparent; color: #64748b;
    transition: color 0.15s, border-color 0.15s;
}
.qr-btn-secondary:hover { color: #94a3b8; border-color: rgba(255,255,255,0.25); }

/* Quiz circuit task description (strict mode) */
.quiz-task {
    margin: 8px 0 4px;
    padding: 10px 12px;
    background: rgba(99,102,241,0.08);
    border: 1px solid rgba(99,102,241,0.25);
    border-radius: 8px;
    font-size: 0.82rem;
}
.quiz-task-label {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #818cf8;
    margin-bottom: 5px;
}
.quiz-task-desc {
    color: #e2e8f0;
    font-size: 0.88rem;
    line-height: 1.45;
    font-weight: 500;
}
.quiz-task-hint {
    font-size: 0.78rem;
    color: #94a3b8;
    line-height: 1.45;
    margin-top: 7px;
    padding-top: 7px;
    border-top: 1px solid rgba(99,102,241,0.2);
}
.quiz-strict-notice {
    font-size: 0.75rem;
    font-weight: 700;
    color: #ef4444;
    margin-top: 5px;
    letter-spacing: 0.02em;
}
#quiz-fail-actions {
    display: flex;
    gap: 10px;
    margin-top: 12px;
    flex-wrap: wrap;
}
#quiz-fail-actions.hidden { display: none; }
.quiz-fail-btn {
    flex: 1;
    min-width: 130px;
    padding: 8px 14px;
    border-radius: 7px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid #334155;
    background: transparent;
    color: #94a3b8;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.quiz-fail-btn:hover {
    border-color: #7c3aed;
    color: #c4b5fd;
}
.quiz-fail-review {
    border-color: #b45309;
    color: #fbbf24;
}
.quiz-fail-review:hover {
    border-color: #f59e0b;
    background: rgba(245,158,11,0.08);
    color: #fde68a;
}
