@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600;700;800;900&display=swap');

/* ======================================================================
   THEME DEFINITIONS
   ====================================================================== */
:root {
    --bg: #1b1b1b;
    --bg-elevated: #151515;
    --surface: rgba(18, 18, 18, 0.75);
    --surface-strong: rgba(25, 25, 25, 0.94);
    --card: #222222;
    --text: #ffffff;
    --muted: #d3d3d3;
    --soft: rgba(255, 255, 255, 0.12);
    --border: rgba(255, 255, 255, 0.12);
    --accent: #2c7ffc;
    --accent-soft: rgba(44, 127, 252, 0.18);
    --shadow: rgba(0, 0, 0, 0.35);
    --danger: #ff5252;
    --success: #3ddc84;
}

body[data-theme="light"] {
    --bg: #eef4ff;
    --bg-elevated: #f9fbff;
    --surface: rgba(255, 255, 255, 0.82);
    --surface-strong: rgba(255, 255, 255, 0.96);
    --card: #edf4ff;
    --text: #111827;
    --muted: #334155;
    --soft: rgba(15, 23, 42, 0.08);
    --border: rgba(15, 23, 42, 0.1);
    --accent: #2563eb;
    --accent-soft: rgba(37, 99, 235, 0.12);
    --shadow: rgba(15, 23, 42, 0.12);
}

body[data-theme="neon"] {
    --bg: #050816;
    --bg-elevated: #0b1020;
    --surface: rgba(12, 18, 34, 0.82);
    --surface-strong: rgba(18, 24, 44, 0.96);
    --card: #0f172a;
    --text: #e2f2ff;
    --muted: #c7dbff;
    --soft: rgba(105, 206, 255, 0.15);
    --border: rgba(89, 190, 255, 0.25);
    --accent: #58d6ff;
    --accent-soft: rgba(88, 214, 255, 0.18);
    --shadow: rgba(28, 132, 255, 0.28);
}

body[data-theme="sunset"] {
    --bg: #1a0f1f;
    --bg-elevated: #160a18;
    --surface: rgba(30, 15, 31, 0.75);
    --surface-strong: rgba(38, 18, 39, 0.94);
    --card: #2a1830;
    --text: #ffe8d6;
    --muted: #e9b896;
    --soft: rgba(255, 126, 95, 0.14);
    --border: rgba(255, 126, 95, 0.2);
    --accent: #ff7e5f;
    --accent-soft: rgba(255, 126, 95, 0.18);
    --shadow: rgba(255, 100, 60, 0.25);
}

body[data-theme="forest"] {
    --bg: #0a1a0f;
    --bg-elevated: #061608;
    --surface: rgba(10, 28, 15, 0.78);
    --surface-strong: rgba(14, 38, 20, 0.95);
    --card: #132a18;
    --text: #d6f5e0;
    --muted: #9fd4a8;
    --soft: rgba(61, 220, 132, 0.12);
    --border: rgba(61, 220, 132, 0.2);
    --accent: #3ddc84;
    --accent-soft: rgba(61, 220, 132, 0.16);
    --shadow: rgba(20, 80, 40, 0.35);
}

body[data-theme="candy"] {
    --bg: #fff0f6;
    --bg-elevated: #ffe4f0;
    --surface: rgba(255, 230, 245, 0.8);
    --surface-strong: rgba(255, 235, 248, 0.95);
    --card: #ffd6e8;
    --text: #7a1746;
    --muted: #b85280;
    --soft: rgba(255, 95, 162, 0.1);
    --border: rgba(255, 95, 162, 0.2);
    --accent: #ff5fa2;
    --accent-soft: rgba(255, 95, 162, 0.15);
    --shadow: rgba(255, 95, 162, 0.2);
}

body[data-theme="vapor"] {
    --bg: #13002a;
    --bg-elevated: #0d001f;
    --surface: rgba(25, 0, 50, 0.8);
    --surface-strong: rgba(35, 5, 65, 0.95);
    --card: #1e0040;
    --text: #fff;
    --muted: #c7a8ff;
    --soft: rgba(255, 44, 223, 0.14);
    --border: rgba(255, 44, 223, 0.25);
    --accent: #ff2cdf;
    --accent-soft: rgba(255, 44, 223, 0.18);
    --shadow: rgba(255, 44, 223, 0.25);
}

body[data-theme="carbon"] {
    --bg: #0c0c0c;
    --bg-elevated: #080808;
    --surface: rgba(18, 18, 18, 0.8);
    --surface-strong: rgba(24, 24, 24, 0.95);
    --card: #1a1a1a;
    --text: #f0f0f0;
    --muted: #aaa;
    --soft: rgba(255, 82, 82, 0.12);
    --border: rgba(255, 82, 82, 0.2);
    --accent: #ff5252;
    --accent-soft: rgba(255, 82, 82, 0.16);
    --shadow: rgba(255, 60, 60, 0.2);
}

/* ======================================================================
   RESET & BASE
   ====================================================================== */
* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
    font-family: 'Montserrat', sans-serif;
    background: var(--bg);
    color: var(--text);
}

body {
    background: var(--bg);
    overflow-x: hidden;
    position: relative;
}

body.modal-open {
    overflow: hidden;
}

#backgroundCanvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    opacity: 0.9;
}

nav, .content, .featured, .settings-panel {
    position: relative;
    z-index: 1;
}

/* ======================================================================
   NAV
   ====================================================================== */
nav {
    position: fixed;
    top: 0;
    left: 0;
    backdrop-filter: blur(10px) saturate(200%) brightness(70%);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    color: var(--text);
    display: flex;
    height: 7vw;
    min-height: 72px;
    width: 100%;
    align-items: center;
    justify-content: left;
    padding: 0 1.2rem;
    z-index: 10;
    margin: auto;
}

nav img {
    height: 80%;
    width: auto;
    margin-right: 1%;
    border-radius: 1vw;
    cursor: pointer;
    user-select: none;
    box-shadow: 5px 5px 10px rgba(53, 53, 53, 0.459);
}

nav h1 {
    font-size: clamp(1.5rem, 2.2vw, 4vw);
    font-weight: 800;
    margin-right: auto;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.icon-button,
.ghost-button {
    border: 1px solid var(--border);
    background: var(--surface-strong);
    color: var(--text);
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.icon-button {
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.icon-button:hover,
.ghost-button:hover {
    transform: translateY(-1px);
    border-color: var(--accent);
}

/* ======================================================================
   VIEW NAVIGATION
   ====================================================================== */
.view {
    display: none;
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

.view.active {
    display: block;
}

/* ======================================================================
   HOME - FEATURED
   ====================================================================== */
.featured {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    padding: 1vw;
    margin: 1%;
    margin-top: 6vw;
}

.featured h1 {
    font-size: clamp(1.8rem, 2.4vw, 3.5vw);
    font-weight: 700;
    margin: 1vw 1vw .4vw 1vw;
    width: 83.8%;
    text-align: left;
    color: var(--text);
}

.featured .column {
    display: flex;
    flex-direction: column;
}

.featured img {
    height: 12.5vw;
    width: 12.5vw;
    border-radius: 1vw;
    margin: .5vw;
    cursor: pointer;
    user-select: none;
    transition: all .2s;
    object-fit: cover;
}

.featured img:hover {
    transform: scale(1.02);
    filter: brightness(50%);
}

.featured .row img {
    height: 26vw;
    width: 26vw;
}

.featured a {
    display: inline-block;
    position: relative;
    color: var(--accent);
    text-decoration: none;
}

.featured .play-button {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.2s;
}

.featured a:hover .play-button {
    opacity: 1;
    pointer-events: none;
}

.featured .play-button i {
    font-size: 5vw;
    text-shadow: 0 0 100px var(--accent);
}

/* ======================================================================
   HOME - CONTENT & GAMES GRID
   ====================================================================== */
.content {
    flex-direction: column;
    align-items: left;
    padding: 7vw;
    padding-top: 0vw;
}

.content hr {
    border: 0;
    height: 4px;
    background-image: linear-gradient(to right, rgba(0,0,0,0), var(--text), rgba(0,0,0,0));
    margin: 1vw 0;
}

.search {
    display: flex;
    user-select: none;
    margin-top: 2.5vw;
    margin-left: 1.2vw;
}

.search input {
    background-color: var(--card);
    border: 1px solid var(--border);
    border-radius: 1vw 0 0 1vw;
    color: var(--text);
    font-size: 1.5vw;
    font-weight: 600;
    padding: 0.8vw 1.5vw;
    font-family: 'Montserrat', sans-serif;
    z-index: 1;
    outline: none;
    flex: 1;
    max-width: 500px;
}

.search input::placeholder {
    color: var(--muted);
    font-weight: 600;
    font-size: 1.5vw;
}

.search button {
    background-color: var(--text);
    border: none;
    border-radius: 0 1vw 1vw 0;
    color: var(--bg);
    font-size: 1.5vw;
    font-weight: 600;
    padding: 0.8vw 1vw;
    cursor: pointer;
    font-family: 'Montserrat', sans-serif;
    z-index: 1;
    transition: .3s all ease;
}

.games-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5vw;
    margin-top: .6vw;
    padding: 0;
}

.games-grid a {
    display: inline-block;
    position: relative;
    text-decoration: none;
    border-radius: 1vw;
    overflow: hidden;
    transition: transform .2s;
}

.games-grid a:hover {
    transform: scale(1.03);
}

.games-grid a::after {
    content: attr(data-name);
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.4vw 0.5vw;
    font-size: 0.85vw;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
    text-align: center;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

.games-grid a:hover::after {
    opacity: 1;
}

.games-grid img {
    height: 15.6vw;
    width: 15.6vw;
    border-radius: 1vw;
    cursor: pointer;
    user-select: none;
    transition: transform .2s;
    object-fit: cover;
    display: block;
}

.games-grid img:hover {
    transform: scale(1.01);
}

/* ======================================================================
   SETTINGS PAGE
   ====================================================================== */
.settings-page {
    padding: 7rem 1.25rem 2rem;
}

.settings-shell {
    width: min(820px, 100%);
    margin: 0 auto;
    background: var(--surface-strong);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: 0 24px 60px var(--shadow);
    overflow: hidden;
}

.settings-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.settings-header h2 {
    margin: 0;
    font-size: clamp(1.6rem, 2.2vw, 2.4rem);
}

.settings-content {
    padding: 1.5rem;
}

.settings-section {
    margin-bottom: 2rem;
}

.settings-section:last-child {
    margin-bottom: 0;
}

.section-title {
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
    margin: 0 0 1rem 0;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 0;
    color: var(--text);
}

.setting-row + .setting-row {
    border-top: 1px solid var(--border);
}

.setting-row label,
.setting-row span {
    color: var(--text);
    font-size: 0.95rem;
    flex-shrink: 0;
}

.toggle-row input,
.setting-row select {
    accent-color: var(--accent);
}

.toggle-row {
    cursor: pointer;
}

/* range row */
.range-row {
    flex-direction: column;
    align-items: stretch;
}

.range-row label {
    margin-bottom: 0.5rem;
}

.range-row .value-display {
    font-size: 0.85rem;
    color: var(--muted);
    margin-top: 0.25rem;
}

.range-row input {
    width: 100%;
    margin-top: 0.5rem;
    accent-color: var(--accent);
}

/* action row */
.action-row {
    display: block;
}

.action-row > span {
    display: block;
    margin-bottom: 0.7rem;
}

.inline-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.mini-button {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 10px;
    padding: 0.45rem 0.7rem;
    cursor: pointer;
    font: inherit;
    transition: border-color 0.2s, background 0.2s;
}

.mini-button:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.mini-button.danger {
    color: var(--danger);
    border-color: rgba(255, 82, 82, 0.3);
}

.mini-button.danger:hover {
    background: rgba(255, 82, 82, 0.12);
}

/* ======================================================================
   THEME SELECTOR (cards)
   ====================================================================== */
.theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 0.6rem;
    width: 100%;
}

.theme-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 0.4rem;
    border: 2px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    font: inherit;
    color: var(--text);
}

.theme-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.theme-card.selected {
    border-color: var(--accent);
    box-shadow: 0 4px 16px var(--accent-soft);
    background: var(--accent-soft);
}

.theme-swatch {
    width: 100%;
    height: 36px;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.theme-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-align: center;
}

/* ======================================================================
   PARTICLE TYPE SELECTOR (cards)
   ====================================================================== */
.particle-type-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 0.6rem;
    width: 100%;
}

.particle-type-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 0.4rem;
    border: 2px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    font: inherit;
    color: var(--text);
}

.particle-type-card i {
    font-size: 1.3rem;
}

.particle-type-card span {
    font-size: 0.72rem;
    font-weight: 600;
    text-align: center;
}

.particle-type-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.particle-type-card.selected {
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 4px 16px var(--accent-soft);
    background: var(--accent-soft);
}

/* ======================================================================
   CLOAK PRESET SELECTOR (cards)
   ====================================================================== */
.cloak-preset-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 0.6rem;
    width: 100%;
}

.cloak-preset-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 0.4rem;
    border: 2px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    font: inherit;
    color: var(--text);
}

.cloak-preset-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.cloak-preset-card.selected {
    border-color: var(--accent);
    box-shadow: 0 4px 16px var(--accent-soft);
    background: var(--accent-soft);
}

.cloak-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    object-fit: cover;
}

.cloak-preset-card span {
    font-size: 0.68rem;
    font-weight: 600;
    text-align: center;
    line-height: 1.2;
}

/* ======================================================================
   GAME MODAL
   ====================================================================== */
.game-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(8px);
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.game-modal.open {
    opacity: 1;
    pointer-events: auto;
}

.game-modal-shell {
    position: relative;
    width: min(1200px, 96vw);
    height: min(82vh, 760px);
    background: var(--surface-strong);
    border: 1px solid var(--border);
    border-radius: 22px;
    overflow: hidden;
    box-shadow: 0 20px 60px var(--shadow);
}

.game-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.game-modal-title-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 0;
}

.game-modal-kicker {
    font-size: 0.72rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

#gameModalTitle {
    margin: 0;
    font-size: clamp(1.1rem, 2vw, 1.8rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.game-modal-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.ghost-button {
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.ghost-button.danger {
    color: #ffb4b4;
}

#gameFrame {
    width: 100%;
    height: calc(100% - 74px);
    border: 0;
    background: #000;
}

/* ======================================================================
   TOAST NOTIFICATIONS
   ====================================================================== */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    padding: 0.8rem 1.4rem;
    border-radius: 12px;
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    opacity: 0;
    transform: translateX(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    backdrop-filter: blur(10px);
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast-info {
    background: rgba(44, 127, 252, 0.9);
}

.toast-success {
    background: rgba(61, 220, 132, 0.9);
    color: #063a18;
}

.toast-error {
    background: rgba(255, 82, 82, 0.9);
}

/* ======================================================================
   RESPONSIVE
   ====================================================================== */
@media (max-width: 700px) {
    nav {
        height: 74px;
    }

    .featured {
        margin-top: 5rem;
    }

    .featured .row img,
    .featured img,
    .games-grid img {
        width: 42vw;
        height: 42vw;
    }

    .search input,
    .search button {
        font-size: 1rem;
    }

    .settings-page {
        padding-top: 5.5rem;
    }

    .settings-header {
        padding: 0.9rem 1rem;
    }

    .settings-content {
        padding: 1rem;
    }

    .theme-grid,
    .particle-type-grid,
    .cloak-preset-grid {
        grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    }

    .game-modal {
        padding: 1rem;
    }
}
