*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root,
[data-theme="light"] {
    --bg: #f4f1ec;
    --bg-panel: rgba(255, 255, 255, 0.85);
    --nav-bg: rgba(255, 253, 250, 0.92);
    --ink: #1a1d22;
    --ink-muted: #595f68;
    --ink-dim: #9299a2;
    --accent: #164f75;
    --link: #0f527d;
    --link-underline: rgba(15, 82, 125, 0.5);
    --strong: #111820;
    --border: rgba(26, 29, 34, 0.1);
    --danger: #a03030;
    --danger-soft: rgba(160, 48, 48, 0.08);
    --danger-text: #a03030;
    --own-bubble: #2c5a7a;
    --own-bubble-ink: #f4f1ec;
    --peer-bubble: rgba(26, 29, 34, 0.06);
    --peer-bubble-ink: #1a1d22;
    --user-bubble: #2c5a7a;
    --user-bubble-ink: #f4f1ec;
    --input-bg: rgba(26, 29, 34, 0.04);
    --surface-hover: rgba(26, 29, 34, 0.04);
    --status-waiting-bg: rgba(180, 130, 20, 0.1);
    --status-waiting-ink: #8a6a10;
    --status-active-bg: rgba(44, 90, 122, 0.1);
    --status-active-ink: #2c5a7a;
    --status-closed-bg: rgba(146, 153, 162, 0.1);
    --status-closed-ink: #9299a2;
}

[data-theme="macchiato"] {
    --bg: #181926;
    --bg-panel: #24273a;
    --nav-bg: rgba(36, 39, 58, 0.65);
    --ink: #cad3f5;
    --ink-muted: #a5adcb;
    --ink-dim: #8087a2;
    --accent: #8aadf4;
    --link: #8aadf4;
    --link-underline: rgba(138, 173, 244, 0.5);
    --strong: #c6d0f5;
    --border: rgba(165, 173, 203, 0.15);
    --danger: #ed8796;
    --danger-soft: rgba(237, 135, 150, 0.16);
    --danger-text: #f5c0cf;
    --own-bubble: #8aadf4;
    --own-bubble-ink: #181926;
    --peer-bubble: rgba(138, 173, 244, 0.08);
    --peer-bubble-ink: #cad3f5;
    --user-bubble: #8aadf4;
    --user-bubble-ink: #181926;
    --input-bg: rgba(138, 173, 244, 0.04);
    --surface-hover: rgba(138, 173, 244, 0.06);
    --status-waiting-bg: rgba(238, 153, 160, 0.15);
    --status-waiting-ink: #eed49a;
    --status-active-bg: rgba(138, 173, 244, 0.12);
    --status-active-ink: #8aadf4;
    --status-closed-bg: rgba(165, 173, 203, 0.1);
    --status-closed-ink: #8087a2;
}

html { scroll-behavior: smooth; }

body {
    background: var(--bg);
    color: var(--ink);
    font-family: 'Noto Sans', sans-serif;
    font-size: 0.98rem;
    font-weight: 300;
    line-height: 1.65;
    transition: background 0.3s ease, color 0.3s ease;
}

button, input { font: inherit; }

a {
    color: var(--link);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: all 0.2s ease;
}
a:hover { border-bottom-color: var(--link-underline); }

strong, b {
    color: var(--strong);
    font-weight: 700;
}

/* ---- Nav (shared across all pages) ---- */
nav {
    position: fixed; top: 0; left: 0;
    width: 100%; z-index: 20;
    display: grid;
    grid-template-columns: auto 1fr auto; /* Left: Auto, Center: Grow, Right: Auto */
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 2.5rem;
    background: var(--nav-bg);
    backdrop-filter: blur(12px) saturate(120%);
    -webkit-backdrop-filter: blur(12px) saturate(120%);
    border-bottom: 1px solid var(--border);
    transition: background 0.3s ease;
}

.back-link {
    grid-column: 1;
    justify-self: start;
    font-family: 'Noto Sans', sans-serif;
    font-weight: 400;
    font-size: 0.7rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    white-space: nowrap;
    color: var(--ink-muted);
    text-decoration: none;
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 2px;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.back-link:hover {
    color: var(--ink);
    border-color: var(--ink-muted);
    background: var(--bg-panel);
}

.nav-brand {
    grid-column: 2;
    justify-self: center;
    display: inline-flex;
    align-items: baseline;
    gap: 0.35rem;
    white-space: nowrap;
    font-family: 'Noto Sans', sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
    color: var(--ink);
    text-decoration: none;
}
.nav-brand:hover { color: var(--accent); border-bottom: none; }

.nav-timer {
    grid-column: 3;
    justify-self: end;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--danger-text);
    border: 1px solid var(--danger);
    border-radius: 2px;
    padding: 0.3rem 0.7rem;
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    background: var(--danger-soft);
    white-space: nowrap;
}

.brand-sep {
    font-weight: 300;
    color: var(--ink-dim);
}
.brand-sub {
    font-weight: 400;
    font-size: 0.78rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-muted);
    align-self: center;
    padding-top: 2px;
}

[data-theme="macchiato"] .nav-brand {
    color: #cad3f5;
    text-shadow: 0 0 8px rgba(138, 173, 244, 0.25);
}

/* ---- Footer (shared across all pages) ---- */
footer {
    position: relative;
    z-index: 10;
    padding: 0.9rem 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    font-family: 'Noto Sans', sans-serif;
    font-weight: 300;
    font-size: 0.72rem;
    letter-spacing: 0.05em;
    color: var(--ink-muted);
    border-top: 1px solid var(--border);
    background: var(--nav-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: background 0.3s ease;
}

.footer-icon {
    color: var(--ink-muted);
    text-decoration: none;
    transition: all 0.25s ease;
    display: flex;
    align-items: center;
    border-bottom: none;
}
.footer-icon:hover {
    color: var(--accent);
    border-bottom: none;
}

/* ---- Theme toggle ---- */
.theme-toggle {
    position: fixed;
    bottom: 4rem;
    right: 1.5rem;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid var(--border);
    cursor: pointer;
    padding: 0;
    z-index: 30;
    transition: all 0.3s ease;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}
.theme-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
[data-theme="light"] .theme-toggle {
    background: linear-gradient(135deg, #24273a 0%, #8aadf4 100%);
    border-color: rgba(26, 29, 34, 0.2);
}
[data-theme="macchiato"] .theme-toggle {
    background: #24273a;
    border-color: rgba(138, 173, 244, 0.4);
    box-shadow:
        0 0 10px rgba(138, 173, 244, 0.4),
        0 0 25px rgba(138, 173, 244, 0.2),
        0 0 50px rgba(116, 150, 230, 0.15);
    animation: neon-breathe-toggle 4s ease-in-out infinite;
}

[data-theme="macchiato"] .theme-toggle:hover {
    box-shadow:
        0 0 15px rgba(138, 173, 244, 0.6),
        0 0 35px rgba(138, 173, 244, 0.35),
        0 0 70px rgba(116, 150, 230, 0.25);
}

@keyframes neon-breathe-toggle {
    0%, 100% {
        box-shadow:
            0 0 10px rgba(138, 173, 244, 0.5),
            0 0 25px rgba(138, 173, 244, 0.3),
            0 0 50px rgba(116, 150, 230, 0.2);
    }
    50% {
        box-shadow:
            0 0 15px rgba(138, 173, 244, 0.6),
            0 0 35px rgba(138, 173, 244, 0.4),
            0 0 70px rgba(116, 150, 230, 0.25);
    }
}

/* ---- Animations ---- */
@keyframes panel-in {
    0%   { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* ---- Responsive nav ---- */
@media (max-width: 640px) {
    nav {
        gap: 0.5rem;
        padding: 0.85rem 0.85rem;
    }
    .back-link { font-size: 0.58rem; padding: 0.25rem 0.4rem; letter-spacing: 0.08em; }
    .nav-brand { font-size: 0.9rem; }
    .brand-sub { font-size: 0.6rem; letter-spacing: 0.1em; }
    footer { font-size: 0.65rem; padding: 0.7rem 1rem; }
    .theme-toggle { width: 20px; height: 20px; bottom: 3rem; right: 0.9rem; }
}
