/* ARSEN 우편함 v3 — 공통·화면 스타일
 * 규칙: 모든 크기는 tokens.css 의 4px 격자·서체·컨트롤 높이 토큰만 쓴다.
 *  - 평면 + 1px 선이 기본. 그림자는 떠 있는 것(시트)에만.
 *  - 컨트롤 높이: 마우스 40 · 터치 44 / 작은 컨트롤 32 · 36
 *  - 인라인 style 속성 없이 클래스·데이터 속성으로만 상태 제어(엄격 CSP 호환).
 */

/* =========================================================================
   1. 기본
   ========================================================================= */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  min-height: 100dvh;
  overflow-x: clip;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-15);
  line-height: var(--lh-base);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3,
p,
ul,
ol,
dl,
dd,
figure,
pre {
  margin: 0;
}

ul,
ol {
  padding-left: var(--sp-5);
}

h1 {
  font-size: var(--fs-28);
  font-weight: 700;
  line-height: var(--lh-tight);
  letter-spacing: -0.02em;
}

h2 {
  font-size: var(--fs-22);
  font-weight: 700;
  line-height: var(--lh-tight);
  letter-spacing: -0.015em;
}

h3 {
  font-size: var(--fs-18);
  font-weight: 600;
  line-height: var(--lh-snug);
}

p,
li,
dd,
h1,
h2,
h3,
span,
a,
code,
pre {
  overflow-wrap: anywhere;
  word-break: break-word;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

a:hover {
  color: var(--accent-hover);
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button,
a,
input,
textarea,
select,
summary,
label {
  touch-action: manipulation;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: -120px;
  left: var(--sp-4);
  z-index: 100;
  min-height: var(--control-h);
  display: inline-flex;
  align-items: center;
  padding: 0 var(--sp-4);
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  top: var(--sp-3);
}

/* SVG 선형 아이콘 (1.75px) */
.icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.icon-sm {
  width: 16px;
  height: 16px;
}

.icon-lg {
  width: 24px;
  height: 24px;
}

/* =========================================================================
   2. 컨트롤
   ========================================================================= */
.btn {
  min-height: var(--control-h);
  min-width: var(--control-h);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-14);
  font-weight: 600;
  line-height: 1.3;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s;
}

.btn:hover:not(:disabled) {
  background: var(--surface-subtle);
  color: var(--text);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--accent-ink);
}

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--surface);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-subtle);
}

.btn-block {
  width: 100%;
}

.btn-nowrap {
  white-space: nowrap;
}

.icon-btn {
  min-width: var(--control-h);
  min-height: var(--control-h);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 0.12s, color 0.12s;
}

.icon-btn:hover:not(:disabled) {
  background: var(--surface-subtle);
  color: var(--text);
}

.link-nav {
  min-height: var(--control-h-sm);
  display: inline-flex;
  align-items: center;
  padding: 0 var(--sp-2);
  font-size: var(--fs-13);
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-nav:hover {
  color: var(--text);
}

.mini-action-btn {
  min-height: var(--control-h-sm);
  padding: 0 var(--sp-2);
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-13);
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.mini-action-btn:hover {
  color: var(--text);
  background: var(--surface-subtle);
}

/* 모바일 전용 요소: 컨트롤 정의보다 뒤에 두어 display 가 덮이지 않게 한다 */
.mobile-only {
  display: none;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
}

/* 세그먼트 컨트롤 (테마 · 대화 설정) */
.seg-group {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border-radius: var(--radius);
  background: var(--surface-subtle);
}

.seg-btn {
  min-height: var(--control-h-sm);
  min-width: 0;
  padding: 0 var(--sp-3);
  border-radius: var(--radius-sm);
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-13);
  font-weight: 600;
  cursor: pointer;
}

.seg-btn[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* =========================================================================
   3. 폼
   ========================================================================= */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.field + .field {
  margin-top: var(--sp-4);
}

.field-label {
  font-size: var(--fs-13);
  font-weight: 600;
  color: var(--text);
}

.field-hint {
  font-size: var(--fs-13);
  color: var(--muted);
}

.input,
.select,
.textarea {
  width: 100%;
  max-width: 100%;
  min-height: var(--control-h);
  padding: 0 var(--sp-3);
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-15);
  line-height: var(--lh-base);
}

.select {
  padding-right: var(--sp-2);
}

.textarea {
  padding: var(--sp-2) var(--sp-3);
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus,
.composer-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.check-row {
  min-height: var(--control-h);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-3);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  font-size: var(--fs-14);
}

.check-row input[type="checkbox"],
.check-row input[type="radio"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--accent);
  margin: 0;
}

/* =========================================================================
   4. 표시 요소: 배너 · 칩 · 아바타 · 이름
   ========================================================================= */
.banner {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: var(--fs-13);
  line-height: var(--lh-snug);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.banner-warn {
  background: var(--warn-soft);
  border-color: transparent;
  color: var(--warn);
}

.banner-danger {
  background: var(--danger-soft);
  border-color: transparent;
  color: var(--danger);
}

.banner-accent {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--text);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  min-height: 20px;
  padding: 0 var(--sp-2);
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: var(--fs-12);
  font-weight: 500;
  line-height: 1.3;
}

.chip-relay {
  background: var(--warn-soft);
  border-color: transparent;
  color: var(--warn);
  font-weight: 600;
}

.chip-connected {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
  font-weight: 600;
}

.chip-danger {
  background: var(--danger-soft);
  border-color: transparent;
  color: var(--danger);
  font-weight: 600;
}

/* 아바타: 대화 32 · 묶음 24 · 카드 40 · 상세 48 */
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-13);
  font-weight: 700;
  color: var(--avatar-ink);
  background: var(--kind-other);
  border: 1px solid var(--line);
  overflow: hidden;
  flex-shrink: 0;
  user-select: none;
}

.avatar-sm {
  width: 24px;
  height: 24px;
  font-size: var(--fs-12);
  border: 2px solid var(--surface);
}

.avatar-card {
  width: 40px;
  height: 40px;
}

.avatar-lg {
  width: 48px;
  height: 48px;
  font-size: var(--fs-18);
}

.avatar-spacer {
  width: 32px;
  flex-shrink: 0;
}

.avatar.has-art {
  padding: 0;
  background: var(--surface);
}

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  border-radius: 50%;
}

.avatar-icon {
  width: 58%;
  height: 58%;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.avatar[data-kind="human"] { background: var(--kind-human); }
.avatar[data-kind="claude"] { background: var(--kind-claude); }
.avatar[data-kind="chatgpt"] { background: var(--kind-chatgpt); }
.avatar[data-kind="gemini"] { background: var(--kind-gemini); }
.avatar[data-kind="pickle"] { background: var(--kind-pickle); }
.avatar[data-kind="hark"] { background: var(--kind-hark); }
.avatar[data-kind="vooy"] { background: var(--kind-vooy); }
.avatar[data-kind="cue"] { background: var(--kind-cue); }
.avatar[data-kind="keyring"] { background: var(--kind-keyring); }
.avatar[data-kind="muse"] { background: var(--kind-muse); }
.avatar[data-kind="instinct"] { background: var(--kind-instinct); }
.avatar[data-kind="other"] { background: var(--kind-other); }

.avatar.has-art[data-kind] {
  background: var(--surface);
}

.sender-name {
  font-weight: 600;
  font-size: var(--fs-13);
  color: var(--kind-other-name);
}
.sender-name[data-kind="human"] { color: var(--kind-human-name); }
.sender-name[data-kind="claude"] { color: var(--kind-claude-name); }
.sender-name[data-kind="chatgpt"] { color: var(--kind-chatgpt-name); }
.sender-name[data-kind="gemini"] { color: var(--kind-gemini-name); }
.sender-name[data-kind="pickle"] { color: var(--kind-pickle-name); }
.sender-name[data-kind="hark"] { color: var(--kind-hark-name); }
.sender-name[data-kind="vooy"] { color: var(--kind-vooy-name); }
.sender-name[data-kind="cue"] { color: var(--kind-cue-name); }
.sender-name[data-kind="keyring"] { color: var(--kind-keyring-name); }
.sender-name[data-kind="muse"] { color: var(--kind-muse-name); }
.sender-name[data-kind="instinct"] { color: var(--kind-instinct-name); }
.sender-name[data-kind="other"] { color: var(--kind-other-name); }

.avatar-stack {
  display: inline-flex;
  align-items: center;
}

.avatar-stack .avatar-sm + .avatar-sm {
  margin-left: -6px;
}

.avatar-more {
  font-size: var(--fs-12);
  color: var(--muted);
  margin-left: var(--sp-2);
}

.empty-state {
  margin: auto;
  max-width: 360px;
  padding: var(--sp-8) var(--sp-4);
  text-align: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-4);
}

/* =========================================================================
   5. 공개 화면: 첫 화면 · 공간 만들기 · 열쇠 저장 · 복구
   ========================================================================= */
.public-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 var(--page-gutter) var(--sp-4);
}

.public-header {
  min-height: var(--sp-16);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  padding-block: var(--sp-3);
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  text-decoration: none;
  color: var(--text);
  font-size: var(--fs-16);
  font-weight: 700;
}

.brand-mark-box {
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.public-page > main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--sp-4);
  padding-block: var(--sp-6);
}

.hero-card,
.flow-card,
.settings-card,
.doc-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.hero-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-6);
  padding: var(--sp-5);
}

.flow-card {
  width: 100%;
  max-width: 560px;
  margin-inline: auto;
  padding: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

.flow-card h1 {
  font-size: 24px;
}

.hero-lead {
  font-size: clamp(24px, 1.6vw + 16px, 36px);
  font-weight: 700;
  line-height: var(--lh-tight);
  letter-spacing: -0.025em;
  color: var(--text);
}

.hero-illustration {
  background: var(--bg);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  display: flex;
  justify-content: center;
  align-items: center;
}

.hero-illustration svg {
  width: 100%;
  max-width: 440px;
  height: auto;
  display: block;
}

.hero-actions {
  display: grid;
  gap: var(--sp-3);
}

.hero-actions .btn {
  min-height: var(--sp-12);
}

@media (min-width: 860px) {
  .hero-card {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
    grid-template-areas:
      "lead art"
      "actions art";
    column-gap: var(--sp-10);
    row-gap: var(--sp-6);
    padding: var(--sp-10);
    align-items: center;
  }

  .hero-lead {
    grid-area: lead;
    align-self: end;
  }

  .hero-illustration {
    grid-area: art;
  }

  .hero-actions {
    grid-area: actions;
    align-self: start;
    max-width: 360px;
  }
}

.public-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-2) var(--sp-4);
  padding-top: var(--sp-4);
  font-size: var(--fs-13);
  color: var(--muted);
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1) var(--sp-4);
  /* gridlines: 링크의 8px 누름 여백만큼 당겨 마지막 글자가 카드·머리말 오른쪽 선에 닿게 함 */
  margin-right: calc(-1 * var(--sp-2));
}

.key-box {
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4);
  font-family: var(--font-mono);
  font-size: var(--fs-13);
  line-height: var(--lh-snug);
  color: var(--text);
  word-break: break-all;
}

.recovery-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-2);
  list-style: none;
  padding: 0;
}

.recovery-item {
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--fs-12);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.recovery-num {
  color: var(--muted);
  min-width: 20px;
}

.pwa-guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--sp-3);
}

.pwa-guide-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.pwa-guide-card svg {
  width: 100%;
  max-width: 220px;
  height: auto;
}

/* =========================================================================
   6. 앱 레이아웃 (/app): 방 목록 | 대화 | 참가자
   ========================================================================= */
.app-shell {
  height: 100dvh;
  min-height: 100dvh;
  width: 100%;
  display: grid;
  grid-template-columns: var(--rooms-w) minmax(0, 1fr) var(--members-w);
  background: var(--bg);
  overflow: hidden;
}

.app-shell.is-panel-collapsed,
.app-shell.is-settings-open {
  grid-template-columns: var(--rooms-w) minmax(0, 1fr);
}

.rooms-pane,
.members-pane {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.rooms-pane {
  border-right: 1px solid var(--line);
}

.members-pane {
  border-left: 1px solid var(--line);
}

.pane-topbar {
  min-height: var(--topbar-h);
  padding: 0 var(--sp-3) 0 var(--sp-4);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  flex-shrink: 0;
}

.pane-title {
  font-size: var(--fs-16);
  font-weight: 700;
  line-height: var(--lh-snug);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rooms-toolbar {
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  flex-shrink: 0;
}

.rooms-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 var(--sp-2) var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.room-card {
  width: 100%;
  padding: var(--sp-3);
  border-radius: var(--radius);
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  transition: background-color 0.12s;
}

.room-card:hover {
  background: var(--surface-subtle);
}

.room-card[aria-current="true"] {
  background: var(--accent-soft);
}

.room-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  min-width: 0;
}

.room-card-name {
  font-size: var(--fs-14);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-card-meta {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
}

.room-card-time {
  font-size: var(--fs-12);
  color: var(--muted);
}

.unread-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: var(--fs-12);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.room-card-preview {
  font-size: var(--fs-13);
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-card .avatar-stack {
  margin-top: var(--sp-1);
}

/* 대화 패널 */
.chat-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  min-width: 0;
  flex: 1;
}

.chat-header-right {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex-shrink: 0;
}

.pane-topbar .icon-btn {
  min-width: var(--control-h-sm);
  min-height: var(--control-h-sm);
}

.title-stack {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.title-stack .pane-title {
  line-height: 1.25;
}

.title-sub {
  font-size: var(--fs-12);
  line-height: 1.3;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trust-strip.chat-trust-notice {
  display: block;
  flex-shrink: 0;
  padding-block: 0;
}

.chat-trust-notice > summary {
  min-height: var(--control-h-sm);
  padding-block: var(--sp-2);
  cursor: pointer;
}

.chat-trust-notice > summary:focus-visible {
  outline-offset: -2px;
}

.chat-trust-notice > p {
  margin: 0;
  padding-bottom: var(--sp-2);
}

.status-slot {
  padding: var(--sp-2) var(--sp-4) 0;
}

.status-slot:empty {
  display: none;
}

/* 대화 영역은 아무리 넓어도 읽기 좋은 폭(--measure)으로 가운데에 모은다. */
.messages-scroll,
.status-slot,
.composer-wrap {
  padding-inline: max(var(--sp-4), calc((100% - var(--measure)) / 2));
}

.status-slot .banner > .btn {
  flex-shrink: 0;
  white-space: nowrap;
}


.messages-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-block: var(--sp-5) var(--sp-4);
  display: flex;
  flex-direction: column;
}

.date-divider {
  align-self: center;
  margin: var(--sp-4) 0 var(--sp-1);
  padding: 2px var(--sp-3);
  border-radius: var(--radius-pill);
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: var(--fs-12);
  font-weight: 500;
}

.msg-row {
  display: flex;
  gap: var(--sp-2);
  align-items: flex-start;
  max-width: 100%;
  min-width: 0;
  margin-top: var(--sp-4);
}

.msg-row.is-grouped {
  margin-top: 2px;
}

.date-divider + .msg-row {
  margin-top: var(--sp-3);
}

.msg-row.is-mine {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-col {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
  max-width: min(36rem, calc(100% - 40px));
}

.msg-row.is-mine .msg-col {
  align-items: flex-end;
}

.msg-row.is-mine .avatar-spacer {
  display: none;
}

.msg-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-1) var(--sp-2);
  margin: 0 var(--sp-1) var(--sp-1);
  font-size: var(--fs-12);
  line-height: var(--lh-snug);
  color: var(--muted);
}

.msg-bubble-row {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  max-width: 100%;
  min-width: 0;
}

.msg-row.is-mine .msg-bubble-row {
  flex-direction: row-reverse;
}

.msg-bubble {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-lg);
  border-top-left-radius: var(--sp-1);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: var(--fs-15);
  max-width: 100%;
  min-width: 0;
}

.msg-row.is-mine .msg-bubble {
  background: var(--accent-soft);
  border-color: transparent;
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--sp-1);
}

.msg-reply-ref {
  font-size: var(--fs-12);
  line-height: var(--lh-snug);
  color: var(--muted);
  border-left: 3px solid var(--line-strong);
  padding-left: var(--sp-2);
  margin-bottom: var(--sp-2);
}

.msg-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-body.is-clamped {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 8;
  overflow: hidden;
}

.msg-code {
  margin: var(--sp-2) 0;
  padding: var(--sp-3);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: var(--fs-13);
  line-height: var(--lh-snug);
  white-space: pre-wrap;
  overflow-x: auto;
}

.msg-footer-actions {
  display: flex;
  gap: var(--sp-1);
  align-items: center;
  margin: 2px var(--sp-1) 0;
}

/* 답장: 마우스 올림, 키보드 초점, 터치 선택에 맞춰 표시한다. */
.msg-reply-btn {
  width: var(--control-h-sm);
  height: var(--control-h-sm);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.msg-reply-btn:hover {
  background: var(--surface-subtle);
  color: var(--text);
}

@media (hover: hover) and (pointer: fine) {
  .msg-reply-btn {
    opacity: 0;
  }

  .msg-row:hover .msg-reply-btn,
  .msg-reply-btn:focus-visible {
    opacity: 1;
  }
}

/* 터치: 말풍선을 누르면 그 글 옆에만 답장 버튼이 나온다(항상 떠 있으면 소음) */
@media (pointer: coarse) {
  .msg-reply-btn {
    position: absolute;
    opacity: 0;
    pointer-events: none;
  }

  .msg-row.show-actions .msg-reply-btn,
  .msg-reply-btn:focus-visible {
    position: static;
    opacity: 1;
    pointer-events: auto;
  }
}

/* 입력창 */
.composer-wrap {
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-block: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  flex-shrink: 0;
}

.reply-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: 0 var(--sp-2) 0 var(--sp-3);
  min-height: var(--control-h-sm);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  font-size: var(--fs-13);
  color: var(--muted);
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
}

.composer-input {
  flex: 1;
  min-width: 0;
  min-height: var(--control-h);
  max-height: 180px;
  padding: calc((var(--control-h) - 1.6em - 2px) / 2) var(--sp-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line-strong);
  background: var(--bg);
  color: var(--text);
  line-height: var(--lh-base);
  resize: none;
}

.composer-hint {
  font-size: var(--fs-12);
  line-height: var(--lh-snug);
  color: var(--muted);
  padding-inline: var(--sp-1);
}

.composer-feedback {
  font-size: var(--fs-13);
  color: var(--danger);
  padding-inline: var(--sp-1);
}

/* 참가자 패널 */
.members-toolbar {
  padding: var(--sp-3) var(--sp-4);
}

.members-toolbar .select {
  min-height: var(--control-h-sm);
  font-size: var(--fs-13);
}

.members-pane .pane-topbar .btn {
  min-height: var(--control-h-sm);
  padding: 0 var(--sp-3);
}

.members-topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
}
.members-topbar .btn { white-space: nowrap; }

.members-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--sp-2) var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.member-row {
  width: 100%;
  flex-shrink: 0;
  padding: var(--sp-3);
  border-radius: var(--radius);
  border: 0;
  background: transparent;
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  text-align: left;
  cursor: pointer;
  word-break: keep-all;
  transition: background-color 0.12s;
}

.member-row:hover {
  background: var(--surface-subtle);
}

.member-row-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.member-row-title {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  font-size: var(--fs-14);
  font-weight: 600;
}

.member-row-sub,
.member-schedule-line {
  font-size: var(--fs-12);
  color: var(--muted);
  line-height: var(--lh-snug);
  overflow-wrap: anywhere;
}

.participant-notes {
  display: flex;
  flex: 1 1 100%;
  min-width: 0;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-12);
}

.participant-device {
  flex: 0 1 auto;
  max-width: 45%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.participant-role-note {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.question-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-1) 6px;
  margin-top: var(--sp-2);
}

.question-chips .chip {
  white-space: normal;
}

.profile-device-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.profile-device-options button {
  cursor: pointer;
}

/* =========================================================================
   7. 설정 화면
   ========================================================================= */
.settings-pane {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.settings-scroll {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-6) var(--page-gutter) var(--sp-10);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  max-width: 672px;
  width: 100%;
  margin: 0 auto;
}

.settings-card {
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.settings-card h2 {
  font-size: var(--fs-16);
  letter-spacing: -0.01em;
}

.usage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--sp-3);
}

.usage-stat {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius);
  background: var(--bg);
}

.usage-stat-label {
  font-size: var(--fs-12);
  color: var(--muted);
}

.usage-stat-val {
  font-size: var(--fs-18);
  font-weight: 700;
  color: var(--text);
  margin-top: 2px;
}

/* =========================================================================
   8. 시트 · 참가자 종류 · 주기 · 상세
   ========================================================================= */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
}

.sheet-panel {
  width: 100%;
  max-width: 480px;
  max-height: min(88dvh, 760px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-float);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--line-strong);
  margin: var(--sp-2) auto 0;
  display: none;
}

.sheet-header {
  min-height: var(--topbar-h);
  padding: 0 var(--sp-3) 0 var(--sp-5);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  flex-shrink: 0;
}

.sheet-header .icon-btn {
  min-width: var(--control-h-sm);
  min-height: var(--control-h-sm);
}

.sheet-body {
  padding: var(--sp-5);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

.message-full-meta {
  margin: 0;
  overflow-wrap: anywhere;
}

.message-full-text {
  min-width: 0;
}

.kind-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-2);
}

.kind-card {
  min-height: 88px;
  padding: var(--sp-3);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-2);
  text-align: left;
  cursor: pointer;
  min-width: 0;
}

.kind-card:hover {
  border-color: var(--line-strong);
}

.kind-card[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.kind-card-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}

.kind-card-titles {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 1px;
}

.kind-card-name {
  font-size: var(--fs-14);
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex-wrap: wrap;
}

.kind-card-freq {
  font-size: var(--fs-12);
  color: var(--accent);
  font-weight: 600;
}

.kind-card-mode {
  font-size: var(--fs-12);
  color: var(--muted);
  line-height: 1.3;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.interval-presets {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.interval-preset-btn {
  min-height: var(--control-h-sm);
  min-width: var(--control-h);
  padding: 0 var(--sp-3);
  border-radius: var(--radius-pill);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-13);
  font-weight: 600;
  cursor: pointer;
}

.interval-preset-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.interval-custom-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--sp-2);
  align-items: center;
}

.schedule-summary-grid,
.stage-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-2);
}

.schedule-stat {
  padding: var(--sp-3);
  border-radius: var(--radius);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.schedule-stat-label {
  font-size: var(--fs-12);
  color: var(--muted);
}

.schedule-stat-val {
  font-size: var(--fs-14);
  font-weight: 600;
  color: var(--text);
}

.stage-step {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: var(--fs-12);
  color: var(--muted);
}

.stage-step.is-active {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
}

/* =========================================================================
   9. 초대받은 사람 화면 (/r/{room}/#k=)
   ========================================================================= */
.guest-shell {
  height: 100dvh;
  min-height: 100dvh;
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.guest-shell .pane-topbar,
.guest-shell .chat-header-right {
  flex-wrap: nowrap;
}

.guest-shell .chat-pane {
  flex: 1;
}

/* =========================================================================
   10. 도움말 · 개인정보 (/help.html)
   ========================================================================= */
.doc-page {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 var(--page-gutter) var(--sp-16);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.doc-section {
  padding: var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.doc-section h2 {
  font-size: var(--fs-18);
}

.doc-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.doc-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-14);
}

.doc-table th,
.doc-table td {
  padding: var(--sp-3);
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.doc-table th {
  color: var(--muted);
  font-size: var(--fs-12);
  font-weight: 600;
}

/* 작업실 스킨 보조 */
.workspace-own-avatar,
.workspace-author {
  display: none;
}

:root[data-chat-skin="workspace"] #messages-scroll-box .workspace-own-avatar { display: inline-flex; }
:root[data-chat-skin="workspace"] #messages-scroll-box .workspace-author { display: inline; font-weight: 650; }
:root[data-chat-skin="workspace"] #messages-scroll-box .msg-row.is-mine::before { display: none; }

/* =========================================================================
   11. 반응형
   ========================================================================= */
/* 중간 폭: 참가자 패널은 접어서 시작하므로 방 목록만 줄인다 */
@media (max-width: 1180px) {
  :root {
    --rooms-w: 248px;
    --members-w: 280px;
  }
}

/* 폰·태블릿 세로·가로로 눕힌 폰: 방 목록 → 대화 → 아래에서 올라오는 시트 */
@media (max-width: 960px), (max-height: 500px) and (max-width: 1100px) {
  .mobile-only {
    display: inline-flex;
  }

  .desktop-only {
    display: none !important;
  }

  .app-shell,
  .app-shell.is-panel-collapsed,
  .app-shell.is-settings-open {
    grid-template-columns: minmax(0, 1fr);
  }

  .app-shell[data-mobile-pane="rooms"] .chat-pane,
  .app-shell[data-mobile-pane="rooms"] .members-pane,
  .app-shell[data-mobile-pane="rooms"] .settings-pane,
  .app-shell[data-mobile-pane="chat"] .rooms-pane,
  .app-shell[data-mobile-pane="chat"] .members-pane,
  .app-shell[data-mobile-pane="chat"] .settings-pane,
  .app-shell[data-mobile-pane="settings"] .rooms-pane,
  .app-shell[data-mobile-pane="settings"] .chat-pane,
  .app-shell[data-mobile-pane="settings"] .members-pane {
    display: none !important;
  }

  .rooms-pane {
    border-right: 0;
  }

  .rooms-toolbar,
  .rooms-list {
    width: 100%;
    max-width: 600px;
    margin-inline: auto;
  }

  .sheet-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .sheet-panel {
    max-width: 560px;
    max-height: 90dvh;
    margin-inline: auto;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom: 0;
  }

  .sheet-handle {
    display: block;
  }

  .guest-shell {
    border-left: 0;
    border-right: 0;
  }

  .msg-row {
    max-width: 100%;
  }
}

@media (max-width: 640px) {
  .hero-card {
    padding: var(--sp-4);
  }

  .flow-card {
    padding: var(--sp-5);
  }

  .settings-card,
  .doc-section {
    padding: var(--sp-4);
  }

  .sheet-body {
    padding: var(--sp-4);
  }
}

@media (max-width: 520px) {
  .public-header .action-row {
    width: 100%;
    justify-content: space-between;
    flex-wrap: nowrap;
  }

  .usage-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--sp-2);
  }
}

@media (max-width: 480px) {
  .chat-header-right .btn-label {
    display: none;
  }

  .chat-header-right .btn.mobile-only {
    padding: 0;
  }

  .kind-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .schedule-summary-grid,
  .interval-custom-row {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* 터치 기기: 입력은 16px 이상(iOS 확대 방지), 단축키 안내는 숨김 */
@media (pointer: coarse) {
  .input,
  .select,
  .textarea,
  .composer-input {
    font-size: var(--fs-16);
  }

  .pane-topbar .icon-btn,
  .sheet-header .icon-btn {
    min-width: var(--control-h);
    min-height: var(--control-h);
  }

  #composer-shortcut-hint {
    display: none;
  }

  .members-toolbar .select {
    font-size: var(--fs-16);
  }

  .profile-device-options button {
    min-height: var(--control-h-sm);
  }
}

/* ---- 마감 보정 ---- */
label:not(.check-row) {
  font-size: var(--fs-13);
  font-weight: 600;
}

.seg-group {
  align-self: flex-start;
}

.settings-card form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.settings-card form > label {
  margin-top: var(--sp-2);
}

.settings-card form > label:first-child {
  margin-top: 0;
}

.flow-card h2 {
  font-size: var(--fs-18);
}

.recovery-grid {
  grid-template-columns: minmax(0, 1fr);
}

.recovery-item {
  min-height: 36px;
}

/* 공통 안내 띠 */
.trust-strip,
.guest-key-notice {
  padding: var(--sp-2) max(var(--sp-4), calc((100% - var(--measure)) / 2));
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: var(--fs-12);
  line-height: var(--lh-snug);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.guest-key-notice {
  background: var(--warn-soft);
  color: var(--warn);
  font-weight: 600;
}

.guest-shell .pane-topbar .check-row {
  min-height: var(--control-h-sm);
  padding: 0 var(--sp-2);
  border: 0;
  background: transparent;
  font-size: var(--fs-13);
  color: var(--muted);
}

/* Private message images use the active chat surface and bubble radius. */
.composer-add-image {
  flex: none;
}

.image-draft {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-1);
  background: var(--surface-subtle);
  color: var(--text);
  border-radius: var(--radius);
}

.image-draft[hidden] { display: none; }
.image-draft img { border-radius: var(--radius-sm); object-fit: cover; }
.image-draft button { margin-inline-start: auto; }

.message-image-frame { max-inline-size: 100%; }
.message-image {
  display: block;
  max-width: 100%;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: inherit;
  background: var(--surface-subtle);
  cursor: zoom-in;
}
.message-image-frame { border-radius: inherit; }
.message-image[hidden] { display: none; }
.message-image img {
  display: block;
  max-width: 100%;
  max-height: 320px;
  height: auto;
  object-fit: contain;
}
.message-image-frame + .msg-body { margin-block-start: var(--sp-1); }

.image-dialog {
  max-width: min(100vw - 24px, 1200px);
  max-height: calc(100dvh - 24px);
  border: 0;
  border-radius: var(--radius);
  padding: var(--sp-3);
  color: var(--text);
  background: var(--surface);
}
.image-dialog::backdrop { background: rgb(0 0 0 / 83%); }
.image-dialog-actions { justify-content: flex-end; }
.image-dialog img {
  display: block;
  margin: var(--sp-2) auto 0;
  max-width: 100%;
  max-height: calc(100dvh - 120px);
  object-fit: contain;
}

/* ── 첫 화면 그림: Stageshow(MIT, Benji Taylor) 구도 ──
   모서리 bleed: 창은 위·왼쪽에서 한 간격(gutter) 들어오고 오른쪽·아래로 무대 밖까지 이어진다.
   잘리는 건 빈 여백과 자리 표시 막대뿐, 실제 글자는 모두 무대 안에 온전히 둔다. */
.hero-illustration {
  padding: 0;
  display: block;
  overflow: hidden;
  position: relative;
  --hs-gutter: 28px;
  --hs-bleed: 72px;
}
.hs-stage {
  position: relative;
  height: 312px;
}
.hs-window {
  position: absolute;
  top: var(--hs-gutter);
  left: var(--hs-gutter);
  right: calc(-1 * var(--hs-bleed));
  bottom: calc(-1 * var(--hs-bleed));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow), 0 14px 32px -18px rgba(35, 34, 31, 0.32);
  overflow: hidden;
}
.hs-head {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--line);
}
.hs-room {
  font-size: var(--fs-15);
  font-weight: 700;
  color: var(--text);
}
.hs-count {
  font-size: var(--fs-12);
  color: var(--muted);
}
.hs-body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4) calc(var(--hs-bleed) + var(--hs-gutter)) var(--sp-4) var(--sp-4);
}
.hs-row {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  min-width: 0;
}
.hs-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.hs-col .sender-name {
  font-size: var(--fs-12);
  line-height: var(--lh-snug);
  margin-left: var(--sp-1);
}
.hs-row .msg-bubble {
  word-break: keep-all;
}
.hs-mine {
  justify-content: flex-end;
}
.hs-mine .msg-bubble {
  background: var(--accent-soft);
  border-color: transparent;
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--sp-1);
}
.hs-filler {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding-block: var(--sp-3);
}
.hs-bar {
  display: block;
  height: 6px;
  border-radius: 3px;
  background: var(--line-strong);
}
.hs-bar-name { width: 44px; height: 6px; margin: 5px 0 6px var(--sp-1); background: var(--line); }
.hs-bar-a { width: 168px; }
.hs-bar-b { width: 112px; }

@media (max-width: 559px) {
  .hero-illustration { --hs-gutter: 20px; --hs-bleed: 56px; }
  .hs-stage { height: 256px; }
  .hs-row .msg-bubble { font-size: var(--fs-14, 14px); }
  .hs-body > .hs-row:nth-child(3) { display: none; }
}
