:root {
  --bg: #e6e0d3;
  --phone: #f3efe6;
  --head: #fbf9f4;
  --line: rgba(40, 32, 20, 0.09);
  --ink: #1f2430;
  --ink-dim: #7a7466;
  --ink-faint: #b3ac9c;
  --in: #ffffff;
  --out: #1f3a5f;
  --out-ink: #f1f4fa;
  --accent: #1f5fae;
  --amber: #c98a1b;
  --amber-soft: rgba(201, 138, 27, 0.12);
  --red: #b8412f;
  --paper: #fbf4df;
}

* { 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% -10%, rgba(255, 214, 140, 0.35), 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(0, 0, 0, 0.08);
    box-shadow: 0 0 0 10px #22252b, 0 0 0 11px rgba(0, 0, 0, 0.2), 0 40px 100px rgba(60, 40, 10, 0.35);
  }
}

.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;
  background: var(--head);
  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-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: 78%; 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: 8px;
  padding: 6px 8px 9px;
  border-bottom: 1px solid var(--line);
  background: var(--head);
}
.head-btn {
  border: 0; background: none; padding: 7px; border-radius: 50%; cursor: pointer; color: var(--accent);
  display: flex; position: relative;
}
.head-btn:active { background: rgba(0, 0, 0, 0.05); }
.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: #fff;
  background: linear-gradient(135deg, #d9a23a, #b4562e);
}
.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, .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: '...'; } }
.note-btn { color: var(--amber); }
.note-count {
  position: absolute; top: 1px; right: 0;
  min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  background: var(--amber); color: #fff; font-size: 10.5px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--head);
}
.note-btn.bump { animation: bump 0.6s ease-out; }
@keyframes bump { 0% { transform: scale(1); } 30% { transform: scale(1.3) rotate(-8deg); } 60% { transform: scale(0.95); } 100% { transform: none; } }

.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 15% 20%, rgba(201, 138, 27, 0.05), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(31, 95, 174, 0.04), transparent 40%),
    var(--phone);
  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(0, 0, 0, 0.05);
  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; box-shadow: 0 1px 1px rgba(60, 40, 10, 0.08); }
.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-faint);
  font-variant-numeric: tabular-nums;
  user-select: none;
}
.msg.out .meta { color: rgba(241, 244, 250, 0.55); }
.ticks { margin-left: 3px; letter-spacing: -3px; }
.ticks.read { color: #8fc0ff; }
.msg.photo { padding: 3px; }
.msg.photo img { display: block; width: 250px; 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.45); color: #eee; padding: 1px 6px; border-radius: 8px;
}

/* the anonymous number, forwarded */
.msg.fwd { border-left: 3px solid var(--red); background: #fff7f4; }
.fwd-from { font-size: 11.5px; font-weight: 600; color: var(--red); margin-bottom: 3px; }

/* a clue I send */
.msg.attach { padding: 5px; max-width: 86%; }
.msg.attach .clue-card { background: var(--paper); color: var(--ink); }
.msg.attach .meta { margin-top: 4px; }

/* system lines */
.sys {
  align-self: center;
  margin: 10px 0;
  font-size: 12.5px;
  color: var(--ink-dim);
  text-align: center;
  max-width: 85%;
}
.clue-line {
  color: #8a5d0f;
  background: var(--amber-soft);
  border: 1px dashed rgba(201, 138, 27, 0.5);
  padding: 4px 12px;
  border-radius: 12px;
  cursor: pointer;
  animation: pop 0.3s ease-out;
}
.clue-pin { margin-right: 6px; }

.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; box-shadow: 0 1px 1px rgba(60, 40, 10, 0.08);
}
.typing-bubble i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-faint); 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.35; 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; background: var(--phone); }
.replies.open { max-height: 380px; padding-bottom: 8px; overflow-y: auto; }
.timer { height: 3px; background: rgba(0, 0, 0, 0.07); border-radius: 2px; margin: 6px 4px 8px; overflow: hidden; visibility: hidden; }
.timer.on { visibility: visible; }
.timer-fill { height: 100%; width: 100%; background: var(--red); transform-origin: left; }
.reply-list { display: flex; flex-direction: column; gap: 6px; }
.reply {
  text-align: left;
  border: 1px solid rgba(31, 95, 174, 0.3);
  background: #fff;
  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: #f2f6fc; border-color: rgba(31, 95, 174, 0.55); }
.reply:active { transform: scale(0.985); }
.reply.special { border-color: rgba(201, 138, 27, 0.6); background: #fffaf0; }
.reply.special::before { content: '🔍 '; }
.reply.evidence { border: 1px solid var(--amber); background: var(--paper); font-weight: 600; text-align: center; }

.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(0, 0, 0, 0.04);
  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); }

/* ---------- clue cards (notebook + attachments) ---------- */
.clue-card {
  background: var(--paper);
  border-radius: 10px;
  padding: 10px 12px 11px;
  border: 1px solid rgba(160, 120, 40, 0.25);
  box-shadow: 0 1px 2px rgba(60, 40, 10, 0.08);
  white-space: normal;
}
.clue-title { font-family: 'Playfair Display', Georgia, serif; font-weight: 600; font-size: 16px; margin-bottom: 3px; }
.clue-title::before { content: '📎 '; font-size: 13px; }
.clue-text { font-size: 13.5px; line-height: 1.4; color: #4d4637; }

/* ---------- overlays ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 40;
  display: none; align-items: flex-end; justify-content: center;
  background: rgba(30, 24, 14, 0.4);
  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: var(--head);
  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; }
.notebook { max-height: 82%; background: #f6efdc; }
.notebook .sheet-title { font-family: 'Playfair Display', Georgia, serif; font-size: 21px; }
.note-list { overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 2px; min-height: 60px; }
.note-list .clue-card { background: #fffdf6; }
.note-list .clue-card.focus { border-color: var(--amber); box-shadow: 0 0 0 2px var(--amber-soft); }
.note-list .clue-card.pickable { cursor: pointer; transition: transform 0.12s, border-color 0.12s; }
.note-list .clue-card.pickable:hover { border-color: var(--amber); transform: translateX(3px); }
.note-empty { color: var(--ink-dim); text-align: center; font-size: 14px; padding: 18px 8px; line-height: 1.5; }
.btn {
  display: block; width: 100%; text-align: center; text-decoration: none;
  padding: 13px 16px; border-radius: 14px; border: 1px solid transparent; cursor: pointer;
  background: var(--out); color: #fff; font-weight: 600; font-size: 15px;
}
.btn:active { transform: scale(0.985); }
.btn.ghost { background: rgba(0, 0, 0, 0.03); color: var(--ink); border-color: var(--line); font-weight: 500; }
.btn.ghost:hover { background: rgba(0, 0, 0, 0.06); }
.btn.warn { background: var(--red); color: #fff; }

.ending { align-items: center; padding: 16px; background: rgba(30, 24, 14, 0.6); }
.ending .sheet { border-radius: 20px; border: 1px solid var(--line); max-height: 100%; overflow-y: auto; background: #fbf7ec; }
.end-label { text-align: center; font-size: 11.5px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--amber); }
.end-title { text-align: center; font-family: 'Playfair Display', Georgia, serif; font-size: 27px; margin: 2px 0 6px; }
.end-text { color: #4d4637; line-height: 1.55; 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(--amber); }
.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(10, 8, 5, 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(circle at 50% 34%, rgba(255, 196, 100, 0.45), transparent 32%),
    radial-gradient(ellipse at 50% 110%, rgba(31, 58, 95, 0.25), transparent 60%),
    #efe7d4;
}
.menu.closed { display: none; }
.menu-inner { width: 100%; max-width: 330px; text-align: center; }
.logo {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 600;
  font-size: 50px;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.logo em { font-style: italic; font-weight: 500; color: var(--amber); }
.menu-sub { white-space: pre-line; color: #5e5747; margin: 10px 0 32px; font-size: 14px; line-height: 1.55; }
.menu-btns { display: flex; flex-direction: column; gap: 9px; }
.lang-switch { display: flex; gap: 6px; padding: 4px; border-radius: 14px; background: rgba(0, 0, 0, 0.03); 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: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.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-dim); line-height: 1.5; }
