/* Neutral grayscale theme — a quiet tool surface so the cast content stays in focus. */
:root {
  color-scheme: light;

  --bg-canvas: #fafafa;
  --bg-surface: #ffffff;
  --bg-subtle: #f4f4f5;
  --bg-elevated: #ffffff;
  --border-soft: #e4e4e7;
  --border-strong: #d4d4d8;
  --text-primary: #18181b;
  --text-secondary: #52525b;
  --text-faint: #a1a1aa;

  --accent: #18181b;
  --accent-hover: #27272a;
  --accent-active: #3f3f46;
  --accent-ink: #ffffff;
  --accent-soft: #f4f4f5;
  --accent-strong-ink: #18181b;

  --stage-bg: #0a0a0a;
  --stage-border: #27272a;
  --stage-text: #fafafa;
  --stage-muted: #a1a1aa;

  /* Desaturated semantic colors, used only for status. */
  --ok: #2f6b48;
  --ok-bg: #eff5f1;
  --ok-border: #c9ddd0;
  --warn: #85591a;
  --warn-bg: #f8f4ec;
  --warn-border: #e6d7bb;
  --err: #a63a30;
  --err-bg: #f9efed;
  --err-border: #eccac5;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --radius-xl: 12px;
  --shadow-sm: none;
  --shadow-md: 0 8px 24px -8px rgba(0, 0, 0, 0.14), 0 1px 2px rgba(0, 0, 0, 0.04);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", "Hiragino Sans", "Yu Gothic", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

:root[data-theme="night"] {
  color-scheme: dark;

  --bg-canvas: #0a0a0a;
  --bg-surface: #121212;
  --bg-subtle: #1a1a1a;
  --bg-elevated: #171717;
  --border-soft: #262626;
  --border-strong: #3a3a3a;
  --text-primary: #f5f5f5;
  --text-secondary: #a3a3a3;
  --text-faint: #737373;

  --accent: #f5f5f5;
  --accent-hover: #e5e5e5;
  --accent-active: #d4d4d4;
  --accent-ink: #0a0a0a;
  --accent-soft: #1f1f1f;
  --accent-strong-ink: #f5f5f5;

  --stage-bg: #000000;
  --stage-border: #1f1f1f;

  --ok: #8fc3a3;
  --ok-bg: #131d17;
  --ok-border: #24382b;
  --warn: #d6b47a;
  --warn-bg: #1f1a11;
  --warn-border: #3b311f;
  --err: #e09a90;
  --err-bg: #221413;
  --err-border: #43261f;

  --shadow-md: 0 8px 24px -8px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.04);
}

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  background: var(--bg-canvas);
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg-canvas);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: color-mix(in srgb, var(--text-primary) 18%, transparent);
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 1000;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  left: 16px;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible,
[role="button"]:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
}

.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

.icon-sm {
  width: 16px;
  height: 16px;
}

.icon-lg {
  width: 22px;
  height: 22px;
}

.icon-xl {
  width: 30px;
  height: 30px;
}

/* ---------------- Topbar & Brand ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg-canvas) 86%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
  color: var(--text-primary);
}

.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  min-height: 68px;
  padding: 10px 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text-primary);
  text-decoration: none;
  border-radius: var(--radius-sm);
  padding: 2px;
  transition: opacity 0.15s ease;
}

@media (hover: hover) and (pointer: fine) {
  .brand:hover {
    opacity: 0.72;
  }
}

.brand-mark {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: inline-flex;
  color: var(--text-primary);
}

.brand-mark svg {
  width: 100%;
  height: 100%;
}

.brand-mark .brand-mark-octopus {
  fill: var(--bg-canvas);
}

.brand-mark .brand-mark-signal {
  stroke: var(--bg-canvas);
}

.brand-wordmark {
  font-family: var(--font-sans);
  font-weight: 650;
  font-size: 1.02rem;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--text-primary);
  display: inline-flex;
  align-items: baseline;
  gap: 0.3em;
}

.brand-cast {
  color: var(--text-secondary);
  font-weight: 450;
}

.brand-tag {
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
}

.topbar-secondary {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-menu {
  position: relative;
  display: none;
}

.topbar-menu > summary {
  list-style: none;
}

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

.topbar-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 60;
  width: min(280px, calc(100vw - 28px));
  padding: 8px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-md);
}

.topbar-menu-email {
  display: block;
  padding: 8px 10px 10px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 4px;
}

.topbar-menu-item {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-weight: 600;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: transform 140ms var(--ease-out), background 150ms ease;
}

.topbar-menu-item:hover {
  background: var(--bg-subtle);
}

.topbar-menu-preferences {
  display: none;
  padding-bottom: 6px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border-soft);
}

.topbar-menu-language {
  padding: 4px;
}

.topbar-menu-language .lang-switch {
  width: 100%;
  justify-content: space-between;
}

.topbar-menu-language .lang-btn {
  flex: 1;
}

.topbar-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 600;
  padding: 0 12px;
  border-radius: var(--radius-md);
  transition: background 0.15s ease, color 0.15s ease;
}

.topbar-link:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.user-pill {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  color: var(--text-secondary);
  background: var(--bg-subtle);
  border: 1px solid var(--border-soft);
  padding: 0 14px;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 3px 3px 3px 10px;
  gap: 2px;
}

.lang-switch::before {
  content: "";
  width: 16px;
  height: 16px;
  margin-right: 4px;
  flex-shrink: 0;
  background: var(--text-secondary);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M2 12h20'/%3E%3Cpath d='M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M2 12h20'/%3E%3Cpath d='M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.lang-btn {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  min-height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform 140ms var(--ease-out), background 0.15s ease, color 0.15s ease;
}

.lang-btn:hover:not(.active) {
  color: var(--text-primary);
}

.lang-btn.active {
  background: var(--bg-surface);
  color: var(--accent-strong-ink);
  box-shadow: var(--shadow-sm);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  border: 1px solid var(--border-soft);
  color: var(--text-secondary);
  cursor: pointer;
  transition: transform 140ms var(--ease-out), opacity 140ms ease;
}

.theme-toggle:hover {
  opacity: 0.85;
}

.theme-toggle:active,
.lang-btn:active,
.seg-btn:active,
.topbar-menu-item:active {
  transform: scale(0.97);
}

.theme-toggle .theme-night-icon,
:root[data-theme="night"] .theme-toggle .theme-day-icon {
  display: none;
}

:root[data-theme="night"] .theme-toggle .theme-night-icon {
  display: inline-block;
}

.btn-topbar-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
  min-height: 40px;
  padding: 0 12px;
  font-size: 0.84rem;
  font-weight: 600;
}

.btn-topbar-ghost:hover:not(:disabled) {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

/* ---------------- Login Gate (Neutral, Zero Product Leak) ---------------- */

.gate-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg-canvas);
}

.gate-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xl);
  padding: 32px 28px;
  box-shadow: var(--shadow-md);
}

.gate-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 24px;
}

.gate-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.gate-icon-badge {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.gate-title {
  margin: 0 0 8px;
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.gate-desc {
  margin: 0 0 24px;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.gate-signin-box {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 80px;
  padding: 16px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
}

.gate-footnote {
  margin: 18px 0 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
  text-align: center;
}

/* ---------------- Main Container & Cards ---------------- */

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xl);
  padding: 28px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 20px;
}

.card-title-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.card-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

/* ---------------- Landing ---------------- */

.landing-hero {
  max-width: 760px;
  padding: 56px 0 56px;
}

.landing-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border-soft);
  padding: 5px 12px;
  border-radius: 999px;
  margin-bottom: 22px;
}

.eyebrow-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--ok);
}

.landing-hero h1 {
  margin: 0 0 20px;
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  text-wrap: balance;
}

.landing-hero h1 .accent {
  color: var(--text-secondary);
}

.landing-subtitle {
  margin: 0 0 30px;
  font-size: 1.1rem;
  line-height: 1.8;
  color: var(--text-secondary);
  max-width: 560px;
}

.landing-cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.hero-highlights {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin: 34px 0 0;
  padding: 26px 0 0;
  border-top: 1px solid var(--border-soft);
  list-style: none;
}

.hero-highlights li {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--text-primary);
}

.hero-highlight-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent);
}

.section-heading {
  margin: 0 0 18px;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

.info-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xl);
  padding: 26px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 150ms ease;
}

.info-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.info-card h2 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 600;
  color: var(--text-primary);
}

.info-card p {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-secondary);
}

.support-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.support-grid .card {
  margin-bottom: 0;
}

.support-grid .card-title {
  font-size: 1.1rem;
}

.support-list {
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 12px;
}

.support-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.92rem;
  color: var(--text-secondary);
}

.support-list .icon {
  color: var(--accent);
  margin-top: 3px;
}

.site-footer {
  width: min(1232px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0;
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.84rem;
  color: var(--text-secondary);
}

/* ---------------- Home Role Picker ---------------- */

.home-header {
  margin-bottom: 24px;
}

.home-header h1 {
  margin: 0 0 6px;
  font-size: clamp(1.6rem, 3vw, 2.1rem);
  font-weight: 600;
  letter-spacing: -0.015em;
  color: var(--text-primary);
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.role-card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xl);
  padding: 26px;
  background: var(--bg-canvas);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 22px;
  transition: border-color 150ms ease;
}

.role-card-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 12px;
}

.role-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.role-card h2 {
  margin: 0 0 4px;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.role-card p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.92rem;
}

.role-features {
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.role-features li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.role-features .icon {
  color: var(--accent);
}

/* ---------------- Buttons ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 0 18px;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  transition: transform 140ms var(--ease-out), background 150ms ease, border-color 150ms ease, color 150ms ease, box-shadow 150ms ease, opacity 150ms ease;
  white-space: nowrap;
  user-select: none;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-lg {
  min-height: 54px;
  padding: 0 26px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius-md);
}

.btn-sm {
  min-height: 36px;
  padding: 0 13px;
  font-size: 0.82rem;
  border-radius: var(--radius-sm);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:active:not(:disabled) {
  background: var(--accent-active);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-soft);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-subtle);
}

.btn-danger {
  background: var(--err-bg);
  color: var(--err);
  border-color: var(--err-border);
}

.btn-danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--err) 18%, var(--bg-surface));
}

.btn-danger-outline {
  background: var(--bg-surface);
  color: var(--err);
  border-color: var(--err-border);
}

.btn-danger-outline:hover:not(:disabled) {
  background: var(--err-bg);
}

/* ---------------- Badges & Banners ---------------- */

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.row-between {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border-soft);
  white-space: nowrap;
}

.badge-ok {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: var(--ok-border);
}

.badge-warn {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: var(--warn-border);
}

.badge-err {
  background: var(--err-bg);
  color: var(--err);
  border-color: var(--err-border);
}

.badge-live {
  background: var(--accent-soft);
  color: var(--accent-strong-ink);
  border-color: var(--border-soft);
}

.banner {
  border-radius: var(--radius-md);
  padding: 13px 16px;
  margin-top: 14px;
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.banner-content {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex: 1;
  min-width: 200px;
}

.banner-content .icon {
  margin-top: 2px;
}

.banner-info {
  background: var(--accent-soft);
  color: var(--accent-strong-ink);
  border: 1px solid var(--border-soft);
}

.banner-warn {
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid var(--warn-border);
}

.banner-err {
  background: var(--err-bg);
  color: var(--err);
  border: 1px solid var(--err-border);
}

.muted-text {
  color: var(--text-secondary);
  font-size: 0.88rem;
}

/* ---------------- Segmented & Inputs ---------------- */

.control-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-label {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-primary);
}

.seg-group {
  display: inline-flex;
  flex-wrap: wrap;
  align-self: flex-start;
  background: var(--bg-subtle);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
}

.seg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  padding: 0 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform 140ms var(--ease-out), background 150ms ease, color 150ms ease, box-shadow 150ms ease;
}

.seg-btn:hover:not(:disabled):not(.active) {
  color: var(--text-primary);
  background: color-mix(in srgb, var(--bg-surface) 60%, transparent);
}

.seg-btn.active {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow-sm);
}

.seg-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.input-code,
.input-text {
  font: inherit;
  border: 1.5px solid var(--border-soft);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input-code:focus,
.input-text:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}

.input-code {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-align: center;
  width: 220px;
  max-width: 100%;
  padding: 10px 14px;
}

.input-code::placeholder {
  color: var(--text-faint);
  letter-spacing: 0.24em;
}

.input-text {
  font-size: 0.94rem;
  padding: 11px 14px;
  width: 100%;
  min-width: 180px;
}

.input-text::placeholder {
  color: var(--text-faint);
}

.input-code:disabled,
.input-text:disabled {
  background: var(--bg-subtle);
  color: var(--text-secondary);
}

/* ---------------- Receiver Invite & Stage ---------------- */

.invite-panel {
  background: var(--bg-canvas);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.code-box {
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--accent-soft);
  color: var(--accent-strong-ink);
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-soft);
}

.code-label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--accent-strong-ink);
  opacity: 0.85;
  letter-spacing: 0.04em;
}

.code-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 2.1rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  line-height: 1.15;
  color: var(--accent-strong-ink);
}

.invite-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 220px;
}

.invite-timer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.invite-timer .icon {
  color: var(--text-secondary);
}

.receiver-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.receiver-more {
  position: relative;
}

.receiver-more > summary {
  list-style: none;
}

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

.receiver-more-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 30;
  width: min(260px, calc(100vw - 56px));
  padding: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

.receiver-seat-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px 10px;
}

.receiver-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 2px 10px;
  border-top: 1px solid var(--border-soft);
  cursor: pointer;
}

.rx-lan-inline {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border-soft);
  cursor: pointer;
}

.cast-switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 38px;
  height: 22px;
  margin: 0;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg-subtle);
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 140ms var(--ease-out), border-color 140ms var(--ease-out);
}

.cast-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: transform 140ms var(--ease-out), background-color 140ms var(--ease-out);
}

.cast-switch:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.cast-switch:checked::after {
  transform: translateX(16px);
  background: var(--accent-contrast, var(--bg-surface));
}

.cast-switch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.cast-switch:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.tx-error-actions {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.receiver-menu-item {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: transform 140ms var(--ease-out), background 150ms ease;
}

.receiver-menu-item:hover:not(:disabled) {
  background: var(--bg-subtle);
}

.receiver-menu-item:active:not(:disabled) {
  transform: scale(0.97);
}

.receiver-menu-item:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.receiver-menu-item-danger {
  color: var(--err);
}

.receiver-menu-item-danger:hover:not(:disabled) {
  background: var(--err-bg);
}

.receiver-menu-divider {
  height: 1px;
  margin: 6px 0;
  background: var(--border-soft);
}

.receiver-stage-shell {
  background: var(--bg-subtle);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xl);
  padding: 14px;
  margin-top: 14px;
}

.video-stage {
  background: var(--stage-bg);
  border: 1px solid var(--stage-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-stage video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--stage-bg);
}

#rxEmptyState {
  background: var(--bg-surface);
}

.video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--stage-muted);
  text-align: center;
  padding: 24px;
  gap: 10px;
  pointer-events: none;
}

.placeholder-icon {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.08);
  color: var(--stage-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.placeholder-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--stage-text);
}

.placeholder-desc {
  font-size: 0.9rem;
  max-width: 440px;
  color: var(--stage-muted);
}

#rxEmptyState .video-placeholder {
  color: var(--text-secondary);
}

#rxEmptyState .placeholder-icon {
  background: var(--accent-soft);
  color: var(--accent);
}

#rxEmptyState .placeholder-title {
  color: var(--text-primary);
}

#rxEmptyState .placeholder-desc {
  color: var(--text-secondary);
}

.cast-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
}

.cast-grid[data-count="2"],
.cast-grid[data-count="3"],
.cast-grid[data-count="4"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cast-grid.has-focus {
  grid-template-columns: 1fr;
}

.cast-tile {
  background: var(--bg-surface);
  border: 1.5px solid var(--border-soft);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  position: relative;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.18s ease, filter 0.18s ease;
  outline: none;
  touch-action: pan-y;
}

.cast-tile.is-reorder-ready {
  border-color: var(--accent);
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent),
    0 14px 34px rgba(0, 0, 0, 0.28);
  transform: translateY(-4px) scale(1.015);
  cursor: grabbing;
  user-select: none;
  -webkit-user-select: none;
}

.cast-tile.is-receiver-fullscreen,
.cast-grid.is-receiver-fullscreen[data-count="1"] .cast-tile {
  cursor: default;
}

.cast-tile.is-leaving {
  animation: receiver-tile-leave 200ms var(--ease-out) forwards;
  pointer-events: none;
}

.cast-tile.is-dragging {
  position: fixed !important;
  z-index: 80;
  margin: 0;
  opacity: 0.92;
  pointer-events: none;
  transform: scale(1.035) rotate(0.4deg);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.38);
  transition: none;
}

.cast-tile-placeholder {
  min-height: 0;
  aspect-ratio: 16 / 9;
  background: color-mix(in srgb, var(--text-primary) 5%, transparent);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}

.is-reordering-cast-tiles {
  user-select: none;
  -webkit-user-select: none;
}

@keyframes receiver-tile-leave {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(0.97) translateY(-4px);
  }
}

.cast-grid:not([data-count="0"]):not([data-count="1"]) .cast-tile:not(.is-dragging) {
  cursor: grab;
}

.cast-grid:not([data-count="0"]):not([data-count="1"]) .cast-tile.is-reorder-ready {
  cursor: grabbing;
}

.cast-grid.is-receiver-fullscreen[data-count="1"] .cast-tile.is-reorder-ready {
  cursor: default;
}

.cast-tile.is-focused {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
  order: -1;
}

.cast-grid.has-focus .cast-tile:not(.is-focused) {
  opacity: 0.9;
}

.tile-media {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--stage-bg);
  overflow: hidden;
}

.cast-tile:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 24%, transparent);
}

.tile-main-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: var(--stage-bg);
}

.tile-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  color: var(--stage-text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 16px;
  font-size: 0.92rem;
  font-weight: 600;
  z-index: 3;
}

/* Dual-source PiP (click to cycle corner so captions/edges aren't blocked) */
.pip-wrap {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 24%;
  min-width: 108px;
  max-width: 220px;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
  background: var(--stage-bg);
  z-index: 2;
  cursor: pointer;
}

.pip-wrap[data-corner="top-right"] {
  top: 12px;
  right: 12px;
  bottom: auto;
  left: auto;
}

.pip-wrap[data-corner="bottom-left"] {
  left: 12px;
  bottom: 12px;
  right: auto;
  top: auto;
}

.pip-wrap[data-corner="top-left"] {
  top: 12px;
  left: 12px;
  right: auto;
  bottom: auto;
}

.pip-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.pip-label {
  position: absolute;
  left: 6px;
  top: 6px;
  background: rgba(0, 0, 0, 0.72);
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}

.tile-controls {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.82), transparent 65%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s ease, visibility 0.15s ease;
}

.tile-controls .row {
  max-width: 100%;
  flex-wrap: wrap;
  justify-content: center;
}

.tile-controls .tile-title-wrap {
  pointer-events: none;
  justify-content: center;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.76);
  backdrop-filter: blur(8px);
}

.tile-controls .tile-device-name {
  color: #ffffff;
}

.tile-controls.is-open,
.cast-tile:focus-within .tile-controls {
  opacity: 1;
  visibility: visible;
}

@media (hover: hover) and (pointer: fine) {
  .cast-tile:hover .tile-controls {
    opacity: 1;
    visibility: visible;
  }
}

.tile-controls .row {
  pointer-events: auto;
}

.cast-tile:hover .tile-controls.is-idle,
.cast-tile:focus-within .tile-controls.is-idle,
.cast-tile .tile-controls.is-open.is-idle,
.receiver-fullscreen-exit.is-idle {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.tile-title-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.tile-device-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.btn-tile {
  min-height: 34px;
  padding: 0 11px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-tile-dark {
  background: var(--bg-subtle);
  color: var(--text-primary);
  border-color: var(--border-soft);
}

.btn-tile-dark:hover:not(:disabled) {
  background: var(--accent-soft);
  color: var(--accent-strong-ink);
}

.btn-tile-muted {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: var(--warn-border);
}

.btn-tile-muted:hover:not(:disabled) {
  background: color-mix(in srgb, var(--warn) 12%, var(--bg-surface));
}

.receiver-fullscreen-exit {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 100;
  min-height: 40px;
  padding: 0 14px;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.78);
  border-color: rgba(255, 255, 255, 0.42);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(10px);
  transition: opacity 0.15s ease, visibility 0.15s ease;
}

.has-receiver-fallback-fullscreen {
  overflow: hidden;
}

.is-receiver-fullscreen {
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  border-radius: 0 !important;
  background: var(--stage-bg);
}

.cast-grid.is-receiver-fullscreen {
  padding: 0;
  gap: 0;
  align-content: stretch;
  grid-auto-rows: minmax(0, 1fr);
}

.cast-grid.is-receiver-fullscreen .cast-tile {
  min-height: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: var(--stage-bg);
}

.cast-grid.is-receiver-fullscreen .cast-tile-placeholder {
  aspect-ratio: auto;
  border-radius: 0;
}

.cast-grid.is-receiver-fullscreen .tile-media {
  min-height: 0;
  flex: 1;
  aspect-ratio: auto;
}

.cast-tile.is-receiver-fullscreen .tile-media {
  flex: 1;
  aspect-ratio: auto;
  min-height: 0;
}

.cast-tile.is-receiver-fullscreen {
  border: 0;
  box-shadow: none;
  background: var(--stage-bg);
}

.is-fallback-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 90;
}

/* ---------------- Sender Workspace ---------------- */

.sender-workspace {
  display: grid;
  grid-template-columns: minmax(320px, 440px) minmax(0, 1fr);
  grid-template-areas:
    "source preview"
    "pairing preview";
  gap: 22px;
  align-items: start;
}

.sender-source-pane {
  grid-area: source;
}

.sender-pairing-pane {
  grid-area: pairing;
}

.sender-preview-pane {
  grid-area: preview;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sender-capture-actions .btn,
.sender-cast-actions .btn {
  flex: 1;
}

.sender-section-box {
  background: var(--bg-canvas);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.permission-note {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  font-size: 0.84rem;
  color: var(--text-primary);
}

.permission-note .icon {
  color: var(--text-secondary);
  margin-top: 2px;
}

.permission-details {
  flex: 1;
  min-width: 0;
}

.permission-details summary {
  cursor: pointer;
  font-weight: 600;
}

.permission-details p {
  margin: 8px 0 0;
  color: var(--text-secondary);
}

.meter-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-canvas);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 11px 14px;
}

.meter-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 180px;
}

.meter-left .icon {
  color: var(--accent);
}

.meter-bar-bg {
  flex: 1;
  max-width: 240px;
  height: 10px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  overflow: hidden;
}

.meter-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.08s linear;
}

/* ---------------- Collapsible Diagnostics ---------------- */

.diag-details {
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.diag-summary {
  list-style: none;
  cursor: pointer;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-weight: 600;
  color: var(--text-primary);
  user-select: none;
}

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

.diag-summary:hover {
  background: var(--bg-subtle);
}

.diag-summary .icon {
  color: var(--accent);
}

.diag-chevron {
  transition: transform 0.18s ease;
}

.diag-details[open] .diag-chevron {
  transform: rotate(180deg);
}

.diag-body {
  padding: 18px 24px 24px;
  border-top: 1px solid var(--border-soft);
}

.diag-body > .meter-wrap {
  margin-top: 10px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.stat-item {
  background: var(--bg-canvas);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 11px 13px;
}

.stat-label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 3px;
  word-break: break-word;
}

.peer-stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.peer-stats-table th,
.peer-stats-table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-soft);
  font-family: var(--font-mono);
}

.peer-stats-table th {
  font-family: inherit;
  color: var(--text-secondary);
  background: var(--bg-canvas);
  font-weight: 600;
}

.log-box {
  background: var(--stage-bg);
  color: #d4d4d4;
  font-family: var(--font-mono);
  font-size: 0.79rem;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  max-height: 190px;
  overflow-y: auto;
  white-space: pre-wrap;
  margin-top: 14px;
  border: 1px solid var(--stage-border);
}

/* ---------------- Responsive ---------------- */

@media (max-width: 1020px) {
  .topbar-inner {
    flex-wrap: nowrap;
  }

  .topbar-secondary {
    display: none;
  }

  .topbar-menu {
    display: block;
  }

  .landing-hero {
    padding: 24px 0 36px;
  }

  .info-grid,
  .support-grid,
  .sender-workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "source"
      "preview"
      "pairing";
  }
}

@media (max-width: 780px) {
  .topbar-inner {
    padding: 10px 14px;
  }

  .user-pill {
    display: none;
  }

  .container {
    padding: 18px 14px 44px;
  }

  .card {
    padding: 20px 16px;
    border-radius: var(--radius-lg);
  }

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

  .receiver-tools {
    width: 100%;
  }

  .receiver-tools > .btn {
    flex: 1;
  }

  .receiver-more {
    flex: 0 0 auto;
  }

  .receiver-more-panel {
    position: fixed;
    top: auto;
    right: 14px;
    bottom: 14px;
    width: calc(100vw - 28px);
    max-width: 360px;
  }

  .sender-capture-actions .btn,
  .sender-cast-actions .btn:not(.sender-preview-btn) {
    flex-basis: 100%;
  }

  .hero-highlights {
    gap: 10px;
  }

  .hero-highlights li {
    font-size: 0.84rem;
  }

  .cast-grid[data-count="2"],
  .cast-grid[data-count="3"],
  .cast-grid[data-count="4"] {
    grid-template-columns: 1fr;
  }

  .cast-grid.is-receiver-fullscreen[data-count="2"],
  .cast-grid.is-receiver-fullscreen[data-count="3"],
  .cast-grid.is-receiver-fullscreen[data-count="4"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .code-value {
    font-size: 1.7rem;
  }
}

@media (max-width: 640px) {
  .topbar-inner {
    min-height: 64px;
  }

  .topbar-actions {
    flex-wrap: nowrap;
  }

  .topbar-actions > .topbar-inline-preference {
    display: none;
  }

  .topbar-menu-preferences {
    display: block;
  }

  .topbar-menu > summary,
  .topbar-menu-preferences .topbar-menu-item,
  .topbar-menu-language .lang-btn {
    min-height: 44px;
  }

  .topbar-menu > summary {
    width: 44px;
    height: 44px;
  }
}

/* ---------------- Cast App Shell (Receiver-First + Full-Viewport Stage) ---------------- */

.cast-app-body {
  --app-topbar-height: 56px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.cast-app-body[data-receiving="true"] {
  --app-topbar-height: 48px;
}

.cast-app-body[data-receiving="true"] .app-topbar-inner,
.cast-app-body[data-casting="true"] .app-topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cast-app-body[data-receiving="true"] .mode-tabs,
.cast-app-body[data-casting="true"] .mode-tabs,
.cast-app-body[data-receiving="true"] .app-theme-inline,
.cast-app-body[data-receiving="true"] .app-lang-inline {
  display: none;
}

.cast-app-body[data-receiving="true"] .app-menu-theme-wrap,
.cast-app-body[data-receiving="true"] .app-menu-lang-wrap {
  display: block;
}

.app-topbar {
  min-height: var(--app-topbar-height);
}

.app-topbar-inner {
  max-width: none;
  min-height: var(--app-topbar-height);
  padding: 6px 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.app-topbar-inner > .brand {
  justify-self: start;
}

.app-topbar-actions {
  justify-self: end;
  flex-wrap: nowrap;
  gap: 6px;
}

.app-topbar .theme-toggle {
  width: 34px;
  height: 34px;
}

.app-topbar .lang-switch {
  min-height: 34px;
  padding: 2px 2px 2px 8px;
}

.app-topbar .lang-btn {
  min-height: 28px;
  padding: 0 8px;
  font-size: 0.76rem;
}

.app-overflow-menu {
  display: block;
}

.app-menu-theme-wrap {
  display: none;
}

.app-menu-theme-btn .theme-night-icon,
:root[data-theme="night"] .app-menu-theme-btn .theme-day-icon {
  display: none;
}

:root[data-theme="night"] .app-menu-theme-btn .theme-night-icon {
  display: inline-block;
}

.app-menu-lang-wrap {
  display: none;
  padding: 6px 4px 8px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 4px;
}

.app-menu-lang-wrap .lang-switch {
  width: 100%;
  justify-content: space-between;
}

.app-menu-lang-wrap .lang-btn {
  flex: 1;
}

/* Segmented Mode Tabs in Topbar */
.mode-tabs {
  justify-self: center;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  border: 1px solid var(--border-soft);
}

.mode-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition:
    transform 140ms var(--ease-out),
    background-color 180ms var(--ease-out),
    color 160ms var(--ease-out);
}

.mode-tab:active {
  transform: scale(0.97);
}

.mode-tab.active {
  background: var(--accent);
  color: var(--accent-ink);
}

@media (hover: hover) and (pointer: fine) {
  .mode-tab:hover:not(.active) {
    color: var(--text-primary);
    background: color-mix(in srgb, var(--bg-surface) 70%, transparent);
  }
}

/* Origin-aware popovers & menus */
.topbar-menu-panel,
.receiver-more-panel {
  transform-origin: top right;
  transition: opacity 180ms var(--ease-out), transform 180ms var(--ease-out);
}

@starting-style {
  .topbar-menu[open] > .topbar-menu-panel,
  .receiver-more[open] > .receiver-more-panel {
    opacity: 0;
    transform: scale(0.95) translateY(-4px);
  }
}

/* Active Receiver Toolbar inside Topbar */
.rx-active-toolbar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.rx-active-toolbar .btn-sm {
  min-height: 34px;
  padding: 0 11px;
}

.rx-invite-popover-wrap {
  position: relative;
}

.rx-invite-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 70;
  width: min(300px, calc(100vw - 24px));
  padding: 16px;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  transform-origin: top right;
  opacity: 0;
  transform: scale(0.95) translateY(-4px);
  pointer-events: none;
  transition: opacity 140ms var(--ease-out), transform 140ms var(--ease-out);
}

.rx-invite-popover[data-open="true"] {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
  transition: opacity 180ms var(--ease-out), transform 180ms var(--ease-out);
}

.rx-popover-qr {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.rx-popover-code-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.rx-popover-code-row {
  width: 100%;
}

.rx-popover-meta {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.rx-popover-rotate {
  width: 100%;
}

/* Main Area */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.receiver-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Waiting Stage: Centered Pairing Card */
.rx-waiting-stage {
  flex: 1;
  min-height: calc(100dvh - var(--app-topbar-height));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 28px 18px 40px;
}

.rx-pairing-card {
  width: min(420px, 100%);
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xl);
  padding: 26px 26px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
  transition: opacity 220ms var(--ease-out), transform 220ms var(--ease-out);
}

@starting-style {
  .rx-pairing-card {
    opacity: 0;
    transform: scale(0.97) translateY(4px);
  }
}

.rx-pairing-status {
  display: flex;
  align-items: center;
  justify-content: center;
}

.rx-pairing-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rx-pairing-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.rx-pairing-subtitle {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--text-secondary);
  max-width: 330px;
}

/* Placeholder QR Code */
.rx-qr-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.rx-qr-frame {
  position: relative;
  width: 176px;
  height: 176px;
  padding: 12px;
  border-radius: var(--radius-lg);
  background: var(--bg-canvas);
  border: 1px solid var(--border-soft);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.rx-qr-frame-sm {
  width: 132px;
  height: 132px;
  padding: 10px;
}

.rx-qr-svg {
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0.86;
}

.rx-qr-center-mark {
  position: absolute;
  width: 34px;
  height: 34px;
  padding: 3px;
  border-radius: 10px;
  background: var(--bg-canvas);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.rx-qr-center-mark svg {
  width: 100%;
  height: 100%;
}

.rx-qr-center-mark .brand-mark-octopus {
  fill: var(--bg-canvas);
}

.rx-qr-center-mark .brand-mark-signal {
  stroke: var(--bg-canvas);
}

.rx-qr-caption {
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-faint);
  letter-spacing: 0.01em;
}

/* Divider */
.rx-pairing-divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 500;
}

.rx-pairing-divider::before,
.rx-pairing-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-soft);
}

/* Room Code Pill */
.rx-code-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
}

.rx-code-pill {
  flex: 1;
  min-height: 56px;
  padding: 8px 14px 8px 18px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-soft);
  background: var(--bg-subtle);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  font: inherit;
  transition:
    transform 140ms var(--ease-out),
    border-color 150ms ease,
    background-color 150ms ease;
}

.rx-code-pill:active {
  transform: scale(0.97);
}

.rx-code-pill-sm {
  width: 100%;
  min-height: 46px;
  padding: 6px 12px 6px 14px;
}

.rx-code-digits {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  line-height: 1.1;
  color: var(--text-primary);
}

.rx-code-pill-sm .rx-code-digits {
  font-size: 1.35rem;
  letter-spacing: 0.12em;
}

.rx-code-copy-action,
.rx-code-copy-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: color 140ms ease, border-color 140ms ease;
}

.rx-icon-btn {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-soft);
  background: var(--bg-surface);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    transform 140ms var(--ease-out),
    background-color 150ms ease,
    border-color 150ms ease,
    color 150ms ease;
}

.rx-icon-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.rx-icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.rx-icon-btn-sm {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-md);
}

@media (hover: hover) and (pointer: fine) {
  .rx-code-pill:hover {
    border-color: var(--border-strong);
    background: var(--bg-surface);
  }

  .rx-code-pill:hover .rx-code-copy-action,
  .rx-code-pill:hover .rx-code-copy-badge {
    color: var(--text-primary);
    border-color: var(--border-strong);
  }

  .rx-icon-btn:hover:not(:disabled) {
    background: var(--bg-subtle);
    border-color: var(--border-strong);
    color: var(--text-primary);
  }
}

.rx-pairing-footer {
  width: 100%;
  padding-top: 12px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 12px;
}

.rx-pairing-footer .invite-timer {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.rx-seat-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.rx-seat-inline-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.seg-group-compact {
  padding: 2px;
  gap: 2px;
}

.seg-group-compact .seg-btn {
  min-height: 26px;
  padding: 0 9px;
  font-size: 0.78rem;
}

.rx-retry-btn {
  margin-top: 2px;
}

.rx-waiting-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
  text-align: center;
  max-width: 460px;
}

/* Full-Viewport Receiving Stage (fills nearly the entire screen below slim topbar) */
.rx-receiving-stage {
  position: relative;
  width: 100%;
  height: calc(100vh - var(--app-topbar-height));
  height: calc(100dvh - var(--app-topbar-height));
  background: var(--stage-bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.rx-stage-banners {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  width: min(640px, calc(100% - 24px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.rx-floating-banner {
  margin-top: 0;
  pointer-events: auto;
  box-shadow: var(--shadow-md);
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out);
}

@starting-style {
  .rx-floating-banner {
    opacity: 0;
    transform: scale(0.96) translateY(-6px);
  }
}

.rx-stage-grid {
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  gap: 2px;
  padding: 0;
  align-content: stretch;
  grid-auto-rows: minmax(0, 1fr);
}

.rx-stage-grid .cast-tile {
  min-height: 0;
  height: 100%;
  border: 0;
  border-radius: 0;
  background: var(--stage-bg);
}

.rx-stage-grid .tile-media {
  flex: 1;
  height: 100%;
  min-height: 0;
  aspect-ratio: auto;
}

.rx-stage-grid .cast-tile-placeholder {
  aspect-ratio: auto;
  border-radius: 0;
}

.rx-stage-grid.has-focus .cast-tile:not(.is-focused) {
  display: none;
}

/* Diagnostics drawer wrapper */
.app-diag-wrap {
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 16px 24px 32px;
}

/* Compact single-screen Sender layout */
.sender-container {
  padding: 18px 24px 28px;
}

.sender-card {
  padding: 20px;
  margin-bottom: 0;
}

.sender-workspace-compact {
  grid-template-columns: minmax(340px, 430px) minmax(0, 1fr);
  grid-template-areas: "controls preview";
  gap: 18px;
  align-items: start;
}

.sender-workspace-compact .sender-controls-pane {
  grid-area: controls;
  padding: 16px;
  gap: 14px;
}

.sender-pairing-row {
  display: grid;
  grid-template-columns: 156px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.input-code-compact {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  font-size: 1.15rem;
  line-height: 1;
  letter-spacing: 0.14em;
}

.input-code-compact::placeholder {
  letter-spacing: 0.14em;
}

.sender-workspace-compact .input-text {
  height: 44px;
  padding: 0 12px;
  line-height: 1;
  min-width: 0;
}

.sender-workspace-compact .sender-cast-actions {
  flex-wrap: nowrap;
}

.sender-quality-block {
  min-width: 0;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
}

.sender-quality-block legend {
  padding: 0 5px;
}

.sender-quality-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(64px, 0.7fr) minmax(0, 1fr);
  gap: 8px;
}

.sender-quality-field {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 600;
}

.quality-select {
  width: 100%;
  height: 38px;
  padding: 0 28px 0 10px;
  font: inherit;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: 7px;
}

.quality-select:disabled {
  color: var(--text-secondary);
  background: var(--bg-subtle);
}

.sender-quality-note,
.sender-quality-status {
  margin: 7px 0 0;
  font-size: 0.72rem;
  line-height: 1.45;
}

.sender-quality-note {
  color: var(--text-secondary);
}

.sender-quality-status {
  color: var(--text-primary);
  white-space: pre-line;
}

.sender-quality-block .banner {
  margin-top: 7px;
  padding: 8px 9px;
  font-size: 0.74rem;
}

.sender-workspace-compact .sender-preview-btn {
  flex: 0 0 auto;
  padding: 0 16px;
}

.sender-workspace-compact .sender-start-btn,
.sender-workspace-compact #btnStopCast {
  flex: 1 1 auto;
}

.permission-note-compact {
  padding: 9px 11px;
  font-size: 0.8rem;
}

.cast-app-body[data-receiving="true"] .app-diag-wrap {
  max-width: none;
  padding: 12px 16px 20px;
}

/* Responsive adjustments for Cast App */
@media (max-width: 1020px) {
  .app-lang-inline {
    display: none;
  }

  .app-menu-lang-wrap {
    display: block;
  }

  .app-topbar-inner {
    padding: 6px 12px;
    gap: 8px;
  }

  #btnRxFullscreenLabel,
  #btnRxCloseLabel {
    display: none;
  }

  .sender-workspace-compact {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "controls"
      "preview";
  }
}

@media (max-width: 520px) {
  .sender-pairing-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .sender-quality-grid {
    grid-template-columns: minmax(0, 1fr) minmax(76px, 0.55fr);
  }

  .sender-quality-field:last-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 780px) {
  .app-topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .app-topbar .brand-wordmark {
    display: none;
  }

  .mode-tab {
    padding: 0 11px;
    font-size: 0.8rem;
  }

  .rx-active-toolbar #rxSeatBadge,
  .rx-active-toolbar #btnRxToggleInviteLabel {
    display: none;
  }

  .rx-pairing-card {
    padding: 22px 18px 18px;
  }

  .rx-code-digits {
    font-size: 1.5rem;
  }

  .rx-stage-grid[data-count="2"],
  .rx-stage-grid[data-count="3"],
  .rx-stage-grid[data-count="4"] {
    grid-template-columns: 1fr;
  }

  .rx-stage-grid.is-receiver-fullscreen[data-count="2"],
  .rx-stage-grid.is-receiver-fullscreen[data-count="3"],
  .rx-stage-grid.is-receiver-fullscreen[data-count="4"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .rx-invite-popover {
    position: fixed;
    top: calc(var(--app-topbar-height) + 8px);
    right: 12px;
    left: 12px;
    width: auto;
    max-width: 340px;
    margin-left: auto;
  }
}

@media (hover: hover) and (pointer: fine) {
  .info-card:hover,
  .role-card:hover {
    border-color: var(--border-strong);
  }
}

@media (hover: none), (pointer: coarse) {
  .btn,
  .seg-btn,
  .lang-btn,
  .theme-toggle,
  .topbar-menu-item,
  .receiver-menu-item,
  .mode-tab {
    min-height: 44px;
  }

  .app-topbar .theme-toggle {
    width: 44px;
    height: 44px;
  }

  .theme-toggle {
    width: 44px;
    height: 44px;
  }

}

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