.shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.shell__content {
    flex: 1 1 auto;
    width: 100%;
}

/* ------------------------------------------------------------------ top bar */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--topbar-height);
    padding: 0 18px;
    border-bottom: 1px solid var(--border);
    background-color: var(--bg-elevated);
}

.topbar__identity {
    display: flex;
    align-items: baseline;
    gap: 10px;
    min-width: 0;
    flex: 1 1 auto;
}

.topbar__app {
    min-width: 0;
    overflow: hidden;
    color: var(--text);
    font-size: 1.05rem;
    font-weight: 700;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar__separator {
    align-self: center;
    flex: 0 0 auto;
    width: 1px;
    height: 20px;
    background-color: var(--border-strong);
}

.topbar__screen {
    min-width: 0;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar__actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex: 0 0 auto;
}

.topbar__player {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 220px;
    min-width: 0;
    padding: 3px 10px 3px 4px;
    border-radius: 999px;
    background-color: var(--bg-sunken);
    color: inherit;
    text-decoration: none;
}

.topbar__nick {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.topbar__link {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.topbar__link-icon {
    display: block;
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
}

.topbar__link--active {
    color: var(--accent);
    box-shadow: inset 0 -2px 0 var(--accent);
}

.topbar__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background-color: transparent;
    color: var(--text);
    font: inherit;
    line-height: 1;
    cursor: pointer;
}

.topbar__icon svg {
    display: block;
    width: 18px;
    height: 18px;
}

.topbar__menu {
    position: relative;
}

.topbar__menu > summary {
    list-style: none;
}

.topbar__menu > summary::-webkit-details-marker {
    display: none;
}

.topbar__menu-list {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 170px;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background-color: var(--bg-elevated);
    box-shadow: var(--shadow);
}

.topbar__menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: var(--radius-sm);
    background-color: transparent;
    color: var(--text);
    font: inherit;
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
}

.topbar__menu-check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    color: var(--accent);
}

.topbar__menu-check svg {
    display: block;
    width: 14px;
    height: 14px;
}

.topbar__menu-item[aria-current="true"] {
    color: var(--accent);
    font-weight: 600;
}

.topbar__logout {
    display: inline-flex;
    margin: 0;
}

.topbar__app:hover,
.topbar__link:hover,
.topbar__link--active:hover {
    color: var(--accent);
}

.topbar__player:hover,
.topbar__link:hover,
.topbar__icon:hover,
.topbar__menu-item:hover {
    background-color: var(--bg-hover);
}

@media (prefers-reduced-motion: no-preference) {
    .topbar__app,
    .topbar__player,
    .topbar__link,
    .topbar__icon,
    .topbar__menu-item {
        transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
    }

    .topbar__menu[open] .topbar__menu-list {
        animation: topbar-menu-in 0.14s ease-out;
    }
}

@keyframes topbar-menu-in {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .topbar__menu[open] .topbar__menu-list {
        animation: none;
    }
}

/* ------------------------------------------------------------- session gate */

.session-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    max-width: 520px;
    margin: 80px auto;
    padding: 28px;
    text-align: center;
}

.session-block__title {
    font-size: 1.35rem;
}

.session-block__text {
    color: var(--text-muted);
}

/* ---------------------------------------------------- anonymous sign-in CTA */

.signin-cta {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    max-width: 520px;
    margin: 72px auto;
    padding: 28px;
    text-align: center;
}

.signin-cta__title {
    font-size: 1.35rem;
}

.signin-cta__text {
    color: var(--text-muted);
}

.signin-cta__agents {
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.7;
}

/* --------------------------------------------------------- agent landing page */

.agents-page {
    display: flex;
    flex-direction: column;
    gap: 18px;
    max-width: 880px;
    margin: 24px auto 64px;
}

.agents-page__head,
.agents-page__section {
    padding: 22px 26px;
}

.agents-page__title {
    margin-bottom: 10px;
    font-size: 1.5rem;
}

.agents-page__lead {
    line-height: 1.65;
}

.agents-page__note,
.agents-page__text {
    margin-top: 8px;
    color: var(--text-muted);
    line-height: 1.65;
}

.agents-page__heading {
    margin-bottom: 8px;
    font-size: 1.1rem;
}

.agents-page__caption {
    margin: 16px 0 6px;
    font-weight: 600;
}

.agents-page__code {
    margin: 0;
    padding: 12px 14px;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-sunken);
    font-size: 0.85rem;
    line-height: 1.5;
}

.agents-page__links {
    margin: 8px 0 0;
    padding-left: 20px;
    line-height: 1.9;
}

.shell__auth-notice {
    max-width: var(--content-max);
    margin: 14px auto 0;
}

/* ----------------------------------------------------------- rooms browser */

.rooms {
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 20px 18px 48px;
}

.rooms__header {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px 16px;
    padding: 18px;
}

.rooms__heading {
    min-width: 0;
}

.rooms__title {
    font-size: 1.5rem;
}

.rooms__subtitle {
    margin-top: 4px;
    color: var(--text-muted);
}

.rooms__toolbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.rooms__list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 16px;
}

.rooms__state {
    padding: 32px 0;
    color: var(--text-muted);
    text-align: center;
}

.rooms__empty {
    padding: 48px 16px;
    text-align: center;
}

.rooms__empty-title {
    font-size: 1.15rem;
    font-weight: 700;
}

.rooms__empty-hint {
    margin-top: 6px;
    color: var(--text-muted);
}

/* ------------------------------------------------------------------ room row */

.room-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background-color: var(--bg-elevated);
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.12s ease, border-color 0.12s ease, transform 0.12s ease;
}

.room-row:hover:not(:disabled) {
    background-color: var(--bg-hover);
    border-color: var(--border-strong);
}

.room-row:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.room-row__main {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.room-row__name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1.02rem;
    font-weight: 700;
}

.room-row__leader {
    color: var(--text-muted);
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.room-row__leader::before {
    content: "·";
    margin-right: 8px;
}

.room-row__meta {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.room-row__action {
    min-width: 84px;
    color: var(--accent);
    font-weight: 700;
    text-align: right;
}

/* ---------------------------------------------------------------- not found */

.not-found {
    max-width: 520px;
    margin: 80px auto;
    padding: 0 18px;
    text-align: center;
}

.not-found__title {
    font-size: 1.5rem;
}

.not-found__text {
    margin: 8px 0 18px;
    color: var(--text-muted);
}

/* --------------------------------------------------------------- responsive */

/*
    The bar always stays a single row: the identity shrinks (its text truncates) while the controls keep
    their size. At 720px the screen name and nickname go away and the history link collapses to its clock
    icon; at 480px the paddings, gaps and icon buttons shrink further, so the full control set (logo,
    profile, history, theme, language, logout) still fits one line at 360px and 320px.
*/
@media (max-width: 720px) {
    .topbar {
        padding: 0 10px;
        gap: 8px;
    }

    .topbar__screen,
    .topbar__separator,
    .topbar__nick,
    .topbar__link-text {
        display: none;
    }

    .topbar__player {
        padding: 3px;
    }

    .topbar__link {
        justify-content: center;
        gap: 0;
        width: 34px;
        padding: 0;
    }

    .rooms {
        padding: 14px 10px 40px;
    }

    .rooms__toolbar {
        flex-wrap: wrap;
    }

    .room-row {
        grid-template-columns: minmax(0, 1fr);
        gap: 6px;
    }

    .room-row__meta {
        flex-wrap: wrap;
    }

    .room-row__action {
        min-width: 0;
        text-align: left;
    }
}

@media (max-width: 480px) {
    .topbar {
        padding: 0 6px;
        gap: 6px;
    }

    .topbar__actions {
        gap: 4px;
    }

    .topbar__app {
        font-size: 0.95rem;
    }

    .topbar__link,
    .topbar__icon {
        width: 30px;
        height: 30px;
        min-height: 30px;
    }

    .topbar__player {
        padding: 2px;
    }

    .topbar__menu-list {
        min-width: 150px;
    }
}
