/* components.css. The parts every page shares: header, footer, buttons, panels, inputs, the sign-in dialog.
   Loaded after tokens.css and base.css, and after each page's older stylesheets.
   The header and the footer use their own class names (sg-...), so they work on every page.
   Buttons, panels and inputs are restyled only on pages that have moved to the new design, they carry
   class "sg-page" on <body> (added by _tools/build_site.py). Game and admin pages keep their older look
   until their own stage. */

/* ── Header ─────────────────────────────────────────────────────────────────── */
.sg-header {
    position: sticky;
    top: 0;
    z-index: 60;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
}

.sg-header-inner {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    max-width: var(--content-width);
    min-height: var(--header-height);
    margin: 0 auto;
    padding: 0 var(--space-4);
}

.sg-brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    color: var(--text);
    text-decoration: none;
    flex: none;
}

.sg-brand-mark {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    object-fit: cover;
    border: 1px solid var(--line);
}

.sg-brand-name {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: var(--text-sm);
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.sg-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    flex: 1 1 auto;
}

.sg-nav a,
.sg-nav summary {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 var(--space-3);
    border-radius: var(--radius-md);
    color: var(--muted);
    font-size: var(--text-sm);
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    list-style: none;
    transition: color 150ms var(--ease), background-color 150ms var(--ease);
}

.sg-nav summary::-webkit-details-marker {
    display: none;
}

.sg-nav summary::after {
    content: "";
    width: 6px;
    height: 6px;
    margin: -3px 0 0 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
}

.sg-nav a:hover,
.sg-nav summary:hover,
.sg-nav details[open] > summary {
    color: var(--text);
    background: var(--surface-2);
}

.sg-nav a[aria-current="page"],
.sg-nav details[data-current="true"] > summary {
    color: var(--text);
    box-shadow: inset 0 -2px 0 var(--action);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.sg-menu {
    position: relative;
}

.sg-menu-list {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 5;
    display: grid;
    min-width: 200px;
    padding: var(--space-2);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.sg-menu-list a {
    justify-content: flex-start;
    color: var(--text);
}

.sg-account {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex: none;
    margin-left: auto;
}

.sg-account .auth-user-label {
    display: none;
}

/* One button for the avatar, the name and the rank line, it opens the profile. */
.sg-profile-chip {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 44px;
    max-width: 240px;
    padding: 4px var(--space-3) 4px 6px;
    color: var(--text);
    text-decoration: none;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    transition: border-color 150ms var(--ease);
}

.sg-profile-chip:hover {
    border-color: var(--accent);
}

.sg-profile-chip .auth-user-copy {
    min-width: 0;
}

.sg-profile-chip .auth-user-name {
    max-width: 150px;
    font-size: var(--text-sm);
    line-height: 1.2;
}

.sg-account .sg-theme-menu summary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    list-style: none;
}

.sg-account .sg-theme-menu summary::-webkit-details-marker {
    display: none;
}

.sg-account .sg-theme-menu summary:hover,
.sg-account .sg-theme-menu[open] > summary {
    background: var(--surface-2);
}

.sg-account .sg-theme-menu .sg-swatch {
    margin: 0;
}

.sg-account .auth-controls {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.sg-account .auth-user-chip {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0;
    background: none;
    border: 0;
}

.sg-menu-button {
    display: none;
    min-height: 44px;
    margin-left: auto;
    padding: 0 var(--space-4);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

/* On phones with scripts the menu folds into a sheet under the bar. Without scripts the links just wrap. */
@media (max-width: 900px) {
    .sg-header-inner {
        flex-wrap: wrap;
        row-gap: 0;
    }

    .sg-nav {
        order: 3;
        flex: 1 1 100%;
        flex-wrap: wrap;
        justify-content: flex-start;
        padding-bottom: var(--space-2);
    }

    .sg-account {
        order: 2;
    }

    .sg-js .sg-menu-button {
        display: inline-flex;
        align-items: center;
        order: 2;
    }

    .sg-js .sg-account {
        order: 2;
        margin-left: 0;
    }

    .sg-js .sg-nav {
        display: none;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
    }

    .sg-js .sg-nav.is-open {
        display: flex;
    }

    .sg-js .sg-nav a,
    .sg-js .sg-nav summary {
        min-height: 48px;
    }

    .sg-js .sg-menu-list {
        position: static;
        border: 0;
        box-shadow: none;
        padding: 0 0 0 var(--space-4);
    }
}

@media (max-width: 480px) {
    .sg-brand-name {
        font-size: var(--text-xs);
    }
}

/* ── Footer ─────────────────────────────────────────────────────────────────── */
.sg-footer {
    margin-top: var(--space-7);
    border-top: 1px solid var(--line);
    background: var(--bg-alt);
    color: var(--muted);
}

.sg-footer-inner {
    max-width: var(--content-width);
    margin: 0 auto;
    padding: var(--space-7) var(--space-4) var(--space-5);
}

.sg-footer-cols {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--space-6);
}

.sg-footer-title {
    margin: 0 0 var(--space-3);
    color: var(--text);
    font-size: var(--text-sm);
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.sg-footer ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.sg-footer li {
    margin: 0;
    line-height: 1.4;
}

.sg-footer a {
    display: inline-block;
    padding: 6px 0;
    color: var(--muted);
    font-size: var(--text-md);
    text-decoration: none;
}

.sg-footer a:hover {
    color: var(--accent-text);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.sg-footer-line {
    margin: var(--space-6) 0 0;
    padding-top: var(--space-4);
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: var(--text-sm);
    text-align: center;
}

@media (max-width: 800px) {
    .sg-footer-cols {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: var(--space-5);
    }
}

/* ── Sign-in dialog (all pages) ─────────────────────────────────────────────── */
.auth-modal {
    background: var(--overlay);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}

.auth-dialog {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.auth-field input {
    min-height: 44px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
}

.auth-field input:focus {
    border-color: var(--accent);
    outline: 2px solid var(--accent-text);
    outline-offset: 1px;
}

/* ── Pages that have moved to the new design ────────────────────────────────── */
.sg-page .glass-panel,
.sg-page .panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
}

.sg-page .primary-button,
.sg-page .secondary-button,
.sg-page .ghost-button,
.sg-page .danger-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 44px;
    padding: 10px 18px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    box-shadow: none;
    transform: none;
    transition: background-color 150ms var(--ease), border-color 150ms var(--ease), color 150ms var(--ease);
}

.sg-page .primary-button {
    background: var(--action);
    border-color: var(--action);
    color: var(--on-action);
}

.sg-page .primary-button:hover {
    background: color-mix(in srgb, var(--action) 88%, white);
    border-color: color-mix(in srgb, var(--action) 88%, white);
}

.sg-page .secondary-button {
    background: transparent;
    border-color: var(--accent);
    color: var(--accent-text);
}

.sg-page .secondary-button:hover {
    background: var(--surface-2);
}

.sg-page .ghost-button {
    background: transparent;
    border-color: var(--line);
    color: var(--text);
}

.sg-page .ghost-button:hover {
    background: var(--surface-2);
    border-color: var(--accent);
}

.sg-page .danger-button {
    background: transparent;
    border-color: var(--danger);
    color: var(--danger);
}

.sg-page .danger-button:hover {
    background: var(--danger);
    color: var(--bg);
}

.sg-page .eyebrow {
    color: var(--accent-text);
}

.sg-page input[type="text"],
.sg-page input[type="email"],
.sg-page input[type="password"],
.sg-page input[type="search"],
.sg-page select,
.sg-page textarea {
    min-height: 44px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
}

.sg-page textarea {
    min-height: 120px;
}

.sg-page input:focus,
.sg-page select:focus,
.sg-page textarea:focus {
    border-color: var(--accent);
}

/* ── Theme menu and picker ──────────────────────────────────────────────────── */
/* A swatch carries data-theme or data-board itself, so it shows that choice's own colors (tokens.css). */
.sg-swatch {
    display: inline-block;
    flex: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(128, 128, 128, 0.55);
}

.sg-swatch-theme {
    background: linear-gradient(135deg, var(--bg) 0 50%, var(--accent) 50% 100%);
}

.sg-swatch-board {
    border-radius: 6px;
    background: conic-gradient(var(--bt-a) 25%, var(--bt-b) 0 50%, var(--bt-a) 0 75%, var(--bt-b) 0);
}

.sg-theme-list {
    left: auto;
    right: 0;
    z-index: 80;
    min-width: min(300px, calc(100vw - 2 * var(--space-4)));
    max-height: min(75vh, 680px);
    overflow-y: auto;
    padding: var(--space-4) var(--space-4) 0;
}

.sg-picker-title {
    margin: 0 0 var(--space-2);
    color: var(--muted);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.sg-picker-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.sg-choice {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 44px;
    padding: 0 var(--space-3);
    background: transparent;
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    font: inherit;
    font-size: var(--text-sm);
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}

.sg-choice:hover {
    background: var(--surface-2);
}

.sg-choice[aria-pressed="true"] {
    background: var(--surface-2);
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
}



/* The e-mail address is a picture with pale text for the dark themes. On the light theme it is turned dark. */
[data-theme="light"] .email-image {
    filter: invert(1) hue-rotate(180deg);
}

/* The social buttons of the older pages were written with fixed pale colors, they now follow the theme. */
.social-link {
    color: var(--text);
    border-color: var(--line);
    background: var(--surface-2);
}

.social-link:hover,
.social-link:focus-visible {
    border-color: var(--accent);
    background: var(--surface-2);
}

/* ── Signed-in flash ────────────────────────────────────────────────────────── */
/* For a player who was signed in last time the sign-in buttons stay out of sight until the page has painted the
   saved name (auth-shared-themed.js removes the class). If that script never runs they come back after 2 seconds. */
.sg-cached-user #auth-logged-out {
    visibility: hidden;
    animation: sg-reveal 0s linear 2s forwards;
}

@keyframes sg-reveal {
    to { visibility: visible; }
}

@media print {
    .sg-skip,
    .sg-header,
    .sg-footer {
        display: none;
    }
}

/* A button or link switched off with the hidden attribute stays hidden (the button styles set their own display). */
.primary-button[hidden], .ghost-button[hidden], .secondary-button[hidden] { display: none !important; }

/* Grey placeholder bars while a value loads (profile). No blur, the real text replaces them. */
.is-skeleton { position: relative; display: inline-block; min-width: 9em; min-height: 1.1em; color: transparent !important; }
.is-skeleton::after {
    content: "";
    position: absolute;
    inset: 2px 0;
    border-radius: 6px;
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%);
    background-size: 200% 100%;
    animation: sg-skeleton 1.3s linear infinite;
}
@keyframes sg-skeleton { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .is-skeleton::after { animation: none; } }

/* The rank and rating points under the player's name in the header (auth-shared-themed.js) */
.sg-rank-line { color: var(--muted); font-size: .72rem; font-weight: 600; line-height: 1.2; white-space: nowrap; }

/* Badges as medals and streak flames (drawn by /assets/progress.js), on the profile, the result card and home. */
.sg-medals { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: var(--space-3, 12px); margin: 8px 0 0; padding: 0; list-style: none; }
.sg-medal { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px 12px; text-align: center; background: var(--bg); border: 1px solid var(--line); border-radius: 16px; }
.sg-medal-art { width: 64px; height: 76px; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .25)); }
.sg-medal-tag { margin-top: -10px; padding: 1px 8px; color: #1b1530; font-size: .66rem; font-weight: 800; letter-spacing: .02em; text-transform: uppercase; background: #fff; border-radius: 999px; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.sg-medal-name { color: var(--text); font-size: .74rem; font-weight: 700; line-height: 1.25; }
.sg-medal-name b { color: var(--accent-text); }
.sg-medal-gold { border-color: rgba(255, 196, 64, .55); }
.sg-medal-platinum { border-color: rgba(120, 190, 230, .55); }
.sg-medal-diamond { border-color: rgba(140, 110, 255, .7); box-shadow: 0 0 0 1px rgba(140, 110, 255, .25), 0 6px 18px rgba(108, 76, 240, .25); }
.sg-medals-empty { grid-column: 1 / -1; padding: 10px; color: var(--muted); font-size: var(--text-sm); border: 1px dashed var(--line); border-radius: 12px; }
.sg-medals-small { grid-template-columns: repeat(auto-fit, minmax(84px, 108px)); justify-content: center; }
.sg-medals-small .sg-medal { padding: 6px 4px 8px; }
.sg-medals-small .sg-medal-art { width: 48px; height: 57px; }
.sg-medals-small .sg-medal-name { font-size: .68rem; }

.sg-flames { --flame: 20px; display: inline-flex; align-items: flex-end; flex-wrap: wrap; gap: 3px; vertical-align: middle; }
.sg-flame { display: inline-block; width: calc(var(--flame) * .9); height: var(--flame); }
.sg-flame svg { display: block; width: 100%; height: 100%; }
.sg-flame path { fill: #ff8a1f; }
.sg-flame.is-day svg { filter: drop-shadow(0 0 3px rgba(255, 138, 31, .55)); }
.sg-flame.is-week { width: calc(var(--flame) * 1.4); height: calc(var(--flame) * 1.55); }
.sg-flame.is-week path { fill: #ff4d1a; }
.sg-flame.is-week path.sg-flame-core { fill: #ffd54a; }
.sg-flame.is-week svg { filter: drop-shadow(0 0 6px rgba(255, 90, 30, .7)); }
.sg-flame.is-empty path { fill: none; stroke: var(--muted); stroke-width: 1.5; opacity: .6; }
.sg-flames-weeks { align-self: center; margin: 0 4px 0 2px; color: #ff7a2a; font-size: .8rem; font-weight: 800; }

/* The daily puzzle streak line (assets/streak-line.js), on the home page and the puzzles page. */
.hm-streak { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 8px 0 0; color: var(--action); font-weight: 700; }
.hm-streak[hidden] { display: none; }
.hm-streak .sg-flames { --flame: 25px; }

/* The monthly challenge (SMGProgress.challengeHtml), on the home page and the profile. */
.sg-challenge-kicker { color: var(--muted); font-size: var(--text-sm); text-transform: uppercase; letter-spacing: .08em; }
.sg-challenge-head h3 { margin: 4px 0 10px; font-size: 1.25rem; color: var(--text); }
.sg-goals { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.sg-goal { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; color: var(--text); font-size: var(--text-sm); }
.sg-goal strong { color: var(--accent-text); }
.sg-goal-bar { grid-column: 1 / -1; height: 6px; overflow: hidden; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; }
.sg-goal-bar i { display: block; height: 100%; background: var(--action); }
.sg-goal.is-done .sg-goal-bar i { background: #3fb950; }
.sg-challenge-note { margin: 10px 0 0; color: var(--muted); font-size: var(--text-sm); }

/* The dot on the profile button, and the count on the Messages tab, while a message is waiting. */
.sg-profile-chip { position: relative; }
.sg-unread-dot { position: absolute; top: 2px; right: 2px; width: 12px; height: 12px; background: var(--action); border: 2px solid var(--surface-2); border-radius: 50%; }
.profile-unread-badge { margin-left: 8px; padding: 1px 8px; color: #1a1205; font-size: .72rem; font-weight: 800; background: var(--action, #f5a623); border-radius: 999px; }
.profile-unread-badge[hidden] { display: none; }

/* ── The three ways to start a game, the same colors on the game page and the home page cards ── */
.sg-btn-quick, .sg-btn-friend, .sg-btn-setup { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 var(--space-4); font: inherit; font-size: var(--text-sm); font-weight: 800; text-decoration: none; border: 0; border-radius: 999px; cursor: pointer; transition: transform 150ms var(--ease), filter 150ms var(--ease); }
.sg-btn-quick { color: #1a1205; background: #ffb02e; }
.sg-btn-friend { color: #04201c; background: #2dd4bf; }
.sg-btn-setup { color: #fff; background: #6f5cf0; }
.sg-btn-quick:hover, .sg-btn-friend:hover, .sg-btn-setup:hover { filter: brightness(1.08); transform: translateY(-1px); }

/* ── The header on a phone ──
   The Menu and the Theme panels open over the page, under the header, like a sub menu on a computer. They no longer
   push the header taller. The buttons are a little smaller and have room above and below. */
@media (max-width: 900px) {
    .sg-header-inner { position: relative; row-gap: var(--space-2); min-height: 0; padding: var(--space-2) var(--space-3); }
    .sg-brand-mark { width: 32px; height: 32px; }
    .sg-js .sg-menu-button { min-height: 40px; padding: 0 14px; }
    .sg-js .sg-account { flex: 1 1 100%; flex-wrap: nowrap; min-height: 54px; gap: var(--space-2); }
    .sg-js .sg-account .auth-controls { flex-wrap: nowrap; gap: var(--space-2); min-width: 0; }
    .sg-js .sg-account .auth-guest-name { font-size: .85rem; }
    .sg-js .sg-account .ghost-button, .sg-js .sg-account .primary-button { min-height: 38px; padding: 0 12px; font-size: .85rem; white-space: nowrap; }
    .sg-js .sg-account .sg-theme-menu summary { width: 40px; height: 40px; }
    .sg-js .sg-account .sg-profile-chip { min-height: 44px; max-width: calc(100vw - 170px); padding: 4px 12px 4px 6px; }
    .sg-js .sg-account .sg-profile-chip .auth-user-copy { min-width: 0; overflow: hidden; }
    .sg-js .sg-account .sg-profile-chip .auth-user-name { max-width: 100%; overflow: hidden; font-size: .85rem; text-overflow: ellipsis; white-space: nowrap; }
    .sg-js .sg-account .sg-rank-line { display: block; overflow: hidden; font-size: .68rem; text-overflow: ellipsis; white-space: nowrap; }

    .sg-js .sg-nav.is-open {
        position: absolute;
        top: calc(100% - var(--space-1, 4px));
        left: var(--space-3);
        right: var(--space-3);
        z-index: 70;
        padding: var(--space-2);
        max-height: calc(100vh - 180px);
        overflow-y: auto;
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow);
    }

    .sg-js .sg-account .sg-theme-menu { position: static; }
    .sg-js .sg-account .sg-theme-menu .sg-theme-list {
        position: absolute;
        top: calc(100% - var(--space-1, 4px));
        left: var(--space-3);
        right: var(--space-3);
        z-index: 70;
        min-width: 0;
        max-height: calc(100vh - 180px);
        padding: var(--space-4) var(--space-4) 0;
        overflow-y: auto;
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow);
    }
}

/* With larger text chosen the header may need a second row. */
.sg-text-scaled .sg-header-inner { flex-wrap: wrap; row-gap: var(--space-2); }
.sg-text-scaled .sg-nav { flex-wrap: wrap; }

/* The accessibility link in the footer carries a small wheelchair icon, and the picker ends with a help link. */
.sg-footer-icon { width: 1.05em; height: 1.05em; margin-right: 6px; vertical-align: -0.18em; }
.sg-picker-help { margin: var(--space-3) 0 var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--line); font-size: var(--text-sm); }
