:root {
  --bg: #050608;
  --phone: #0b0d12;
  --head: #12151c;
  --line: rgba(255, 255, 255, 0.06);
  --ink: #e4e7ee;
  --ink-dim: #7d8597;
  --ink-faint: #4a5163;
  --in: #1a1e27;
  --out: #2b3a52;
  --out-ink: #e8eefa;
  --accent: #8fa8d6;
  --blood: #c94a4a;
  --unknown: #2a1d1f;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% 120%, rgba(201, 74, 74, 0.08), transparent 60%),
    var(--bg);
}
button { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- phone frame ---------- */
.phone {
  position: relative;
  width: 100%;
  height: 100dvh;
  max-width: 430px;
  background: var(--phone);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
@media (min-width: 600px) and (min-height: 700px) {
  .phone {
    height: min(880px, calc(100dvh - 48px));
    border-radius: 38px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 10px #0e0f13, 0 0 0 11px rgba(255, 255, 255, 0.05), 0 40px 120px rgba(0, 0, 0, 0.8);
  }
}

.statusbar {
  flex: none;
  height: 30px;
  padding: max(6px, env(safe-area-inset-top)) 22px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.sb-right { display: flex; align-items: center; gap: 8px; }
.signal { display: flex; align-items: flex-end; gap: 2px; height: 11px; }
.signal i { display: block; width: 3px; background: var(--ink); border-radius: 1px; }
.signal i:nth-child(1) { height: 4px; }
.signal i:nth-child(2) { height: 6px; }
.signal i:nth-child(3) { height: 8px; }
.signal i:nth-child(4) { height: 11px; }
.sb-nosignal { display: none; font-size: 11px; font-weight: 500; color: var(--blood); }
.phone.no-signal .signal i { background: var(--ink-faint); }
.phone.no-signal .sb-nosignal { display: inline; }
.sb-battery {
  width: 22px; height: 11px; border: 1.5px solid var(--ink); border-radius: 3px; padding: 1px; position: relative;
}
.sb-battery::after { content: ''; position: absolute; right: -4px; top: 3px; width: 2px; height: 4px; background: var(--ink); border-radius: 1px; }
.sb-battery i { display: block; height: 100%; width: 64%; background: var(--ink); border-radius: 1px; }

/* ---------- chat ---------- */
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--head);
}
.head-btn {
  border: 0; background: none; padding: 6px; border-radius: 50%; cursor: pointer; color: var(--accent);
  display: flex;
}
.head-btn:active { background: rgba(255, 255, 255, 0.06); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 16px; color: #dfe6f3;
  background: linear-gradient(135deg, #3c4a63, #222a39);
  position: relative;
  transition: filter 0.4s;
}
.phone.dead .avatar { filter: grayscale(1) brightness(0.6); }
.head-info { flex: 1; min-width: 0; }
.head-name { font-weight: 600; font-size: 16px; }
.head-status { font-size: 12.5px; color: var(--ink-dim); height: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-status.online { color: var(--accent); }
.head-status.typing { color: var(--accent); }
.head-status.typing::after { content: ''; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

.feed {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background:
    radial-gradient(circle at 20% 10%, rgba(143, 168, 214, 0.035), transparent 40%),
    radial-gradient(circle at 80% 90%, rgba(201, 74, 74, 0.03), transparent 40%);
  scrollbar-width: none;
}
.feed::-webkit-scrollbar { display: none; }

.day {
  align-self: center;
  margin: 8px 0 10px;
  font-size: 12px;
  color: var(--ink-dim);
  background: rgba(255, 255, 255, 0.04);
  padding: 3px 10px;
  border-radius: 10px;
}

.msg {
  max-width: 82%;
  padding: 7px 10px 6px;
  border-radius: 16px;
  line-height: 1.38;
  position: relative;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: pop 0.22s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }
.msg.in { align-self: flex-start; background: var(--in); border-bottom-left-radius: 5px; }
.msg.out { align-self: flex-end; background: var(--out); color: var(--out-ink); border-bottom-right-radius: 5px; }
.msg.gap { margin-top: 7px; }
.meta {
  float: right;
  margin: 6px 0 -3px 10px;
  font-size: 11px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
  user-select: none;
}
.msg.out .meta { color: rgba(232, 238, 250, 0.55); }
.ticks { margin-left: 3px; letter-spacing: -3px; }
.ticks.read { color: var(--accent); }
.undelivered { color: var(--blood); font-weight: 700; margin-left: 4px; }
.msg.deleted { font-style: italic; color: var(--ink-dim); }
.msg.corrupt { color: #d9b8b8; }
.msg.photo { padding: 3px; }
.msg.photo img { display: block; width: 240px; max-width: 100%; border-radius: 13px; cursor: zoom-in; }
.msg.photo.captioned { padding-bottom: 6px; }
.msg.photo .cap { padding: 6px 7px 0; }
.msg.photo:not(.captioned) .meta {
  position: absolute; right: 9px; bottom: 7px; margin: 0; float: none;
  background: rgba(0, 0, 0, 0.5); color: #ddd; padding: 1px 6px; border-radius: 8px;
}

/* voice */
.voice { display: flex; align-items: center; gap: 10px; min-width: 210px; }
.voice-play {
  width: 36px; height: 36px; border-radius: 50%; border: 0; flex: none; cursor: pointer;
  background: var(--accent); color: #0b0d12; display: flex; align-items: center; justify-content: center;
}
.voice-wave { flex: 1; display: flex; align-items: center; gap: 2px; height: 26px; }
.voice-wave i { flex: 1; background: var(--ink-faint); border-radius: 2px; min-height: 3px; transition: background 0.1s; }
.voice-wave i.on { background: var(--accent); }
.voice-dur { font-size: 11px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.voice-tr {
  margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line);
  font-size: 13.5px; font-style: italic; color: #b9a4a4;
}

/* system lines + unknown-number cards */
.sys {
  align-self: center;
  margin: 10px 0;
  font-size: 12.5px;
  color: var(--ink-dim);
  text-align: center;
  max-width: 85%;
}
.sys.alert { color: var(--blood); }
.unknown {
  align-self: flex-start;
  max-width: 86%;
  margin: 3px 0;
  padding: 8px 11px 7px;
  background: var(--unknown);
  border: 1px solid rgba(201, 74, 74, 0.25);
  border-radius: 12px;
  line-height: 1.38;
  white-space: pre-wrap;
  animation: pop 0.22s ease-out;
}
.unknown-from { font-size: 11.5px; font-weight: 600; color: var(--blood); margin-bottom: 2px; letter-spacing: 0.02em; }

.typing-bubble {
  align-self: flex-start; background: var(--in); padding: 11px 14px; border-radius: 16px; border-bottom-left-radius: 5px;
  display: flex; gap: 4px; margin-top: 7px;
}
.typing-bubble i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-dim); animation: blink 1.2s infinite; }
.typing-bubble i:nth-child(2) { animation-delay: 0.2s; }
.typing-bubble i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* replies */
.replies { flex: none; padding: 0 10px; max-height: 0; overflow: hidden; transition: max-height 0.3s ease; }
.replies.open { max-height: 340px; padding-bottom: 8px; }
.timer { height: 3px; background: rgba(255, 255, 255, 0.06); border-radius: 2px; margin: 6px 4px 8px; overflow: hidden; visibility: hidden; }
.timer.on { visibility: visible; }
.timer-fill { height: 100%; width: 100%; background: var(--blood); transform-origin: left; }
.reply-list { display: flex; flex-direction: column; gap: 6px; }
.reply {
  text-align: left;
  border: 1px solid rgba(143, 168, 214, 0.28);
  background: rgba(143, 168, 214, 0.06);
  color: var(--ink);
  padding: 10px 13px;
  border-radius: 14px;
  cursor: pointer;
  line-height: 1.3;
  transition: background 0.15s, border-color 0.15s;
  animation: pop 0.25s ease-out both;
}
.reply:hover { background: rgba(143, 168, 214, 0.13); border-color: rgba(143, 168, 214, 0.5); }
.reply:active { transform: scale(0.985); }
.reply.special { border-color: rgba(201, 74, 74, 0.45); background: rgba(201, 74, 74, 0.08); }

.composer {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--head);
}
.composer-input {
  flex: 1;
  padding: 9px 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink-faint);
  font-size: 14.5px;
  user-select: none;
}
.composer-send { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; color: var(--ink-faint); }

/* ---------- push ---------- */
.push {
  position: absolute;
  left: 10px; right: 10px; top: 36px;
  padding: 10px 14px 11px;
  border-radius: 16px;
  background: rgba(38, 30, 32, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(201, 74, 74, 0.3);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  transform: translateY(-140%);
  transition: transform 0.35s cubic-bezier(.2, .9, .3, 1.1);
  z-index: 30;
  pointer-events: none;
}
.push.show { transform: none; }
.push-app { font-size: 11px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.08em; }
.push-from { font-weight: 600; margin: 2px 0; color: #f0d6d6; }
.push-text { font-size: 14px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- overlays ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 40;
  display: none; align-items: flex-end; justify-content: center;
  background: rgba(3, 4, 6, 0.7);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.overlay.open { display: flex; animation: fadein 0.25s; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  width: 100%;
  padding: 22px 18px max(22px, env(safe-area-inset-bottom));
  background: #111419;
  border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  display: flex; flex-direction: column; gap: 9px;
  animation: slideup 0.3s ease-out;
}
@keyframes slideup { from { transform: translateY(30px); } to { transform: none; } }
.sheet-title { font-weight: 600; font-size: 17px; text-align: center; margin-bottom: 6px; }
.btn {
  display: block; width: 100%; text-align: center; text-decoration: none;
  padding: 13px 16px; border-radius: 14px; border: 1px solid transparent; cursor: pointer;
  background: #d9dee8; color: #0b0d12; font-weight: 600; font-size: 15px;
}
.btn:active { transform: scale(0.985); }
.btn.ghost { background: rgba(255, 255, 255, 0.04); color: var(--ink); border-color: var(--line); font-weight: 500; }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.08); }
.btn.warn { background: var(--blood); color: #fff; }

.ending { align-items: center; padding: 16px; background: rgba(3, 4, 6, 0.86); }
.ending .sheet { border-radius: 20px; border: 1px solid var(--line); max-height: 100%; overflow-y: auto; }
.end-label { text-align: center; font-size: 11.5px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--blood); }
.end-title { text-align: center; font-family: 'Special Elite', monospace; font-size: 26px; margin: 2px 0 6px; }
.end-text { color: #b8bfcc; line-height: 1.5; font-size: 14.5px; white-space: pre-wrap; margin-bottom: 6px; }
.end-found { font-size: 12px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.1em; margin-top: 4px; }
.end-list { list-style: none; padding: 0; margin: 0 0 8px; font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.end-list li { color: var(--ink-faint); }
.end-list li.got { color: var(--ink); }
.end-list li.got::before { content: '● '; color: var(--blood); }
.end-list li:not(.got)::before { content: '○ '; }

.viewer {
  position: absolute; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.94); cursor: zoom-out;
}
.viewer.open { display: flex; animation: fadein 0.2s; }
.viewer img { max-width: 100%; max-height: 100%; }

/* ---------- menu ---------- */
.menu {
  position: absolute; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(143, 168, 214, 0.06), transparent 60%),
    radial-gradient(ellipse at 50% 100%, rgba(201, 74, 74, 0.1), transparent 55%),
    #07080b;
}
.menu.closed { display: none; }
.menu-inner { width: 100%; max-width: 330px; text-align: center; }
.logo {
  font-family: 'Special Elite', monospace;
  font-size: 46px;
  letter-spacing: 0.02em;
  position: relative;
  display: inline-block;
  color: #e6e9ef;
  text-shadow: 0 0 24px rgba(201, 74, 74, 0.25);
}
.logo::before, .logo::after {
  content: attr(data-text); position: absolute; inset: 0; pointer-events: none; opacity: 0.7;
}
.logo::before { color: var(--blood); animation: jitter 5s infinite steps(1); clip-path: inset(0 0 60% 0); }
.logo::after { color: var(--accent); animation: jitter 7s infinite reverse steps(1); clip-path: inset(55% 0 0 0); }
@keyframes jitter {
  0%, 92%, 100% { transform: none; opacity: 0; }
  93% { transform: translate(-3px, 1px); opacity: 0.7; }
  95% { transform: translate(3px, -1px); opacity: 0.7; }
  97% { transform: translate(-1px, 0); opacity: 0.5; }
}
.menu-sub { white-space: pre-line; color: var(--ink-dim); margin: 8px 0 34px; font-size: 14px; line-height: 1.5; }
.menu-btns { display: flex; flex-direction: column; gap: 9px; }
.lang-switch { display: flex; gap: 6px; padding: 4px; border-radius: 14px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); }
.lang-switch button {
  flex: 1; padding: 9px; border-radius: 10px; border: 0; background: none; color: var(--ink-dim); cursor: pointer; font-weight: 500;
}
.lang-switch button.on { background: rgba(255, 255, 255, 0.1); color: var(--ink); }
.menu-found { margin-top: 22px; font-size: 12px; color: var(--ink-dim); letter-spacing: 0.08em; text-transform: uppercase; min-height: 15px; }
.menu-hint { white-space: pre-line; margin-top: 10px; font-size: 12px; color: var(--ink-faint); line-height: 1.5; }

/* ---------- effects ---------- */
.glitch { position: absolute; inset: 0; pointer-events: none; z-index: 70; opacity: 0; }
.glitch.on {
  animation: glitch 0.9s steps(2) forwards;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.04) 0 2px, transparent 2px 4px),
    linear-gradient(90deg, rgba(201, 74, 74, 0.25), transparent 30%, transparent 70%, rgba(143, 168, 214, 0.2));
}
@keyframes glitch {
  0% { opacity: 1; transform: translateX(-4px); }
  20% { opacity: 0.2; transform: translateX(5px); }
  40% { opacity: 0.9; transform: translateX(-2px) skewX(2deg); }
  60% { opacity: 0.1; }
  80% { opacity: 0.6; transform: translateX(3px); }
  100% { opacity: 0; transform: none; }
}
.phone.shake { animation: shake 0.5s; }
@keyframes shake {
  0%, 100% { transform: none; }
  20% { transform: translate(-3px, 1px); }
  40% { transform: translate(3px, -1px); }
  60% { transform: translate(-2px, 2px); }
  80% { transform: translate(2px, 0); }
}
.phone.flash::after {
  content: ''; position: absolute; inset: 0; background: #fff; z-index: 80; pointer-events: none;
  animation: flash 1.6s ease-out forwards;
}
@keyframes flash { 0% { opacity: 0.9; } 100% { opacity: 0; } }
.phone.dark .feed { filter: brightness(0.75) saturate(0.6); transition: filter 2s; }
