:root {
  color-scheme: light;
  --primary: #0056b3;
  --primary-hover: #004494;
  --primary-soft: #eef6ff;
  --bg: #f7f9fc;
  --surface: #ffffff;
  --text: #202b3c;
  --muted: #64748b;
  --border: #e3e9f1;
  --success: #16803d;
  --success-bg: #edf9f0;
  --danger: #b42318;
  --shadow: 0 10px 35px rgba(18, 44, 78, .06);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.6;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }
a { color: var(--primary); }
.container { width: min(1120px, calc(100% - 36px)); margin-inline: auto; }
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.header-inner { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--text); text-decoration: none; font-weight: 750; letter-spacing: -.02em; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; color: #fff; background: var(--primary); font-size: .9rem; font-weight: 800; }
.header-link { text-decoration: none; font-size: .92rem; font-weight: 650; color: var(--muted); }
.header-link:hover { color: var(--primary); }
.main-content { padding-block: 38px 24px; }
.tool-header { text-align: center; max-width: 760px; margin: 0 auto 28px; }
.eyebrow, .step-label { display: inline-block; color: var(--primary); font-size: .74rem; font-weight: 800; letter-spacing: .09em; }
.tool-header h1 { margin: 7px 0 10px; font-size: clamp(1.8rem, 4vw, 2.5rem); letter-spacing: -.04em; line-height: 1.2; }
.tool-header > p:last-child { max-width: 690px; margin: 0 auto; color: var(--muted); }
.tool-card { overflow: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); }
.tabs { display: flex; gap: 5px; padding: 10px 12px 0; background: #fbfcfe; border-bottom: 1px solid var(--border); }
.tab-btn { position: relative; border: 0; border-radius: 10px 10px 0 0; background: transparent; color: var(--muted); padding: 15px 23px; font-weight: 750; }
.tab-btn:hover { color: var(--primary); background: #f2f7fd; }
.tab-btn.active { color: var(--primary); background: var(--surface); }
.tab-btn.active::after { content: ""; position: absolute; bottom: -1px; left: 15px; right: 15px; height: 3px; background: var(--primary); border-radius: 3px 3px 0 0; }
.tab-content { padding: 24px; }
.hidden { display: none !important; }
.sync-grid { display: grid; grid-template-columns: minmax(300px, .88fr) minmax(0, 1.25fr); gap: 18px; align-items: stretch; }
.panel { min-width: 0; border: 1px solid var(--border); border-radius: 14px; padding: 22px; background: #fff; }
.panel-heading { margin-bottom: 18px; }
.panel-heading h2, .camera-copy h2 { margin: 4px 0 7px; font-size: 1.24rem; letter-spacing: -.025em; }
.panel-heading p, .camera-copy p { margin: 0; color: var(--muted); font-size: .91rem; }
.room-flex { display: grid; grid-template-columns: minmax(145px, 200px) minmax(0, 1fr); align-items: start; gap: 19px; }
.qr-frame { min-width: 0; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: #fff; text-align: center; }
#room-qr-canvas { display: block; width: 100%; max-width: 200px; height: auto; margin: 0 auto; image-rendering: pixelated; }
.qr-caption { display: block; margin-top: 8px; color: var(--muted); font-size: .76rem; }
.room-details { min-width: 0; }
.field-label { display: block; margin-bottom: 7px; font-size: .88rem; font-weight: 750; }
.room-code-row { display: flex; align-items: center; gap: 7px; margin-bottom: 12px; }
.room-code { display: block; min-width: 0; overflow-wrap: anywhere; padding: 10px 11px; border: 1px solid #c9dcf2; border-radius: 9px; background: var(--primary-soft); color: var(--primary); font-size: .92rem; font-weight: 800; letter-spacing: .025em; }
.icon-button { flex: 0 0 auto; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); font-size: .78rem; font-weight: 700; }
.field-divider { display: flex; align-items: center; gap: 10px; margin: 15px 0; color: #8793a5; font-size: .75rem; }
.field-divider::before, .field-divider::after { content: ""; height: 1px; flex: 1; background: var(--border); }
.join-form input, textarea, select { width: 100%; border: 1px solid #cfd8e4; border-radius: 9px; padding: 11px 12px; color: var(--text); background: #fff; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, textarea:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0, 86, 179, .12); }
textarea { display: block; resize: vertical; min-height: 112px; line-height: 1.55; }
.field-help { display: block; margin: 5px 0 0; color: var(--muted); font-size: .78rem; }
.join-form .field-help { margin-bottom: 10px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 10px 15px; border: 1px solid transparent; border-radius: 9px; font-weight: 750; font-size: .9rem; line-height: 1.3; transition: background .15s, border-color .15s, transform .15s; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { border-color: var(--border); background: #f8fafc; color: #344256; }
.btn-secondary:hover:not(:disabled) { background: #edf3f9; border-color: #cbd7e5; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #116b32; }
.btn-quiet { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-full { width: 100%; }
.join-form .btn { margin-top: 2px; }
.data-panel { display: flex; flex-direction: column; }
.field-group { margin-bottom: 17px; }
.action-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 9px; }
.action-row .field-help { margin: 0; }
.received-block { border-top: 1px solid var(--border); padding-top: 17px; margin-top: auto; }
.received-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.received-heading h3, .preview-title h3 { margin: 0; font-size: 1rem; }
.receive-content { min-height: 112px; max-height: 280px; overflow: auto; padding: 13px; border: 1px solid var(--border); border-radius: 9px; background: #f8fafc; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .91rem; }
.camera-panel { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.camera-copy { max-width: 620px; }
.camera-controls { display: flex; flex-wrap: wrap; gap: 9px; }
.reader { flex: 0 0 100%; width: min(520px, 100%); margin: 4px auto 0; border: 1px dashed #b9cbe0; border-radius: 12px; overflow: hidden; }
.status-message { min-height: 22px; margin: 14px 2px 0; color: var(--muted); font-size: .88rem; }
.status-message.success { color: var(--success); }
.status-message.error { color: var(--danger); }
.generator-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, .85fr); gap: 28px; align-items: start; }
.generator-form { min-width: 0; }
.generator-form .panel-heading { margin-bottom: 22px; }
.generator-preview { min-width: 0; padding: 18px; border: 1px solid var(--border); border-radius: 14px; background: #fbfcfe; }
.preview-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 15px; }
.preview-badge { padding: 3px 8px; border-radius: 6px; background: #eaf6ee; color: var(--success); font-size: .7rem; font-weight: 800; }
.qr-preview { display: grid; place-items: center; min-height: 300px; padding: 16px; border: 1px dashed #d4deea; border-radius: 12px; background: #fff; }
#qr-result-canvas { display: block; width: min(100%, 360px); height: auto; image-rendering: pixelated; }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 7px; text-align: center; color: var(--muted); font-size: .85rem; }
.empty-state strong { color: var(--text); }
.empty-icon { display: grid; place-items: center; width: 56px; height: 56px; border: 1px solid var(--border); border-radius: 14px; color: var(--primary); background: var(--primary-soft); font-size: 2rem; }
.generator-preview .btn { margin-top: 13px; }
.privacy-note { margin: 18px 2px 0; padding: 15px 17px; border: 1px solid #dbe7f4; border-radius: 12px; background: #f0f7ff; color: #35516f; font-size: .84rem; }
.privacy-note strong { display: block; margin-bottom: 3px; color: #234669; }
.privacy-note p { margin: 0; }
.site-footer { margin-top: 18px; border-top: 1px solid var(--border); background: #fff; color: var(--muted); font-size: .82rem; }
.footer-inner { display: flex; justify-content: space-between; gap: 12px; padding-block: 20px; }
@media (max-width: 920px) {
  .sync-grid { grid-template-columns: 1fr; }
  .camera-panel { grid-column: auto; }
  .room-flex { grid-template-columns: minmax(170px, 220px) minmax(0, 1fr); }
}
@media (max-width: 680px) {
  .container { width: min(100% - 22px, 1120px); }
  .header-inner { min-height: 62px; }
  .brand { font-size: .92rem; }
  .brand-mark { width: 36px; height: 36px; }
  .header-link { font-size: .82rem; }
  .main-content { padding-top: 25px; }
  .tool-header { margin-bottom: 20px; }
  .tool-header h1 { font-size: 1.85rem; }
  .tool-card { border-radius: 13px; }
  .tabs { padding-inline: 6px; }
  .tab-btn { flex: 1; padding: 13px 8px; font-size: .86rem; }
  .tab-content { padding: 12px; }
  .panel { padding: 16px; }
  .room-flex { grid-template-columns: 1fr; }
  .qr-frame { width: min(240px, 100%); margin-inline: auto; }
  #room-qr-canvas { max-width: 210px; }
  .room-details { width: 100%; }
  .action-row { align-items: stretch; flex-direction: column; }
  .action-row .btn { width: 100%; }
  .camera-panel { align-items: stretch; }
  .camera-controls .btn { flex: 1; }
  .generator-layout { grid-template-columns: 1fr; gap: 20px; }
  .qr-preview { min-height: 240px; }
  .footer-inner { flex-direction: column; align-items: center; text-align: center; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}

/* ===== ROOM CONNECTION LAYOUT: CONSOLIDATED FIX ===== */

/* Room panel and QR layout */
.room-panel,
.room-panel * {
  box-sizing: border-box;
}

.room-panel,
.room-flex,
.room-details,
.room-code-row,
#join-room-form,
#join-room-form .join-controls {
  min-width: 0;
  max-width: 100%;
}

.room-flex {
  display: grid;
  grid-template-columns: minmax(0, 200px) minmax(0, 1fr);
  align-items: start;
  gap: 19px;
}

.qr-frame {
  width: 100%;
  min-width: 0;
}

#room-qr-canvas {
  display: block;
  width: 100%;
  max-width: 200px;
  height: auto;
  margin-inline: auto;
}

.room-details {
  width: 100%;
}

.room-code-row {
  display: flex;
  width: 100%;
  margin-bottom: 12px;
}

.room-code {
  display: block;
  width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

#btn-copy-room-link {
  width: 100%;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}

/* Join form: label, controls and help text are separate rows */
#join-room-form.room-join-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  min-width: 0;
  margin: 0;
  gap: 0;
}

#join-room-form > .field-label {
  display: block;
  width: 100%;
  margin: 0 0 8px;
}

#join-room-form .join-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  margin: 0;
}

#join-room-form .join-controls input {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 11px 12px;
  box-sizing: border-box;
}

#join-room-form .join-controls button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  margin: 0;
  white-space: nowrap;
}

#join-room-form #room-input-help {
  display: block;
  width: 100%;
  margin: 8px 0 0;
  overflow-wrap: anywhere;
  word-break: normal;
}

/* Received-data action buttons */
.received-actions {
  display: flex;
  justify-content: flex-end;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 10px;
}

.received-actions .btn {
  min-width: 0;
}

/* Tablet and mobile */
@media (max-width: 680px) {
  .room-flex {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
  }

  .qr-frame {
    width: min(240px, 100%);
    margin-inline: auto;
  }

  #room-qr-canvas {
    max-width: 210px;
  }

  .room-details {
    width: 100%;
  }
}

/* Narrow phones */
@media (max-width: 480px) {
  #join-room-form .join-controls {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }

  #join-room-form .join-controls button {
    width: 100%;
    white-space: normal;
  }

  .received-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .received-actions .btn {
    width: 100%;
    padding-inline: 8px;
  }
}

@media (max-width: 360px) {
  #join-room-form .join-controls input,
  #join-room-form .join-controls button {
    font-size: 14px;
  }

  .field-divider {
    gap: 6px;
  }

  .field-divider span {
    text-align: center;
    overflow-wrap: anywhere;
  }
}



/* QR content field sizing and three equal quick-action columns */
.qr-mode-panel textarea,
.qr-mode-panel input {
  display: block;
  width: 100%;
  min-height: 140px;
  padding: 11px 12px;
  border: 1px solid #cfd8e4;
  border-radius: 9px;
  color: var(--text);
  background: #fff;
  font: inherit;
  line-height: 1.55;
}
.qr-mode-panel input { box-sizing: border-box; }
.qr-quick-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: stretch;
}
.qr-quick-actions select,
.qr-quick-actions .btn {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  padding: 8px 9px;
  font-size: .82rem;
}
.qr-quick-actions .btn { white-space: normal; overflow-wrap: anywhere; }
@media (max-width: 420px) {
  .qr-quick-actions { gap: 6px; }
  .qr-quick-actions select,
  .qr-quick-actions .btn { padding: 7px 5px; font-size: .74rem; }
}

/* QR generator content modes and scanner */
.sub-tabs {
  display: flex;
  gap: 6px;
  margin: 0 0 10px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f5f8fc;
}
.sub-tab-btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 40px;
  padding: 8px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-weight: 750;
}
.sub-tab-btn.active {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 1px 4px rgba(18, 44, 78, .12);
}
.qr-mode-panel { min-width: 0; }
.qr-mode-panel input { width: 100%; min-height: 46px; padding: 11px 12px; border: 1px solid #cfd8e4; border-radius: 9px; }
.qr-scan-panel { margin-top: 24px; }
.qr-scan-actions { display: flex; flex-wrap: wrap; gap: 9px; }
.file-button { cursor: pointer; }
.visually-hidden-input { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }
.qr-scan-paste-zone { margin-top: 12px; padding: 18px 14px; border: 1px dashed #b9cbe0; border-radius: 10px; background: #f8fafc; color: var(--muted); text-align: center; font-size: .88rem; outline: none; }
.qr-scan-paste-zone:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0, 86, 179, .12); }
.qr-scan-camera-controls { margin-top: 10px; }
@media (max-width: 600px) {
  .qr-scan-actions { display: grid; grid-template-columns: minmax(0, 1fr); }
  .qr-scan-actions .btn, .qr-scan-actions .file-button { width: 100%; }
  .qr-scan-panel { padding: 16px; }
  .qr-scan-paste-zone { padding: 15px 10px; }
}
