:root {
    /* Dark Mode Palette based on Matrix Memory */
    --primary-color: #3B82F6;
    --primary-hover: #2563EB;
    --bg-color: #0F172A;
    --card-bg: #1E293B;
    --text-color: #F8FAFC;
    --text-muted: #94A3B8;
    --border-color: #475569;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --warning-text: #FBBF24;
    --highlight-color: #F59E0B;
    --success-color: #10B981;
    --danger-color: #EF4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    /* Important for mobile web apps */
    overflow: hidden;
}

#app-container {
    width: 100%;
    max-width: 600px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--card-bg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

/* Screens */
.screen {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 0;
    left: 0;
    padding: 20px;
    overflow-y: auto;
}

/* Card layout for Login / Game Over */
.card {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    text-align: center;
    margin: auto;
    /* Center vertically and horizontally */
    width: 100%;
}

.card h1,
.card h2 {
    color: var(--primary-color);
    margin-bottom: 10px;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 25px;
    font-size: 1.1rem;
}

#guest-form {
    display: flex;
    flex-direction: column;
    text-align: left;
    margin-bottom: 20px;
}

#guest-form label {
    font-weight: bold;
    margin-bottom: 8px;
}

#guest-form input {
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    margin-bottom: 15px;
    background: var(--bg-color);
    color: var(--text-color);
    outline: none;
    transition: border-color 0.2s;
}

#guest-form input:focus {
    border-color: var(--primary-color);
}

.warning-box {
    background-color: var(--warning-bg);
    color: var(--warning-text);
    padding: 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    line-height: 1.4;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.warning-box a {
    color: #FCD34D;
    text-decoration: underline;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 14px 24px;
    font-size: 1.1rem;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    width: 100%;
    transition: background-color 0.2s;
}

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

.btn-primary:disabled {
    background-color: #a0aab5;
    cursor: not-allowed;
}

/* Game Screen Layout */
#game-screen {
    padding: 0;
    /* Full bleed for map */
    display: flex;
    flex-direction: column;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: var(--card-bg);
    color: var(--text-color);
    border-bottom: 1px solid var(--border-color);
    z-index: 10;
}

.stats {
    display: flex;
    gap: 20px;
    font-weight: bold;
    font-size: 1.1rem;
}

.lives {
    display: flex;
    gap: 5px;
    font-size: 1.2rem;
}

.heart {
    transition: transform 0.3s ease;
}

.heart.lost {
    opacity: 0.3;
    filter: grayscale(100%);
}

.instruction-box {
    padding: 15px 20px;
    background: var(--card-bg);
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    z-index: 10;
}

.instruction-text {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    max-height: 100px;
    opacity: 1;
    overflow: hidden;
    transition: max-height 0.5s ease-in-out, opacity 0.5s ease-in-out, margin 0.5s ease-in-out;
}

@keyframes flashShadow {

    0%,
    100% {
        text-shadow: 0 0 0px var(--primary-color);
        color: var(--text-muted);
    }

    50% {
        text-shadow: 0 0 8px var(--primary-color), 0 0 15px var(--highlight-color);
        color: #fff;
    }
}

.instruction-text.flash {
    animation: flashShadow 1s ease-in-out 3;
}

.instruction-text.hide-instruction {
    max-height: 0;
    margin-bottom: 0;
    opacity: 0;
}

.target-name {
    font-size: 1.8rem;
    color: var(--primary-color);
    font-weight: 800;
    letter-spacing: 0.5px;
}

.map-wrapper {
    flex-grow: 1;
    position: relative;
    background: var(--bg-color);
    /* Dark water */
    overflow: hidden;
}

#map-container {
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

/* SVG Styling */
.map-district {
    fill: #334155;
    stroke: #94A3B8;
    stroke-width: 0.5px;
    transition: fill 0.2s;
}

.map-district:hover {
    fill: #475569;
}

.map-district-boundary {
    fill: none;
    stroke: #9e9e9e;
    stroke-width: 0.5px;
}

/* Map Controls */
.map-controls {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 20;
}

.map-controls button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--text-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
}

.map-controls button:hover {
    background: #334155;
}

.map-controls button:active {
    transform: scale(0.95);
}

/* Game Over Screen */
.final-stats {
    margin: 20px 0 30px;
    font-size: 1.2rem;
}

.highlight-score {
    font-size: 2rem;
    color: var(--highlight-color);
    font-weight: bold;
    display: block;
    margin-top: 5px;
}

/* Toast Messages */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    padding: 15px 30px;
    border-radius: 8px;
    color: white;
    font-weight: bold;
    font-size: 1.2rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    text-align: center;
}

.toast.hidden {
    opacity: 0;
    transform: translate(-50%, 20px);
}

.toast-excellent {
    background-color: var(--success-color);
}

/* Green */
.toast-good {
    background-color: #2196f3;
}

/* Blue */
.toast-ok {
    background-color: var(--highlight-color);
}

/* Orange */
.toast-bad {
    background-color: var(--danger-color);
}

/* Red */