:root {
    --text-color: #1A1A1A;
    --accent: #D32F2F; /* Red Thread / Accent */
    --border-radius: 6px;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --cork-color: #D4B08C;
    --desk-color: #3E2723;
    --sticky-yellow: #FFF9C4;
}

* { box-sizing: border-box; }

body {
    background-color: var(--desk-color); /* Detective Desk */
    color: var(--text-color);
    font-family: var(--font-family);
    margin: 0; display: flex; justify-content: center;
    padding: 10px; overflow-x: hidden;
    -webkit-touch-callout: none; -webkit-user-select: none;
}

.game-container { width: 100%; max-width: 500px; text-align: center; position: relative;}

/* Screens & Backgrounds */
.screen-layer { background: radial-gradient(circle, #5D4037, #3E2723); border-radius: 12px; padding: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); min-height: 80vh; display: flex; align-items: center; justify-content: center;}
.intro-card { background: white; padding: 30px; border-radius: 4px; box-shadow: 0 4px 15px rgba(0,0,0,0.3); }
.theme-icons { font-size: 2rem; margin: 15px 0; letter-spacing: 15px; }

#main-game { background: white; border-radius: 12px; padding: 15px; box-shadow: 0 5px 20px rgba(0,0,0,0.4); min-height: 85vh;}

header { margin-bottom: 15px; position: relative;}
h1 { margin: 0; font-size: 1.8rem; font-weight: 800; text-transform: uppercase; letter-spacing: 1px;}
.subtitle { margin-top: 5px; opacity: 0.7; font-weight: bold; }
#timer-display { font-size: 1.4rem; font-weight: bold; margin-top: 10px; font-family: monospace;}
#penalty-msg { color: var(--accent); font-weight: bold; position: absolute; top: 100%; left: 50%; transform: translateX(-50%); animation: fade-up 1.5s forwards;}

.mute-btn { position: absolute; top: 0; right: 0; background: none; border: none; font-size: 1.3rem; cursor: pointer; opacity: 0.65; padding: 4px; line-height: 1; transition: opacity 0.15s, transform 0.1s; z-index: 5; }
.mute-btn:hover { opacity: 1; }
.mute-btn:active { transform: scale(0.85); }

.instructions { font-weight: bold; margin-bottom: 15px; }
.white-text { color: white; text-shadow: 1px 1px 3px rgba(0,0,0,0.8);}
.hidden { display: none !important; }

/* Progress Tracker */
.progress-tracker { display: flex; align-items: center; justify-content: center; margin: 15px 0; }
.progress-dot { width: 30px; height: 30px; border-radius: 50%; background: #E0E0E0; display: flex; align-items: center; justify-content: center; font-weight: bold; color: #888; transition: all 0.3s; z-index: 2;}
.progress-dot.active { background: #4CAF50; color: white; box-shadow: 0 0 10px #4CAF50; transform: scale(1.1);}
.progress-line { height: 4px; width: 40px; background: #E0E0E0; margin: 0 -5px; z-index: 1; transition: background 0.3s;}
.progress-line.active { background: #4CAF50; }

/* Phase 1: Crime Scene (Asphalt + Tape) */
.crime-scene { background: #2c3e50; border-radius: 8px; padding: 15px; position: relative; overflow: hidden; }
.police-tape { background: repeating-linear-gradient(45deg, #FFC107, #FFC107 10px, #111 10px, #111 20px); color: white; font-weight: 900; letter-spacing: 2px; padding: 5px; transform: rotate(-2deg) scale(1.1); margin-bottom: 15px; box-shadow: 0 2px 5px rgba(0,0,0,0.5);}

.ws-grid { display: grid; gap: 4px; margin: 0 auto 15px auto; }
.ws-cell { background: rgba(255,255,255,0.9); aspect-ratio: 1/1; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 1.1rem; cursor: pointer; border-radius: 4px; transition: transform 0.1s;}
.ws-cell:active { transform: scale(0.9); }
.ws-cell.found { background: #4CAF50; color: white; opacity: 0.6; }
/* .selected is listed after .found so a re-used (overlapping) green tile still
   shows the active highlight; opacity:1 overrides .found's dimming. */
.ws-cell.selected { background: #FFC107; color: black; opacity: 1; box-shadow: 0 0 8px #FFC107; }

.ws-controls { display: flex; justify-content: center; align-items: center; margin-bottom: 15px; min-height: 30px; }
#current-selection { font-size: 1.5rem; font-weight: 900; letter-spacing: 3px; color: #FFC107; text-shadow: 1px 1px 2px black;}

.word-bank { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; font-size: 0.8rem;}
.wb-word { background: rgba(255,255,255,0.8); padding: 4px 8px; border-radius: 4px; font-weight: bold;}
.wb-word.found { text-decoration: line-through; opacity: 0.3; }

/* Phase 2: Corkboard & Sticky Notes */
.corkboard { background: var(--cork-color); background-image: radial-gradient(#a37c5b 15%, transparent 16%), radial-gradient(#a37c5b 15%, transparent 16%); background-size: 20px 20px; background-position: 0 0, 10px 10px; border-radius: 8px; padding: 15px; border: 4px solid #5D4037; box-shadow: inset 0 0 20px rgba(0,0,0,0.5); }

.grid-board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 15px; }

.tile {
    background-color: var(--sticky-yellow); color: black;
    aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center;
    font-weight: 900; font-size: 0.75rem; text-transform: uppercase; cursor: pointer; padding: 2px;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.3); position: relative; transition: all 0.2s;
}
/* Thumbtack effect */
.tile::before { content: ''; position: absolute; top: 4px; left: 50%; transform: translateX(-50%); width: 8px; height: 8px; background: radial-gradient(circle, #ddd, #666); border-radius: 50%; box-shadow: 1px 1px 2px rgba(0,0,0,0.5);}

.tile.selected { background-color: #81D4FA; transform: scale(1.1) rotate(0deg) !important; z-index: 10;}
.completed-row { grid-column: span 4; background: white; border-radius: 4px; padding: 10px; text-align: center; margin-bottom: 8px; box-shadow: 2px 2px 5px rgba(0,0,0,0.3);}
.completed-row h3 { margin: 0; text-transform: uppercase; font-size: 1rem; }
.completed-row p { margin: 4px 0 0 0; font-size: 0.8rem; font-weight: bold; opacity: 0.8;}

/* Phase 3: Red Thread & Hangman */
.health-bar { font-size: 1.5rem; margin-bottom: 15px; letter-spacing: 5px; }

.mystery-display { display: flex; justify-content: center; gap: 8px; margin-bottom: 0; position: relative; z-index: 2;}
.mystery-word-box { background: var(--sticky-yellow); color: black; padding: 8px 12px; font-weight: 900; font-size: 0.8rem; box-shadow: 2px 2px 5px rgba(0,0,0,0.4); position: relative; }
.mystery-word-box::before { content: ''; position: absolute; top: 4px; left: 50%; transform: translateX(-50%); width: 6px; height: 6px; background: radial-gradient(circle, #f44336, #b71c1c); border-radius: 50%;}

.red-thread-container { display: flex; flex-direction: column; align-items: center; position: relative; margin-bottom: 25px;}
.red-thread-line { width: 2px; height: 40px; border-left: 3px dashed var(--accent); margin: 0 auto; }

/* Animated red thread (Phase 3) — SVG injected by effects.js */
.thread-path { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.45)); }
.thread-pin { fill: #b71c1c; stroke: #fff; stroke-width: 1; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.5)); }

.hangman-display { display: flex; justify-content: center; flex-wrap: wrap; gap: 5px; background: rgba(255,255,255,0.9); padding: 15px; border-radius: 4px; box-shadow: 0 4px 8px rgba(0,0,0,0.3); border: 2px solid var(--accent);}
.hm-letter { width: 25px; height: 35px; border-bottom: 3px solid black; display: flex; align-items: flex-end; justify-content: center; font-size: 1.3rem; font-weight: 900; color: black; }
.hm-space { width: 10px; }

.keyboard { display: flex; flex-direction: column; gap: 6px; align-items: center; background: rgba(255,255,255,0.8); padding: 10px; border-radius: 8px;}
.key-row { display: flex; gap: 6px; justify-content: center; }
.key { background: #FFF; border: 1px solid #CCC; padding: 14px 10px; border-radius: 4px; font-weight: 900; font-size: 1rem; cursor: pointer; min-width: 34px; box-shadow: 0 2px 0 #CCC; transition: all 0.1s;}
.key:active { transform: translateY(2px); box-shadow: 0 0 0 #CCC;}
.key.disabled { opacity: 0.3; cursor: not-allowed; }
.key.wrong { background: #D32F2F; color: white; border-color: #B71C1C;}
.key.right { background: #4CAF50; color: white; border-color: #388E3C;}

/* Utilities & Animations */
.action-btn { background-color: #E0E0E0; border: none; padding: 14px 24px; border-radius: 30px; font-size: 1rem; font-weight: bold; cursor: pointer; font-family: inherit;}
.action-btn-accent { background-color: var(--text-color); color: white; }
.action-btn:disabled { opacity: 0.5; }
.shake { animation: shake 0.4s ease-in-out; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
@keyframes fade-up { 0% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -20px); } }
.fade-in { animation: fadeIn 0.5s ease-in; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px);} to { opacity: 1; transform: translateY(0);} }

/* Modal */
.result-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); display: flex; justify-content: center; align-items: center; z-index: 100; }
.modal-content { background: white; padding: 30px; border-radius: var(--border-radius); width: 90%; max-width: 400px; position: relative; overflow: hidden; }

/* "CASE CLOSED" rubber stamp — slams in on a win */
.case-stamp { display: none; position: absolute; top: 14px; right: 12px; color: var(--accent); border: 4px double var(--accent); border-radius: 8px; padding: 6px 12px; font-weight: 900; font-size: 1rem; line-height: 1.05; letter-spacing: 2px; text-transform: uppercase; text-align: center; transform: rotate(-14deg) scale(1); opacity: 0.9; pointer-events: none; }
.case-stamp.instant { display: block; }
.case-stamp.show { display: block; animation: stampSlam 0.5s cubic-bezier(0.2, 0.8, 0.3, 1.3) forwards; }
@keyframes stampSlam {
    0% { opacity: 0; transform: rotate(-14deg) scale(2.6); }
    55% { opacity: 1; }
    100% { opacity: 0.9; transform: rotate(-14deg) scale(1); }
}
#results-emojis { font-size: 1.2rem; white-space: pre-wrap; margin: 15px 0; background: #F5F5F5; padding: 10px; border-radius: 4px; text-align: left; font-family: monospace;}
.share-notice { color: #4CAF50; font-weight: bold; margin-top: 10px;}