:root {
  --bg: #f6f6f8;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --text: #1d1d1f;
  --text-2: #6b6b70;
  --text-3: #9b9ba1;
  --border: #e6e6ea;
  --accent: #4f46e5;
  --accent-strong: #4338ca;
  --accent-soft: #eef0ff;
  --danger: #d33131;
  --danger-strong: #b92b2b;
  --danger-soft: #fdecec;
  --green: #1a9e5c;
  --amber: #d98a12;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 20, 40, 0.04), 0 10px 30px rgba(20, 20, 40, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
input, textarea { font: inherit; color: var(--text); }
button svg { pointer-events: none; }

#app { height: 100%; display: flex; flex-direction: column; }

.view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 24px 20px;
  min-height: 0;
}

.hidden { display: none !important; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 48px;
  padding: 0 20px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.06s ease;
}
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.55; cursor: default; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: #f1f1f4; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-strong); }
.btn-danger-outline { background: var(--surface); color: var(--danger); border-color: #f0c9c9; }
.btn-danger-outline:hover { background: var(--danger-soft); }

.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: 0 14px; font-size: 14px; border-radius: 9px; }

.icon-label { padding: 0 16px; }

.link-btn {
  background: none;
  border: none;
  color: var(--text-2);
  text-decoration: underline;
  text-underline-offset: 3px;
  font-size: 14px;
  padding: 10px 8px;
  min-height: 44px;
}
.link-btn:hover { color: var(--text); }

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

.landing {
  width: 100%;
  max-width: 460px;
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px 4px 40px;
}

.mark {
  width: 56px;
  height: 56px;
  border-radius: 17px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  margin-bottom: 26px;
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.28);
}

.landing h1 {
  font-size: 31px;
  line-height: 1.16;
  letter-spacing: -0.02em;
  font-weight: 700;
  margin-bottom: 16px;
}

.lead { color: var(--text-2); font-size: 16px; max-width: 36ch; margin-bottom: 28px; }

.landing-actions { width: 100%; display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }

.join-form { width: 100%; display: flex; flex-direction: column; gap: 10px; margin-bottom: 22px; }
.hint { font-size: 13px; color: var(--text-3); }

.features {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 20px;
  color: var(--text-2);
  font-size: 13px;
}
.features li::before { content: "·"; margin-right: 7px; color: var(--accent); font-weight: 700; }

/* ---------- Room settings ---------- */

.settings-panel { width: 100%; margin-bottom: 24px; }

.room-settings {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 4px 18px;
  margin-top: 10px;
  text-align: left;
  box-shadow: var(--shadow);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }

.setting-text, .switch-text { min-width: 0; }
.setting-label { font-size: 14px; font-weight: 600; color: var(--text); }
.setting-hint { font-size: 12px; color: var(--text-3); margin-top: 2px; }

.select {
  flex: none;
  max-width: 150px;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 14px;
  padding: 0 8px;
  color: var(--text);
  outline: none;
}
.select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}
.switch-row:last-child { border-bottom: none; }

.switch { position: relative; width: 46px; height: 27px; flex: none; cursor: pointer; }
.switch input { position: absolute; inset: 0; opacity: 0; cursor: pointer; z-index: 2; }
.switch .track { position: absolute; inset: 0; background: #d9d9de; border-radius: 999px; transition: background 0.15s ease; }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.15s ease; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track + .knob { transform: translateX(19px); }

.settings-card { max-width: 440px; }
.settings-card .modal-sub { color: var(--text-3); font-size: 13px; margin-top: -4px; }
.settings-card .room-settings { box-shadow: none; margin-top: -4px; }

.waiting-settings { font-size: 13px; color: var(--text-3); margin-top: -4px; }

/* ---------- Cards (waiting / join / notice) ---------- */

.card {
  width: 100%;
  max-width: 440px;
  margin: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 34px 24px 26px;
  box-shadow: var(--shadow);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.card h1 { font-size: 24px; letter-spacing: -0.015em; line-height: 1.25; }
.card .lead { font-size: 15px; margin-bottom: 2px; }

.field { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 7px; font-size: 14px; font-weight: 600; color: var(--text); margin-top: 4px; }

input[type="text"], textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.link-row { display: flex; gap: 8px; width: 100%; }
.link-row input { flex: 1; min-width: 0; background: var(--surface-2); font-size: 13.5px; color: var(--text-2); }
.link-row .btn { flex-shrink: 0; }

.waiting-status {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text-2);
  font-size: 14px;
  margin-top: 4px;
}

.pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.15); }
}

.notice-icon {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}
.notice-actions { width: 100%; display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }

/* ---------- Chat ---------- */

.chat-app {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex: none;
}

.brand {
  font-weight: 650;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
}
.brand-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); flex: none; }

.header-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-2);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 11px;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: none;
}
.status-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: #c4c4cb; flex: none; }
.status-pill.is-connected .dot { background: var(--green); }
.status-pill.is-waiting .dot { background: var(--accent); animation: pulse 1.6s ease-in-out infinite; }
.status-pill.is-reconnecting .dot { background: var(--amber); animation: pulse 1.1s ease-in-out infinite; }
.status-pill.is-bad .dot { background: var(--danger); }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  border: 1px solid transparent;
  background: none;
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

.menu {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 58px);
  right: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 13px;
  box-shadow: var(--shadow);
  z-index: 60;
  min-width: 190px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  animation: menu-in 0.12s ease;
}
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.menu button {
  background: none;
  border: none;
  text-align: left;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 15px;
  color: var(--text);
  min-height: 46px;
}
.menu button:hover { background: var(--bg); }
.menu button.danger { color: var(--danger); }

.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  padding: 9px 14px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  color: #3d3d85;
  flex: none;
}
.banner.is-bad { background: #fdf1f1; color: #8a2f2f; border-bottom-color: #f3d6d6; }

.chat-body { flex: 1; min-height: 0; position: relative; background: var(--surface-2); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

.messages {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 18px 14px 10px;
  display: flex;
  flex-direction: column;
  touch-action: manipulation;
  gap: 5px;
  -webkit-overflow-scrolling: touch;
}

.message { display: flex; flex-direction: column; max-width: 78%; animation: msg-in 0.18s ease; position: relative; }
.message.mine { align-self: flex-end; align-items: flex-end; }
.message.theirs { align-self: flex-start; align-items: flex-start; }
.message.is-blurred { cursor: pointer; }
.message.is-blurred .bubble {
  filter: blur(9px);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.msg-hint {
  display: none;
  position: absolute;
  inset: 14px 6px;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-2);
  background: rgba(251, 251, 253, 0.6);
  border-radius: 10px;
  pointer-events: none;
}
.message.is-blurred .msg-hint { display: flex; }
.message.is-blurred .msg-time { opacity: 0.4; }

.msg-name { font-size: 11.5px; color: var(--text-3); margin: 0 7px 3px; font-weight: 600; }

.bubble {
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 15.5px;
  line-height: 1.42;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  word-break: break-word;
}
.mine .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.theirs .bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 5px; }

.msg-time { font-size: 10.5px; opacity: 0.6; margin: 3px 7px 0; }

.system {
  align-self: center;
  font-size: 12.5px;
  color: var(--text-3);
  background: var(--bg);
  border-radius: 999px;
  padding: 5px 12px;
  margin: 8px 0;
  text-align: center;
  max-width: 90%;
}
@keyframes msg-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.typing {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 16px 5px;
  font-size: 13px;
  color: var(--text-3);
  min-height: 22px;
  background: var(--surface);
  flex: none;
}
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots span { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: tp 1.2s infinite ease-in-out; }
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes tp { 0%, 60%, 100% { opacity: 0.25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-2px); } }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex: none;
}
.composer textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  max-height: 120px;
  min-height: 46px;
  padding: 11px 15px;
  border-radius: 23px;
  overflow-y: auto;
  line-height: 1.35;
  background: var(--surface-2);
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}
.send-btn {
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, opacity 0.15s ease, transform 0.06s ease;
}
.send-btn:hover:not(:disabled) { background: var(--accent-strong); }
.send-btn:active:not(:disabled) { transform: scale(0.95); }
.send-btn:disabled { opacity: 0.38; cursor: default; }
.send-btn svg { width: 20px; height: 20px; }

.watermark { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.watermark span {
  position: absolute;
  color: var(--text);
  opacity: 0.05;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  transform: rotate(-20deg);
  white-space: nowrap;
}

/* ---------- Modals ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(24, 24, 36, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  animation: fade-in 0.15s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  background: var(--surface);
  border-radius: 18px;
  padding: 24px;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 13px;
}
.modal-card h2 { font-size: 19px; letter-spacing: -0.01em; }
.modal-card p { color: var(--text-2); font-size: 15px; }

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }
.modal-actions .btn { min-width: 108px; }

.info-list { list-style: none; display: flex; flex-direction: column; gap: 11px; font-size: 15px; margin-top: 2px; }
.info-list li { padding-left: 27px; position: relative; color: var(--text); text-align: left; }
.info-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-soft);
}
.info-list li::after {
  content: "✓";
  position: absolute;
  left: 6px;
  top: 1px;
  font-size: 10px;
  color: var(--accent);
  font-weight: 700;
}
.info-note { font-size: 13px; color: var(--text-3); text-align: left; }

/* ---------- Privacy overlays / toast / print ---------- */

.privacy-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex-direction: column;
}
.privacy-overlay-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 0 24px; }
.privacy-overlay p { color: var(--text); font-size: 17px; font-weight: 600; }
.privacy-overlay p.sub { color: var(--text-2); font-size: 14px; font-weight: 400; margin-top: -6px; }
.privacy-overlay .mark { margin-bottom: 2px; }

.flash { background: rgba(255, 255, 255, 0.97); z-index: 101; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(26px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #2a2a30;
  color: #fff;
  font-size: 14px;
  padding: 11px 18px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 90;
  max-width: 86vw;
  text-align: center;
  animation: toast-in 0.2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

#print-notice { display: none; }

@media print {
  .privacy-overlay, .toast, .modal, .menu { display: none !important; }
  body:not(.no-deterrent) #app { display: none !important; }
  body:not(.no-deterrent) #print-notice { display: block; padding: 40px; font-size: 16px; color: #333; }
}

/* ---------- Desktop / tablet ---------- */

@media (min-width: 760px) {
  .landing h1 { font-size: 36px; }
  .chat-app {
    height: calc(100dvh - 32px);
    margin: 16px auto;
    border: 1px solid var(--border);
    border-radius: 22px;
    box-shadow: var(--shadow);
  }
  .menu { right: 20px; }
}
