/* ── CARD MOBILE (index.html) ── */
body.app-body {
  overflow: hidden; position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  height: 100%; height: -webkit-fill-available;
}
.card.app-card {
  width: 390px; max-width: 100vw; height: 100%; max-height: 720px;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: var(--shadow-lg); position: relative;
  padding: 0;
}
@media (max-width: 480px) {
  body.app-body { align-items: stretch; background: var(--surface); }
  .card.app-card { width: 100%; max-width: 100%; height: 100%; max-height: 100%; border-radius: 0; border: none; }
}
.card-inner {
  padding: 1.75rem; display: flex; flex-direction: column;
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.card-inner::-webkit-scrollbar { display: none; }

/* ── LOGO ROW ── */
.logo-row {
  display: flex; align-items: center; justify-content: center;
  gap: .5rem; margin-bottom: 1.5rem; flex-shrink: 0;
}
.logo-icon {
  width: 40px; height: 40px; background: var(--accent);
  border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; box-shadow: 0 0 20px rgba(233,69,96,0.3); flex-shrink: 0;
}
.logo-text { font-size: 1.5rem; font-weight: 800; letter-spacing: -1px; }
.logo-text span { color: var(--accent); }
.section-hint {
  font-size: .78rem; font-weight: 600; color: var(--muted); text-align: center;
  margin-bottom: 1.25rem; text-transform: uppercase; letter-spacing: 1px; flex-shrink: 0;
}
.badge-chip {
  display: inline-flex; align-items: center; gap: .35rem;
  background: var(--accent); color: #fff; border-radius: 99px;
  padding: .3rem .875rem; font-weight: 800; font-size: 1rem;
}

/* ── CHAT TOPBAR ── */
.chat-topbar {
  padding: .875rem 1.1rem .75rem; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; flex-shrink: 0;
}
.chat-topbar-left  { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.chat-topbar-right { display: flex; gap: .4rem; align-items: center; flex-shrink: 0; }
.safeplace-btn {
  display: inline-flex; align-items: center; gap: .3rem;
  background: rgba(100,180,255,0.1); border: 1px solid rgba(100,180,255,0.25);
  color: #64b4ff; border-radius: 99px; padding: .35rem .7rem;
  font-size: .72rem; font-weight: 700; cursor: pointer; transition: background .15s;
  white-space: nowrap; -webkit-tap-highlight-color: transparent;
}
.safeplace-btn:active { background: rgba(100,180,255,0.22); }
.refresh-btn {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  background: var(--surface2); border: 1px solid var(--border2); border-radius: 99px;
  cursor: pointer; font-size: .9rem; color: var(--muted2);
  -webkit-tap-highlight-color: transparent; flex-shrink: 0;
}

/* ── CONVERSATION LIST ── */
.conv-list {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: .75rem 1rem; display: flex; flex-direction: column; gap: .4rem;
}
.conv-list::-webkit-scrollbar { display: none; }
.conv-new-btn {
  margin: 0 1rem .875rem; display: flex; align-items: center; gap: .6rem;
  background: rgba(16,185,129,0.06); border: 1.5px dashed rgba(16,185,129,0.25);
  border-radius: var(--radius); padding: .8rem 1rem; cursor: pointer;
  color: var(--green); font-weight: 600; font-size: .875rem; flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.conv-item {
  display: flex; align-items: center; gap: .75rem;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .75rem .875rem;
  cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.conv-item.unread       { border-color: rgba(245,158,11,0.4); background: rgba(245,158,11,0.05); }
.conv-item.lottery-win  { border-color: rgba(245,159,11,0.5); background: rgba(245,158,11,0.07); animation: lotteryGlow 2s ease-in-out infinite; }
.conv-item.lottery-win-read { border-color: rgba(16,185,129,0.4); background: rgba(16,185,129,0.06); }
.conv-item.lottery-lose { border-color: var(--border); background: rgba(255,255,255,0.02); }
.conv-item.expired      { opacity: .55; }
@keyframes lotteryGlow { 0%,100%{box-shadow:none} 50%{box-shadow:0 0 16px rgba(245,158,11,0.3)} }

.conv-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .85rem; flex-shrink: 0; color: #fff;
}
.conv-avatar.unread       { background: linear-gradient(135deg, var(--gold), #d97706); }
.conv-avatar.lottery      { background: linear-gradient(135deg, var(--gold), #d97706); font-size: 1.2rem; }
.conv-avatar.lottery-lose { background: linear-gradient(135deg, #444, #333); font-size: 1.2rem; }
.conv-avatar.expired      { background: var(--surface2); color: var(--muted); }
.conv-body    { flex: 1; min-width: 0; }
.conv-name    { font-weight: 700; font-size: .875rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-preview { font-size: .75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: .1rem; }
.conv-badge   { background: var(--gold); color: #1a1200; border-radius: 99px; padding: .12rem .5rem; font-size: .68rem; font-weight: 800; flex-shrink: 0; }
.conv-countdown { font-size: .65rem; font-weight: 700; padding: .15rem .45rem; border-radius: 6px; flex-shrink: 0; white-space: nowrap; }
.conv-countdown.urgent      { color: #ff4444; background: rgba(255,68,68,0.12); animation: urgentPulse 1s ease-in-out infinite; }
.conv-countdown.warning     { color: var(--gold);  background: rgba(245,158,11,0.12); }
.conv-countdown.normal      { color: var(--muted); background: rgba(255,255,255,0.05); }
.conv-countdown.expired-tag { color: var(--muted); background: rgba(255,255,255,0.04); }
@keyframes urgentPulse { 0%,100%{opacity:1} 50%{opacity:.45} }

/* ── THREAD ── */
.thread-wrap { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.thread-header {
  display: flex; align-items: center; gap: .75rem;
  padding: .875rem 1rem .75rem; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.back-btn {
  width: 36px; height: 36px; background: var(--surface2); border: 1px solid var(--border2);
  border-radius: 10px; color: var(--text); font-size: 1rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; -webkit-tap-highlight-color: transparent;
}
.thread-info   { flex: 1; min-width: 0; }
.thread-name   { font-weight: 700; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-status { font-size: .7rem; color: var(--muted); margin-top: .1rem; transition: color .3s; }
.thread-status.read { color: var(--green); }
.thread-countdown-area { padding: 0 1rem; flex-shrink: 0; }
.thread-countdown {
  display: flex; align-items: center; gap: .5rem; font-size: .75rem;
  padding: .4rem .75rem; border-radius: 10px; margin: .4rem 0 .2rem; font-weight: 600; flex-wrap: wrap;
}
.thread-countdown.normal  { background: rgba(255,255,255,0.04); color: var(--muted); }
.thread-countdown.warning { background: rgba(245,158,11,0.1); color: var(--gold); border: 1px solid rgba(245,158,11,0.2); }
.thread-countdown.urgent  { background: rgba(255,68,68,0.1); color: #ff4444; border: 1px solid rgba(255,68,68,0.25); animation: urgentPulse 1s ease-in-out infinite; }
.thread-countdown.expired { background: rgba(255,255,255,0.04); color: var(--muted); border: 1px solid var(--border); }
.time-progress-bar  { height: 3px; background: rgba(255,255,255,0.05); border-radius: 99px; overflow: hidden; margin-bottom: .2rem; }
.time-progress-fill { height: 100%; border-radius: 99px; transition: width .5s linear, background .5s; }
.request-time-btn {
  margin-left: auto; background: rgba(59,130,246,0.12); border: 1px solid rgba(59,130,246,0.25);
  color: #60a5fa; border-radius: 6px; padding: .2rem .55rem; font-size: .72rem; font-weight: 700;
  cursor: pointer; white-space: nowrap; -webkit-tap-highlight-color: transparent;
}
.thread-msgs {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: .875rem 1rem; display: flex; flex-direction: column; gap: .45rem;
}
.thread-msgs::-webkit-scrollbar { display: none; }
.bubble { max-width: 78%; padding: .6rem .875rem; border-radius: 16px; font-size: .875rem; line-height: 1.45; }
.bubble.recv          { background: var(--surface2); border-bottom-left-radius: 4px; align-self: flex-start; }
.bubble.sent          { background: var(--accent);   border-bottom-right-radius: 4px; align-self: flex-end; }
.bubble.contact       { background: rgba(16,185,129,0.12); border: 1px solid rgba(16,185,129,0.3); align-self: flex-start; }
.bubble.lottery_win   { background: linear-gradient(135deg,#2a1f00,#3d2e00); border: 1.5px solid var(--gold); align-self: center; max-width: 92%; text-align: center; }
.bubble.lottery_lose  { background: rgba(255,255,255,0.03); border: 1.5px solid #444; align-self: center; max-width: 92%; text-align: center; color: var(--muted); }
.bubble.system-expired { background: rgba(255,255,255,0.03); border: 1px dashed #444; align-self: center; max-width: 88%; text-align: center; color: var(--muted); font-style: italic; font-size: .8rem; border-radius: 10px; }
.bubble.system-info    { background: rgba(59,130,246,0.07); border: 1px dashed rgba(59,130,246,0.25); align-self: center; max-width: 88%; text-align: center; color: #60a5fa; font-style: italic; font-size: .8rem; border-radius: 10px; }
.bubble .bts      { font-size: .62rem; color: rgba(255,255,255,0.3); margin-top: .25rem; display: block; }
.bubble.sent .bts { color: rgba(255,255,255,0.5); }
.bubble .read-tick { font-size: .62rem; color: var(--green); margin-top: .1rem; display: block; text-align: right; }
.thread-input-area { padding: .65rem 1rem .75rem; border-top: 1px solid var(--border); flex-shrink: 0; }
.thread-input-area textarea { height: 52px; margin-bottom: .5rem; font-size: 16px; }
.back-link { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; font-weight: 600; color: var(--muted2); cursor: pointer; margin-bottom: 1.25rem; -webkit-tap-highlight-color: transparent; }

/* ── CODE JOIN INPUT ── */
.code-input-wrap { text-align: center; margin-bottom: 1.5rem; }
.code-input-wrap .code-icon { font-size: 2.5rem; margin-bottom: .75rem; }
.code-input-wrap .code-hint { font-size: .875rem; color: var(--muted2); line-height: 1.55; }
#join-code-input {
  text-align: center !important; font-size: 1.6rem !important; font-weight: 900 !important;
  letter-spacing: 6px !important; text-transform: uppercase;
  font-family: ui-monospace, 'Courier New', monospace !important;
}

/* ── QUIZ MODAL ── */
#quiz-modal {
  position: fixed; inset: 0; z-index: 5000;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(6px);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 1rem;
}
.quiz-modal-content {
  background: var(--card,#fff); border-radius: 1rem;
  padding: 1.5rem; width: 100%; max-width: 500px;
  max-height: 90dvh; overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,.2);
}
.quiz-header { text-align: center; margin-bottom: 1.5rem; }
.quiz-spice { font-size: 2rem; margin-bottom: .5rem; }
.quiz-question { margin: 0 0 .5rem; font-weight: 600; color: var(--text); }
.quiz-type-hint { font-size: .85rem; color: var(--muted2); margin: 0; }
.quiz-answers { display: flex; gap: .5rem; flex-direction: column; }
.quiz-answer-btn {
  padding: .75rem; border: 1px solid var(--border,#ccc);
  border-radius: .5rem; background: var(--bg,#f9f9f9);
  color: var(--text,#000); font-size: .95rem; cursor: pointer;
  text-align: left; transition: all .2s;
  -webkit-tap-highlight-color: transparent; min-height: 44px;
}
.quiz-answer-btn:active { background: var(--accent); color: #fff; }
.quiz-textarea {
  padding: .75rem; border: 1px solid var(--border,#ccc);
  border-radius: .5rem; background: var(--bg,#f9f9f9);
  color: var(--text,#000); font-size: .95rem;
  min-height: 80px; resize: vertical;
  font-family: inherit; -webkit-tap-highlight-color: transparent;
}
.quiz-btn-submit {
  margin-top: .5rem; padding: .75rem;
  background: var(--accent); color: #fff;
  border: none; border-radius: .5rem;
  font-weight: 600; cursor: pointer; width: 100%;
  -webkit-tap-highlight-color: transparent; min-height: 44px;
}
.quiz-btn-close {
  margin-top: .5rem; padding: .75rem;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: .5rem;
  font-weight: 600; cursor: pointer; width: 100%;
  -webkit-tap-highlight-color: transparent; min-height: 44px;
}

/* ── POPUPS (lottery, match, expiry) ── */
.confetti-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 499; }
.lottery-overlay { position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.92); backdrop-filter: blur(8px); animation: fadeIn .35s ease; padding: 1rem; }
@keyframes fadeIn { from{opacity:0} to{opacity:1} }
.lottery-win-box  { background: linear-gradient(135deg,#1a1200,#2a1f00); border: 2px solid var(--gold); border-radius: var(--radius-lg); padding: 2rem 1.5rem; text-align: center; max-width: 320px; width: 100%; box-shadow: 0 0 60px rgba(245,158,11,0.4); animation: winPop .55s cubic-bezier(.34,1.56,.64,1); }
.lottery-lose-box { background: var(--surface); border: 1px solid #444; border-radius: var(--radius-lg); padding: 1.75rem 1.5rem; text-align: center; max-width: 300px; width: 100%; animation: losePop .45s cubic-bezier(.34,1.2,.64,1); }
@keyframes winPop  { from{transform:scale(0.3) rotate(-6deg);opacity:0} to{transform:scale(1) rotate(0);opacity:1} }
@keyframes losePop { from{transform:scale(0.5);opacity:0} to{transform:scale(1);opacity:1} }
.win-emoji  { font-size: 3.5rem; display: block; margin-bottom: .875rem; animation: bounce 1s ease-in-out infinite alternate; }
@keyframes bounce { from{transform:translateY(0)} to{transform:translateY(-10px)} }
.win-title  { color: var(--gold); font-size: 1.5rem; font-weight: 900; margin-bottom: .4rem; }
.win-lot    { color: var(--text); font-size: 1rem; font-weight: 700; margin-bottom: .4rem; }
.win-desc   { color: var(--muted2); font-size: .875rem; margin-bottom: 1.25rem; line-height: 1.5; }
.lose-emoji    { font-size: 2.75rem; display: block; margin-bottom: .75rem; }
.lose-title    { color: var(--muted2); font-size: 1.1rem; font-weight: 700; margin-bottom: .4rem; }
.lose-subtitle { color: var(--muted); font-size: .85rem; margin-bottom: 1.1rem; line-height: 1.5; }
.match-overlay { position: fixed; inset: 0; z-index: 700; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.92); backdrop-filter: blur(10px); animation: fadeIn .3s ease; padding: 1rem; }
.match-box { background: linear-gradient(135deg,#1a003a,#2d0050); border: 2px solid var(--pink); border-radius: var(--radius-lg); padding: 2rem 1.5rem; text-align: center; max-width: 300px; width: 100%; box-shadow: 0 0 80px rgba(255,105,180,0.5); animation: matchPop .65s cubic-bezier(.34,1.56,.64,1); }
@keyframes matchPop { from{transform:scale(0.2) rotate(8deg);opacity:0} to{transform:scale(1) rotate(0);opacity:1} }
.match-emoji { font-size: 3.5rem; display: block; margin-bottom: .75rem; animation: heartbeat .8s ease-in-out infinite alternate; }
@keyframes heartbeat { from{transform:scale(1)} to{transform:scale(1.18)} }
.match-title { color: var(--pink); font-size: 2rem; font-weight: 900; margin-bottom: .4rem; letter-spacing: 3px; text-shadow: 0 0 20px rgba(255,105,180,0.7); }
.match-sub   { color: var(--muted2); font-size: .9rem; margin-bottom: 1.25rem; line-height: 1.55; }
.expiry-overlay { position: fixed; inset: 0; z-index: 800; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.88); backdrop-filter: blur(6px); animation: fadeIn .3s ease; padding: 1rem; }
.expiry-box          { background: var(--surface); border: 1.5px solid var(--gold); border-radius: var(--radius-lg); padding: 1.75rem 1.5rem; text-align: center; max-width: 300px; width: 100%; animation: losePop .45s cubic-bezier(.34,1.2,.64,1); }
.expiry-box.critical { border-color: #ff4444; }
.expiry-box.ended    { border-color: #444; }
.ack-overlay { position: fixed; inset: 0; z-index: 600; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.92); backdrop-filter: blur(8px); padding: 1rem; }
.ack-box { border-radius: var(--radius-lg); padding: 2rem 1.5rem; text-align: center; max-width: 320px; width: 100%; }
.ack-box.win  { background: linear-gradient(135deg,#1a1200,#2a1f00); border: 2px solid var(--gold); box-shadow: 0 0 50px rgba(245,158,11,0.3); animation: winPop .55s cubic-bezier(.34,1.56,.64,1); }
.ack-box.lose { background: var(--surface); border: 1px solid #444; animation: losePop .45s cubic-bezier(.34,1.2,.64,1); }

/* ── TIME REQUEST DIALOG ── */
.dialog.safeplace    { border-color: rgba(100,180,255,0.3); }
.dialog.safeplace h3 { color: #64b4ff; }
.dialog.time-request    { border-color: rgba(96,165,250,0.3); }
.dialog.time-request h3 { color: #60a5fa; }
.time-slider-wrap { margin: .875rem 0; }
.time-slider-wrap input[type=range] { width: 100%; accent-color: var(--blue); height: 5px; cursor: pointer; background: rgba(255,255,255,0.08); border-radius: 3px; border: none; padding: 0; margin-bottom: .5rem; outline: none; }
.time-slider-label { text-align: center; font-size: 1.1rem; font-weight: 800; color: #60a5fa; }

/* ── FOOTER ── */
footer {
  position: fixed; bottom: 0; left: 0; width: 100%; text-align: center;
  font-size: .65rem; color: var(--muted); padding: .6rem;
  pointer-events: none; z-index: 10;
  background: rgba(8,8,15,0.95); backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}
footer a { color: var(--accent); pointer-events: all; text-decoration: none; }
#s-chat .conv-list { padding-bottom: 4rem; }
#s-chat .conv-new-btn { margin: 0 1rem 4.5rem; }
@media (max-width: 480px) { footer { padding: .8rem .4rem; font-size: .7rem; } }

.msg {
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
  word-break: break-word;
}

.msg span {
  flex: 1;
}

.msg-receipt {
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
  min-width: 20px;
  text-align: center;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.msg-receipt.read-receipt {
  opacity: 1;
  color: var(--accent);
  font-weight: 800;
}

.unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  background: var(--destructive);
  color: white;
  border-radius: 99px;
  font-size: 0.65rem;
  font-weight: 700;
  margin-left: 0.4rem;
}

.conv-item.has-unread {
  border-left: 3px solid var(--accent);
}