/* ============================================================
   NAVBAR
   ============================================================ */

/* A floating glass "island": detached from the top edge, rounded, blurred.
   The <nav> itself is an invisible fixed strip (pointer-events pass through);
   the island look lives on .navbar so the collapse panel can float below it. */
nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2000;
    padding: 14px clamp(12px, 3vw, 24px) 0;
    background: transparent;
    pointer-events: none;
    transition: padding 0.3s ease;
}

/* Scrolled: the floating island docks into a full-width frosted bar. */
nav.scrolled:not(.nav-minimal) { padding: 0; }

/* Once the page is scrolled, a frosted-glass strip fills the area around the
   island: page text passing beneath is blurred out rather than hidden behind
   solid white. The mask fades the glass away toward the bottom edge. */
nav:not(.nav-minimal)::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: calc(100% + 22px);
    z-index: -1;
    background: rgba(255, 255, 255, 0.42);
    backdrop-filter: blur(14px) saturate(1.4);
    -webkit-backdrop-filter: blur(14px) saturate(1.4);
    -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 55%, transparent 100%);
            mask-image: linear-gradient(to bottom, #000 0%, #000 55%, transparent 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

/* (Scrolled state: the bar itself goes full-width — see below — so the
   extra glass strip stays hidden; two stacked white layers looked washed out.) */

/* ── 3-column island: logo left | links centre | auth right ── */

.navbar {
    pointer-events: auto;
    display: flex;
    align-items: center;
    height: 62px;
    max-width: 1240px;
    margin: 0 auto;
    padding: 0 12px 0 22px;
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(18px) saturate(1.6);
    -webkit-backdrop-filter: blur(18px) saturate(1.6);
    border: 1px solid var(--hairline);
    border-radius: 18px;
    box-shadow: 0 2px 14px rgba(15, 23, 42, 0.05), 0 1px 0 rgba(255, 255, 255, 0.8) inset;
    transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease,
                border-radius 0.3s ease, max-width 0.3s ease;
}

nav.scrolled:not(.nav-minimal) .navbar {
    max-width: 100vw;
    border-radius: 0;
    border-top: none;
    border-left: none;
    border-right: none;
    background: rgba(255, 255, 255, 0.72);
    border-color: var(--hairline-strong);
    box-shadow: 0 14px 40px rgba(15, 23, 42, 0.10);
    padding: 0 clamp(16px, 4vw, 48px);
}

/* ── Minimal nav (game pages): no bar — a floating logo chip on the left
      and a single "All Games" pill on the right. ── */

.nav-minimal {
    position: absolute;   /* scrolls away with the page — game boards get the full screen */
    top: 0;
    left: 0;
    right: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px clamp(12px, 3vw, 24px) 0;
    background: transparent;
    pointer-events: none;
}

.nav-mini-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-mini-logo,
.nav-mini-howto,
.nav-mini-sound,
.nav-mini-back {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    height: 46px;
    padding: 0 16px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(18px) saturate(1.6);
    -webkit-backdrop-filter: blur(18px) saturate(1.6);
    border: 1px solid var(--hairline);
    box-shadow: 0 2px 14px rgba(15, 23, 42, 0.05), 0 1px 0 rgba(255, 255, 255, 0.8) inset;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease, color 0.25s ease, transform 0.25s ease;
}

nav.nav-minimal.scrolled .nav-mini-logo,
nav.nav-minimal.scrolled .nav-mini-howto,
nav.nav-minimal.scrolled .nav-mini-sound,
nav.nav-minimal.scrolled .nav-mini-back {
    background: rgba(255, 255, 255, 0.94);
    border-color: var(--hairline-strong);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12), 0 1px 0 rgba(255, 255, 255, 0.9) inset;
}

.nav-mini-logo {
    font-family: 'Orbitron', sans-serif;
    font-size: 17px;
    font-weight: 800;
    color: var(--dark);
    letter-spacing: -0.3px;
}

.nav-mini-logo:hover { color: var(--primary); }
.nav-mini-logo:hover .logo { transform: rotate(-8deg) scale(1.08); }

/* "How to play" — labeled chip; the label collapses on small screens */
.nav-mini-howto {
    gap: 8px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-dark);
}

.nav-mini-howto i { font-size: 0.85rem; color: var(--primary); }

.nav-mini-howto:hover {
    border-color: rgba(37, 99, 235, 0.35);
    background: rgba(37, 99, 235, 0.07);
    color: var(--primary);
    transform: translateY(-1px);
}

/* Sound on/off — icon-only chip injected by sound.js */
.nav-mini-sound {
    width: 46px;
    padding: 0;
    font-size: 1rem;
    color: var(--gray-dark);
}

.nav-mini-sound i { color: var(--primary); }
.nav-mini-sound[aria-pressed="true"] i { color: var(--muted); }

.nav-mini-sound:hover {
    border-color: rgba(37, 99, 235, 0.35);
    background: rgba(37, 99, 235, 0.07);
    transform: translateY(-1px);
}

/* "Back to all games" — arrow + grid symbol chip */
.nav-mini-back {
    gap: 9px;
    padding: 0 15px;
    font-size: 1rem;
    color: var(--gray-dark);
}

.nav-mini-back .fa-arrow-left {
    font-size: 0.8rem;
    color: var(--muted);
    transition: transform 0.25s ease, color 0.25s ease;
}

.nav-mini-back:hover .fa-arrow-left {
    transform: translateX(-2px);
    color: #fff;
}

.nav-mini-back:hover {
    background: var(--dark);
    border-color: var(--dark);
    color: #fff;
    transform: translateY(-1px);
}

@media screen and (max-width: 600px) {
    .nav-minimal { padding-top: 10px; }
    .nav-mini-logo span { display: none; }     /* logo mark only on small phones */
    .nav-mini-logo { padding: 0 12px; }
    .nav-mini-howto span { display: none; }    /* book icon only */
    .nav-mini-howto { width: 46px; padding: 0; }
    .nav-mini-howto i { color: var(--gray-dark); font-size: 1rem; }
}

.navbar-left {
    flex: 1;
    display: flex;
    align-items: center;
}

.nav-menu {
    display: flex;
    list-style: none;
    gap: 4px;
    align-items: center;
}

.navbar-right {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

/* ── Logo ── */

.nav-logo-link {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 20px;
    font-weight: 800;
    text-decoration: none;
    font-family: 'Orbitron', sans-serif;
    color: var(--dark);
    letter-spacing: -0.3px;
    transition: color 0.2s ease;
    white-space: nowrap;
}

.nav-logo-link:hover { color: var(--primary); }

.logo {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s ease;
    flex-shrink: 0;
}

.logo-mark {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px;
    width: 24px;
    height: 24px;
}

.logo-mark span {
    display: block;
    border-radius: 3px;
}

/* Canonical four-tile mark (matches the footer & auth logo) */
.logo-mark span:nth-child(1) { background: var(--primary); }
.logo-mark span:nth-child(2) { background: var(--primary-light); }
.logo-mark span:nth-child(3) { background: var(--accent-cyan); }
.logo-mark span:nth-child(4) { background: var(--accent); }

.nav-logo-link:hover .logo {
    transform: rotate(-8deg) scale(1.08);
}

/* ── Nav Links (desktop) ── */

.nav-item { position: relative; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    font-weight: 500;
    font-size: 14.5px;
    user-select: none;
    padding: 9px 14px;
    position: relative;
    border-radius: 8px;
    text-decoration: none;
    color: var(--gray-dark);
    transition: color 0.2s ease;
    overflow: hidden;
    white-space: nowrap;
}

.nav-link::before {
    content: '';
    inset: 0;
    opacity: 0;
    position: absolute;
    border-radius: 8px;
    transform: scale(0.92);
    transition: opacity 0.2s ease, transform 0.2s ease;
    background: var(--dark);
}

.nav-link:hover::before,
.nav-link.active::before {
    opacity: 1;
    transform: scale(1);
}

.nav-link:hover,
.nav-link.active { color: white; }

.nav-link span,
.nav-link i {
    position: relative;
    z-index: 1;
}


/* ── Desktop auth ── */

.nav-auth {
    display: flex;
    align-items: center;
    gap: 6px;
}

.nav-login-btn-ghost {
    color: var(--gray-dark) !important;
    padding: 9px 14px !important;
    border-radius: 8px !important;
    font-weight: 500 !important;
    font-size: 14px !important;
    text-decoration: none !important;
    display: flex !important;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--light-quaternary) !important;
    transition: all 0.2s ease;
    background: none !important;
    white-space: nowrap;
    overflow: hidden;
    position: relative;
}

.nav-login-btn-ghost:hover {
    color: white !important;
    border-color: var(--dark) !important;
    background: var(--dark) !important;
}

.nav-signup-btn {
    background: var(--dark) !important;
    color: white !important;
    padding: 9px 18px !important;
    border-radius: 8px !important;
    font-weight: 600 !important;
    font-size: 14px !important;
    border: none !important;
    text-decoration: none !important;
    display: flex !important;
    align-items: center;
    gap: 6px;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    white-space: nowrap;
    box-shadow: var(--shadow-sm);
}

.nav-signup-btn:hover {
    background: var(--dark-secondary) !important;
    color: white !important;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* ── User dropdown (desktop) ── */

.nav-user-dropdown { position: relative; }

.nav-user-btn {
    background: none;
    border: 1px solid var(--light-quaternary);
    font-family: inherit;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 7px 12px;
    border-radius: 8px;
    color: var(--gray-dark);
    transition: all 0.2s ease;
    white-space: nowrap;
    position: relative;
    z-index: 1;
    overflow: hidden;
}

/* The user chip keeps its own light hover: the dark .nav-link pill
   (::before) would swallow the avatar and turn the text unreadable. */
.nav-user-btn::before { content: none; }

.nav-user-btn:hover,
.nav-user-btn[aria-expanded="true"] {
    background: rgba(37, 99, 235, 0.07);
    border-color: rgba(37, 99, 235, 0.3);
    color: var(--primary);
}

.nav-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    font-size: 1rem;    /* emoji avatar */
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Long full names must not stretch the chip */
.nav-user-btn > span {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-chevron {
    font-size: 0.65rem !important;
    transition: transform 0.25s ease;
}

.nav-user-btn[aria-expanded="true"] .nav-chevron { transform: rotate(180deg); }

.nav-user-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 185px;
    background: white;
    border: 1px solid var(--light-quaternary);
    border-radius: 10px;
    box-shadow: 0 10px 28px rgba(0,0,0,0.09), 0 3px 10px rgba(0,0,0,0.05);
    padding: 6px;
    opacity: 0;
    transform: translateY(-6px) scale(0.97);
    pointer-events: none;
    transition: all 0.2s ease;
    z-index: 3000;
}

.nav-user-menu.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.nav-user-menu-item {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-dark);
    text-decoration: none;
    transition: all 0.15s ease;
    background: none;
    border: none;
    width: 100%;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
}

.nav-user-menu-item:hover {
    background: var(--light-secondary);
    color: var(--primary);
}

.nav-user-menu-item i {
    width: 15px;
    font-size: 0.8rem;
    color: var(--primary);
    text-align: center;
}

.nav-user-menu-divider {
    height: 1px;
    background: var(--light-quaternary);
    margin: 4px 0;
}

.nav-user-menu-logout { color: #dc2626; }
.nav-user-menu-logout:hover { background: rgba(239, 68, 68, 0.07); color: #dc2626; }
.nav-user-menu-logout i { color: #dc2626; }

/* ── Hamburger ── */

.nav-toggle {
    padding: 4px;
    display: none;
    cursor: pointer;
    border-radius: 6px;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
}

.hamburger {
    width: 24px;
    height: 18px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.line {
    width: 24px;
    height: 2.5px;
    border-radius: 3px;
    background-color: var(--dark);
    transition: all 0.3s ease;
}

.hamburger.active .line:first-child { transform: rotate(45deg) translate(5.5px, 5.5px); }
.hamburger.active .line:last-child  { transform: rotate(-45deg) translate(5.5px, -5.5px); }
.hamburger.active .line:nth-child(2){ opacity: 0; transform: scaleX(0); }

/* ── Mobile collapse panel ── */

.nav-collapse {
    display: none;
    max-width: 1240px;
    margin: 8px auto 0;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(18px) saturate(1.6);
    -webkit-backdrop-filter: blur(18px) saturate(1.6);
    border: 1px solid var(--hairline);
    border-radius: 16px;
    box-shadow: 0 18px 44px rgba(15, 23, 42, 0.14);
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transform: translateY(-6px) scale(0.99);
    padding: 0 20px;
    pointer-events: none;
    transition: max-height 0.35s ease, opacity 0.25s ease, padding 0.25s ease, transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.nav-collapse.active {
    max-height: 540px;
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    padding: 16px 20px 20px;
}

.nav-collapse-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nav-collapse-links li { display: block; }

.nav-collapse-link {
    display: block;
    width: 100%;
    padding: 11px 16px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    color: var(--gray-dark);
    text-decoration: none;
    background: var(--light-secondary);
    border: 1px solid var(--light-quaternary);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    text-align: left;
    font-family: inherit;
    box-sizing: border-box;
}

.nav-collapse-link:hover,
.nav-collapse-link.active {
    background: var(--dark);
    border-color: var(--dark);
    color: white;
}

.nav-collapse-divider {
    height: 1px;
    background: var(--light-quaternary);
    margin: 14px 0;
}

.nav-collapse-auth {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.nav-collapse-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--light-secondary);
    border-radius: 8px;
    margin-bottom: 4px;
    font-weight: 600;
    color: var(--gray-dark);
    font-size: 15px;
}

.nav-collapse-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    font-size: 1.1rem;   /* emoji avatar */
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Orbitron', monospace;
    flex-shrink: 0;
}

.nav-collapse-logout { color: #dc2626 !important; }
.nav-collapse-logout:hover {
    background: rgba(239, 68, 68, 0.07) !important;
    border-color: rgba(239, 68, 68, 0.2) !important;
    color: #dc2626 !important;
}

.nav-collapse-btn-ghost {
    display: block;
    width: 100%;
    padding: 11px 16px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    border: 1px solid var(--light-quaternary);
    background: var(--light-secondary);
    color: var(--gray-dark);
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.nav-collapse-btn-ghost:hover {
    background: var(--dark);
    border-color: var(--dark);
    color: white;
}

.nav-collapse-btn-primary {
    display: block;
    width: 100%;
    padding: 11px 16px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    border: none;
    background: var(--primary);
    color: white;
    transition: background 0.2s ease;
    box-sizing: border-box;
}

.nav-collapse-btn-primary:hover {
    background: var(--primary-dark);
    color: white;
}

/* ── Responsive breakpoints ── */

@media screen and (max-width: 1380px) {
    .navbar { padding: 0 10px 0 18px; }
}

@media screen and (max-width: 1024px) {
    nav { padding-top: 10px; }
    .navbar { height: 58px; border-radius: 16px; }
    body { margin-top: 74px; }

    .nav-toggle  { display: flex; }
    .nav-menu    { display: none; }
    .nav-auth    { display: none; }

    .nav-collapse { display: block; }
}

@media screen and (max-width: 768px) {
    .navbar { padding: 0 8px 0 14px; }
    .nav-logo-link { font-size: 18px; }
    .logo { width: 30px; height: 30px; font-size: 14px; border-radius: 8px; }
}
