@layer reset, tokens, base, layout, components, states, responsive;

@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  * {
    margin: 0;
  }

  button,
  input {
    font: inherit;
  }

  button,
  label {
    -webkit-tap-highlight-color: transparent;
  }
}

@layer tokens {
  :root {
    color-scheme: light;

    --page: #f2f2f7;
    --page-2: #ffffff;
    --ink: #1c1c1e;
    --ink-soft: #3a3a3c;
    --ink-muted: #8e8e93;

    --panel: color-mix(in srgb, white 78%, transparent);
    --panel-solid: #ffffff;
    --panel-tint: #f2f2f7;
    --line: color-mix(in srgb, #c6c6c8 72%, transparent);

    --blue: #007aff;
    --blue-strong: #0057b8;
    --green-weak: #cdeecd;
    --green: #34c759;
    --green-strong: #0abb52;
    --red: #ff3b30;
    --amber: #ff9500;
    --teal: #00c7be;
    --cyan: #32ade6;
    --graphite: #6e6e73;

    --shadow: 0 22px 55px rgb(55 75 95 / 16%);
    --shadow-soft: 0 10px 28px rgb(55 75 95 / 12%);
    --blur: blur(18px) saturate(1.35);

    --radius: 8px;
    --radius-sm: 6px;
    --space: 16px;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --border: var(--line);
    --surface: var(--panel-tint);
    --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'JetBrains Mono', Menlo, Consolas, monospace;
    --font:
      'Poppins', 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
      sans-serif;
  }

  /* Dark theme tokens — Apple-like tones */
  .dark,
  [data-theme='dark'] {
    color-scheme: dark;
    --page: #0b0b0c;
    --page-2: #121214;
    --ink: #f2f2f7;
    --ink-soft: #d1d1d6;
    --ink-muted: #8e8e93;

    --panel: color-mix(in srgb, rgba(255, 255, 255, 0.02), transparent);
    --panel-solid: #1c1c1e;
    --panel-tint: #141416;
    --line: rgba(255, 255, 255, 0.06);

    --blue: #0a84ff;
    --blue-strong: #007aff;
    --green-weak: #1f7a3b;
    --green: #30d158;
    --green-strong: #00c853;
    --red: #ff453a;
    --amber: #ff9f0a;
    --teal: #19e6c7;
    --cyan: #60bfff;
    --graphite: #2c2c2e;

    --shadow: 0 12px 40px rgb(0 0 0 / 60%);
    --shadow-soft: 0 6px 16px rgb(0 0 0 / 40%);
    --blur: blur(10px) saturate(1.1);

    --font:
      'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  }
}

@layer base {
  html {
    min-block-size: 100%;
    background:
      linear-gradient(135deg, color-mix(in srgb, var(--page-2), white 20%), transparent 40%),
      linear-gradient(180deg, var(--page), var(--page-2));
  }

  body {
    min-block-size: 100dvh;
    color: var(--ink);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.45;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
  }

  body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
      linear-gradient(90deg, var(--line) 1px, transparent 1px),
      linear-gradient(var(--line) 1px, transparent 1px);
    background-size: 42px 42px;
    mask-image: linear-gradient(to bottom, rgb(0 0 0 / 55%), transparent 70%);
  }

  :focus-visible {
    outline: 3px solid color-mix(in srgb, var(--blue), white 24%);
    outline-offset: 3px;
  }

  .sr-only {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .hidden {
    display: none !important;
  }
}

@layer layout {
  #app-shell {
    min-block-size: 100dvh;
  }

  .screen {
    display: none;
  }

  .screen.active {
    display: flex;
    flex-direction: column;
    min-block-size: 100dvh;
  }

  #screen-home {
    align-items: center;
    justify-content: center;
    gap: 22px;
    padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  }

  #screen-room.active {
    container-type: inline-size;
    block-size: 100dvh;
    overflow: hidden;
  }

  .room-body {
    container-type: inline-size;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 270px;
    flex: 1;
    min-block-size: 0;
    margin: 14px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: var(--blur);
  }

  .room-main {
    display: flex;
    flex-direction: column;
    min-block-size: 0;
    overflow-y: auto;
    padding-block-end: 14px;
  }
}

@layer components {
  .brand-lockup {
    display: grid;
    justify-items: center;
    gap: 8px;
    inline-size: min(100%, 430px);
    text-align: center;
  }

  .brand-mark {
    position: relative;
    display: grid;
    place-items: center;
    inline-size: 142px;
    aspect-ratio: 1;
    isolation: isolate;
  }

  /* Make the brand mark act like a large primary button */
  #brand-mark {
    cursor: pointer;
    outline: none;
  }

  #brand-mark:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--green), white 18%);
    outline-offset: 6px;
  }

  .radar-ring {
    position: absolute;
    inset: calc(var(--i, 0) * 18px);
    border: 1px solid color-mix(in srgb, var(--blue), transparent 34%);
    border-radius: 50%;
    background: color-mix(in srgb, var(--blue), transparent 94%);
  }

  .radar-ring:nth-child(1) {
    --i: 0;
    opacity: 0.24;
  }
  .radar-ring:nth-child(2) {
    --i: 1;
    opacity: 0.42;
  }
  .radar-ring:nth-child(3) {
    --i: 2;
    opacity: 0.66;
  }

  .radar-core {
    z-index: 1;
    display: grid;
    place-items: center;
    inline-size: 52px;
    aspect-ratio: 1;
    border-radius: 50%;
    background: linear-gradient(
      160deg,
      color-mix(in srgb, var(--cyan), white 12%),
      var(--blue) 62%,
      var(--blue-strong)
    );
    box-shadow: 0 10px 24px rgb(0 122 255 / 28%);
  }

  /* When creating a room, show the brand-mark as green */
  #brand-mark.creating .radar-core {
    background: linear-gradient(
      160deg,
      color-mix(in srgb, var(--green), white 12%),
      var(--green) 64%
    );
    box-shadow: 0 14px 34px rgb(52 199 89 / 28%);
  }

  .radar-core::before,
  .radar-core::after {
    content: '';
    position: absolute;
    border: 2px solid rgb(255 255 255 / 92%);
    border-block-start: 0;
    border-inline-start: 0;
    border-radius: 0 0 18px 0;
    transform: rotate(45deg);
  }

  .radar-core::before {
    inline-size: 18px;
    block-size: 18px;
  }

  .radar-core::after {
    inline-size: 28px;
    block-size: 28px;
    opacity: 0.52;
  }

  .eyebrow {
    color: var(--ink-muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .brand-sub {
    color: var(--ink-muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    margin-top: -2px;
    text-transform: none;
  }

  .brand-lockup h1 {
    color: var(--ink);
    font-size: 42px;
    font-weight: 760;
    letter-spacing: 0;
  }

  /* Adjust the initial: use a friendly display font for brand */
  .brand-initial {
    font-family: 'Poppins', var(--font);
    font-weight: 700;
    display: inline-block;
    margin-inline-end: 6px;
    color: var(--blue-strong);
    font-size: 46px;
    transform: translateY(-2px);
    letter-spacing: -0.02em;
    line-height: 1;
  }

  .tagline {
    color: var(--ink-soft);
    font-size: 15px;
  }

  .home-actions {
    display: grid;
    gap: 12px;
    inline-size: min(100%, 340px);
  }

  .divider {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 10px;
    color: var(--ink-muted);
    font-size: 12px;
  }

  .divider::before,
  .divider::after {
    content: '';
    block-size: 1px;
    background: var(--line);
  }

  .join-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
  }

  input[type='text'],
  .expiry-input {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    color: var(--ink);
    background: var(--panel-solid);
    outline: none;
    transition:
      border-color 160ms ease,
      box-shadow 160ms ease,
      background 160ms ease;
  }

  input[type='text'] {
    inline-size: 100%;
    padding: 10px 12px;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.28em;
    font-size: 18px;
    font-weight: 700;
  }

  input[type='text']::placeholder {
    color: var(--ink-muted);
    letter-spacing: 0.12em;
    font-size: 13px;
  }

  input[type='text']:focus,
  .expiry-input:focus {
    border-color: color-mix(in srgb, var(--blue), white 10%);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--blue), transparent 84%);
    background: var(--panel-solid);
  }

  .btn,
  .btn-icon,
  .btn-download,
  .btn-delete,
  .btn-kick,
  .btn-ban {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    min-block-size: 28px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 700;
    font-size: 13px;
    line-height: 1;
    transition:
      transform 140ms ease,
      border-color 160ms ease,
      background 160ms ease,
      box-shadow 160ms ease;
  }

  .btn {
    border: 1px solid transparent;
    padding: 4px 10px;
    height: 28px;
    min-block-size: 28px;
  }

  .btn-small {
    padding: 2px 8px;
    height: 24px;
    min-block-size: 24px;
    font-size: 12px;
  }

  .btn:active,
  .btn-icon:active,
  .btn-download:active,
  .btn-delete:active {
    transform: translateY(1px);
  }

  .btn-primary {
    color: white;
    background: linear-gradient(180deg, color-mix(in srgb, var(--blue), white 18%), var(--blue));
    box-shadow: 0 10px 24px rgb(0 122 255 / 24%);
  }

  /* Keep `#btn-create` visible (used by compiled JS). If you want to hide it later,
     ensure the built JS is regenerated. */

  .btn-secondary,
  .btn-ghost,
  .btn-icon {
    color: var(--ink);
    border-color: var(--line);
    background: var(--panel-solid);
  }

  .btn-secondary:hover,
  .btn-ghost:hover,
  .btn-icon:hover {
    border-color: color-mix(in srgb, var(--blue), transparent 56%);
    background: var(--panel-tint);
  }

  .btn-ghost {
    color: var(--blue-strong);
    background: color-mix(in srgb, var(--blue), transparent 92%);
  }

  .btn-destructive {
    color: var(--red);
    background: var(--panel-solid);
    border: 1px solid var(--red);
    box-shadow: none;
  }

  .btn-destructive:hover {
    background: var(--panel-solid);
    filter: none;
  }

  .is-mobile #btn-scan-qr {
    order: -1;
  }

  .btn-icon {
    padding: 4px 8px;
    font-size: 13px;
    height: 28px;
    min-inline-size: 40px;
    inline-size: auto;
  }

  .error-msg {
    min-block-size: 18px;
    color: var(--red);
    font-size: 12px;
    text-align: center;
  }

  .scanner-dialog {
    inline-size: min(94vw, 420px);
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: transparent;
    box-shadow: var(--shadow);
  }

  .scanner-dialog::backdrop {
    background: rgb(28 28 30 / 36%);
    backdrop-filter: blur(10px);
  }

  .scanner-card {
    display: grid;
    gap: 12px;
    padding: 12px;
    border-radius: inherit;
    background: var(--panel-solid);
  }

  .scanner-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .scanner-header h2 {
    font-size: 16px;
  }

  .qr-video {
    inline-size: 100%;
    aspect-ratio: 1;
    border-radius: var(--radius);
    background: var(--ink);
    object-fit: cover;
  }

  .scanner-status {
    color: var(--ink-soft);
    font-size: 13px;
  }

  .room-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-block-end: 1px solid var(--line);
    background: var(--panel);
    backdrop-filter: var(--blur);
  }

  .logo-small {
    margin-inline-end: auto;
    color: var(--ink);
    font-size: 16px;
    font-weight: 760;
  }

  .room-info {
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .room-code {
    padding: 5px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    color: var(--blue-strong);
    background: var(--panel-solid);
    font-size: 17px;
    font-weight: 760;
    letter-spacing: 0.26em;
  }

  .status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-block-size: 30px;
    padding-inline: 10px;
    border: 1px solid currentColor;
    border-radius: var(--radius);
    background: var(--panel-solid);
    font-size: 12px;
    font-weight: 700;
  }

  .status-dot {
    inline-size: 7px;
    aspect-ratio: 1;
    border-radius: 50%;
    background: currentColor;
  }

  .share-banner {
    margin: 12px 14px 0;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel-solid);
    box-shadow: var(--shadow-soft);
  }

  .relay-warning {
    margin: 10px 14px 0;
    padding: 10px 12px;
    border: 1px solid color-mix(in srgb, var(--amber), transparent 40%);
    border-left-width: 6px;
    border-left-color: var(--amber);
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--amber), var(--panel-solid) 92%);
    color: var(--ink);
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }

  /* Confirm modal for desktop */
  .confirm-backdrop {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgb(0 0 0 / 24%);
    z-index: 1200;
  }

  .confirm-modal {
    background: var(--panel-solid);
    border: 1px solid var(--line);
    padding: 18px;
    border-radius: 10px;
    box-shadow: var(--shadow);
    max-inline-size: 420px;
    width: min(92vw, 420px);
    text-align: left;
  }

  .confirm-modal h3 {
    margin-bottom: 6px;
    font-size: 16px;
  }
  .confirm-modal p {
    color: var(--ink-soft);
    margin-bottom: 12px;
  }

  .confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
  }

  .share-label,
  .drop-sub,
  .client-since,
  .client-browser,
  .file-size {
    color: var(--ink-soft);
    font-size: 12px;
  }

  .share-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-block-start: 8px;
  }

  .qr-card {
    display: grid;
    justify-items: center;
    gap: 8px;
    margin-block-start: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: white; /* blanco fijo: el QR necesita fondo blanco para ser escaneable */
  }

  /* Default QR size (smaller than before) and responsive adjustment */
  .room-qr {
    inline-size: min(152px, 56vw); /* ~80% of previous 190px / 70vw */
    aspect-ratio: 1;
    image-rendering: pixelated;
  }

  /* Sidebar modifier: make sure QR fits nicely in the right column */
  .qr-card--sidebar {
    margin-block-start: 18px;
    background: transparent;
    border: none;
    padding: 8px 6px 12px 6px;
  }

  @media (min-width: 760px) {
    /* Ensure the QR card sits visually in the right column and is centered */
    .clients-panel {
      display: flex;
      flex-direction: column;
      align-items: center;
    }

    .qr-card--sidebar {
      width: 100%;
      max-inline-size: 220px;
      box-sizing: border-box;
    }

    .room-qr {
      inline-size: min(152px, 80%);
    }
  }

  .qr-card figcaption {
    color: var(--ink-soft);
    font-size: 12px;
    text-align: center;
  }

  .share-url {
    flex: 1;
    min-inline-size: 0;
    overflow-wrap: anywhere;
    color: var(--blue-strong);
    font-size: 13px;
    font-weight: 650;
  }

  .drop-zone {
    display: grid;
    place-items: center;
    flex: 1;
    min-block-size: 260px;
    margin: 14px;
    border: 1.5px dashed color-mix(in srgb, var(--graphite), transparent 48%);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--panel-solid) 72%, transparent);
    transition:
      border-color 180ms ease,
      background 180ms ease,
      transform 180ms ease;
  }

  .drop-content {
    display: grid;
    justify-items: center;
    gap: 8px;
    max-inline-size: 320px;
    padding: 24px;
    text-align: center;
  }

  .drop-icon {
    display: grid;
    place-items: center;
    inline-size: 44px;
    aspect-ratio: 1;
    border-radius: 50%;
    color: white;
    background: linear-gradient(160deg, var(--teal), var(--blue));
    font-size: 21px;
    font-weight: 800;
    line-height: 1;
  }

  .drop-label {
    color: var(--ink);
    font-size: 16px;
    font-weight: 750;
  }

  .expiry-bar {
    display: grid;
    gap: 8px;
    inline-size: min(100%, 290px);
    margin-block-start: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel-solid);
  }

  .expiry-bar legend {
    padding-inline: 4px;
    color: var(--ink-muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .expiry-option {
    display: flex;
    align-items: center;
    gap: 7px;
    color: var(--ink-soft);
    font-size: 12px;
  }

  .expiry-option input[type='checkbox'] {
    accent-color: var(--blue);
  }

  .expiry-input {
    inline-size: 56px;
    min-block-size: 28px;
    padding: 3px 6px;
    text-align: center;
    font-size: 12px;
  }

  .expiry-option:not(:has(input[type='checkbox']:checked)) .expiry-input {
    opacity: 0.44;
    pointer-events: none;
  }

  .clients-panel {
    overflow-y: auto;
    padding: 14px;
    border-inline-start: 1px solid var(--line);
    background: color-mix(in srgb, var(--panel-tint), transparent 16%);
  }

  .section-title {
    color: var(--ink-muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .clients-list,
  .file-list {
    display: grid;
    gap: 8px;
    margin-block-start: 10px;
    list-style: none;
    padding: 0;
    min-width: 0;
  }

  .client-item,
  .file-item {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel-solid);
  }

  .client-item {
    padding: 10px;
  }

  .client-item.is-self {
    border-color: color-mix(in srgb, var(--blue), transparent 48%);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--blue), transparent 82%);
  }

  .client-role {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--ink-muted);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .you-badge {
    border-radius: var(--radius-sm);
    padding: 1px 5px;
    color: var(--blue-strong);
    background: color-mix(in srgb, var(--blue), transparent 88%);
    font-size: 9px;
    letter-spacing: 0;
    text-transform: none;
  }

  .client-ip {
    margin-block-start: 5px;
    color: var(--ink);
    font-size: 13px;
    font-weight: 750;
  }

  .client-since span {
    color: var(--blue-strong);
    font-weight: 750;
  }

  .peer-actions,
  .ban-row {
    display: grid;
    gap: 6px;
    margin-block-start: 8px;
  }

  .ban-row {
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
  }

  .btn-kick,
  .btn-ban {
    min-block-size: 30px;
    border: 1px solid color-mix(in srgb, var(--red), transparent 62%);
    color: var(--red);
    background: var(--panel-solid);
    font-size: 11px;
  }

  .ban-unit {
    color: var(--ink-muted);
    font-size: 11px;
  }

  .file-list-section {
    padding: 0 14px 14px;
  }

  .file-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 11px;
  }

  .file-icon {
    display: grid;
    place-items: center;
    inline-size: 44px;
    aspect-ratio: 1;
    border-radius: 8px;
    background: linear-gradient(
      160deg,
      color-mix(in srgb, var(--blue), var(--panel-solid) 88%),
      color-mix(in srgb, var(--teal), var(--panel-solid) 88%)
    );
    color: var(--blue-strong);
    font-size: 0; /* svg will provide visuals */
  }

  .file-icon .icon-svg svg {
    width: 22px;
    height: 22px;
    color: inherit;
    stroke: currentColor;
    fill: none;
  }
  .file-icon .icon-svg svg path,
  .file-icon .icon-svg svg rect {
    stroke: currentColor;
  }

  .file-name {
    overflow: hidden;
    color: var(--ink);
    font-size: 13px;
    font-weight: 750;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .file-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 5px;
  }

  .progress-wrap {
    overflow: hidden;
    block-size: 4px;
    margin-block-start: 7px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--graphite), transparent 84%);
  }

  .progress-bar {
    block-size: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--teal), var(--blue));
    transition:
      inline-size 120ms linear,
      width 120ms linear;
  }

  .badge,
  .expiry-tag {
    border-radius: 999px;
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 750;
    white-space: nowrap;
  }

  /* Ensure badges inside file-actions are vertically centered */
  .file-actions .badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    margin-right: 8px;
  }

  .badge-sending,
  .expiry-tag.dl {
    color: var(--blue-strong);
    background: color-mix(in srgb, var(--blue), transparent 88%);
  }

  .badge-receiving,
  .expiry-tag.time {
    color: var(--amber);
    background: color-mix(in srgb, var(--amber), transparent 86%);
  }

  .badge-done {
    color: var(--green-strong);
    background: color-mix(in srgb, var(--green-weak), transparent 86%);
  }

  .expiry-tag.urgent {
    color: var(--red);
    background: color-mix(in srgb, var(--red), transparent 84%);
  }

  .btn-download,
  .btn-delete {
    min-block-size: 30px;
    border: 1px solid var(--line);
    background: var(--panel-solid);
    padding: 5px 10px;
    font-size: 12px;
    text-decoration: none;
  }

  .btn-download {
    color: var(--green);
    border-color: color-mix(in srgb, var(--green), transparent 60%);
  }

  .btn-delete {
    color: var(--ink-muted);
  }

  /* ── Theme toggle ──────────────────────────────────────────── */
  .theme-toggle {
    position: fixed;
    inset-block-start: max(16px, env(safe-area-inset-top));
    inset-inline-end: 16px;
    z-index: 100;
    display: grid;
    place-items: center;
    inline-size: 36px;
    block-size: 36px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--panel-solid);
    color: var(--ink-soft);
    cursor: pointer;
    box-shadow: var(--shadow-soft);
    transition:
      background 0.18s,
      color 0.18s,
      border-color 0.18s,
      transform 0.12s;
  }

  .theme-toggle:hover {
    color: var(--ink);
    background: var(--panel-tint);
    transform: scale(1.08);
  }

  .theme-toggle:active {
    transform: scale(0.94);
  }

  .theme-toggle--inline {
    position: static;
    box-shadow: none;
    flex-shrink: 0;
  }

  /* ── Home floating controls (lang + theme) ─────────────────── */
  .home-controls {
    position: fixed;
    inset-block-start: max(14px, env(safe-area-inset-top));
    inset-inline-end: 14px;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  /* ── Language selector ─────────────────────────────────────── */
  .lang-select {
    padding: 0 8px;
    block-size: 36px;
    min-inline-size: 80px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel-solid);
    color: var(--ink-soft);
    font-size: 13px;
    font-weight: 700;
    font-family: var(--font);
    cursor: pointer;
    box-shadow: var(--shadow-soft);
    transition:
      background 0.18s,
      color 0.18s,
      border-color 0.18s;
  }

  .lang-select:hover {
    color: var(--ink);
    background: var(--panel-tint);
  }

  .lang-select--inline {
    box-shadow: none;
    min-inline-size: 72px;
  }

  /* ── Inline text messages ───────────────────────────────────── */
  .message-bubble {
    background: color-mix(in srgb, var(--panel-solid), rgba(255,255,255,0.08));
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-2);
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .message-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-1);
    font-size: 0.75rem;
  }

  .message-content {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    line-height: 1.5;
    overflow-x: hidden;
    white-space: pre-wrap;
    word-break: break-word;
    min-width: 0;
    max-width: 100%;
  }

  .message-content pre,
  .message-content code {
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    min-width: 0;
    max-width: 100%;
  }

  .message-content.collapsed {
    max-height: 120px;
    overflow: hidden;
    position: relative;
  }

  .message-content.collapsed::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: linear-gradient(transparent, color-mix(in srgb, var(--panel-solid), rgba(255,255,255,0.08)));
  }

  .message-actions {
    display: flex;
    gap: var(--space-1);
    margin-top: var(--space-1);
    align-items: center;
  }

  .expand-toggle {
    font-size: 0.75rem;
    line-height: 1;
    padding: 2px 6px;
    cursor: pointer;
  }

  .expand-toggle::before {
    content: '▼';
    display: inline-block;
    transition: transform 0.15s ease;
  }

  .expand-toggle[aria-expanded="true"]::before {
    transform: rotate(180deg);
  }

  .expiry-indicator {
    font-size: 0.6875rem;
    color: var(--ink-muted);
    margin-inline-start: auto;
  }

  /* Syntax highlighting */
  .syntax-plain { color: var(--ink); }
  .syntax-json .key { color: var(--blue); }
  .syntax-json .string { color: var(--green); }
  .syntax-json .number { color: var(--amber); }
  .syntax-json .bool { color: #AF52DE; }
  .syntax-json .null { color: var(--ink-muted); }
  .syntax-yaml .key { color: var(--blue); }
  .syntax-yaml .string { color: var(--green); }
  .syntax-yaml .number { color: var(--amber); }
  .syntax-html .tag { color: var(--red); }
  .syntax-html .attr-name { color: var(--blue); }
  .syntax-html .attr-value { color: var(--green); }
  .syntax-html .comment { color: var(--ink-muted); font-style: italic; }
  .syntax-xml .tag { color: var(--red); }
  .syntax-xml .attr-name { color: var(--blue); }
  .syntax-xml .attr-value { color: var(--green); }
  .syntax-markdown .heading { color: var(--blue); font-weight: 600; }
  .syntax-markdown .bold { font-weight: 700; }
  .syntax-markdown .italic { font-style: italic; }
  .syntax-markdown .code { background: var(--surface); border-radius: 4px; padding: 0 4px; }
  .syntax-markdown .link { color: var(--blue); }

  /* Format badges */
  .format-badge {
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--surface);
    color: var(--ink-soft);
  }
  .format-badge[data-format="json"] { background: rgba(0, 122, 255, 0.15); color: var(--blue); }
  .format-badge[data-format="yaml"] { background: rgba(88, 86, 214, 0.15); color: #5856D6; }
  .format-badge[data-format="html"] { background: rgba(255, 59, 48, 0.15); color: var(--red); }
  .format-badge[data-format="xml"] { background: rgba(255, 149, 0, 0.15); color: var(--amber); }
  .format-badge[data-format="markdown"] { background: rgba(52, 199, 89, 0.15); color: var(--green); }
  .format-badge[data-format="plain"] { background: var(--surface); color: var(--ink-soft); }

  .message-copy-btn.copied { color: var(--green); }
  .message-time { color: var(--ink-muted); font-size: 0.6875rem; }
}

@layer states {
  .status-waiting {
    color: var(--amber);
  }
  .status-connected {
    color: var(--green-strong);
  }
  .status-relay {
    color: var(--green);
  }
  .status-disconnected {
    color: var(--red);
  }

  .status-waiting .status-dot {
    animation: pulse 1.4s ease-in-out infinite;
  }

  .drop-zone.disabled {
    cursor: not-allowed;
    opacity: 0.62;
  }

  .drop-zone.disabled .drop-content {
    pointer-events: none;
  }

  .drop-zone.drag-over {
    border-color: var(--blue);
    background: linear-gradient(
      180deg,
      color-mix(in srgb, var(--blue), white 90%),
      color-mix(in srgb, var(--teal), white 88%)
    );
    transform: translateY(-1px);
  }

  .drop-zone:not(.disabled):hover {
    border-color: color-mix(in srgb, var(--blue), transparent 25%);
  }

  .btn-kick:hover,
  .btn-ban:hover,
  .btn-delete:hover {
    border-color: color-mix(in srgb, var(--red), transparent 44%);
    color: var(--red);
  }

  @keyframes pulse {
    50% {
      opacity: 0.34;
      transform: scale(0.86);
    }
  }

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

@layer responsive {
  @container (max-width: 760px) {
    .room-body {
      grid-template-columns: 1fr;
    }

    .clients-panel {
      max-block-size: 220px;
      border-block-start: 1px solid var(--line);
      border-inline-start: 0;
    }

    .clients-list {
      grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    }
  }

  @media (max-width: 760px) {
    #screen-room.active {
      block-size: auto;
      min-block-size: 100dvh;
      overflow-y: auto;
    }

    .room-body {
      display: grid;
      grid-template-columns: 1fr;
      grid-template-rows: minmax(0, auto) auto;
      margin: 10px;
      overflow-x: hidden;
    }

    .room-main {
      overflow-x: hidden;
      padding-block-end: 0;
    }

    .clients-panel {
      max-block-size: 220px;
      border-block-start: 1px solid var(--line);
      border-inline-start: 0;
    }

    .clients-list {
      grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    }

    .room-header {
      align-items: flex-start;
      flex-wrap: wrap;
    }

    .room-info {
      order: 3;
      inline-size: 100%;
    }

    .room-code {
      flex: 1;
      text-align: center;
    }

    .share-row,
    .join-form {
      grid-template-columns: 1fr;
    }

    .share-row {
      display: grid;
    }

    .drop-zone {
      min-block-size: 210px;
      margin: 10px;
      overflow: hidden;
    }

    .drop-content {
      inline-size: 100%;
      max-inline-size: 100%;
      padding: 18px 12px;
    }

    #drop-ready {
      grid-template-columns: 1fr;
    }

    .drop-label,
    .drop-sub {
      max-inline-size: 100%;
      overflow-wrap: anywhere;
    }

    .expiry-bar {
      inline-size: min(100%, 260px);
      justify-self: center;
    }

    .expiry-option {
      display: grid;
      grid-template-columns: auto auto minmax(48px, 1fr) auto;
      inline-size: 100%;
      min-inline-size: 0;
    }

    .expiry-input {
      inline-size: 100%;
      min-inline-size: 0;
    }

    .file-item {
      grid-template-columns: auto minmax(0, 1fr);
    }

    .file-actions {
      grid-column: 1 / -1;
      justify-content: flex-start;
    }
  }

  @media (max-width: 420px) {
    .brand-mark {
      inline-size: 122px;
    }

    .brand-lockup h1 {
      font-size: 34px;
    }

    .home-actions {
      inline-size: 100%;
    }
  }
}

@supports not (color: color-mix(in srgb, white, black)) {
  :root {
    --panel: rgba(255, 255, 255, 0.78);
    --line: rgba(109, 127, 143, 0.26);
  }
}
