*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--on-surface);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  transition: var(--theme-transition);
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }

.app { position: relative; height: 100dvh; overflow: hidden; }

/* ---------- views ---------- */
.view {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  opacity: 0; visibility: hidden; transform: translateY(8px);
  transition: opacity var(--dur-med) var(--ease-emphasized), transform var(--dur-med) var(--ease-emphasized), visibility 0s linear var(--dur-med);
  background: var(--bg);
}
.view.is-active {
  opacity: 1; visibility: visible; transform: none;
  transition: opacity var(--dur-med) var(--ease-emphasized), transform var(--dur-med) var(--ease-emphasized), visibility 0s;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  min-height: 64px;
}
.topbar-title { font-size: 1.05rem; font-weight: 600; }
.topbar-actions { margin-left: auto; display: flex; gap: 4px; }
.spacer { flex: 1; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--primary); color: var(--on-primary);
  font-weight: 700; font-size: 1rem;
}
.brand-name { font-weight: 650; letter-spacing: -0.01em; }

/* ---------- home ---------- */
.home {
  flex: 1; display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  padding: 24px; gap: 48px; text-align: center;
}
.hero { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.wordmark {
  font-size: clamp(3rem, 12vw, 4.75rem); font-weight: 700;
  letter-spacing: -0.035em; line-height: 1;
  color: var(--primary);
}
.byline { color: var(--on-surface-muted); font-size: 0.95rem; letter-spacing: 0.02em; }
.tagline { margin-top: 14px; font-size: 1.1rem; color: var(--on-surface); max-width: 22ch; }
.home-actions { display: flex; flex-direction: column; gap: 12px; width: min(340px, 100%); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 48px; padding: 0 22px; border: 0; border-radius: var(--radius-pill);
  font-weight: 600; font-size: 0.98rem; cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-emphasized), background-color var(--dur-fast), box-shadow var(--dur-fast);
  user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible, .icon-btn:focus-visible, .input:focus-visible, .composer-input:focus-visible, .attach-option:focus-visible {
  outline: 3px solid var(--primary); outline-offset: 2px;
}
.btn-xl { height: 58px; font-size: 1.05rem; }
.btn-filled { background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow); }
.btn-filled:hover { filter: brightness(1.05); }
.btn-tonal { background: var(--primary-container); color: var(--on-primary-container); }
.btn-tonal:hover { filter: brightness(0.98); }
.btn-text { background: transparent; color: var(--primary); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }

.icon-btn {
  width: 44px; height: 44px; border-radius: var(--radius-pill);
  display: grid; place-items: center; border: 0; background: transparent;
  color: var(--on-surface); cursor: pointer;
  transition: background-color var(--dur-fast), transform var(--dur-fast);
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.small { width: 36px; height: 36px; }
.icon-btn.small svg { width: 18px; height: 18px; }

/* ---------- cards & forms ---------- */
.panel { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; max-width: 520px; width: 100%; margin: 0 auto; }
.card {
  background: var(--surface); border-radius: var(--radius-l);
  padding: 22px; box-shadow: var(--shadow); border: 1px solid var(--outline);
}
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.card-title { font-size: 1.2rem; font-weight: 650; }
.hint { color: var(--on-surface-muted); font-size: 0.9rem; line-height: 1.5; }
.fineprint { color: var(--on-surface-muted); font-size: 0.82rem; margin-top: 12px; line-height: 1.5; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 0.85rem; font-weight: 600; color: var(--on-surface-muted); }
.input {
  height: 52px; padding: 0 16px; border-radius: var(--radius-m);
  border: 1px solid var(--outline); background: var(--surface-2);
  transition: border-color var(--dur-fast), background-color var(--dur-fast);
}
.input:focus { border-color: var(--primary); background: var(--surface); outline: none; }
.error { color: var(--danger); font-size: 0.92rem; line-height: 1.45; }
.invite-box { background: var(--surface-2); border-radius: var(--radius-m); padding: 14px; overflow-wrap: anywhere; }
.invite-link { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.82rem; line-height: 1.5; }
.safety-box { border-top: 1px dashed var(--outline); padding-top: 16px; display: flex; flex-direction: column; gap: 6px; }
.safety-number { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 0.06em; word-spacing: 0.4em; font-size: 0.95rem; }
.success-badge {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--primary-container); color: var(--on-primary-container);
  display: grid; place-items: center;
}
.success-badge svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.loading-card { display: flex; align-items: center; gap: 14px; }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--outline); border-top-color: var(--primary);
  animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- chat ---------- */
.chat-top { min-height: 68px; }
.chat-peer { display: flex; flex-direction: column; min-width: 0; }
.peer-name { font-size: 1.05rem; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-status { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--on-surface-muted); }
.dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--outline);
  transition: background-color var(--dur-med), transform var(--dur-med);
}
.dot.online { background: var(--success); transform: scale(1.1); }
.dot.reconnecting { background: #c9a227; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

.conn-banner {
  padding: 8px 16px; font-size: 0.85rem; text-align: center;
  background: var(--surface-3); color: var(--on-surface);
  animation: slideDown var(--dur-med) var(--ease-emphasized);
}
@keyframes slideDown { from { transform: translateY(-100%); opacity: 0; } }

.messages {
  flex: 1; overflow-y: auto; padding: 12px 14px 20px;
  display: flex; flex-direction: column; gap: 4px;
  scroll-behavior: smooth; overscroll-behavior: contain;
}
.empty-state { margin: auto; text-align: center; color: var(--on-surface-muted); padding: 24px; font-size: 0.92rem; line-height: 1.6; }
.day-sep { align-self: center; margin: 12px 0 6px; font-size: 0.78rem; color: var(--on-surface-muted); background: var(--surface-2); padding: 4px 12px; border-radius: var(--radius-pill); }

.msg {
  max-width: min(78%, 560px); display: flex; flex-direction: column;
  padding: 9px 13px 6px; border-radius: 20px; position: relative;
  animation: msgIn var(--dur-med) var(--ease-emphasized) both;
  word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.in { align-self: flex-start; background: var(--bubble-in); color: var(--on-bubble-in); border-bottom-left-radius: 6px; box-shadow: var(--shadow); }
.msg.out { align-self: flex-end; background: var(--bubble-out); color: var(--on-bubble-out); border-bottom-right-radius: 6px; }
.msg.grouped { margin-top: -2px; }
.msg-body { white-space: pre-wrap; line-height: 1.45; font-size: 0.97rem; }
.msg-meta { display: flex; align-items: center; justify-content: flex-end; gap: 5px; font-size: 0.72rem; opacity: 0.72; margin-top: 2px; }
.msg-status { font-size: 0.8rem; letter-spacing: -0.2em; }
.msg-status.seen { color: var(--primary); opacity: 1; }
.msg-actions { position: absolute; top: -10px; opacity: 0; transition: opacity var(--dur-fast); }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; }
.msg.in .msg-actions { right: -10px; }
@media (hover: none) { .msg-actions { opacity: 1; } }
.msg.out .msg-actions { left: -10px; }
.msg-actions button {
  border: 0; background: var(--surface-2); color: var(--on-surface); border-radius: var(--radius-pill);
  height: 28px; padding: 0 10px; font-size: 0.75rem; cursor: pointer; box-shadow: var(--shadow);
}
.quote {
  display: block; text-align: left; border: 0; background: rgba(127, 127, 127, 0.14);
  border-left: 3px solid var(--primary); border-radius: 8px; padding: 6px 9px; margin-bottom: 6px;
  font-size: 0.82rem; cursor: pointer; color: inherit; max-width: 100%;
}
.quote strong { display: block; font-size: 0.76rem; color: var(--primary); margin-bottom: 2px; }
.quote span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0.85; }
.msg.flash { animation: flash 1.2s var(--ease-emphasized); }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--primary); } 100% { box-shadow: none; } }
.msg.failed .msg-body { text-decoration: line-through; opacity: 0.7; }
.msg-error { color: var(--danger); font-size: 0.75rem; margin-top: 4px; }

.file-card {
  display: flex; flex-direction: column; gap: 8px; min-width: 220px;
}
.file-row { display: flex; align-items: center; gap: 10px; }
.file-ico {
  flex: 0 0 40px; height: 40px; border-radius: 12px; background: var(--surface-3);
  display: grid; place-items: center; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.04em;
}
.file-name { font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.file-size { font-size: 0.78rem; opacity: 0.75; }
.progress { height: 6px; background: var(--surface-3); border-radius: var(--radius-pill); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--primary); border-radius: inherit; transition: width var(--dur-med) linear; }
.file-actions { display: flex; gap: 8px; }
.file-actions button {
  border: 0; border-radius: var(--radius-pill); height: 32px; padding: 0 14px;
  background: var(--primary); color: var(--on-primary); font-size: 0.82rem; font-weight: 600; cursor: pointer;
}
.file-actions button.ghost { background: var(--surface-3); color: var(--on-surface); }
.thumb {
  width: 220px; max-width: 100%; aspect-ratio: 4 / 3; border-radius: 14px; overflow: hidden;
  background: var(--surface-3); cursor: zoom-in; border: 0; padding: 0; display: block;
  position: relative;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.thumb-note { position: absolute; inset: auto 8px 8px auto; font-size: 0.7rem; background: rgba(0, 0, 0, 0.5); color: #fff; padding: 3px 8px; border-radius: var(--radius-pill); }

.reply-bar {
  display: flex; align-items: center; gap: 10px;
  margin: 0 12px; padding: 10px 12px; border-radius: var(--radius-m);
  background: var(--surface-2); border-left: 3px solid var(--primary);
  animation: rise var(--dur-med) var(--ease-emphasized);
}
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }
.reply-bar-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.reply-bar-label { font-size: 0.78rem; color: var(--primary); font-weight: 600; }
.reply-bar-snippet { font-size: 0.86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--on-surface-muted); }

.composer {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--bg);
  border-top: 1px solid var(--outline);
}
.composer-input {
  flex: 1; min-width: 0; resize: none; max-height: 140px; min-height: 44px;
  padding: 11px 16px; border-radius: 22px; border: 1px solid var(--outline);
  background: var(--surface); line-height: 1.4; font-size: 1rem;
  transition: border-color var(--dur-fast);
}
.composer-input:focus { outline: none; border-color: var(--primary); }
.composer .icon-btn.attach { width: 44px; height: 44px; flex: 0 0 44px; }
.composer .icon-btn.send {
  background: var(--primary); color: var(--on-primary); flex: 0 0 44px;
}
.composer .icon-btn.send:hover { background: var(--primary); filter: brightness(1.06); }
.composer .icon-btn.send:disabled { opacity: 0.4; }

/* ---------- sheets, dialogs, viewer ---------- */
dialog { border: 0; padding: 0; background: transparent; color: var(--on-surface); }
dialog::backdrop { background: var(--scrim); animation: fadeIn var(--dur-med) var(--ease-emphasized); }
dialog[open] { animation: dialogIn var(--dur-med) var(--ease-emphasized); }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes dialogIn { from { opacity: 0; transform: translateY(16px) scale(0.98); } }

.dialog, .sheet { width: min(92vw, 480px); }
.sheet { position: fixed; bottom: 0; margin: 0; width: 100%; max-width: 520px; border-radius: var(--radius-xl) var(--radius-xl) 0 0; }
.sheet, .dialog { background: var(--surface); border-radius: var(--radius-xl); box-shadow: var(--shadow); }
.sheet-inner { padding: 24px; display: flex; flex-direction: column; gap: 16px; max-height: 86dvh; overflow-y: auto; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.attach-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.attach-option {
  border: 1px solid var(--outline); background: var(--surface-2); border-radius: var(--radius-l);
  padding: 16px 8px; display: flex; flex-direction: column; align-items: center; gap: 8px;
  cursor: pointer; font-size: 0.88rem; transition: transform var(--dur-fast) var(--ease-emphasized), background-color var(--dur-fast);
}
.attach-option:hover { background: var(--surface-3); }
.attach-option:active { transform: scale(0.96); }
.attach-ico {
  width: 48px; height: 48px; border-radius: 16px; background: var(--primary-container); color: var(--on-primary-container);
  display: grid; place-items: center; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.05em;
}

.viewer { width: 100vw; height: 100dvh; max-width: none; max-height: none; background: #000; }
.viewer::backdrop { background: #000; }
.viewer-inner { position: relative; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.viewer-inner img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.viewer-close { position: absolute; top: calc(env(safe-area-inset-top) + 8px); right: 8px; color: #fff; background: rgba(255, 255, 255, 0.12); }
.viewer-note { position: absolute; bottom: calc(env(safe-area-inset-bottom) + 16px); color: #ddd; }

.about { width: min(94vw, 540px); }
.about-section { display: flex; flex-direction: column; gap: 8px; padding-top: 14px; border-top: 1px solid var(--outline); }
.about-section h3 { font-size: 0.95rem; font-weight: 650; color: var(--primary); }
.about-section p, .about-list li { line-height: 1.6; font-size: 0.92rem; }
.about-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
.maker-name { font-size: 1.1rem; font-weight: 650; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 90px); transform: translateX(-50%);
  background: var(--on-surface); color: var(--bg); padding: 10px 18px; border-radius: var(--radius-pill);
  font-size: 0.88rem; box-shadow: var(--shadow); z-index: 50; max-width: 90vw; text-align: center;
  animation: toastIn var(--dur-med) var(--ease-emphasized);
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- responsive ---------- */
@media (min-width: 900px) {
  .messages { padding-left: max(24px, calc((100% - 760px) / 2)); padding-right: max(24px, calc((100% - 760px) / 2)); }
  .composer { padding-left: max(24px, calc((100% - 760px) / 2)); padding-right: max(24px, calc((100% - 760px) / 2)); }
  .reply-bar { margin: 0 max(24px, calc((100% - 760px) / 2)); }
  .topbar { padding-left: 24px; padding-right: 24px; }
}

/* ---------- v2: message menu, settings, theme picker ---------- */
.msg { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.msg.in, .msg.out { transition: transform var(--dur-fast) var(--ease-emphasized); }
.msg-actions { display: none; }

.menu-preview {
  font-size: 0.86rem; color: var(--on-surface-muted);
  padding: 10px 14px; border-radius: var(--radius-m); background: var(--surface-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.menu-list { display: flex; flex-direction: column; gap: 4px; }
.menu-item {
  height: 52px; border: 0; background: transparent; border-radius: var(--radius-m);
  padding: 0 14px; text-align: left; font-size: 1rem; font-weight: 500;
  color: var(--on-surface); cursor: pointer; transition: background-color var(--dur-fast);
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: none; }
.menu-item.danger { color: var(--danger); }

.settings { width: min(94vw, 520px); }
.settings-group { display: flex; flex-direction: column; gap: 10px; padding-top: 16px; border-top: 1px solid var(--outline); }
.group-title { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--primary); }
.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.theme-swatch {
  border: 1px solid var(--outline); background: var(--surface-2); color: var(--on-surface);
  border-radius: var(--radius-m); padding: 10px; display: flex; flex-direction: column; gap: 8px;
  cursor: pointer; font-size: 0.82rem; font-weight: 600;
  transition: transform var(--dur-fast) var(--ease-emphasized), border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.theme-swatch:active { transform: scale(0.96); }
.theme-swatch[aria-pressed="true"] { border-color: var(--primary); box-shadow: inset 0 0 0 2px var(--primary); }
.swatch { display: block; height: 44px; border-radius: 12px; }
[data-theme-choice="sand"] .swatch     { background: linear-gradient(135deg, #f7f4ee 55%, #8a4b2a 55%); }
[data-theme-choice="mist"] .swatch     { background: linear-gradient(135deg, #f3f6f9 55%, #2f6690 55%); }
[data-theme-choice="sage"] .swatch     { background: linear-gradient(135deg, #f4f7f2 55%, #3f6b3c 55%); }
[data-theme-choice="midnight"] .swatch { background: linear-gradient(135deg, #1b2030 55%, #9ec5ff 55%); }
[data-theme-choice="ember"] .swatch    { background: linear-gradient(135deg, #211b16 55%, #f0b27a 55%); }
[data-theme-choice="forest"] .swatch   { background: linear-gradient(135deg, #17221b 55%, #9fd6b0 55%); }

.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 56px; padding: 12px 16px; border-radius: var(--radius-m);
  background: var(--surface-2); color: var(--on-surface); text-decoration: none;
  font-weight: 600; font-size: 0.95rem; transition: background-color var(--dur-fast);
}
.setting-row:hover { background: var(--surface-3); }
.setting-row small { display: block; font-weight: 400; font-size: 0.82rem; color: var(--on-surface-muted); margin-top: 2px; }
.setting-row::after { content: "\203A"; font-size: 1.4rem; color: var(--on-surface-muted); }
.about-text, .about-list li { line-height: 1.6; font-size: 0.92rem; }
.about-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
.maker { gap: 6px; }
.maker-name { font-size: 1.15rem; font-weight: 650; }
.maker-love { color: var(--primary); font-weight: 600; font-size: 0.95rem; margin-top: 4px; }
.pull-quote {
  margin: 8px 0 0; padding: 4px 0 4px 14px; border-left: 3px solid var(--primary);
  color: var(--on-surface-muted); font-style: italic; line-height: 1.5;
}
#btn-resume { width: 100%; }

/* ---------- v3: validity, invite strip, anchored message popup, games, full-page settings ---------- */
[hidden] { display: none !important; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--outline); background: var(--surface-2); color: var(--on-surface); font: inherit; font-size: 0.92rem; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--primary-container); color: var(--on-primary-container); border-color: transparent; font-weight: 600; }
.chip:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.custom-ttl { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.custom-ttl input, .custom-ttl select { min-height: 44px; border-radius: var(--radius-m); border: 1px solid var(--outline); background: var(--surface-2); color: var(--on-surface); padding: 0 10px; font: inherit; }
.custom-ttl input { width: 96px; }
.validity { font-size: 0.9rem; color: var(--on-surface-muted); }
.validity-note { font-size: 0.88rem; color: var(--on-surface-muted); line-height: 1.4; }
.validity-note.ok { color: var(--success); }
.validity-note.bad { color: var(--danger); }

.invite-strip { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--surface-2); border-bottom: 1px solid var(--outline); }
.invite-strip-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.invite-strip-label { font-size: 0.76rem; color: var(--on-surface-muted); }
.invite-strip-link { display: block; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.76rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.invite-strip-btn { min-height: 36px; padding: 0 14px; font-size: 0.85rem; flex: none; }

.msg-pop { position: fixed; z-index: 60; min-width: 190px; padding: 6px; display: flex; flex-direction: column; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); }
.msg-pop .menu-item { display: block; width: 100%; min-height: 44px; padding: 0 14px; border: 0; border-radius: 10px; background: transparent; color: var(--on-surface); font: inherit; font-size: 0.95rem; text-align: left; cursor: pointer; }
.msg-pop .menu-item:hover, .msg-pop .menu-item:focus-visible { background: var(--surface-3); outline: none; }
.msg-pop .menu-item.danger { color: var(--danger); }

.game-picker { display: flex; flex-direction: column; gap: 10px; }
.game-option { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 64px; padding: 12px 16px; border: 1px solid var(--outline); border-radius: 20px; background: var(--surface-2); color: var(--on-surface); font: inherit; font-size: 1rem; text-align: left; cursor: pointer; }
.game-option small { display: block; margin-top: 2px; color: var(--on-surface-muted); font-size: 0.85rem; }
.game-option:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.game-glyph { width: 40px; height: 40px; flex: none; border-radius: 12px; display: grid; place-items: center; background: var(--primary-container); color: var(--on-primary-container); font-size: 1.2rem; font-weight: 700; }

.game-card { display: flex; flex-direction: column; gap: 10px; min-width: 220px; }
.game-title { font-weight: 650; font-size: 0.95rem; }
.game-status { font-size: 0.88rem; color: var(--on-surface-muted); line-height: 1.4; }
.ttt-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.ttt-cell { aspect-ratio: 1; min-width: 56px; border: 0; border-radius: 12px; background: var(--surface-3); color: var(--on-surface); font: inherit; font-size: 1.6rem; font-weight: 700; cursor: pointer; }
.ttt-cell:not(:disabled) { background: var(--primary-container); color: var(--on-primary-container); }
.ttt-cell:disabled { cursor: default; opacity: 1; }
.ttt-cell:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.rps-row { display: flex; gap: 6px; flex-wrap: wrap; }
.rps-choice { flex: 1 1 0; min-height: 44px; padding: 0 8px; border: 0; border-radius: 12px; background: var(--primary-container); color: var(--on-primary-container); font: inherit; font-size: 0.9rem; cursor: pointer; }
.game-again { align-self: flex-start; min-height: 36px; padding: 0 14px; border: 0; border-radius: 999px; background: var(--surface-3); color: var(--on-surface); font: inherit; font-size: 0.88rem; cursor: pointer; }

.settings-page { width: 100%; max-width: 640px; margin: 0 auto; padding: 8px 16px 40px; }

/* v4: validity chips and custom row never overlap */
.validity { display: flex; flex-direction: column; gap: 12px; min-width: 0; margin: 0; padding: 12px 14px 16px; border: 1px solid var(--outline); border-radius: var(--radius-m); }
.validity > .field-label { padding: 0 4px; }
.chips { gap: 10px; }
.chip { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; box-sizing: border-box; height: 44px; line-height: 1; white-space: nowrap; }
.custom-ttl { position: relative; margin-top: 4px; align-items: stretch; }
.custom-ttl > * { position: static; transform: none; }
.custom-ttl input, .custom-ttl select { box-sizing: border-box; height: 48px; }
.validity-hint, .validity > .hint { margin: 0; }

/* ===== v4.1: voice notes, voice calls, and more games (Material 3 Expressive) ===== */

/* Shared: expressive shapes and pressed states */
.btn-voice-note { gap: 10px; min-height: 56px; border-radius: 28px; font-weight: 650; }
.btn-voice-note svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn-voice-note { display: flex; align-items: center; justify-content: center; }
.game-glyph { font-size: 1.3rem; }

/* Voice note bubble */
.voice-card { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; min-width: 210px; animation: msgIn var(--dur-med) var(--ease-emphasized) both; }
.voice-play {
  width: 46px; height: 46px; flex: none; border: 0; border-radius: 22px; display: grid; place-items: center;
  background: var(--primary); color: var(--on-primary); cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-emphasized), border-radius var(--dur-med) var(--ease-emphasized);
}
.voice-play:active { transform: scale(0.9); border-radius: 50%; }
.voice-play:disabled { opacity: 0.45; cursor: default; }
.voice-play svg { width: 22px; height: 22px; fill: currentColor; }
.voice-track { flex: 1; height: 8px; min-width: 90px; border-radius: var(--radius-pill); background: var(--surface-3); overflow: hidden; }
.voice-fill { height: 100%; width: 0; border-radius: inherit; background: var(--primary); transition: width 200ms linear; }
.voice-time { font-size: 0.8rem; font-variant-numeric: tabular-nums; opacity: 0.8; min-width: 36px; text-align: right; }
.voice-card .progress { flex-basis: 100%; }

/* Voice recorder sheet */
.voice-sheet { align-items: stretch; }
.voice-stage { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 8px 0; }
.voice-clock { font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: 0; letter-spacing: -0.02em; }
.voice-main { display: grid; place-items: center; }
.voice-rec {
  width: 104px; height: 104px; border: 0; padding: 0; cursor: pointer; display: grid; place-items: center;
  border-radius: 38px; background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow);
  transition: border-radius var(--dur-slow) var(--ease-emphasized), background-color var(--dur-med) var(--ease-emphasized), transform var(--dur-fast) var(--ease-emphasized);
}
.voice-rec:active { transform: scale(0.94); }
.voice-rec-core { width: 36px; height: 36px; border-radius: 50%; background: var(--on-primary); transition: border-radius var(--dur-slow) var(--ease-emphasized), width var(--dur-slow) var(--ease-emphasized), height var(--dur-slow) var(--ease-emphasized); }
.voice-rec[data-state="recording"] { border-radius: 50%; background: var(--danger); animation: voice-pulse 1.4s var(--ease-emphasized) infinite; }
.voice-rec[data-state="recording"] .voice-rec-core { border-radius: 10px; width: 30px; height: 30px; }
@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 40%, transparent); }
  60% { box-shadow: 0 0 0 16px color-mix(in srgb, var(--danger) 0%, transparent); }
}
.voice-preview { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.voice-preview audio { width: 100%; }
.voice-status { text-align: center; margin: 0; }

/* Call screen: full-height, expressive */
dialog.call { width: 100%; max-width: 100%; height: 100%; max-height: 100%; margin: 0; border: 0; padding: 0; background: var(--bg); color: var(--on-surface); }
dialog.call::backdrop { background: var(--bg); }
.call-body { min-height: 100%; min-height: 100dvh; box-sizing: border-box; display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 24px; padding: 56px 24px 40px; }
.call-who { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.call-avatar {
  width: 148px; height: 148px; border-radius: 52px; display: grid; place-items: center;
  background: var(--primary-container); color: var(--on-primary-container); font-size: 3.6rem; font-weight: 700;
  box-shadow: var(--shadow); animation: call-breathe 2.6s var(--ease-emphasized) infinite;
}
@keyframes call-breathe { 0%, 100% { border-radius: 52px; } 50% { border-radius: 64px; } }
.call-name { margin: 8px 0 0; font-size: 1.6rem; font-weight: 700; }
.call-status { margin: 0; color: var(--on-surface-muted); font-size: 1rem; }
.call-timer { margin: 0; font-size: 1.4rem; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--primary); }
.call-note { text-align: center; max-width: 32ch; margin: 0; }
.call-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; width: 100%; }
.call-pill { min-width: 128px; min-height: 64px; border-radius: 32px; font-size: 1.05rem; font-weight: 650; }
.call-pill[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .voice-rec[data-state="recording"], .call-avatar { animation: none; }
}

/* v4.3: sheets are full-screen pages with a top app bar and back button */
.sheet { inset: 0; width: 100%; max-width: none; height: 100dvh; max-height: none; margin: 0; border-radius: 0; background: var(--bg); }
.sheet-inner { max-height: none; height: 100%; box-sizing: border-box; padding: 0 20px calc(env(safe-area-inset-bottom) + 24px); overflow-y: auto; }
.app-bar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px; padding: calc(env(safe-area-inset-top) + 8px) 8px 8px 4px; margin: 0 -20px; background: var(--bg); }
.app-title { margin: 0 0 0 6px; font-size: 1.3rem; font-weight: 650; }
.app-bar .icon-btn { width: 48px; height: 48px; }
.call-bar { position: absolute; top: 0; left: 0; right: 0; z-index: 3; margin: 0; padding: calc(env(safe-area-inset-top) + 8px) 8px 0 4px; background: transparent; }
.call-bar .icon-btn { color: var(--on-surface); }
#call-speaker[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); }

/* v4.4: chat name and code */
.code-card { display: flex; flex-direction: column; gap: 6px; padding: 16px; border-radius: var(--radius-lg); background: var(--surface-2); border: 1px solid var(--outline); }
.code-name { margin: 0; font-size: 1.2rem; font-weight: 650; word-break: break-word; }
.code-value { display: block; font-size: 1.6rem; font-weight: 700; letter-spacing: 0.06em; word-break: break-all; color: var(--primary); }
.invite-strip-name { display: block; font-weight: 650; }
.invite-strip-code { display: block; font-size: 1.05rem; letter-spacing: 0.05em; word-break: break-all; }
.confirm-body { display: flex; flex-direction: column; gap: 12px; padding: 8px 0 24px; }

/* v4.5: version line in About */
.app-version { margin: 4px 0 0; text-align: center; font-size: 0.8rem; color: var(--on-surface-muted); }
