/* ---------- Wide refinements ---------- */
@media (max-width: 1320px) {
    .home-scroll {
        padding-left: 32px;
        padding-right: 32px;
    }

    .home-hero {
        padding: 40px;
    }

    .home-hero-copy h1 {
        font-size: 44px;
    }

    .members-panel {
        width: 236px;
    }

    .sidebar {
        width: 264px;
    }
}

@media (max-width: 1140px) {
    .auth-story {
        padding: 34px 38px 28px;
    }

    .auth-story-copy h1 {
        font-size: 45px;
    }

    .home-hero {
        grid-template-columns: 1fr .92fr;
        gap: 18px;
        padding: 36px;
    }

    .home-hero-copy h1 {
        font-size: 40px;
    }

    .home-hero-art {
        transform: scale(.9);
    }

    .members-panel {
        width: 224px;
    }
}

/* ---------- Tablet / compact desktop ---------- */
@media (max-width: 980px) {
    .home-hero {
        grid-template-columns: 1fr;
        min-height: auto;
    }

    .home-hero-copy h1 {
        font-size: 43px;
    }

    .home-hero-art {
        display: none;
    }

    .home-hero::after {
        right: -20%;
    }

    .home-values {
        grid-template-columns: 1fr 1fr;
    }

    .value-card:last-child {
        grid-column: 1 / -1;
    }

    .chat-header-topic {
        max-width: 30vw;
    }

    .members-panel {
        width: 216px;
    }

    .member-copy small {
        max-width: 120px;
    }
}

@media (max-width: 840px) {
    .server-rail {
        width: 68px;
    }

    .rail-button {
        width: 46px;
        height: 46px;
    }

    .rail-active-indicator,
    .rail-server .rail-unread {
        left: -11px;
    }

    .sidebar {
        position: fixed;
        left: 68px;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: 60;
        transform: translateX(calc(-100% - 80px));
        transition: transform .24s cubic-bezier(.2, .8, .2, 1);
        box-shadow: 18px 0 50px rgba(0, 0, 0, .35);
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    .sidebar-close {
        display: grid;
    }

    .mobile-scrim {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 55;
        background: rgba(4, 5, 9, .62);
        backdrop-filter: blur(3px);
        opacity: 0;
        visibility: hidden;
        transition: opacity .22s ease, visibility .22s;
    }

    .mobile-scrim.is-visible {
        opacity: 1;
        visibility: visible;
    }

    .mobile-only {
        display: grid !important;
    }

    .chat-header {
        padding-left: 14px;
    }

    .home-header {
        padding-left: 16px;
    }

    #home-mobile-nav {
        display: none !important;
    }

    .members-panel {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        z-index: 65;
        width: min(300px, 84vw);
        box-shadow: -18px 0 50px rgba(0, 0, 0, .38);
        transform: translateX(102%);
        transition: transform .24s cubic-bezier(.2, .8, .2, 1);
    }

    .members-panel.is-open {
        transform: translateX(0);
    }

    .members-close {
        display: grid;
    }

    .members-panel .presence-dot {
        border-color: #161822;
    }

    .home-scroll {
        padding: 26px 24px 40px;
    }

    .home-hero {
        padding: 34px;
    }

    .home-hero-copy h1 {
        font-size: 39px;
    }

    .message-scroll {
        scrollbar-gutter: auto;
    }

    .channel-hero {
        padding: 34px 26px 20px;
    }

    .message {
        grid-template-columns: 44px minmax(0, 1fr);
        padding-left: 4px;
        padding-right: 12px;
    }

    .message-list {
        padding: 0 8px;
    }

    .composer {
        padding-left: 16px;
        padding-right: 16px;
    }

    .composer-meta {
        display: none;
    }

    .chat-header-topic {
        max-width: 24vw;
    }

    .auth-shell {
        grid-template-columns: .95fr 1.05fr;
    }

    .auth-story {
        padding: 30px 30px 24px;
    }

    .auth-story-copy h1 {
        font-size: 39px;
    }

    .auth-story-lede {
        font-size: 13px;
    }

    .auth-chat-visual {
        margin-top: 22px;
    }

    .auth-panel-inner {
        width: min(370px, calc(100% - 52px));
    }
}

/* ---------- Small tablet ---------- */
@media (max-width: 740px) {
    .auth-view {
        padding: 18px;
    }

    .auth-shell {
        display: block;
        height: auto;
        min-height: 0;
        max-height: none;
        width: 100%;
        max-width: 500px;
        border-radius: 24px;
    }

    .auth-story {
        display: none;
    }

    .auth-panel {
        min-height: 0;
    }

    .auth-panel-inner {
        width: min(400px, calc(100% - 48px));
        padding: 31px 0 34px;
    }

    .auth-mobile-brand {
        display: flex;
        align-items: center;
        gap: 9px;
        margin-bottom: 26px;
        font-size: 17px;
        font-weight: 730;
        letter-spacing: -.035em;
    }

    .auth-mobile-brand .brand-mark {
        width: 34px;
        height: 34px;
        border-radius: 10px;
    }

    .auth-mobile-brand .brand-mark svg {
        width: 23px;
        height: 23px;
    }

    .auth-footer {
        padding-bottom: 4px;
    }

    .home-values {
        grid-template-columns: 1fr;
    }

    .value-card:last-child {
        grid-column: auto;
    }

    .home-hero {
        padding: 28px 26px;
        border-radius: 22px;
    }

    .home-hero-copy h1 {
        font-size: 36px;
    }

    .home-hero-copy > p {
        font-size: 13px;
    }

    .home-cta-row .button {
        flex: 1;
        min-width: 150px;
    }

    .server-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .server-card {
        min-height: 150px;
    }

    .chat-header-topic {
        display: none;
    }

    .chat-header-actions .icon-button {
        width: 34px;
        height: 34px;
    }

    .channel-hero {
        padding: 27px 22px 18px;
    }

    .channel-hero-icon {
        width: 54px;
        height: 54px;
        border-radius: 16px;
    }

    .channel-hero-icon .icon {
        width: 25px;
        height: 25px;
    }

    .channel-hero h1 {
        font-size: 23px;
    }

    .channel-hero p {
        font-size: 12px;
    }

    .message-content {
        font-size: 13px;
    }

    .message-author {
        font-size: 13px;
    }

    .date-divider {
        margin-left: 17px;
        margin-right: 17px;
    }

    .typing-indicator {
        padding-left: 22px;
    }

    .composer {
        padding: 0 12px 12px;
    }

    .composer-shell {
        min-height: 47px;
    }

    .message-toolbar {
        right: 8px;
    }

    .modal-root {
        padding: 0;
        align-items: end;
    }

    .modal-card,
    .modal-card--sm,
    .modal-card--lg,
    .modal-card--xl {
        width: 100%;
        max-height: 91dvh;
        border-radius: 22px 22px 0 0;
        border-bottom: 0;
        transform: translateY(28px);
    }

    .modal-root.is-open .modal-card {
        transform: translateY(0);
    }

    .modal-header {
        padding: 24px 22px 5px;
    }

    .modal-body {
        padding: 18px 22px 26px;
    }

    .modal-footer {
        padding: 16px 22px calc(20px + env(safe-area-inset-bottom));
    }

    .modal-close {
        top: 14px;
        right: 14px;
    }

    .modal-card::before {
        content: "";
        display: block;
        width: 35px;
        height: 4px;
        border-radius: 99px;
        background: rgba(255, 255, 255, .12);
        margin: 8px auto 0;
    }

    .toast-region {
        right: 12px;
        bottom: 12px;
        left: 12px;
        align-items: stretch;
        max-width: none;
    }

    .toast {
        width: 100%;
    }
}

/* ---------- Role manager ---------- */
@media (max-width: 860px) {
    .role-manager {
        grid-template-columns: 1fr;
        height: auto;
        min-height: 0;
    }

    .role-list-pane {
        padding-right: 0;
        padding-bottom: 14px;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .role-list {
        flex: none;
        max-height: 220px;
    }

    .role-order-hint {
        margin-top: 9px;
        padding-top: 9px;
    }

    .role-editor-pane {
        overflow: visible;
        padding-right: 0;
        padding-top: 4px;
    }

    .role-editor-empty {
        min-height: 210px;
    }
}

@media (max-width: 700px) {
    .role-editor-fields {
        grid-template-columns: 1fr;
    }

    .permission-grid {
        grid-template-columns: 1fr;
    }

    .role-editor-actions,
    .role-delete-confirm {
        align-items: stretch;
        flex-direction: column;
    }

    .role-delete-confirm > div {
        justify-content: flex-end;
    }
}

/* ---------- Phones ---------- */
@media (max-width: 600px) {
    .server-rail {
        width: 62px;
        padding-top: 10px;
        gap: 8px;
    }

    .rail-button {
        width: 43px;
        height: 43px;
        border-radius: 14px;
    }

    .rail-add {
        border-radius: 50%;
    }

    .rail-home-mark {
        width: 28px;
        height: 28px;
    }

    .rail-divider {
        width: 28px;
    }

    .rail-active-indicator,
    .rail-server .rail-unread {
        left: -9px;
    }

    .rail-user-button {
        width: 34px;
        height: 34px;
    }

    .rail-user-button .avatar {
        width: 32px;
        height: 32px;
        font-size: 9px;
    }

    .sidebar {
        left: 62px;
        width: min(286px, calc(100vw - 62px));
    }

    .chat-header {
        height: 57px;
        gap: 8px;
        padding: 0 10px;
    }

    .home-header {
        height: 57px;
    }

    .chat-header-title {
        gap: 6px;
    }

    .chat-header-title h2 {
        font-size: 14px;
    }

    .header-hash .icon {
        width: 18px;
        height: 18px;
    }

    .chat-header-actions .icon-button {
        width: 32px;
        height: 32px;
    }

    .home-scroll {
        padding: 18px 14px 34px;
    }

    .home-hero {
        padding: 26px 21px;
        border-radius: 20px;
    }

    .home-hero-copy h1 {
        margin-top: 13px;
        font-size: 33px;
        letter-spacing: -.05em;
    }

    .home-hero-copy > p {
        margin-top: 13px;
        font-size: 12.5px;
    }

    .home-cta-row {
        flex-direction: column;
        align-items: stretch;
        margin-top: 20px;
    }

    .home-cta-row .button {
        width: 100%;
        flex: none;
    }

    .home-proof {
        margin-top: 18px;
        font-size: 9.5px;
    }

    .home-section {
        margin-top: 29px;
    }

    .section-title-row h2 {
        font-size: 20px;
    }

    .server-grid {
        grid-template-columns: 1fr;
    }

    .server-card {
        min-height: 133px;
        padding: 15px;
    }

    .server-card-body {
        margin-top: 11px;
    }

    .server-card-footer {
        padding-top: 9px;
    }

    .home-values {
        margin-top: 26px;
    }

    .home-footer {
        flex-direction: column;
        text-align: center;
        gap: 6px;
        line-height: 1.5;
        padding-top: 28px;
    }

    .channel-hero {
        padding: 24px 18px 15px;
    }

    .channel-hero-icon {
        width: 48px;
        height: 48px;
        border-radius: 14px;
    }

    .channel-hero-icon .icon {
        width: 22px;
        height: 22px;
    }

    .channel-hero h1 {
        margin-top: 13px;
        font-size: 21px;
    }

    .channel-hero p {
        font-size: 11.5px;
    }

    .welcome-pill {
        display: none;
    }

    .message-list {
        padding: 0 4px;
    }

    .message {
        grid-template-columns: 40px minmax(0, 1fr);
        padding: 4px 8px 4px 2px;
    }

    .message-avatar-slot .avatar {
        width: 36px;
        height: 36px;
        font-size: 9.5px;
    }

    .message-header {
        gap: 5px;
    }

    .message-author {
        font-size: 12.5px;
    }

    .message-time {
        font-size: 8.5px;
    }

    .message-content {
        font-size: 12.5px;
        line-height: 1.48;
    }


    .message-reply-ref {
        max-width: 100%;
    }

    .message-reactions {
        margin-top: 5px;
    }

    .date-divider {
        margin: 14px 12px 9px;
    }

    .typing-indicator {
        min-height: 18px;
        padding-left: 16px;
        font-size: 8.5px;
    }

    .composer {
        padding: 0 8px calc(8px + env(safe-area-inset-bottom));
    }

    .composer-shell {
        border-radius: 12px;
        min-height: 46px;
        padding: 5px;
    }

    .composer-emoji {
        width: 32px;
        height: 32px;
    }

    .composer-send {
        width: 34px;
        height: 34px;
    }

    .composer-input {
        padding-top: 7px;
        padding-bottom: 6px;
        font-size: 13px;
    }

    .reply-banner {
        padding: 7px 8px;
    }

    .members-panel {
        width: min(310px, 88vw);
    }

    .members-header {
        min-height: 69px;
        padding-top: 11px;
    }

    .auth-view {
        padding: 12px;
    }

    .auth-shell {
        border-radius: 21px;
    }

    .auth-panel-inner {
        width: calc(100% - 34px);
        padding: 26px 0 30px;
    }

    .auth-heading {
        margin: 21px 0 18px;
    }

    .auth-heading h2 {
        font-size: 25px;
    }

    .auth-heading p {
        font-size: 12px;
    }

    .auth-form {
        gap: 12px;
    }

    .field-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .input-wrap {
        height: 46px;
    }

    .auth-switch {
        margin-top: 18px;
    }

    .auth-fineprint {
        margin-top: 17px;
        padding-top: 15px;
    }

    .auth-footer {
        font-size: 9px;
        text-align: center;
        line-height: 1.5;
        margin-top: 12px;
    }

    .modal-header {
        padding-left: 18px;
        padding-right: 52px;
    }

    .modal-body {
        padding-left: 18px;
        padding-right: 18px;
    }

    .modal-footer {
        padding-left: 18px;
        padding-right: 18px;
    }

    .account-meta {
        grid-template-columns: 1fr;
    }

    .danger-zone-row {
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
    }

    .danger-zone-row .button {
        width: 100%;
    }

    .quick-switch-list {
        max-height: 48vh;
    }

    .profile-main {
        padding-left: 15px;
        padding-right: 15px;
    }

    .emoji-popover-panel {
        max-width: calc(100vw - 20px) !important;
    }
}

@media (max-width: 420px) {
    .server-rail {
        width: 58px;
    }

    .rail-button {
        width: 41px;
        height: 41px;
    }

    .sidebar {
        left: 58px;
        width: calc(100vw - 58px);
    }

    .rail-active-indicator {
        left: -7px;
    }

    .rail-server .rail-unread {
        left: -9px;
    }

    .chat-header {
        padding-left: 7px;
    }

    .chat-header-actions {
        gap: 0;
    }

    .home-header {
        padding-left: 12px;
        padding-right: 12px;
    }

    .home-hero-copy h1 {
        font-size: 30px;
    }

    .home-hero-copy .eyebrow {
        font-size: 9px;
    }

    .message-toolbar button:nth-last-child(1) {
        display: none;
    }

    .auth-panel-inner {
        width: calc(100% - 28px);
    }

    .auth-tabs {
        width: 100%;
    }

    .auth-tab {
        flex: 1;
    }
}

/* ---------- Accessibility / motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}

@media (pointer: coarse) {
    [data-tooltip]::after,
    [data-tooltip]::before {
        display: none !important;
    }

    .message:hover {
        background: transparent;
    }

    .message-toolbar {
        display: none !important;
    }
}

@media (max-width: 700px) {
    .message-toolbar {
        display: none;
    }
}

@media (max-width: 840px) {
    .channel-category-settings,
    .channel-section .icon-button {
        opacity: 1;
        pointer-events: auto;
    }
}
