/* Magnet Mayhem — "Neon Magnetic Arcade" visual style.
   Mobile-first, fully responsive, dark navy/black base with cyan/red
   polarity accents. */

:root {
    --bg: #05070f;
    --panel: #0d1530;
    --panel-2: #131c3d;
    --cyan: #4fd8ff;
    --red: #ff5a3c;
    --gold: #ffd23c;
    --purple: #b98bff;
    --text: #eaf2ff;
    --text-dim: #93a3c9;
    --radius: 16px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
    overscroll-behavior: none;
    overflow-x: hidden;
}

/* This single rule pins [hidden] to win regardless of any other display
   rule declared on the same element (standing-conventions.md #3) — covers
   every current and future overlay/modal/screen/icon-button in this game. */
[hidden] { display: none !important; }

a { color: var(--cyan); }

.container {
    max-width: 980px;
    margin: 0 auto;
    padding: 0 16px;
}

/* ---------------------------------------------------------------------
   Game shell
   --------------------------------------------------------------------- */
#game-shell {
    position: relative;
    width: 100%;
    max-width: 720px;
    aspect-ratio: 3 / 4;
    max-height: min(88vh, 900px);
    margin: 10px auto 0;
    border-radius: var(--radius);
    overflow: hidden;
    background: #05070f;
    box-shadow: 0 0 0 1px rgba(79, 216, 255, 0.15), 0 20px 60px rgba(0, 0, 0, 0.55);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

@media (min-width: 900px) {
    #game-shell { aspect-ratio: 16 / 10; max-width: 900px; }
}

#game-shell:fullscreen,
#game-shell:-webkit-full-screen {
    max-width: 100vw;
    max-height: 100vh;
    aspect-ratio: auto;
    border-radius: 0;
    margin: 0;
}

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

/* ---------------------------------------------------------------------
   HUD
   --------------------------------------------------------------------- */
#hud {
    position: absolute;
    top: calc(10px + var(--safe-top));
    left: calc(12px + var(--safe-left));
    right: calc(12px + var(--safe-right));
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    pointer-events: none;
    z-index: 5;
}

.hud-block { display: flex; flex-direction: column; }
.hud-label { font-size: 11px; letter-spacing: 0.12em; color: var(--text-dim); font-weight: 600; }
#hud-score { font-size: clamp(22px, 6vw, 32px); font-weight: 800; color: var(--text); text-shadow: 0 0 14px rgba(79,216,255,0.35); }
#hud-best { font-size: clamp(15px, 3.6vw, 18px); font-weight: 700; color: var(--gold); }

#hud-combo {
    position: absolute;
    top: calc(56px + var(--safe-top));
    left: 50%;
    transform: translateX(-50%);
    font-weight: 800;
    font-size: clamp(16px, 4.2vw, 20px);
    color: var(--gold);
    text-shadow: 0 0 12px rgba(255, 210, 60, 0.6);
    z-index: 5;
}
#hud-combo.pulse { animation: comboPulse 0.32s ease-out; }
@keyframes comboPulse {
    0% { transform: translateX(-50%) scale(1.5); }
    100% { transform: translateX(-50%) scale(1); }
}

#polarity-badge {
    position: absolute;
    bottom: calc(18px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 18px;
    border-radius: 999px;
    font-weight: 800;
    letter-spacing: 0.08em;
    font-size: clamp(13px, 3.4vw, 15px);
    border: 2px solid var(--cyan);
    color: var(--cyan);
    background: rgba(79, 216, 255, 0.08);
    box-shadow: 0 0 18px rgba(79, 216, 255, 0.35);
    z-index: 5;
    pointer-events: none;
    transition: color 0.15s, border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
#polarity-badge[data-polarity="REPEL"] {
    color: var(--red);
    border-color: var(--red);
    background: rgba(255, 90, 60, 0.1);
    box-shadow: 0 0 18px rgba(255, 90, 60, 0.4);
}

/* Icon button row — top-right, kept clear of edges/notches. */
.icon-row {
    position: absolute;
    top: calc(10px + var(--safe-top));
    right: calc(12px + var(--safe-right));
    display: flex;
    gap: 6px;
    z-index: 6;
}
.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.15);
    background: rgba(10, 16, 36, 0.65);
    color: var(--text);
    font-size: 17px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(4px);
}
.icon-btn:active { transform: scale(0.94); }

/* Tutorial hint */
#tutorial-hint {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(5, 8, 20, 0.72);
    border: 1px solid rgba(79, 216, 255, 0.4);
    padding: 10px 18px;
    border-radius: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    font-size: clamp(13px, 3.6vw, 16px);
    text-align: center;
    z-index: 7;
    pointer-events: none;
    animation: hintFloat 1.6s ease-in-out infinite;
}
@keyframes hintFloat { 0%, 100% { transform: translate(-50%, -50%); } 50% { transform: translate(-50%, -56%); } }

/* Floating score text + banners */
#float-layer, #banner-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 8;
    overflow: hidden;
}
.float-text {
    position: absolute;
    transform: translate(-50%, -50%);
    font-weight: 800;
    font-size: 15px;
    color: var(--gold);
    text-shadow: 0 0 8px rgba(0,0,0,0.6);
    animation: floatUp 0.9s ease-out forwards;
}
.float-crystal { color: var(--purple); font-size: 17px; }
.float-golden { color: var(--gold); font-size: 19px; }
.float-perfect { color: var(--cyan); font-size: 14px; white-space: nowrap; }
@keyframes floatUp {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
    15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
    100% { opacity: 0; transform: translate(-50%, -140%) scale(1); }
}

.banner-text {
    position: absolute;
    top: 34%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.6);
    font-weight: 900;
    font-size: clamp(20px, 6vw, 30px);
    letter-spacing: 0.03em;
    color: var(--gold);
    text-shadow: 0 0 18px rgba(255, 210, 60, 0.7);
    white-space: nowrap;
    animation: bannerPop 1.2s cubic-bezier(.2,.9,.3,1) forwards;
}
.banner-big { font-size: clamp(24px, 8vw, 38px); color: var(--cyan); text-shadow: 0 0 22px rgba(79,216,255,0.7); }
.banner-golden { color: var(--gold); }
.banner-chaos { color: var(--red); text-shadow: 0 0 22px rgba(255,59,59,0.8); }
@keyframes bannerPop {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    18% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
    30% { transform: translate(-50%, -50%) scale(1); }
    80% { opacity: 1; }
    100% { opacity: 0; transform: translate(-50%, -60%) scale(1); }
}

#achievement-popup {
    position: fixed;
    left: 50%;
    bottom: calc(18px + var(--safe-bottom));
    transform: translate(-50%, 140%);
    background: rgba(10, 16, 36, 0.92);
    border: 1px solid var(--gold);
    color: var(--text);
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    z-index: 50;
    max-width: 90vw;
    transition: transform 0.3s ease;
}
#achievement-popup.show { transform: translate(-50%, 0); }

/* ---------------------------------------------------------------------
   Overlays (all position: fixed, per standing-conventions.md — an
   overlay positioned absolute inside a shell whose intrinsic height is
   shorter than the card it centers can render partially off-screen on a
   short mobile viewport; fixed always anchors to the true viewport).
   --------------------------------------------------------------------- */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px calc(16px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(16px + var(--safe-left));
    background: rgba(3, 5, 12, 0.72);
    backdrop-filter: blur(3px);
}

.card {
    width: 100%;
    max-width: 420px;
    max-height: 100%;
    overflow-y: auto;
    background: linear-gradient(180deg, var(--panel-2), var(--panel));
    border: 1px solid rgba(79, 216, 255, 0.2);
    border-radius: var(--radius);
    padding: 22px 22px 18px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    scrollbar-width: thin;
}
.card::-webkit-scrollbar { width: 6px; }
.card::-webkit-scrollbar-thumb { background: rgba(79,216,255,0.3); border-radius: 6px; }

.card h1 {
    font-size: clamp(24px, 7vw, 32px);
    margin: 0 0 2px;
    letter-spacing: 0.03em;
    background: linear-gradient(90deg, var(--cyan), var(--purple));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.card .brand-sub { color: var(--text-dim); font-size: 12px; letter-spacing: 0.15em; margin-bottom: 18px; }
.card h2 { font-size: 19px; margin: 0 0 14px; }

.btn {
    display: block;
    width: 100%;
    padding: 13px 18px;
    margin: 8px 0;
    border-radius: 12px;
    border: none;
    font-weight: 800;
    font-size: 15px;
    letter-spacing: 0.04em;
    cursor: pointer;
    color: #05070f;
    background: linear-gradient(135deg, var(--cyan), #2ea9d6);
    box-shadow: 0 8px 22px rgba(79, 216, 255, 0.35);
}
.btn:active { transform: scale(0.98); }
.btn.secondary {
    background: rgba(255,255,255,0.06);
    color: var(--text);
    border: 1px solid rgba(255,255,255,0.18);
    box-shadow: none;
}
.btn.ghost {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid rgba(255,255,255,0.12);
    box-shadow: none;
}

.brand-title { font-size: 12px; color: var(--text-dim); letter-spacing: 0.2em; margin-top: 4px; }

/* Countdown */
#screen-countdown .card { background: transparent; border: none; box-shadow: none; }
#countdown-num {
    font-size: clamp(64px, 22vw, 120px);
    font-weight: 900;
    color: var(--cyan);
    text-shadow: 0 0 30px rgba(79,216,255,0.7);
}

/* Boot splash */
#screen-boot {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.35s ease;
}
#screen-boot.fade-out { opacity: 0; }
#screen-boot .boot-title {
    font-size: clamp(28px, 8vw, 44px);
    font-weight: 900;
    letter-spacing: 0.04em;
    background: linear-gradient(90deg, var(--cyan), var(--purple));
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
#screen-boot .boot-sub { color: var(--text-dim); margin-top: 10px; font-size: 13px; letter-spacing: 0.05em; }

/* Game-over stat grid */
.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 14px 0;
}
.stat-cell {
    background: rgba(255,255,255,0.04);
    border-radius: 10px;
    padding: 10px 8px;
}
.stat-cell .label { font-size: 11px; color: var(--text-dim); letter-spacing: 0.08em; }
.stat-cell .value { font-size: 22px; font-weight: 800; }
#go-newbest { color: var(--gold); font-weight: 800; margin: 4px 0 10px; font-size: 14px; letter-spacing: 0.06em; }
#go-status-note { color: var(--text-dim); font-size: 12px; margin: 6px 0; }
#go-reason { color: var(--text-dim); font-size: 13px; margin: 0 0 6px; }

#nickname-form { display: flex; gap: 8px; margin: 10px 0; }
#nickname-input {
    flex: 1;
    padding: 11px 12px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.18);
    background: rgba(255,255,255,0.05);
    color: var(--text);
    font-size: 14px;
}
#nickname-form .btn { width: auto; margin: 0; padding: 11px 16px; }
#nickname-error { color: var(--red); font-size: 12px; margin: 4px 0 8px; text-align: left; }
#nickname-saved { color: var(--cyan); font-size: 13px; margin: 6px 0; font-weight: 700; }
#submit-retry { color: var(--red); font-size: 12px; margin: 6px 0; }
#submit-retry .btn { margin-top: 6px; }

/* Leaderboard */
.lb-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.lb-tab {
    flex: 1;
    padding: 8px 6px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.14);
    background: transparent;
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}
.lb-tab.active { background: rgba(79,216,255,0.14); color: var(--cyan); border-color: rgba(79,216,255,0.4); }

#leaderboard-list { list-style: none; margin: 0; padding: 0; text-align: left; max-height: 42vh; overflow-y: auto; }
.lb-row {
    display: grid;
    grid-template-columns: 34px 1fr auto;
    align-items: center;
    padding: 8px 6px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    font-size: 14px;
}
.lb-rank { color: var(--text-dim); font-weight: 700; }
.lb-top1 .lb-rank { color: var(--gold); }
.lb-top2 .lb-rank { color: #c9d3e6; }
.lb-top3 .lb-rank { color: #d99a5b; }
.lb-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 6px; }
.lb-score { font-weight: 800; color: var(--gold); }
.lb-empty { text-align: center; color: var(--text-dim); padding: 20px 0; }
#leaderboard-my-rank { margin-top: 10px; font-size: 13px; color: var(--cyan); font-weight: 700; }

/* How to play */
.howto-list { text-align: left; font-size: 14px; line-height: 1.55; color: var(--text); padding-left: 18px; margin: 0 0 12px; }
.howto-list li { margin-bottom: 6px; }

/* ---------------------------------------------------------------------
   Below-fold SEO content (outside the game canvas)
   --------------------------------------------------------------------- */
.seo-content { padding: 40px 0 60px; color: var(--text); }
.seo-content h2 { font-size: 24px; margin: 40px 0 14px; color: var(--text); }
.seo-content h2:first-child { margin-top: 0; }
.seo-content p, .seo-content li { color: #c3cee6; line-height: 1.7; font-size: 15px; }
.seo-content ul, .seo-content ol { padding-left: 22px; }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin: 14px 0; }
.feature-card { background: var(--panel); border: 1px solid rgba(255,255,255,0.06); border-radius: 12px; padding: 16px; }
.feature-card h3 { margin: 0 0 6px; font-size: 15px; color: var(--cyan); }
.feature-card p { margin: 0; font-size: 13.5px; color: var(--text-dim); }
.faq-item { margin-bottom: 16px; }
.faq-item h3 { font-size: 16px; margin: 0 0 4px; color: var(--text); }
.related-games { display: flex; flex-wrap: wrap; gap: 10px; }
.related-games a {
    display: inline-block;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid rgba(79,216,255,0.3);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
}
.site-footer { text-align: center; padding: 24px 0 50px; color: var(--text-dim); font-size: 12px; }
.site-header { text-align: center; padding: 18px 0 4px; }
.site-header .logo { font-weight: 900; font-size: 18px; letter-spacing: 0.06em; color: var(--text); text-decoration: none; }
.site-header .logo span { color: var(--cyan); }

h1.page-title { text-align: center; font-size: clamp(26px, 6vw, 38px); margin: 6px 0 4px; }
.page-subtitle { text-align: center; color: var(--text-dim); max-width: 640px; margin: 0 auto 6px; font-size: 15px; }

@media (max-width: 480px) {
    .card { padding: 18px 16px 14px; }
}
