@layer states {

  .reaction-button:hover,
  .reaction-button:focus-visible {
    transform: translateY(-1px);
    border-color: var(--color-accent);
    box-shadow: 0 6px 16px var(--shadow-accent-alt);
    outline: none;
  }
}

@layer components {
  .icon-inline {
    width: 1.25em;
    height: 1.25em;
    display: inline-block;
    vertical-align: middle;
    fill: currentcolor;
    pointer-events: none;
  }

  /* Optimization: Pre-reserve space for iconify-icon to prevent CLS and massive reflows */
  iconify-icon {
    display: inline-block;
    width: 1em;
    height: 1em;
    line-height: 1;
    flex: 0 0 auto;
    vertical-align: -0.125em;
    /* Matches Iconify's default optical alignment */
  }

  :where(.home-empty,
    .hero-points,
    .field.checkbox,
    .invite-link,
    .chat-log,
    .chat-log-list,
    .share-inline) {
    display: flex;
    /* Ensure these are flex/grid items for gap to work */
    gap: var(--size-2);
  }

  .chat-bubble {
    /* No gap needed, display is block */
  }

  :where(.flash, .chat-entry, .connection-banner, .system-share) {
    padding: var(--size-2);
  }

  .home-empty {
    text-align: center;
    display: flex;
    flex-direction: column;
    padding: var(--size-4);
    max-width: 26.25rem;
    /* 420px */
  }

  .home-empty .icon-inline {
    color: var(--color-accent);
  }

  .hero-points {
    list-style: none;
    padding: 0;
    margin: var(--size-4) 0 0;
    display: grid;
  }

  .hero-points li::before {
    content: "•";
    color: var(--color-accent);
    margin-right: var(--size-2);
  }

  .icon-btn {
    width: 2.75rem;
    /* 44px */
    height: 2.75rem;
    /* 44px */
    border-radius: 1rem;
    /* 16px */
    border: var(--border-width) solid transparent;
    background: var(--veil-2);
    color: var(--color-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    text-decoration: none;
    transition:
      background 0.2s var(--motion-snappy),
      border-color 0.2s var(--motion-snappy);
  }

  .icon-btn:hover {
    background: var(--veil-8);
    border-color: var(--veil-15);
  }

  .icon-btn.is-active {
    background: var(--accent-veil-15);
    color: var(--color-accent);
    border-color: var(--accent-veil-35);
  }

  .icon-btn:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
    background: var(--accent-veil-35);
  }

  /* ===== Chat Composer Component ===== */
  .composer-bar {
    width: 100%;
    margin: 0;
    margin-bottom: var(--size-2);
  }

  .chat-composer {
    width: 100%;
    border: var(--border-width) solid var(--border);
    border-radius: var(--radius-panel);
    background: var(--bg-surface-alt);
    padding: 0.5rem;
    margin-top: auto;
    position: relative;
  }

  .chat-composer__sender {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    padding-left: 0.5rem;
  }

  .chat-composer__row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
  }

  .chat-composer__actions {
    display: flex;
    gap: 0.25rem;
    padding-bottom: 0.25rem;
  }

  .chat-composer__action-btn {
    width: 1.75rem;
    /* 28px */
    height: 1.75rem;
    /* 28px */
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .chat-composer__action-btn:hover {
    color: var(--primary);
  }

  .chat-composer__action-btn iconify-icon {
    font-size: 1.1rem;
  }

  .chat-composer__textarea {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0.5rem;
    resize: none;
    font-size: 1rem;
    line-height: 1.4;
    outline: none;
    color: var(--text-main);
    min-height: 3.5rem;
    /* ~2 lines */
    max-height: 12rem;
    /* ~6-7 lines */
  }

  .chat-composer__textarea::placeholder {
    color: var(--text-muted);
  }

  .chat-composer__send {
    width: 2rem;
    /* 32px */
    height: 2rem;
    /* 32px */
    border: none;
    background: var(--primary);
    color: var(--on-primary);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-bottom: 0.25rem;
    transition: background 0.2s ease;
  }

  .chat-composer__send:hover {
    background: var(--primary-hover);
  }

  .chat-composer__send iconify-icon {
    font-size: 1rem;
  }

  fieldset {
    border: none;
    margin: 0;
    padding: 0 0 var(--size-3);
  }

  legend {
    font-weight: 600;
    margin-bottom: var(--size-2);
  }

  .field {
    display: flex;
    flex-direction: column;
    gap: var(--size-1);
    margin-bottom: var(--size-3);
    font-size: 0.95rem;
  }

  .field input,
  .field select {
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    border: var(--border-width) solid var(--border);
    background: var(--bg-surface-alt);
    color: var(--color-text);
  }

  /* Room composer input (keeps layout tight and consistent) */
  .chat-input {
    height: 2.75rem; /* 44px */
    padding: 0.6rem 0.9rem;
    border-radius: var(--radius-sm);
    border: var(--border-width) solid var(--border);
    background: var(--bg-surface);
    color: var(--color-text);
    width: 100%;
    min-width: 0;
  }

  .chat-input:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
  }

  .field.checkbox {
    flex-direction: row;
    align-items: center;
  }

  .cta {
    width: 100%;
    padding: 0.95rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--color-accent);
    color: var(--color-on-accent, #fff);
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 12px 24px var(--accent-veil-35);
    transition: box-shadow 0.2s var(--motion-snappy);
  }

  .cta:hover {
    background: var(--color-accent-alt);
    color: var(--color-on-accent);
    transform: translateY(-2px);
    box-shadow: 0 16px 32px var(--shadow-accent-alt);
  }

  .ghost {
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    border: 2px solid var(--veil-8);
    background: var(--veil-2);
    color: var(--color-text);
    cursor: pointer;
    transition:
      background 0.2s var(--motion-snappy),
      border-color 0.2s var(--motion-snappy);
  }

  .ghost:hover {
    background: var(--veil-8);
    border-color: var(--veil-30);
  }

  .invite-result {
    margin-top: var(--size-3);
    padding: var(--size-3);
    border-radius: var(--radius-sm);
    background: var(--bg-overlay-60);
    border: 1px dashed var(--muted-border-40);
    min-height: 80px;
  }

  .invite-result.success {
    border-color: var(--accent-alt-veil-35);
  }

  .invite-result.error {
    border-color: var(--accent-veil-35);
    color: var(--color-accent-alt);
  }

  .invite-link {
    display: flex;
    margin-top: var(--size-2);
  }

  .invite-link input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface-alt);
    color: var(--color-text);
    font-family: var(--font-mono);
  }

  .voice-test .controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--size-3);
  }

  .voice-test .actions {
    display: flex;
    gap: var(--size-3);
    margin-top: var(--size-3);
  }

  .voice-test .field select {
    min-height: 2.5rem;
  }

  .voice-test .monitor {
    min-height: 2.75rem;
  }

  .voice-test .status {
    min-height: 1.25rem;
  }

  .monitor {
    width: 100%;
    margin-top: var(--size-3);
  }

  .level-meter {
    width: 100%;
    height: 12px;
    border-radius: 999px;
    background: var(--veil-8);
    border: 1px solid var(--veil-12);
    overflow: hidden;
    margin-top: var(--size-3);
  }

  .level-meter__bar {
    height: 100%;
    background: linear-gradient(90deg, var(--teal-4), var(--pink-5));
    transition: width 0.15s var(--motion-snappy);
  }

  .level-meter__status {
    margin-top: 0.35rem;
    font-size: 0.9rem;
    color: var(--color-muted);
  }

  .status {
    margin-top: var(--size-2);
    color: var(--color-muted);
  }

  .flash {
    border-radius: var(--radius-sm);
    margin-top: var(--size-2);
  }

  .flash-error {
    background: var(--red-0);
    border: 1px solid var(--red-3);
    color: var(--red-9);
  }

  .chat-body {
    margin-top: var(--size-1);
    font-size: 1rem;
  }

  .chat-empty {
    text-align: center;
    color: var(--color-muted);
  }

  /* Chat layout */

  /* Chat layout */
  .room-shell {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;

    /* Keep content inside app-main so it doesn't slide under the sidebar on mobile. */
    overflow: visible;
    gap: 0;
    padding: 0;
  }

  .room-shell.media-focus .app-sidebar {
    display: none;
  }

  .room-shell.media-focus .chat-log {
    padding: var(--size-4);
  }

  .room-shell.media-focus .user-id-card {
    display: none;
  }

  @media (width <=640px) {
    .room-shell.media-focus .composer-bar {
      display: none;
    }
  }



  /* APP-SIDEBAR OVERRIDES - These must stay but should be in a layer */
  /* APP-SIDEBAR OVERRIDES - These must stay but should be in a layer */

  .chat-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    border: 1px solid var(--veil-4);
    border-radius: var(--radius-md);
    min-height: 70vh;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    position: relative;
  }

  /* --- Sticky Header --- */
  .sticky-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-surface-alt);
    padding: var(--size-3) var(--size-4);
    display: flex;
    flex-direction: column;
    gap: var(--size-2);
    box-shadow: 0 4px 12px -2px var(--veil);
  }

  .header-content {
    display: flex;
    align-items: center;
    gap: var(--size-3);
    width: 100%;
  }

  .header-group {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--text-main);
  }

  .header-icon-large {
    font-size: 1.5rem;
    /* Larger icon */
    color: var(--primary);
    width: 1.5rem;
    height: 1.5rem;
    line-height: 1;
    display: inline-block;
  }

  .header-text-large {
    font-size: 1.1rem;
    /* Larger text */
    font-weight: 600;
  }

  .header-actions-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .icon-btn.large {
    width: 2.5rem;
    height: 2.5rem;
  }

  .icon-btn.large iconify-icon {
    font-size: 1.5rem;
  }

  .header-divider-line {
    height: 1px;
    background: var(--border);
    width: 100%;
    margin-top: 0.25rem;
  }

  .vertical-divider.large {
    height: 1.5rem;
    width: 1px;
    background: var(--border);
    margin: 0 0.5rem;
  }

  /* --- Chat Log Scrolling --- */
  .chat-log {
    flex: 1;
    overflow-y: auto;
    padding: var(--size-3) var(--size-4);
    /* Reduced top padding from size-7/8 */
    display: flex;
    flex-direction: column;
    gap: var(--size-3);
    scroll-behavior: smooth;

    /* Hide Scrollbar */
    scrollbar-width: none;
    /* Firefox */
  }

  .chat-log::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
  }

  /* Alive Background Effect */
  .chat-pane::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 60%;
    background: radial-gradient(circle at 50% 0%,
        var(--accent-veil-12),
        transparent 70%);
    pointer-events: none;
    opacity: 0.4;
    /* Slightly lowered since it's static now */
  }

  .chat-header {
    width: 100%;
    padding: var(--size-2) var(--size-3);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: auto;
    position: relative;
    z-index: 10;
    background: var(--bg-surface-alt);
    gap: var(--size-3);
  }

  .header-actions {
    display: inline-flex;
    gap: 0.2rem;
    flex-wrap: wrap;
    align-items: center;
  }

  .icon-action-cluster {
    display: inline-flex;
    gap: 0.2rem;
  }

  .ghost.is-active {
    background: var(--veil-8);
    border-color: var(--veil-30);
  }

  .user-id-card {
    margin: var(--size-3);
    padding: var(--size-3);
    border-radius: var(--radius-md);
    border: 2px dashed var(--accent-veil-35);
    background: var(--accent-veil-15);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--size-3);
    flex-wrap: wrap;
    box-shadow: inset 0 0 0 1px var(--veil-4);
  }

  .user-id-token {
    font-family: var(--font-mono);
    font-size: 1rem;
    letter-spacing: 0.02em;
    padding: 0.4rem 0.65rem;
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    border: 1px solid var(--veil-8);
    word-break: break-all;
    /* Prevent overflow */
  }

  .status-chip-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.4rem;
  }

  .status-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    border: 1px solid var(--tone-accent-strong-border);
    background: var(--tone-accent-soft);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .status-chip__icon {
    font-weight: 700;
  }

  .status-chip__label {
    color: var(--color-text);
  }

  .status-chip[data-tone="success"] {
    border-color: var(--tone-success-border);
    background: var(--tone-success-bg);
  }

  .status-chip[data-tone="warn"] {
    border-color: var(--tone-warn-border);
    background: var(--tone-warn-bg);
  }

  .status-chip[data-tone="info"] {
    border-color: var(--tone-info-border);
    background: var(--tone-info-bg);
  }

  .pill-row {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    flex-wrap: wrap;
  }

  .pill {
    display: inline-flex;
    align-items: center;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    background: var(--color-surface);
    border: 1px solid var(--veil-12);
    font-size: 0.8rem;
    color: var(--color-text);
  }

  .pill--state {
    background: var(--tone-accent-soft);
    border-color: var(--tone-accent-strong-border);
    color: var(--color-text);
  }

  .chat-log {
    flex: 1;
    overflow-y: auto;
    padding: var(--size-3);
    min-height: 320px;
  }

  .chat-log-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    /* Ensure children fill width */
    width: 100%;
  }

  .chat-entry {
    display: flex;
    flex-direction: row;
    width: 100%;
    max-width: 100%;
    /* Override phantom max-width constraints */
    /* Default: no specific alignment */
  }

  .chat-entry--self {
    justify-content: flex-start;
    /* LEFT */
  }

  .chat-entry--peer {
    justify-content: flex-end;
    /* RIGHT */
  }

  .chat-entry--system {
    justify-content: flex-end;
    /* RIGHT */
  }

  /* Force bubble alignment with auto-margins */
  .chat-entry--self .message-wrapper,
  .chat-entry--self .chat-bubble {
    margin-right: auto;
    margin-left: 0;
  }

  .chat-entry--peer .message-wrapper,
  .chat-entry--peer .chat-bubble,
  .chat-entry--system .message-wrapper,
  .chat-entry--system .chat-bubble {
    margin-left: auto;
    margin-right: 0;
  }

  .chat-bubble {
    max-width: min(90%, 500px);
    padding: var(--size-2);
    border-radius: var(--radius-3);
    border: 2px solid var(--border);
    display: block;
    text-align: left;
    box-shadow: none;
    overflow: hidden;
    transition: border-color 0.2s var(--motion-snappy);
  }

  .chat-entry--self .chat-bubble:hover {
    border-color: var(--border-bubble-self);
  }

  .chat-entry--peer .chat-bubble:hover {
    border-color: currentColor;
    /* Will use peer theme border */
  }

  .chat-bubble--self {
    margin-right: auto;
    /* Force Left */
    background: var(--bg-bubble-self);
    border-color: var(--border-bubble-self);
    color: var(--gray-12);
    /* Force visible text color (dark) for light mode default */
  }

  .chat-bubble--peer {
    margin-left: auto;
    /* Force Right */
    background: var(--bg-bubble-peer);
    border-color: var(--border-bubble-peer);
  }

  /* Peer Theme Application */
  .chat-bubble--peer[data-peer-theme="1"] {
    background: var(--peer-theme-1-bg);
    border-color: var(--peer-theme-1-border);
  }

  .chat-bubble--peer[data-peer-theme="2"] {
    background: var(--peer-theme-2-bg);
    border-color: var(--peer-theme-2-border);
  }

  .chat-bubble--peer[data-peer-theme="3"] {
    background: var(--peer-theme-3-bg);
    border-color: var(--peer-theme-3-border);
  }

  .chat-bubble--peer[data-peer-theme="4"] {
    background: var(--peer-theme-4-bg);
    border-color: var(--peer-theme-4-border);
  }

  .chat-bubble--peer[data-peer-theme="5"] {
    background: var(--peer-theme-5-bg);
    border-color: var(--peer-theme-5-border);
  }

  .chat-bubble--peer[data-peer-theme="6"] {
    background: var(--peer-theme-6-bg);
    border-color: var(--peer-theme-6-border);
  }

  .chat-bubble--system {
    margin-left: auto;
    /* Force Right */
    background: var(--bg-bubble-system);
    border-color: var(--border-bubble-system);
    color: var(--color-text);
  }

  .chat-bubble--system p,
  .chat-bubble--system div,
  .chat-bubble--system span {
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Message Wrapper for Name + Bubble */
  .message-wrapper {
    display: flex;
    flex-direction: column;
    gap: var(--size-1);
    width: 100%;
  }

  /* Peer Name Above Message */
  .peer-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding-left: var(--size-2);
    align-self: flex-start;
    /* Align to left */
  }

  /* System messages should align right */
  .chat-entry--system .peer-name {
    align-self: flex-end;
    /* Align to right for system */
    padding-left: 0;
    padding-right: var(--size-2);
  }

  /* System Message Components */
  .system-invite-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-start;
    text-align: left;
    padding-top: 0.5rem;
  }

  .system-invite-label {
    font-weight: 600;
    font-size: 0.9em;
    margin: 0;
  }

  .system-invite-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-surface-alt);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    border: 1px solid var(--border);
  }

  .system-invite-code {
    font-family: var(--font-mono);
    font-size: 0.95em;
    border: none;
    background: transparent;
  }

  .system-invite-copy-btn {
    width: 1.5rem;
    /* 24px */
    height: 1.5rem;
    /* 24px */
    min-width: 1.5rem;
    border-radius: 4px;
  }

  .system-invite-copy-btn iconify-icon {
    font-size: 0.875rem;
    /* 14px */
  }

  .system-invite-hint {
    font-size: 0.85em;
    opacity: 0.8;
    margin: 0;
  }

  .system-message-content {
    padding-top: 0.5rem;
    text-align: left;
  }

  .system-message-text {
    font-size: 0.95em;
    color: var(--text-main);
  }

  /* Layout Utilities */
  .brand-tagline {
    font-weight: 400;
    opacity: 0.7;
    font-size: 0.9em;
  }

  .header-icon {
    font-size: 20px;
    width: 20px;
    height: 20px;
    line-height: 1;
    display: inline-block;
  }

  .header-extras {
    font-family: var(--font-mono);
    font-size: var(--font-size-0);
    color: var(--text-2);
  }

  .header-extras span {
    display: inline-block;
    min-width: 5ch;
    text-align: right;
    font-variant-numeric: tabular-nums;
  }

  .main-relative {
    position: relative;
  }

  .footer-relative {
    position: relative;
    overflow: hidden;
  }

  .footer-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--size-3);
    flex-wrap: wrap;
    height: 100%;
    padding: 0 var(--size-3);
    font-size: 0.85rem;
    color: var(--color-muted);
    transition: opacity 0.2s;
  }

  .footer-nav {
    display: flex;
    gap: var(--size-2);
  }

  .footer-link {
    color: inherit;
    text-decoration: none;
  }

  .footer-hover-overlay {
    position: absolute;
    inset: 0;
    background: var(--color-accent);
    color: var(--color-on-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    z-index: 10;
  }

  /* Room Header Components */
  .room-heading-flex {
    flex-direction: row;
    align-items: center;
    gap: var(--size-3);
    width: 100%;
  }

  .user-identity {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .avatar-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
  }

  .user-nickname {
    font-weight: 600;
    color: var(--text-main);
  }

  .vertical-divider {
    width: 1px;
    height: 16px;
    background: var(--border);
  }

  .room-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .room-name {
    color: var(--text-muted);
  }

  .flex-spacer {
    flex: 1;
  }

  .status-peer-count {
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
  }

  .peer-count-badge {
    font-weight: 700;
    font-size: 0.9rem;
    font-family: var(--font-mono);
  }

  .download-icon {
    font-size: 24px;
  }

  .upload-form-hidden {
    display: none;
  }

  /* Static Page Utilities */
  .home-container {
    display: grid;
    place-items: center;
    height: 100%;
    text-align: center;
  }

  .redirect-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--size-4);
    color: var(--text-muted);
  }

  .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--surface-3);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
  }

  @keyframes spin {
    to {
      transform: rotate(360deg);
    }
  }

  /* Utility class for spinning any element */
  .spin {
    animation: spin 1s linear infinite;
  }

  .empty-state-icon {
    font-size: 3rem;
    color: var(--veil-20);
  }

  .loading-center {
    text-align: center;
    padding: 1rem;
  }

  /* Loading Skeleton */
  .loading-skeleton {
    display: flex;
    flex-direction: column;
    padding: var(--size-4);
    gap: var(--size-4);
    height: 100%;
  }

  .skeleton-header {
    display: flex;
    gap: var(--size-3);
    padding: var(--size-3);
    background: var(--surface-2);
    border-radius: var(--radius-2);
  }

  .skeleton-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--size-3);
    padding: var(--size-4);
  }

  .skeleton-message {
    display: flex;
    gap: var(--size-3);
    align-items: flex-start;
  }

  .skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
  }

  .skeleton-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--size-2);
  }

  .skeleton-bar {
    height: 16px;
    border-radius: var(--radius-1);
    background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
  }

  .skeleton-footer {
    padding: var(--size-3);
  }

  @keyframes skeleton-shimmer {
    0% {
      background-position: 200% 0;
    }
    100% {
      background-position: -200% 0;
    }
  }

  /* Onboarding Tooltips */
  .onboarding-wrapper {
    position: relative;
    display: inline-flex;
  }

  .onboarding-tooltip {
    position: absolute;
    top: calc(100% + var(--size-2));
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    width: 250px;
    background: var(--surface-1);
    border: 2px solid var(--blue-5);
    border-radius: var(--radius-3);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    padding: var(--size-3);
  }

  .onboarding-tooltip::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 8px solid var(--blue-5);
  }

  .onboarding-tooltip::after {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid var(--surface-1);
  }

  .onboarding-content p {
    margin: 0 0 var(--size-2);
    font-size: var(--font-size-0);
    color: var(--text-1);
  }

  .onboarding-content p:last-of-type {
    margin-bottom: var(--size-3);
    color: var(--text-2);
  }

  .onboarding-actions {
    display: flex;
    gap: var(--size-2);
    justify-content: flex-end;
  }

  /* Toast Icon */
  .toast-icon {
    font-size: 1.25rem;
  }

  /* Welcome Button */
  .welcome-cta {
    width: auto;
    display: inline-block;
  }

  /* Toasts */
  /* toast-stack removed (status messages use footer) */

  .chat-bubble__body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
    line-height: 1.4;
  }

  .chat-name-line {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
  }

  .chat-tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
  }

  .chat-tag--self {
    background: var(--accent-alt-veil-35);
    color: var(--gray-12);
  }

  .chat-tag--peer {
    background: var(--accent-veil-35);
    color: var(--gray-12);
  }

  .chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--avatar-color, var(--color-accent));
    color: var(--gray-12);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
  }

  .chat-entry--self .chat-avatar {
    order: 2;
  }

  .chat-entry--self .chat-bubble__body {
    align-items: flex-end;
    text-align: right;
  }

  .chat-meta-line {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.78rem;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }

  .chat-meta-line time {
    opacity: 0;
    flex: 1;
    text-align: right;
    transition: opacity 0.2s ease;
  }

  .chat-entry:hover time {
    opacity: 1;
  }

  .chat-body {
    margin: var(--size-1) 0 0;
    white-space: pre-wrap;
  }

  .chat-attachment {
    display: inline-flex;
    gap: 0.4rem;
    align-items: center;
    margin-top: var(--size-1);
    color: var(--color-accent);
    font-weight: 600;
  }

  .chat-attachment-preview {
    display: block;
    margin-top: 0.35rem;
    max-width: 220px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--color-border);
    box-shadow: 0 8px 24px var(--shadow-dark);
  }

  .chat-attachment-audio {
    display: block;
    margin-top: 0.35rem;
    width: 220px;

    /* ... checking ... */

    /* ... existing styles ... */

    /* Hero Section */
    .hero-section {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      flex: 1;
      min-height: 320px;
      padding: var(--size-4);
      text-align: center;
      background: var(--hero-gradient, none);
    }

    .hero-content {
      max-width: 480px;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: var(--size-4);
    }

    .hero-title {
      font-size: clamp(2.5rem, 5vw, 4rem);
      font-weight: 800;
      line-height: 1.1;
      letter-spacing: -0.02em;
      margin: 0;
    }

    .hero-subtitle {
      font-size: 1.25rem;
      color: var(--color-muted);
      line-height: 1.5;
      margin: 0;
      max-width: 32ch;
    }

    .cta .hero-features {
      list-style: none;
      padding: 0;
      margin: var(--size-4) 0 0;
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      gap: var(--size-2);
    }

    .reaction-pill {
      display: inline-flex;
      align-items: center;
      gap: 0.3rem;
      padding: 0.15rem 0.6rem;
      border-radius: 999px;
      background: var(--veil-8);
      border: 1px solid var(--veil-12);
      font-size: 0.8rem;
    }

    .reaction-emoji {
      font-size: 1rem;
    }

    .reaction-count {
      font-weight: 600;
      color: var(--color-muted);
    }

    .reaction-picker {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      margin-top: 0.4rem;
      font-size: 0.8rem;
      color: var(--color-muted);
    }

    .reaction-picker__buttons {
      display: none;
      /* Hidden by default */
      gap: 0.4rem;
      flex-wrap: wrap;
    }

    /* Show reaction buttons on message hover */
    .chat-entry:hover .reaction-picker__buttons {
      display: inline-flex;
    }

    .reaction-button {
      border: 1px solid var(--veil-30);
      background: var(--veil-5);
      color: var(--color-text);
      border-radius: 12px;
      width: 32px;
      height: 32px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      transition: border-color 0.15s var(--motion-snappy);
    }

    .reaction-button:hover,
    .reaction-button:focus-visible {
      transform: translateY(-1px);
      border-color: var(--color-accent);
      box-shadow: 0 6px 16px var(--shadow-accent-alt);
      outline: none;
    }

    .chat-empty {
      text-align: center;
      color: var(--color-muted);
    }

    @media (width <=960px) {
      .room-shell {
        flex-direction: column;
      }

      /* Sidebar layout is controlled in layout.css (incl. mobile bottom-nav). */

      .slide-panel {
        position: fixed;
        top: var(--size-2);
        right: var(--size-2);
        left: var(--size-2);
      }
    }

    @media (width <=768px) {
      .room-shell {
        gap: var(--size-3);
      }

      /* Sidebar layout is controlled in layout.css (incl. mobile bottom-nav). */

      .hero-cta {
        width: 100%;
        justify-content: center;
      }

      /* Enforce Thick Borders (Pop Aesthetic) - Scoped to Components Layer */
      :where(.app-sidebar,
        .app-main,
        .app-header,
        .app-footer,
        .status-hud,
        .modal-panel,
        input,
        select,
        textarea,
        button,
        .icon-btn,
        .chat-bubble,
        .connection-banner) {
        border-width: 2px;
      }

      :where(.icon-btn:hover, input:focus, button:hover, .cta:hover) {
        border-color: var(--primary);
      }

      /* --- Component Additions --- */

      /* MESSAGE INPUT STYLES REMOVED - TO BE REDESIGNED */

      /* Hidden Utility Elements */
      .upload-form {
        display: none;
      }

      .remote-audio {
        width: 100%;
        opacity: 0;
        height: 0;
      }
    }
  }
}

/* New Panel Styles */
/* Small popover panel (e.g. Filter dropdown) */
.action-panel {
  position: absolute;
  top: 3rem;
  right: 1rem;
  background: var(--bg-panel);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius-panel);
  padding: 1rem;
  box-shadow: var(--shadow-pop);
  z-index: 20;
  width: 260px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Mobile-only backdrop for right-side drawers. */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 45%);
  backdrop-filter: blur(2px);
  z-index: calc(var(--layer-panel) - 1);
}

@media (min-width: 769px) {
  .drawer-backdrop {
    display: none;
  }
}

/* Right-side panels should behave like a drawer and never be clipped. */
.action-panel.right {
  position: fixed;
  top: calc(var(--size-1) + 4.5rem + var(--size-2));
  bottom: calc(var(--size-1) + 2.75rem + var(--size-2));
  right: var(--size-2);
  width: min(92vw, 420px);
  max-height: none;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-panel);
  border: var(--border-width) solid var(--border);
  border-radius: var(--radius-4);
  box-shadow: var(--shadow-6);
  z-index: var(--layer-panel);
  opacity: 1;
}

@media (max-width: 768px) {
  /* Keep drawers above the mobile bottom-nav + footer (and safe-area). */
  .action-panel.right {
    bottom: calc(env(safe-area-inset-bottom, 0px) + var(--size-1) + 2.75rem + var(--size-2) + 4.25rem + var(--size-2));
  }
}

@media (width <= 640px) {
  .action-panel.right {
    right: var(--size-1);
    left: auto;
    width: calc(100vw - var(--size-1) * 2);
  }
}

.slide-panel {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  width: min(80vw, 420px);
  /* Responsive width, max 420px */
  background: var(--bg-panel);
  border-left: var(--border-width) solid var(--border);
  box-shadow: var(--shadow-6);
  z-index: var(--layer-modal);
  /* Above other content, below other modals */
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  /* Start off-screen */
  transition: transform 0.3s ease-out;
  /* Slide in/out animation */
}

/* Alpine.js transitions */
.slide-panel[x-cloak].x-transition-enter-start,
.slide-panel[x-cloak].x-transition-leave-end {
  transform: translateX(100%);
}

.slide-panel[x-cloak].x-transition-enter-end,
.slide-panel[x-cloak].x-transition-leave-start {
  transform: translateX(0);
}

.slide-panel .panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--size-4);
  border-bottom: var(--border-width) solid var(--border);
}

.slide-panel .panel-header h3 {
  margin: 0;
  font-size: 1.25rem;
}

.slide-panel .panel-header .icon-btn {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: var(--bg-surface-alt);
}

  .slide-panel .panel-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--size-4);
    min-height: 55vh;
  }

.action-panel h3 {
  margin-bottom: 0.5rem;
  font-size: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.25rem;
}

/* Composer Tweaks */
.chat-composer__textarea {
  min-height: 3.5rem;
  /* ~2 lines comfortably */
  max-height: 200px;
  transition: height 0.1s ease;
}

/* Invite Link Tweaks */
.system-invite-code {
  font-size: 0.8rem;
  font-weight: 700;
  /* Bold */
  font-family: var(--font-mono);
  /* Monospace ideal for links/tokens */
  opacity: 0.9;
  letter-spacing: -0.01em;
}

/* Empty State Card */
.empty-state-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--size-7) var(--size-5);
  text-align: center;
  background: var(--surface-2);
  border: 2px solid var(--surface-3);
  border-radius: var(--radius-3);
  margin: var(--size-6) auto;
  max-width: 480px;
}

.empty-state-title {
  margin-top: var(--size-2);
  font-size: var(--font-size-3);
  font-weight: 800;
  color: var(--text-1);
}

.empty-state-body {
  margin-top: var(--size-2);
  color: var(--text-2);
  font-size: var(--font-size-1);
  line-height: 1.5;
  max-width: 34ch;
}

.empty-state-body p {
  margin: 0 0 var(--size-2);
}

.empty-state-body p:last-child {
  margin-bottom: 0;
}

.empty-state-inline-icon {
  vertical-align: -0.1em;
  color: var(--primary);
}

@media (width <=768px) {
  .empty-state-card {
    padding: var(--size-4) var(--size-3);
    margin: var(--size-3) auto;
  }

  .empty-state-body {
    max-width: 100%;
    font-size: var(--font-size-0);
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  .empty-state-body p {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25em;
  }
}

.panel-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--size-2);
}

.action-panel .close-btn {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
}
