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

:root {
  --bg:        #0f0f0f;
  --surface:   #1a1a1a;
  --surface2:  #222222;
  --border:    #2e2e2e;
  --text:      #e2e2e2;
  --text-dim:  #777;
  --text-muted:#444;
  --accent:    #3b82f6;
  --accent-h:  #2563eb;
  --green:     #22c55e;
  --yellow:    #eab308;
  --red:       #ef4444;
  --own-bg:    #1d3a6e;
  --peer-bg:   #222;
  --radius:    12px;
  --radius-sm: 6px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── View switcher ───────────────────────────────────────────────────────── */
.view { display: flex; flex-direction: column; height: 100dvh; }
.view[hidden] { display: none; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary   { background: var(--accent);  color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-h); }

.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-wide { width: 100%; }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}
.icon-btn:hover:not(:disabled) { background: var(--surface2); }
.icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.icon-btn--danger:hover:not(:disabled) { background: #2a1010; border-color: var(--red); }

.back-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  padding: 4px 0;
}
.back-btn:hover { color: var(--text); }

/* ── HOME VIEW ───────────────────────────────────────────────────────────── */
.view-home {
  align-items: center;
  justify-content: space-between;
  padding: 40px 24px;
  padding-top: max(40px, calc(env(safe-area-inset-top) + 16px));
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.home-header { text-align: center; }

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
}
.logo-icon { font-size: 36px; }
.logo-text { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }

.tagline {
  color: var(--text-dim);
  font-size: 16px;
}

.home-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}

.card-btn {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
  width: 100%;
  color: var(--text);
  font-family: var(--font);
}
.card-btn:hover { border-color: var(--accent); background: #1a2030; }

.card-icon { font-size: 28px; flex-shrink: 0; }
.card-copy { display: flex; flex-direction: column; gap: 4px; }
.card-copy strong { font-size: 15px; font-weight: 600; }
.card-copy small  { font-size: 13px; color: var(--text-dim); }

.home-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.6;
}

/* ── Install prompt ──────────────────────────────────────────────────────── */
.install-section { width: 100%; }
.install-section[hidden] { display: none; }

.install-btn {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  width: 100%;
  background: linear-gradient(135deg, #0f2340 0%, #1a3a6e 100%);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font-family: var(--font);
  transition: border-color 0.15s, background 0.15s;
}
.install-btn:hover { background: linear-gradient(135deg, #162d50 0%, #1d4080 100%); }
.install-btn[hidden] { display: none; }

.ios-hint {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  width: 100%;
  background: #0f1f0f;
  border: 1px solid #22c55e44;
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
}
.ios-hint[hidden] { display: none; }

.install-icon { font-size: 28px; flex-shrink: 0; }

/* ── CHAT VIEW ───────────────────────────────────────────────────────────── */
.view-chat { height: 100dvh; }

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  padding-top: max(10px, calc(env(safe-area-inset-top) + 10px));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.chat-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-mark { font-size: 20px; }

#enc-indicator {
  font-size: 12px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 20px;
}
.enc-on  { background: #052e10; color: var(--green); }
.enc-off { background: #1c1a08; color: var(--yellow); }

.chat-actions { display: flex; align-items: center; gap: 8px; }

.status-bar {
  padding: 6px 16px;
  font-size: 12px;
  color: var(--text-dim);
  background: #141414;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  transition: color 0.3s;
}
.status-bar.status-error { color: var(--red); }

/* Message list */
.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.notice {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 6px 0 10px;
  border-bottom: 1px dashed var(--border);
  margin-bottom: 4px;
}

/* Message bubbles */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 72%;
}
.msg.own  { align-self: flex-end;  align-items: flex-end; }
.msg.peer { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.own  .bubble { background: var(--own-bg);  border-bottom-right-radius: 3px; }
.peer .bubble { background: var(--peer-bg); border-bottom-left-radius: 3px; border: 1px solid var(--border); }

.msg-img {
  max-width: 260px;
  max-height: 320px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  object-fit: contain;
}

.ts {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
  padding: 0 4px;
}

.err-msg {
  align-self: center;
  font-size: 12px;
  color: var(--red);
  font-style: italic;
}

/* Chat footer */
.chat-footer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.message-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px; /* must be ≥16px — iOS Safari zooms in on any focused input below this */
  padding: 9px 12px;
  resize: none;
  outline: none;
  min-height: 38px;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
}
.message-input:focus { border-color: var(--accent); }
.message-input:disabled { opacity: 0.4; cursor: not-allowed; }
.message-input::placeholder { color: var(--text-muted); }

/* ── PAGE VIEWS (secret create / read) ──────────────────────────────────── */
.view-page {
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
  padding: 0 20px;
}

.page-header {
  padding: 24px 0 16px;
  padding-top: max(24px, calc(env(safe-area-inset-top) + 12px));
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
}
.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  margin-top: 8px;
}

.page-main { display: flex; flex-direction: column; gap: 20px; }

.page-desc {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.6;
}

/* Secret create */
.secret-textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono);
  font-size: 16px; /* must be ≥16px — prevents iOS Safari zoom on focus */
  padding: 14px;
  resize: vertical;
  outline: none;
  min-height: 140px;
}
.secret-textarea:focus { border-color: var(--accent); }
.secret-textarea::placeholder { color: var(--text-muted); font-family: var(--font); }

.secret-result {
  background: var(--surface);
  border: 1px solid var(--green);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.result-label { font-size: 14px; font-weight: 500; }

.link-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.link-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 12px;
  padding: 8px 10px;
  outline: none;
  min-width: 0;
}

.result-note {
  font-size: 12px;
  color: var(--text-muted);
}

/* Secret read */
.secret-content-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.content-label { font-size: 13px; color: var(--text-dim); }

.secret-content {
  font-family: var(--mono);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  color: var(--green);
  max-height: 50vh;
  overflow-y: auto;
}

.secret-status {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.6;
  padding: 8px 0;
}
.secret-status.ok  { color: var(--green); }
.secret-status.err { color: var(--red); }

/* ── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .msg { max-width: 88%; }
  .view-page { padding: 0 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
