/* === Beacon sub-site — minimal dark === */

:root {
    --bg: #161616;
    --bg-elevated: #1d1d1d;
    --bg-menu: #111111;
    --text: #e8e0d0;
    --text-muted: #9a9285;
    --accent: #c9a96e;
    --accent-hover: #e6c890;
    --border: #2e2e2e;
    --border-strong: #3a3a3a;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg);
    color: var(--text);
    font-family: 'Merriweather', Georgia, serif;
    font-size: 17px;
    font-weight: 400;
    line-height: 1.75;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* === Dark scrollbars (track = menu background #111111) === */
html {
    color-scheme: dark;
    /* thumb, track — Firefox & Chrome/Edge 121+ */
    scrollbar-color: var(--border-strong) var(--bg-menu);
}

/* WebKit / Chromium */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}
::-webkit-scrollbar-track {
    background-color: var(--bg-menu); /* #111111 */
}
::-webkit-scrollbar-thumb {
    background-color: var(--border-strong);
    border: 3px solid var(--bg-menu); /* inset, so the thumb reads as a pill on the dark track */
    border-radius: 7px;
}
::-webkit-scrollbar-thumb:hover {
    background-color: var(--text-muted);
}
::-webkit-scrollbar-corner {
    background-color: var(--bg-menu);
}

/* === Top menu (sticky) === */

.site-menu {
    position: sticky;
    top: 0;
    z-index: 1000;
    background-color: var(--bg-menu);
    border-bottom: 1px solid var(--border-strong);
}

.menu-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 32px;
    display: flex;
    align-items: stretch;
    flex-wrap: wrap;
}

/* Brand */
.menu-brand {
    display: flex;
    align-items: center;
    padding: 18px 18px 8px 0;
    font-weight: 700;
    font-size: 1.1em;
    color: var(--accent);
    text-decoration: none;
    border-right: 1px solid var(--border);
    margin-right: 8px;
}

.menu-brand:hover {
    color: var(--accent-hover);
}

/* Root list of top-level items */
.menu-root {
    display: flex;
    align-items: stretch;
    flex-wrap: wrap;
    gap: 4px;
    list-style: none;
    margin: 0;
    padding: 0;
}

/* Every item is a positioning context for its own submenu */
.menu-item {
    position: relative;
    margin: 0;
}

.menu-root > .menu-item {
    display: flex;
    align-items: center;
}

/* A real link and a non-clickable label share the same look... */
.menu-link,
.menu-label {
    display: flex;
    align-items: center;
    padding: 18px 5px 8px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.95em;
    font-family: inherit;
    line-height: 1.4;
}

/* ...but a label has no link: it is NOT a button, just a heading that
   reveals its submenu on hover / focus. */
.menu-label {
    cursor: default;
    -webkit-user-select: none;
    user-select: none;
}

.menu-label:focus {
    outline: none;
}

.menu-label:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/* Top-level hover / open highlight */
.menu-root > .menu-item > .menu-link:hover,
.menu-root > .menu-item > .menu-label:hover,
.menu-root > .menu-item:focus-within > .menu-label {
    color: var(--accent);
    background-color: var(--bg-elevated);
}

/* Caret on top-level items that own a submenu */
.menu-root > .menu-item.has-children > .menu-label::after {
    content: "\25BE"; /* ▾ */
    color: var(--text-muted);
    font-size: 0.8em;
    margin-left: 6px;
}

.menu-root > .menu-item.has-children:hover > .menu-label::after,
.menu-root > .menu-item.has-children:focus-within > .menu-label::after {
    color: var(--accent);
}

/* === Submenus (fly-out panels) === */

.submenu {
    display: none;
    position: absolute;
    min-width: 240px;
    margin: 0;
    padding: 8px 0;
    list-style: none;
    background-color: var(--bg-menu);
    border: 1px solid var(--border-strong);
    z-index: 100; /* above the AI disclaimer bar and the page */
}

/* First level drops straight below its top-level item */
.menu-root > .menu-item > .submenu {
    top: 100%;
    left: 0;
    border-top: none;
}

/* Deeper levels fly out to the right of the hovered row */
.submenu .submenu {
    top: -9px; /* line up the first row with the parent row */
    left: 100%;
}

/* Open on hover OR when focus is inside (keyboard navigation / touch tap) */
.menu-item:hover > .submenu,
.menu-item:focus-within > .submenu {
    display: block;
}

/* Rows inside a submenu stack vertically */
.submenu > .menu-item {
    display: block;
}

.submenu .menu-link,
.submenu .menu-label,
.submenu .menu-disabled {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 18px;
    font-size: 0.92em;
    line-height: 1.5;
    white-space: nowrap;
}

.submenu .menu-link,
.submenu .menu-label {
    color: var(--text);
    text-decoration: none;
}

.submenu .menu-link:hover,
.submenu .menu-label:hover,
.submenu .menu-item:focus-within > .menu-label {
    color: var(--accent);
    background-color: var(--bg-elevated);
}

/* Caret on nested items that own a deeper submenu */
.submenu .menu-item.has-children > .menu-label::after {
    content: "\25B8"; /* ▸ */
    color: var(--text-muted);
    font-size: 0.9em;
}

.submenu .menu-item.has-children:hover > .menu-label::after,
.submenu .menu-item.has-children:focus-within > .menu-label::after {
    color: var(--accent);
}

/* === Disabled entry: greyed out, no link, not a button === */
.menu-disabled {
    color: var(--text-muted);
    opacity: 0.55;
    cursor: not-allowed;
    -webkit-user-select: none;
    user-select: none;
}

/* === AI Disclaimer Bar === */
.ai-disclaimer-bar {
    border-top: 1px solid var(--border-strong);
    background-color: var(--bg-menu);
}

.ai-disclaimer-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 4px 32px 2px; /* bottom ridotto: alza la linea inferiore per centrare otticamente il testo maiuscolo */
    display: flex;       /* Attiva l'allineamento flessibile */
    align-items: center; /* Centra perfettamente il testo sull'asse verticale */
}

.ai-disclaimer-inner a {
    display: block;
    font-size: 0.65em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    text-decoration: none;
    line-height: 1; /* Elimina l'altezza riga ereditata per una centratura millimetrica */
}

.ai-disclaimer-inner a:hover {
    color: var(--accent);
}

/* === Page content === */

.page {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 56px 32px 80px;
}

.page-header {
    margin-bottom: 48px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.page-header .eyebrow {
    color: var(--accent);
    font-size: 0.85em;
    text-transform: uppercase;
    margin: 0 0 12px;
    font-weight: 700;
}

.page-header h1 {
    margin: 0;
    font-size: 2.6em;
    font-weight: 900;
    line-height: 1.2;
    color: var(--text);
}

.page-header .subtitle {
    margin: 16px 0 0;
    color: var(--text-muted);
    font-size: 1.1em;
    font-style: italic;
}

h2 {
    font-size: 1.8em;
    font-weight: 700;
    margin: 56px 0 16px;
    color: var(--text);
}

h3 {
    font-size: 1.3em;
    font-weight: 700;
    margin: 36px 0 12px;
    color: var(--accent);
}

p {
    margin: 0 0 18px;
}

a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-color: var(--border-strong);
    text-underline-offset: 3px;
    transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

a:hover {
    color: var(--accent-hover);
    text-decoration-color: var(--accent);
}

ul, ol {
    padding-left: 1.4em;
    margin: 0 0 18px;
}

li {
    margin-bottom: 6px;
}

blockquote {
    border-left: 3px solid var(--accent);
    margin: 24px 0;
    padding: 6px 0 6px 24px;
    color: var(--text-muted);
    font-style: italic;
}

hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 40px 0;
}

.placeholder-note {
    margin-top: 48px;
    padding: 20px 24px;
    background-color: var(--bg-elevated);
    border-left: 3px solid var(--accent);
    color: var(--text-muted);
    font-size: 0.95em;
}

.placeholder-note strong {
    color: var(--text);
}

/* === Footer === */

.site-footer {
    border-top: 1px solid var(--border);
    padding: 24px 32px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85em;
}

/* === Music page playlist placeholders === */

.playlist-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 24px;
}

.playlist-card {
    background-color: var(--bg-elevated);
    border: 1px solid var(--border);
    padding: 24px;
}

.playlist-card h3 {
    margin-top: 0;
}

.playlist-card a {
    word-break: break-all;
}

/* === Responsive === */

@media (max-width: 900px) {
    .menu-inner {
        padding: 0 16px;
        flex-direction: column;
        align-items: stretch;
    }

    .menu-brand {
        border-right: none;
        border-bottom: 1px solid var(--border);
        margin-right: 0;
        padding: 14px 0;
        justify-content: center;
    }

    .menu-root {
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        width: 100%;
    }

    .menu-root > .menu-item {
        display: block;
    }

    .menu-link,
    .menu-label {
        padding: 14px 12px;
        width: 100%;
    }

    /* Caret points down everywhere on mobile (accordion, not fly-out) */
    .submenu .menu-item.has-children > .menu-label::after {
        content: "\25BE"; /* ▾ */
    }

    /* Submenus become inline accordions, revealed on tap (focus-within) */
    .submenu {
        position: static;
        min-width: 0;
        border: none;
        border-top: 1px solid var(--border);
        padding: 0;
        background-color: var(--bg);
    }

    .submenu .menu-link,
    .submenu .menu-label,
    .submenu .menu-disabled {
        justify-content: flex-start;
        padding: 12px 12px 12px 28px;
        white-space: normal;
    }

    .submenu .submenu .menu-link,
    .submenu .submenu .menu-label,
    .submenu .submenu .menu-disabled {
        padding-left: 44px;
    }

    .submenu .submenu .submenu .menu-link,
    .submenu .submenu .submenu .menu-label,
    .submenu .submenu .submenu .menu-disabled {
        padding-left: 60px;
    }

    .ai-disclaimer-inner {
        padding: 4px 16px 2px; /* Adattato lo spessore ridotto anche per il layout mobile */
    }

    .page {
        padding: 32px 18px 64px;
    }

    .page-header h1 {
        font-size: 2em;
    }
}

/* ============================================================
   === Manual / rulebook page (two columns + collapsibles) ===
   ============================================================ */

.manual-layout {
    flex: 1;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 32px 80px;
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    gap: 40px;
    align-items: start;
}

/* --- Sidebar: sticky Table of Contents --- */
.manual-toc {
    position: sticky;
    top: 88px; /* clears the sticky site menu */
    align-self: start;
    max-height: calc(100vh - 108px);
    overflow-y: auto;
    background-color: var(--bg-elevated);
    border: 1px solid var(--border);
    padding: 12px 8px 16px;
    font-size: 0.9em;
}

.toc-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 4px 8px 12px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.toc-title {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.8em;
    font-weight: 700;
    color: var(--accent);
}

.toc-tools { display: flex; gap: 4px; }

.toc-tool-btn {
    width: 24px;
    height: 24px;
    line-height: 1;
    border: 1px solid var(--border);
    background: var(--bg-menu);
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
    transition: color 0.15s ease, border-color 0.15s ease;
}
.toc-tool-btn:hover { color: var(--accent); border-color: var(--border-strong); }

#toc ul { list-style: none; margin: 0; padding: 0; }
.toc-item { margin: 0; }

.toc-row { display: flex; align-items: flex-start; gap: 2px; }

.toc-caret {
    flex: 0 0 auto;
    width: 18px;
    align-self: stretch;
    padding: 0;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.7em;
    text-align: center;
}
.toc-caret::before { content: "\25BC"; } /* ▼ when expanded */
.toc-item.collapsed > .toc-row > .toc-caret::before { content: "\25B6"; } /* ▶ when collapsed */
.toc-caret:hover { color: var(--accent); }
.toc-item.leaf > .toc-row > .toc-caret { visibility: hidden; }

.toc-link {
    flex: 1 1 auto;
    display: block;
    padding: 5px 6px 5px 2px;
    color: var(--text);
    text-decoration: none;
    line-height: 1.35;
}
.toc-link:hover { color: var(--accent); }

.toc-l1 > .toc-row > .toc-link { font-weight: 700; }
.toc-l2 > .toc-row > .toc-link { font-size: 0.95em; }
.toc-l3 > .toc-row > .toc-link { font-size: 0.9em; color: var(--text-muted); }

/* nested indentation with a guide line */
.toc-sublist {
    padding-left: 12px;
    margin-left: 8px;
    border-left: 1px solid var(--border);
}

/* collapse animation for TOC branches (grid 1fr -> 0fr) */
.toc-children {
    display: grid;
    grid-template-rows: 1fr;
    transition: grid-template-rows 0.25s ease;
}
.toc-item.collapsed > .toc-children { grid-template-rows: 0fr; }
.toc-children > .toc-sublist { overflow: hidden; min-height: 0; }

/* --- Main content column --- */
.manual-content { min-width: 0; }

.manual-toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}
.manual-btn {
    font-family: inherit;
    font-size: 0.8em;
    color: var(--text-muted);
    background-color: var(--bg-elevated);
    border: 1px solid var(--border);
    padding: 7px 14px;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}
.manual-btn:hover { color: var(--accent); border-color: var(--border-strong); }

.manual-loading { color: var(--text-muted); font-style: italic; }
.manual-error { color: #ff8f8f; }

/* Headings act as collapse toggles */
.manual-content h1 {
    font-size: 2.1em;
    font-weight: 900;
    line-height: 1.2;
    color: var(--text);
    margin: 44px 0 18px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}
#manual > div > .sec:first-child > h1.sec-head { margin-top: 0; }

.sec-head {
    cursor: pointer;
    scroll-margin-top: 96px; /* so navigation clears the sticky site menu */
}
.sec-head::before {
    content: "\25BC"; /* ▼ expanded */
    display: inline-block;
    width: 1em;
    margin-left: -1.35em;
    margin-right: 0.35em;
    color: var(--text-muted);
    font-size: 0.7em;
    vertical-align: middle;
    transition: color 0.15s ease;
}
.sec.collapsed > .sec-head::before { content: "\25B6"; } /* ▶ collapsed */
.sec-head:hover::before { color: var(--accent); }
.sec-head { padding-left: 1.35em; }
.sec-head:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* the collapsible body (grid 1fr -> 0fr animation) */
.sec-body {
    display: grid;
    grid-template-rows: 1fr;
    transition: grid-template-rows 0.3s ease;
}
.sec.collapsed > .sec-body { grid-template-rows: 0fr; }
.sec-body-inner { overflow: hidden; min-height: 0; }

/* --- Rendered markdown niceties (scoped to the manual) --- */
.manual-content table {
    display: block;
    width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    margin: 0 0 20px;
    font-size: 0.92em;
}
.manual-content th,
.manual-content td {
    border: 1px solid var(--border-strong);
    padding: 8px 12px;
    text-align: left;
    vertical-align: top;
}
.manual-content thead th {
    background-color: var(--bg-elevated);
    color: var(--accent);
}
.manual-content tbody tr:nth-child(even) { background-color: rgba(255, 255, 255, 0.02); }

.manual-content code {
    font-family: 'Courier New', Courier, monospace;
    background-color: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 1px 5px;
    font-size: 0.88em;
}
.manual-content pre {
    background-color: var(--bg-elevated);
    border: 1px solid var(--border);
    padding: 16px;
    overflow-x: auto;
    margin: 0 0 20px;
}
.manual-content pre code { background: none; border: none; padding: 0; }

.manual-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 22px 0;
    border: 1px solid var(--border);
}

/* --- Manual page responsive --- */
@media (max-width: 900px) {
    .manual-layout {
        grid-template-columns: 1fr;
        gap: 0;
        padding: 24px 18px 64px;
    }
    .manual-toc {
        position: static;
        max-height: 50vh;
        margin-bottom: 28px;
    }
    .manual-content h1 { font-size: 1.8em; }
}

/* === Back-to-top button (discreet, fixed bottom-right) === */
.to-top {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 900; /* above content, below the sticky site menu (1000) */
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25em;
    line-height: 1;
    color: var(--text-muted);
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    cursor: pointer;
    /* hidden until the user scrolls down */
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease,
                color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.to-top.is-visible {
    opacity: 0.65;
    visibility: visible;
    transform: translateY(0);
}

.to-top:hover {
    opacity: 1;
    color: var(--accent);
    border-color: var(--accent);
    background-color: var(--bg-menu);
}

.to-top:focus-visible {
    opacity: 1;
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media (max-width: 900px) {
    .to-top {
        right: 14px;
        bottom: 14px;
        width: 40px;
        height: 40px;
    }
}

/* === Bilingual license box (disclaimer page) === */
.license-box {
    margin: 36px 0;
    border: 1px solid var(--border-strong);
    background-color: var(--bg-elevated);
}

.license-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
}

.license-col {
    padding: 20px 24px;
    font-size: 0.9em;
}

.license-col + .license-col {
    border-left: 1px solid var(--border);
}

.license-col p { margin: 0 0 12px; }
.license-col ul { margin: 0 0 12px; }

.license-lang {
    display: block;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.72em;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 14px;
}

@media (max-width: 720px) {
    .license-cols { grid-template-columns: 1fr; }
    .license-col + .license-col {
        border-left: none;
        border-top: 1px solid var(--border);
    }
}
