/* ==========================================================================
   MAGNETIC POLARITY SNAKE - STYLE SHEET
   ========================================================================== */

:root {
    --bg-dark: #060713;
    --card-bg: rgba(12, 16, 33, 0.65);
    --card-border: rgba(255, 255, 255, 0.07);
    --text-primary: #eff3f9;
    --text-muted: #8189b0;
    
    /* Polarity Colors */
    --color-n: #ff3131;
    --color-n-glow: rgba(255, 49, 49, 0.45);
    --color-s: #00d2ff;
    --color-s-glow: rgba(0, 210, 255, 0.45);
    
    /* Common Neon Colors */
    --neon-pink: #ff007f;
    --neon-pink-glow: rgba(255, 0, 127, 0.4);
    --neon-green: #39ff14;
    --neon-green-glow: rgba(57, 255, 20, 0.4);
    
    --container-max-width: 1200px;
    --canvas-size: 600px;
}

/* --- Base Reset --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* --- Star Background & Plasma Glow --- */
.stars-bg {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-image: 
        radial-gradient(1px 1px at 30px 40px, #fff, rgba(0,0,0,0)),
        radial-gradient(1.5px 1.5px at 120px 180px, rgba(255,255,255,0.8), rgba(0,0,0,0)),
        radial-gradient(2px 2px at 280px 100px, #fff, rgba(0,0,0,0)),
        radial-gradient(1.5px 1.5px at 420px 290px, rgba(255,255,255,0.7), rgba(0,0,0,0)),
        radial-gradient(1px 1px at 580px 220px, #fff, rgba(0,0,0,0)),
        radial-gradient(2px 2px at 700px 410px, rgba(255,255,255,0.9), rgba(0,0,0,0));
    background-repeat: repeat;
    background-size: 600px 600px;
    opacity: 0.12;
    z-index: -3;
}

.plasma-glow-red, .plasma-glow-blue {
    position: fixed;
    border-radius: 50%;
    filter: blur(150px);
    opacity: 0.22;
    z-index: -2;
    pointer-events: none;
}

.plasma-glow-red {
    top: -15%;
    left: 5%;
    width: 450px;
    height: 450px;
    background: var(--color-n);
    animation: bounce-glow-1 18s infinite alternate ease-in-out;
}

.plasma-glow-blue {
    bottom: -15%;
    right: 5%;
    width: 500px;
    height: 500px;
    background: var(--color-s);
    animation: bounce-glow-2 22s infinite alternate-reverse ease-in-out;
}

@keyframes bounce-glow-1 {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(40px, 40px) scale(1.1); }
}
@keyframes bounce-glow-2 {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(-50px, -30px) scale(1.05); }
}

/* --- Container & Header --- */
.container {
    width: 100%;
    max-width: var(--container-max-width);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    z-index: 1;
}

.game-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 8px 0;
}

.back-link-container {
    justify-self: start;
}

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--card-border);
    transition: all 0.3s ease;
}

.btn-back:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.05);
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: 'Outfit', sans-serif;
    font-weight: 900;
    font-size: 1.8rem;
    letter-spacing: 1.5px;
}

.logo-sub {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 7px;
    border-radius: 4px;
    letter-spacing: 0.5px;
    margin-left: 4px;
}

.header-status {
    justify-self: end;
}

.polarity-badge {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.polarity-badge.polarity-n {
    background: rgba(255, 49, 49, 0.12);
    color: var(--color-n);
    border: 1px solid rgba(255, 49, 49, 0.35);
    box-shadow: 0 0 10px rgba(255, 49, 49, 0.15);
}

.polarity-badge.polarity-s {
    background: rgba(0, 210, 255, 0.12);
    color: var(--color-s);
    border: 1px solid rgba(0, 210, 255, 0.35);
    box-shadow: 0 0 10px rgba(0, 210, 255, 0.15);
}

/* --- Color utilities --- */
.neon-text-red {
    color: var(--color-n);
    text-shadow: 0 0 10px var(--color-n-glow);
}

.neon-text-blue {
    color: var(--color-s);
    text-shadow: 0 0 10px var(--color-s-glow);
}

/* --- Glass Cards --- */
.glass-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 20px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

/* --- Layout --- */
.game-layout {
    display: grid;
    grid-template-columns: 310px 1fr;
    gap: 20px;
}

.panel-left {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* --- Scoreboard --- */
.scoreboard .score-row {
    display: flex;
    justify-content: space-between;
    gap: 15px;
}

.score-item {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.scoreboard .label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.digital-value {
    font-family: 'Orbitron', monospace;
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1;
}

/* --- Polarity Panel --- */
.polarity-panel h3, .settings-panel h3, .legend-panel h3 {
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 8px;
    color: var(--text-primary);
}

.polarity-visualizer {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 18px;
    border-radius: 12px;
    margin-bottom: 15px;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid transparent;
}

.polarity-visualizer.n-active {
    background: rgba(255, 49, 49, 0.04);
    border-color: rgba(255, 49, 49, 0.25);
    box-shadow: inset 0 0 15px rgba(255, 49, 49, 0.1);
}

.polarity-visualizer.s-active {
    background: rgba(0, 210, 255, 0.04);
    border-color: rgba(0, 210, 255, 0.25);
    box-shadow: inset 0 0 15px rgba(0, 210, 255, 0.1);
}

.polarity-letter {
    font-family: 'Orbitron', sans-serif;
    font-size: 3rem;
    font-weight: 900;
    line-height: 1;
    margin-bottom: 6px;
    transition: all 0.3s;
}

.n-active .polarity-letter {
    color: var(--color-n);
    text-shadow: 0 0 15px var(--color-n-glow);
}

.s-active .polarity-letter {
    color: var(--color-s);
    text-shadow: 0 0 15px var(--color-s-glow);
}

.polarity-desc {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.n-active .polarity-desc { color: var(--color-n); }
.s-active .polarity-desc { color: var(--color-s); }

.btn-switch {
    width: 100%;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
    border: 1px solid var(--card-border);
    padding: 10px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
}

.n-active + .btn-switch:hover {
    background: rgba(255, 49, 49, 0.1);
    border-color: var(--color-n);
    box-shadow: 0 0 12px rgba(255, 49, 49, 0.2);
}

.s-active + .btn-switch:hover {
    background: rgba(0, 210, 255, 0.1);
    border-color: var(--color-s);
    box-shadow: 0 0 12px rgba(0, 210, 255, 0.2);
}

/* --- Settings Panel --- */
.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.setting-row select {
    background: rgba(12, 16, 33, 0.95);
    color: var(--text-primary);
    border: 1px solid var(--card-border);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
}

/* Toggle switch styling */
.toggle-switch {
    position: relative;
    width: 44px;
    height: 22px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-switch label {
    position: absolute; cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--card-border);
    border-radius: 22px;
    transition: .3s;
}
.toggle-switch label:before {
    position: absolute; content: "";
    height: 14px; width: 14px; left: 3px; bottom: 3px;
    background-color: var(--text-muted);
    border-radius: 50%;
    transition: .3s;
}
.toggle-switch input:checked + label {
    background-color: rgba(0, 210, 255, 0.12);
    border-color: rgba(0, 210, 255, 0.35);
}
.toggle-switch input:checked + label:before {
    transform: translateX(22px);
    background-color: var(--color-s);
    box-shadow: 0 0 8px var(--color-s-glow);
}

/* --- Legend Panel --- */
.legend-items {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
}
.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}
.core-n {
    background: var(--color-n);
    box-shadow: 0 0 8px var(--color-n-glow);
}
.core-s {
    background: var(--color-s);
    box-shadow: 0 0 8px var(--color-s-glow);
}
.legend-line {
    width: 20px;
    height: 3px;
    border-radius: 2px;
}
.wall-n {
    background: var(--color-n);
    box-shadow: 0 0 6px var(--color-n);
}
.wall-s {
    background: var(--color-s);
    box-shadow: 0 0 6px var(--color-s);
}
.legend-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* --- Center Board & Canvas --- */
.game-center {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.canvas-container {
    position: relative;
    width: var(--canvas-size);
    height: var(--canvas-size);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5), 0 0 2px rgba(255,255,255,0.08);
    background: #020308;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Screen overlays */
.screen-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(6, 8, 18, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.4s ease, visibility 0.4s;
}

.screen-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.overlay-content {
    max-width: 460px;
    padding: 30px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
}

.overlay-content h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 2.4rem;
    font-weight: 900;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.overlay-desc {
    font-size: 0.88rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.tutorial-box {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    padding: 15px;
    font-size: 0.78rem;
    text-align: left;
    color: var(--text-muted);
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tutorial-box strong { color: var(--text-primary); }
.key {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 1px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-weight: bold;
    color: var(--color-s);
}

.btn {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 0.95rem;
    padding: 12px 26px;
    border-radius: 30px;
    cursor: pointer;
    border: none; outline: none;
    transition: all 0.3s;
}

.btn-primary {
    background: linear-gradient(90deg, var(--color-n), var(--color-s));
    color: #fff;
    box-shadow: 0 4px 15px rgba(0, 210, 255, 0.25);
}
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 210, 255, 0.45), 0 0 15px rgba(255, 49, 49, 0.25);
}

/* Stats on Game Over */
.stats-report {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 15px;
    width: 100%;
}
.stats-report p {
    display: flex;
    justify-content: space-between;
    font-size: 0.88rem;
    color: var(--text-muted);
}
.font-digital {
    font-family: 'Orbitron', monospace;
    font-weight: 700;
}

/* --- Mobile Controls --- */
.mobile-controls {
    display: none;
    margin-top: 20px;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}
.dpad-row {
    display: flex;
    gap: 15px;
    justify-content: center;
    align-items: center;
}
.dpad-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: all 0.2s;
}
.dpad-btn:active {
    background: rgba(0, 210, 255, 0.15);
    border-color: var(--color-s);
    box-shadow: 0 0 15px var(--color-s-glow);
    transform: scale(0.95);
}
.dpad-btn.action-btn {
    width: 70px;
    height: 70px;
    border-radius: 18px;
    font-size: 1rem;
    flex-direction: column;
    gap: 2px;
    background: rgba(255, 49, 49, 0.06);
    border-color: rgba(255, 49, 49, 0.25);
}
.dpad-btn.action-btn:active {
    background: rgba(255, 49, 49, 0.18);
    border-color: var(--color-n);
    box-shadow: 0 0 15px var(--color-n-glow);
}
.dpad-btn.action-btn span {
    font-size: 0.6rem;
    font-weight: 700;
}

/* --- Responsive Adaptations --- */
@media (max-width: 992px) {
    body { padding: 10px; }
    .game-layout { grid-template-columns: 1fr; gap: 15px; }
    .panel-left { order: 2; }
    .game-center { order: 1; }
    .canvas-container {
        width: 100%;
        max-width: 500px;
        height: auto;
        aspect-ratio: 1;
    }
    .game-header { grid-template-columns: 1fr 1fr; }
    .header-status { display: none; }
    .mobile-controls { display: flex; }
}

@media (max-width: 500px) {
    .container { padding: 8px 4px; gap: 8px; }
    .logo { font-size: 1.4rem; }
    .logo-sub { font-size: 0.9rem; }
    .overlay-content h2 { font-size: 1.8rem; }
}
