/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sans: 'DM Sans', sans-serif;
  --mono: 'DM Mono', monospace;
  --bg:             #12121f;
  --bg-secondary:   #1a1a2e;
  --bg-tertiary:    #1f1f35;
  --text-primary:   #f0ede8;
  --text-secondary: #8a8898;
  --text-tertiary:  #4a4a60;
  --border-light:   rgba(255,255,255,0.07);
  --border-mid:     rgba(255,255,255,0.13);
  --border-strong:  rgba(255,255,255,0.22);
  --accent:         #5b9fd6;
  --green:          #4ade80;
  --radius-md:      8px;
  --radius-lg:      12px;
  --logo-t: #E24B4A;
  --logo-p: #EF9F27;
  --logo-r: #185FA5;
  --logo-i: #1D9E75;
}

html, body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text-primary);
  height: 100%;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

#app {
  position: fixed;
  inset: 0;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  display: flex;
  flex-direction: column;
  max-width: 520px;
  margin: 0 auto;
}

/* ── Screens ── */
.screen {
  display: none;
  flex-direction: column;
  overflow: hidden;
  position: absolute;
  inset: 0;
  background: var(--bg);
  z-index: 1;
}
.screen.active {
  display: flex;
  z-index: 3;
}

/* ══════════════════════════════════
   HOME
══════════════════════════════════ */
#home {
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
#home::-webkit-scrollbar {
  display: none;
}

/* Top half — logo vertically centred */
.home-top {
  height: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding-top: 40px;
}

.logo {
  font-family: 'Arial Black', 'Helvetica Neue', Arial, sans-serif;
  font-size: clamp(80px, 22vw, 130px);
  font-weight: 900;
  letter-spacing: -4px;
  line-height: 1;
  text-transform: lowercase;
  display: flex;
  user-select: none;
}
.logo span:nth-child(1) { color: var(--logo-t); }
.logo span:nth-child(2) { color: var(--logo-p); }
.logo span:nth-child(3) { color: var(--logo-r); }
.logo span:nth-child(4) { color: var(--logo-i); }

/* Bottom half — content at top */
.home-bottom {
  height: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 8px 2rem 0;
  gap: 20px;
  flex-shrink: 0;
  margin-top: -65px;
}

/* Sentence block */
.sentence {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  width: 100%;
}



.keyword-input {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 500;
  border: none;
  border-bottom: 1.5px solid var(--border-strong);
  background: transparent;
  color: var(--text-primary);
  padding: 0 0 4px;
  text-align: center;
  outline: none;
  letter-spacing: -0.02em;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  border-radius: 0;
  min-width: 0;
  width: 230px;
  word-spacing: -4px;
}
.keyword-input::placeholder {
  color: var(--text-tertiary);
  font-weight: 400;
  font-size: 24px;
}
.keyword-input:focus { border-color: var(--accent); }

.name-input {
  font-family: var(--sans);
  font-size: 18px;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  padding: 0 0 6px;
  text-align: center;
  outline: none;
  transition: color 0.2s;
  -webkit-appearance: none;
  border-radius: 0;
  width: 100%;
}
.name-input::placeholder { color: var(--text-tertiary); }
.name-input:focus { color: var(--text-secondary); }

.home-desc {
  font-family: 'Verdana', Geneva, sans-serif;
  font-size: 14px;
  font-weight: 400;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.6;
  max-width: 320px;
  margin-bottom: 60px;
}

.join-btn {
  font-family: var(--sans);
  font-size: 16px;
  font-weight: 600;
  padding: 15px 48px;
  border: none;
  background: var(--text-primary);
  color: var(--bg);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  letter-spacing: 0.02em;
  -webkit-tap-highlight-color: transparent;
}
.join-btn:hover:not(:disabled) { opacity: 0.88; }
.join-btn:active:not(:disabled) { transform: scale(0.97); }
.join-btn:disabled { opacity: 0.2; cursor: default; }

/* ══════════════════════════════════
   FOOTER — only visible after scroll
══════════════════════════════════ */
.home-footer {
  border-top: 0.5px solid var(--border-light);
  padding: 10px 12px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 60px;
}

.footer-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.footer-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}

.footer-right {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
}

.footer-bottom {
  display: flex;
  justify-content: center;
}

.home-footer a {
  font-family: var(--sans);
  font-size: 11px;
  color: var(--text-tertiary);
  text-decoration: none;
  transition: color 0.15s;
}
.home-footer a:hover { color: var(--text-secondary); }

.footer-copyright {
  font-size: 10px;
  color: var(--text-tertiary);
  text-align: center;
  padding-top: 4px;
}

/* ══════════════════════════════════
   WAITING
══════════════════════════════════ */
#waiting {
  align-items: center;
  justify-content: center;
  padding: 3rem 2rem;
  text-align: center;
  gap: 0.75rem;
  overflow-y: auto;
}

.wait-label { font-size: 13px; color: var(--text-secondary); }
.wait-kw { font-family: var(--mono); font-size: 22px; font-weight: 500; color: var(--text-primary); letter-spacing: 0.05em; }
.wait-bar { display: flex; gap: 5px; align-items: center; justify-content: center; margin: 0.5rem 0; }
.wait-seg { width: 22px; height: 3px; background: var(--border-light); border-radius: 2px; transition: background 0.3s; }
.wait-seg.filled { background: var(--accent); }
.wait-count { font-size: 26px; font-weight: 300; color: var(--text-primary); }
.wait-sub { font-size: 13px; color: var(--text-tertiary); }

.cancel-btn {
  font-family: var(--sans);
  font-size: 13px;
  border: 0.5px solid var(--border-light);
  background: transparent;
  color: var(--text-tertiary);
  border-radius: var(--radius-md);
  padding: 6px 16px;
  cursor: pointer;
  margin-top: 1.5rem;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.cancel-btn:hover { color: var(--text-secondary); border-color: var(--border-mid); }

/* ══════════════════════════════════
   CHAT
══════════════════════════════════ */
#chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 0.5px solid var(--border-light);
  flex-shrink: 0;
  background: var(--bg);
  z-index: 2;
}

.room-info { display: flex; align-items: center; gap: 10px; }

.room-tag {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  background: var(--bg-secondary);
  border: 0.5px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 3px 9px;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
}

.room-name { font-size: 14px; font-weight: 500; color: var(--text-primary); }

.member-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border-radius: 20px;
  padding: 3px 10px;
  border: 0.5px solid var(--border-light);
}

.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); flex-shrink: 0; }

.leave-btn {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  border: none;
  background: #E24B4A;
  color: #ffffff;
  border-radius: var(--radius-md);
  padding: 6px 14px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.leave-btn:hover { opacity: 0.85; }
.leave-btn:active { transform: scale(0.96); }

.msgs {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 1rem 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.msgs::-webkit-scrollbar { width: 3px; }
.msgs::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

.msg {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 4px 0;
  user-select: text;
  transition: transform 0.22s ease;
}

.msg-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg-name { font-size: 12px; font-weight: 500; color: var(--text-secondary); }
.msg-name.self { color: var(--accent); }
.msg-time { font-size: 11px; color: var(--text-tertiary); font-family: var(--mono); }

.msg-body {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.55;
  word-break: break-word;
}

.msg.system { padding: 6px 0; }
.msg.system .msg-body { font-size: 12px; color: var(--text-tertiary); font-style: italic; text-align: center; }

.swipe-hint {
  position: absolute;
  left: -24px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  color: var(--accent);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  user-select: none;
}

.reply-quote {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--bg-secondary);
  border-left: 2.5px solid var(--accent);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding: 5px 10px;
  margin-bottom: 4px;
  max-width: 100%;
}
.reply-quote-name { font-size: 11px; font-weight: 600; color: var(--accent); }
.reply-quote-text { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.typing-row {
  min-height: 22px;
  padding: 2px 1rem 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  background: var(--bg);
}

.typing-text { font-size: 12px; color: var(--text-tertiary); font-style: italic; }
.typing-dots { display: flex; gap: 3px; align-items: center; }
.typing-dots span {
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: blink 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 60%, 100% { opacity: 0.3; }
  30% { opacity: 1; }
}

.reply-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-top: 0.5px solid var(--border-light);
  flex-shrink: 0;
  animation: slideUp 0.16s ease;
}
.reply-bar.visible { display: flex; }

@keyframes slideUp {
  from { transform: translateY(6px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}

.reply-bar-inner { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.reply-bar-accent { width: 3px; min-height: 32px; border-radius: 2px; background: var(--accent); flex-shrink: 0; }
.reply-bar-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.reply-name { font-size: 12px; font-weight: 600; color: var(--accent); }
.reply-preview { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.reply-cancel {
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: 15px;
  cursor: pointer;
  padding: 4px 6px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
  line-height: 1;
}
.reply-cancel:hover { color: var(--text-secondary); }

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 0.5px solid var(--border-light);
  background: var(--bg);
  box-shadow: 0 -6px 20px rgba(0,0,0,0.2);
  flex-shrink: 0;
  z-index: 10;
}

.msg-input {
  flex: 1;
  font-family: var(--sans);
  font-size: 16px;
  border: 1px solid var(--border-mid);
  border-radius: 22px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 10px 16px;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  min-width: 0;
}
.msg-input::placeholder { color: var(--text-tertiary); }
.msg-input:focus { border-color: var(--border-strong); box-shadow: 0 0 0 3px rgba(91,159,214,0.1); }

.send-btn {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 18px;
  border: 0.5px solid var(--border-mid);
  background: transparent;
  color: var(--text-primary);
  border-radius: 22px;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.send-btn:hover:not(:disabled) { background: var(--bg-secondary); }
.send-btn:active:not(:disabled) { transform: scale(0.96); }
.send-btn:disabled { opacity: 0.35; cursor: default; }

.ctx-menu {
  position: fixed;
  background: var(--bg-secondary);
  border: 0.5px solid var(--border-mid);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  z-index: 999;
  overflow: hidden;
  min-width: 130px;
  animation: fadeIn 0.1s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

.ctx-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.ctx-item:hover { background: var(--bg-tertiary); }
.ctx-report-msg, .ctx-report-user { color: #E24B4A; }
.ctx-report-msg:hover, .ctx-report-user:hover { background: rgba(226,75,74,0.08); }

/* ── Responsive ── */
@media (max-width: 540px) {
  #app { border: none; }
  .logo { font-size: clamp(72px, 24vw, 110px); }
}

@media (max-width: 360px) {
  .logo { font-size: 100px; }
}
/* ── Report dialog ── */
.report-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1.5rem;
}

.report-modal {
  background: var(--bg-secondary);
  border: 0.5px solid var(--border-mid);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: fadeIn 0.15s ease;
}

.report-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.report-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: -6px;
}

.report-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.report-option {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
}

.report-option input[type="radio"] {
  accent-color: #E24B4A;
  width: 16px;
  height: 16px;
  cursor: pointer;
  flex-shrink: 0;
}

.report-textarea {
  font-family: var(--sans);
  font-size: 13px;
  background: var(--bg-tertiary);
  border: 0.5px solid var(--border-light);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  padding: 8px 10px;
  resize: none;
  height: 80px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
.report-textarea:focus { border-color: var(--border-mid); }
.report-textarea::placeholder { color: var(--text-tertiary); }

.report-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.report-cancel-btn {
  font-family: var(--sans);
  font-size: 13px;
  padding: 8px 16px;
  border: 0.5px solid var(--border-light);
  background: transparent;
  color: var(--text-tertiary);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s;
}
.report-cancel-btn:hover { color: var(--text-secondary); border-color: var(--border-mid); }

.report-submit-btn {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  border: none;
  background: #E24B4A;
  color: #ffffff;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: opacity 0.15s;
}
.report-submit-btn:hover { opacity: 0.85; }

/* ── Terms popup ── */
.terms-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
  animation: fadeIn 0.15s ease;
}

.terms-modal {
  background: var(--bg-secondary);
  border: 0.5px solid var(--border-mid);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: env(safe-area-inset-bottom);
}

.terms-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.terms-body {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
}

.terms-body a {
  color: var(--accent);
  text-decoration: underline;
}

.terms-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.terms-decline-btn {
  font-family: var(--sans);
  font-size: 13px;
  padding: 9px 18px;
  border: 0.5px solid var(--border-light);
  background: transparent;
  color: var(--text-tertiary);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s;
}
.terms-decline-btn:hover { color: var(--text-secondary); border-color: var(--border-mid); }

.terms-accept-btn {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  padding: 9px 18px;
  border: none;
  background: var(--text-primary);
  color: var(--bg);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: opacity 0.15s;
}
.terms-accept-btn:hover { opacity: 0.88; }