/* =====================================================================
   css/styles.css - CORE STYLESHEET
   ===================================================================== */

* { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

:root { 
    --bg-color-main: #f3f4f6; --bg-color-content: #ffffff; 
    --text-color: #1f2937; --text-muted: #6b7280; 
    --brand-color: #4f46e5; --brand-hover: #4338ca;
    --border-color: #cbd5e1; --card-bg: #f8fafc;
    --input-bg: #f3f4f6; --palette-bg: #f1f5f9;
    --success: #10b981; --warning: #f97316; --fail: #ef4444; --mindwipe: #8b5cf6;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.04);
    --shadow-md: 0 10px 30px rgba(0,0,0,0.06);
    --shadow-roundel: 0 2px 6px rgba(0,0,0,0.08);
    --shadow-btn: 0 4px 14px rgba(79, 70, 229, 0.3);
    --font-emoji: "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", sans-serif;
}

body.dark-mode {
    --bg-color-main: #111827; --bg-color-content: #1f2937; 
    --text-color: #f9fafb; --text-muted: #9ca3af;
    --brand-color: #6366f1; --brand-hover: #818cf8;
    --border-color: #4b5563; --card-bg: #374151;
    --input-bg: #111827; --palette-bg: #111827;
}

body { 
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", Roboto, sans-serif; 
    background-color: var(--bg-color-main); color: var(--text-color); 
    display: flex; flex-direction: column; align-items: center; 
    margin: 0; min-height: 100vh; overflow-x: hidden; overscroll-behavior-y: none;
    overflow-y: scroll; padding: calc(1rem + env(safe-area-inset-top)) 1rem calc(120px + env(safe-area-inset-bottom)) 1rem;
    transition: background-color 0.3s ease;
}

.brand-logo { width: 100%; height: auto; display: block; margin: 0 auto; overflow: visible; }
.emoji-text { font-family: var(--font-emoji); }

/* --- ADS --- */
.ad-sidebar { position: fixed; top: 50%; transform: translateY(-50%); width: 160px; min-height: 50px; z-index: 5; }
.ad-sidebar.left { left: 1rem; } .ad-sidebar.right { right: 1rem; }
.ad-sidebar .adsbygoogle { display: none !important; }
@media (min-width: 900px) { .ad-sidebar .adsbygoogle { display: block !important; } }
.ad-horizontal { width: 100%; max-width: 728px; min-width: 250px; min-height: 50px; margin: 2rem auto 0 auto; display: flex; justify-content: center; overflow: hidden; }

/* --- CORE CONTAINERS --- */
#game-container { max-width: 500px; width: 100%; background: var(--bg-color-content); padding: 0 1.5rem 2rem 1.5rem; border-radius: 24px; box-shadow: var(--shadow-md); position: relative; box-sizing: border-box; z-index: 10; display: flex; flex-direction: column; align-items: center;}

/* Spinning Icon for Wait Timer */
.spin-icon { width: 18px; height: 18px; animation: spin 1.5s linear infinite; vertical-align: text-bottom; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }
.section { opacity: 0; transform: translateY(8px); transition: opacity 0.3s ease, transform 0.3s ease; pointer-events: none; width: 100%; }
.section.active { opacity: 1; transform: translateY(0); pointer-events: auto; }
h3 { color: inherit; font-weight: 600; margin-bottom: 1rem; margin-top: 0; font-size: 1.15rem; text-align: center;}

/* --- TOAST NOTIFICATION --- */
.toast { position: fixed; top: -100px; left: 50%; transform: translateX(-50%); background: var(--text-color); color: var(--bg-color-content); padding: 12px 24px; border-radius: 99px; font-weight: 700; font-size: 0.95rem; display: flex; align-items: center; gap: 8px; box-shadow: var(--shadow-md); transition: top 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); z-index: 100000; pointer-events: none; }
.toast.show { top: calc(env(safe-area-inset-top) + 20px); }

/* --- BUTTONS --- */
button { background-color: var(--brand-color); color: white; border: none; padding: 1rem; font-size: 1.05rem; border-radius: 99px; cursor: pointer; margin-top: 1rem; font-weight: 700; width: 100%; transition: all 0.2s; box-shadow: var(--shadow-btn); display: flex; justify-content: center; align-items: center; }
button:active:not(:disabled) { transform: scale(0.97); }
button.main-action-btn:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; background-color: var(--border-color); color: var(--text-muted); }
.btn-secondary { background-color: var(--border-color); color: var(--text-color); box-shadow: none; padding: 0.8rem; font-size: 0.95rem; font-weight: 700;} .btn-secondary:hover { opacity: 0.8; }
.try-again-btn { background-color: var(--brand-color) !important; color: #ffffff !important; border: none !important; box-shadow: var(--shadow-btn) !important; }
body.dark-mode .try-again-btn { background-color: var(--brand-color) !important; color: #ffffff !important; border: none !important; }
.btn-split-wrapper { display: flex; gap: 10px; width: 100%; margin-bottom: 10px; flex-wrap: wrap; }
.btn-split-wrapper button { margin-top: 0; flex: 1 1 45%; padding: 0.8rem 0.5rem; font-size: 0.95rem; }

/* Fixed Top Icons */
.icon-btn { 
    background: var(--input-bg); border: none; color: var(--text-muted); 
    width: 42px; height: 42px; display: flex; align-items: center; justify-content: center; 
    border-radius: 50%; margin: 4px; padding: 0; font-size: 1.5rem; 
    transition: opacity 0.2s; box-shadow: none; pointer-events: auto;
    position: relative; z-index: 1000;
} 
.icon-btn:hover { opacity: 0.8; }
.theme-icon { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }

/* --- PROGRESS TRACKER --- */
.progress-container { display: flex; justify-content: center; gap: 8px; margin-top: 0; margin-bottom: 0; }
.progress-node { width: 25px; height: 25px; border-radius: 50%; background: var(--input-bg); display: flex; align-items: center; justify-content: center; font-size: 0.8rem; border: 2px solid var(--border-color); transition: all 0.3s ease; color: var(--text-muted); }
.progress-node.active { border-color: var(--brand-color); background: var(--bg-color-content); transform: scale(1.1); box-shadow: var(--shadow-sm); color: var(--text-color); }
.progress-node.locked { opacity: 0.6; }

/* --- MODALS --- */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); z-index: 1000; display: flex; align-items: center; justify-content: center; opacity: 0; pointer-events: none; transition: opacity 0.3s ease; backdrop-filter: blur(4px);} .modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal-content { background: var(--bg-color-content); color: var(--text-color); padding: 1.5rem; border-radius: 24px; max-width: 400px; width: 85%; position: relative; transform: scale(0.95); transition: transform 0.3s ease; max-height: 85vh; overflow-y: auto; overflow-x: hidden; box-sizing: border-box;} .modal-overlay.active .modal-content { transform: scale(1); }
.rule-step { display: flex; align-items: center; gap: 12px; margin-bottom: 0.8rem; text-align: left; } .rule-emoji { font-size: 1.6rem; background: var(--input-bg); padding: 10px; border-radius: 12px; display: flex; justify-content: center; align-items: center; font-family: var(--font-emoji);} .rule-text { font-size: 0.9rem; line-height: 1.4; font-weight: 500;}
.tut-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-color); transition: background 0.3s; cursor: pointer; }
.tut-dot.active { background: var(--brand-color); }

/* --- STATS --- */
.stat-box { background: var(--card-bg); border-radius: 16px; padding: 1rem; text-align: center; margin-bottom: 0; border: 1px solid var(--border-color); box-shadow: var(--shadow-sm); }
.stat-box h4 { margin: 0 0 5px 0; color: var(--text-muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 1px; }
.stat-box .stat-val { font-size: 1.5rem; font-weight: 800; color: var(--text-color); }
.stat-grid { display: grid; gap: 8px; margin-bottom: 8px; }
.stat-row { display: flex; justify-content: space-between; align-items: center; padding: 0.8rem 0; border-bottom: 1px solid var(--border-color); font-size: 0.95rem; font-weight: 600; } 
.stat-row:last-child { border-bottom: none; } .stat-row span:last-child { color: var(--brand-color); font-weight: 800; font-size: 1.1rem; }

/* --- GAME UI --- */
.content-box { background: var(--card-bg); padding: 1.2rem; border-radius: 16px; border: 1px solid var(--border-color); width: 100%; box-sizing: border-box; display: flex; flex-direction: column; align-items: center; margin-bottom: 1.2rem; }
.difficulty-selector { display: flex; background: var(--input-bg); border: none; padding: 4px; border-radius: 99px; transition: all 0.3s ease; width: 100%; max-width: 250px;}
.diff-btn { background: transparent !important; border: none; box-shadow: none !important; padding: 0.6rem; flex: 1 1 0px; text-align: center; border-radius: 99px; margin: 0; font-weight: 600; font-size: 0.95rem; color: var(--text-muted); opacity: 1; transition: all 0.3s ease;}
#btn-diff-1.active { background: var(--success) !important; color: #ffffff !important; box-shadow: var(--shadow-sm) !important; font-weight: 800; } 
#btn-diff-3.active { background: var(--warning) !important; color: #ffffff !important; box-shadow: var(--shadow-sm) !important; font-weight: 800;} 
#btn-diff-5.active { background: var(--fail) !important; color: #ffffff !important; box-shadow: var(--shadow-sm) !important; font-weight: 800;}

.memory-stack { display: flex; flex-direction: column; gap: 8px; width: 100%; margin-bottom: 1.5rem; }
.numbered-box { padding: 0; background: transparent; width: 100%;}
.box-label { font-size: 0.8rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; display: block; margin-bottom: 0.4rem; text-align: center;}
.item-card { position: relative; background: var(--input-bg); padding: 0; border: none; border-radius: 12px; font-weight: bold; font-size: 1.15rem; min-height: 55px; box-sizing: border-box; cursor: pointer; overflow: hidden; }
.reveal-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--border-color); color: var(--text-color); font-weight: 600; font-size: 1rem; transition: opacity 0.2s, transform 0.2s; z-index: 2; border-radius: 12px; }
.reveal-content { opacity: 0; transform: scale(0.95); transition: opacity 0.2s, transform 0.2s; display: flex; justify-content: center; align-items: center; width: 100%; height: 100%; gap: 10px; position: absolute; inset: 0; }
.item-card.is-revealed .reveal-overlay { opacity: 0; pointer-events: none; transform: scale(1.05); }
.item-card.is-revealed .reveal-content { opacity: 1; transform: scale(1); }
.item-card.is-revealed { border: 2px solid var(--brand-color); background: var(--bg-color-content); }

/* --- SLIDERS --- */
.slider-wrapper { position: relative; width: 100%; margin: 0 0 10px 0; }
input[type=range] { -webkit-appearance: none; width: 100%; background: transparent; position: relative; z-index: 2; margin: 0; height: 50px; cursor: pointer; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; height: 26px; width: 26px; border-radius: 50%; background: var(--brand-color); cursor: pointer; margin-top: -10px; box-shadow: 0 2px 6px rgba(0,0,0,0.2); border: 2px solid #ffffff; }
input[type=range]::-webkit-slider-runnable-track { width: 100%; height: 6px; cursor: pointer; background: var(--border-color); border-radius: 4px; }
.slider-ticks { position: absolute; top: 29px; left: 0; width: 100%; display: flex; justify-content: space-between; padding: 0 10px; box-sizing: border-box; z-index: 1; pointer-events: none; opacity: 0.4; }
.slider-ticks span { height: 6px; width: 2px; background: var(--text-color); border-radius: 2px; }
.custom-time-inputs { display: flex; gap: 10px; width: 100%; margin-top: 10px; } 
.custom-time-inputs select { flex: 1; background: var(--bg-color-content); color: var(--brand-color); border: 1px solid var(--border-color); padding: 0.6rem; border-radius: 8px; font-weight: 700; font-size: 0.95rem; outline: none; text-align: center;}
#timer-display { font-size: 3.2rem; font-family: monospace; font-weight: 800; color: var(--brand-color); margin: 0.5rem 0; text-align: center; display: block; letter-spacing: -1px; }

/* --- INPUTS --- */

/* Card Input Container (Rank & Suit) */
.card-input-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 320px; /* Prevents it from getting too wide on tablets/desktop */
    margin: 0 auto 10px auto; /* Centers the block horizontally */
    padding: 0 16px; /* Safety buffer for mobile edges */
    box-sizing: border-box;
}

.card-input-wrapper input,
.card-input-wrapper select {
    flex: 1; /* Makes both boxes exactly the same width */
    text-align: center; /* Centers the text/emoji inside the box */
    min-width: 0; /* Prevents flexbox blowout on tiny screens */
}

.input-wrapper { position: relative; width: 100%; }
input[type="text"] { background: var(--input-bg); color: var(--text-color); width: 100%; box-sizing: border-box; padding: 1rem 1.2rem; border: 2px solid transparent; border-radius: 12px; font-size: 16px; font-weight: 500; outline: none;}
input:focus { border-color: var(--brand-color); background: var(--bg-color-content); }

.autocomplete-list { position: absolute; top: calc(100% + 4px); left: 0; right: 0; background: var(--bg-color-content); border: 1px solid var(--border-color); border-radius: 12px; z-index: 99; max-height: 180px; overflow-y: auto; box-shadow: var(--shadow-md); padding: 4px; }
.autocomplete-item { padding: 12px; cursor: pointer; font-size: 0.95rem; border-radius: 8px;} .autocomplete-item:hover { background-color: var(--palette-bg); color: var(--brand-color); font-weight: 600;}

.combo-container { display: flex; gap: 8px; justify-content: center; width: 100%; }
.combo-input { width: 55px !important; height: 65px !important; font-size: 2rem !important; text-align: center !important; font-weight: 800 !important; border-radius: 12px !important; padding: 0 !important; font-family: monospace; color: var(--brand-color) !important; background: var(--input-bg) !important; border: 2px solid transparent !important;}
.combo-input:focus { border-color: var(--brand-color) !important; background: var(--bg-color-content) !important; }

/* --- SHAPES & VISUALS --- */
.shape-slot { width: 55px; height: 55px; border: 2px dashed #9ca3af; border-radius: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; margin: 0;} .shape-slot.active { border-color: var(--brand-color); border-style: solid; background: rgba(79, 70, 229, 0.08); transform: scale(1.05);}

/* WINDOWS 11 CHROME FIX ADDED BELOW */
.graphic-shape { width: 30px; height: 30px; display: inline-block; forced-color-adjust: none; -webkit-print-color-adjust: exact; print-color-adjust: exact; }

.red-square { background-color: #ef4444; border-radius: 6px; } .yellow-circle { background-color: #f59e0b; border-radius: 50%; } .blue-triangle { background: none; width: 0; height: 0; border-left: 15px solid transparent; border-right: 15px solid transparent; border-bottom: 30px solid #3b82f6; } .green-star { background-color: #10b981; clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); } .purple-diamond { background-color: #8b5cf6; border-radius: 3px; clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); width: 35px; height: 35px;} .orange-pentagon { background-color: #f97316; clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%); } 
.selector-palette { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; background: var(--palette-bg); padding: 12px; border-radius: 16px; margin-top: 12px; font-size: 1.5rem; }
.shape-sequence-container, .weather-row { display: flex; gap: 8px; justify-content: center; margin: 0.5rem 0; font-size: 1.8rem;}
.weather-slot { padding: 8px; border-radius: 12px; min-width: 45px; background-color: var(--bg-color-content); box-shadow: var(--shadow-roundel); border: 1px solid var(--border-color); text-align: center;} .weather-slot.active { background: rgba(79, 70, 229, 0.08); border-color: var(--brand-color); transform: scale(1.05);}

/* --- DATES & SELECTORS --- */
.custom-select-box { background: var(--input-bg); color: var(--text-color); width: 100%; box-sizing: border-box; padding: 1rem 1.2rem; border: 2px solid transparent; border-radius: 12px; font-size: 16px; font-weight: 500; cursor: pointer; user-select: none; display: flex; align-items: center; min-height: 55px; transition: all 0.2s;}
.grid-btn { padding: 12px 4px; text-align: center; background: var(--input-bg); border-radius: 8px; font-weight: 700; font-size: 0.95rem; cursor: pointer; border: 2px solid transparent; transition: all 0.1s; color: var(--text-color); user-select: none; }
.grid-btn:active { background: var(--palette-bg); color: var(--brand-color); border-color: var(--brand-color); transform: scale(0.95); }
@media (hover: hover) { .grid-btn:hover { background: var(--palette-bg); color: var(--brand-color); } }

/* --- RESULTS & DROPDOWN --- */
#results-breakdown { background: var(--bg-color-content); border-radius: 16px; padding: 0.5rem 1.2rem; margin-bottom: 1rem; width: 100%; box-sizing: border-box; border: 1px solid var(--border-color);}
.breakdown-row { display: flex; justify-content: space-between; align-items: center; padding: 0.8rem 0; border-bottom: 1px solid var(--border-color); font-size: 0.95rem;} .breakdown-row:last-child { border-bottom: none; }
.bd-label { color: var(--text-muted); font-weight: 700; font-size: 0.75rem; text-transform: uppercase;} .bd-ans-correct { color: var(--success); font-weight: 700; } .bd-ans-wrong { color: var(--fail); font-weight: 700; margin-right: 8px; }

#final-time-display { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 4px; margin-top: 0.5rem; font-size: 0.95rem; color: var(--text-muted); } .time-divider { color: var(--border-color); font-weight: normal; } .time-value { color: var(--text-color); font-weight: 700; }

/* THE SCORECARD SQUARES */
.result-grid-container { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin: 1rem 0; }
.result-box { width: 44px; height: 44px; border-radius: 8px; box-shadow: var(--shadow-sm); }
.result-box.correct { background-color: var(--success); } 
.result-box.recovered { background-color: #eab308; } 
.result-box.wrong { background-color: var(--fail); }

.results-dropdown { width: 100%; box-sizing: border-box; }
.results-dropdown summary { display: block; width: 100%; box-sizing: border-box; padding: 15px; text-align: center; user-select: none; }
.results-dropdown summary::-webkit-details-marker { display: none; }

/* --- ROUND 4: TRAPS --- */
.odd-one-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; max-width: 350px; margin: 0 auto 2rem auto;}
.odd-one-cell { background: var(--input-bg); border-radius: 16px; height: 70px; display: flex; align-items: center; justify-content: center; font-size: 2.5rem; cursor: pointer; transition: transform 0.1s;}
.odd-one-cell:active { transform: scale(0.95); }

.mw-dice-container { display: flex; justify-content: center; gap: 15px; margin-top: 20px; margin-bottom: 25px; }
.mw-die { width: 70px; height: 70px; border: 4px solid var(--brand-color); border-radius: 16px; background: #ffffff; cursor: pointer; transition: transform 0.1s, opacity 0.2s, border-color 0.2s; position: relative; }
.mw-die:active { transform: scale(0.95); }
.mw-die.locked { opacity: 0.5; pointer-events: none; border-color: var(--success); }
.mw-die.failed { border-color: var(--fail); }
.pip-grid { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); width: 100%; height: 100%; padding: 8px; box-sizing: border-box; }
.pip { width: 12px; height: 12px; border-radius: 50%; background: #111; justify-self: center; align-self: center; box-shadow: inset -2px -2px 4px rgba(0,0,0,0.6), inset 2px 2px 4px rgba(255,255,255,0.4); }

/* --- ROUND 5: GRIDLOCK --- */
.gridlock-board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; max-width: 300px; margin: 0 auto; perspective: 1000px; }
.gridlock-card { width: 100%; aspect-ratio: 1; position: relative; transition: transform 0.6s; transform-style: preserve-3d; cursor: pointer; }
.gridlock-card.flipped { transform: rotateY(180deg); }
.gl-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; align-items: center; justify-content: center; border-radius: 12px; box-shadow: var(--shadow-sm); box-sizing: border-box; overflow: hidden; padding: 4px;}
.gl-front { background: var(--input-bg); color: var(--text-color); font-weight: bold; text-align: center; border: 2px solid transparent; flex-direction: column; line-height: 1.15; word-wrap: break-word;}
.gl-back { background: var(--brand-color); color: white; transform: rotateY(180deg); font-size: 2.5rem; font-weight: 800; border: 2px solid transparent; transition: border-color 0.2s;}

.gl-correct { pointer-events: none; }
.gl-correct .gl-front { border-color: var(--success); background: var(--bg-color-content); box-shadow: 0 0 15px rgba(16, 185, 129, 0.3); }

/* The animation now explicitly maintains the 180-degree face-down state while shaking */
.gl-wrong { animation: shakeWrongDown 0.4s; }
.gl-wrong .gl-back { border-color: var(--fail); }
@keyframes shakeWrongDown { 
    0%, 100% {transform: rotateY(180deg) translateX(0);} 
    25% {transform: rotateY(180deg) translateX(-5px);} 
    75% {transform: rotateY(180deg) translateX(5px);} 
}

/* Subtly pulse the next unlocked round node in the header */
.pulse-node {
    animation: nodeGlow 2s infinite ease-in-out;
    border-color: var(--warning) !important;
}

@keyframes nodeGlow {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4); }
    50% { transform: scale(1.1); box-shadow: 0 0 12px 4px rgba(245, 158, 11, 0.2); }
}