:root {
  --ink: #17120f;
  --ink-soft: #4b4038;
  --paper: #f7efe1;
  --paper-2: #fff8ec;
  --paper-3: #efe1cb;
  --red: #de4f32;
  --red-dark: #b83220;
  --green: #286c55;
  --blue: #245d8f;
  --yellow: #f2b84b;
  --pink: #ef9ea7;
  --violet: #6e57a8;
  --line: rgba(23, 18, 15, 0.14);
  --shadow: 0 8px 24px rgba(61, 39, 24, 0.1);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 24px;
  --max: 960px;
  --display: "Fraunces", Georgia, serif;
  --sans: "Bricolage Grotesque", Inter, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

img.emoji { height: 1.1em; width: 1.1em; margin: 0 0.05em 0 0.1em; vertical-align: -0.2em; display: inline-block; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
::selection { background: var(--yellow); color: var(--ink); }

.container { width: min(calc(100% - 32px), var(--max)); margin: 0 auto; }

/* ── Nav ──────────────────────────────────────────────────── */
.nav {
  position: sticky; top: 0; z-index: 50;
  background: rgba(247, 239, 225, 0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
.nav-inner {
  display: flex; align-items: center; gap: 16px;
  min-height: 64px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; letter-spacing: -0.03em;
}
.brand-logo { border-radius: 10px; }
.brand-name { font-size: 1.1rem; }
.nav-links {
  display: flex; gap: 4px; margin-left: auto;
  padding: 5px; border: 1px solid var(--line);
  border-radius: 999px; background: rgba(255,248,236,0.6);
}
.nav-link {
  padding: 7px 12px; border-radius: 999px;
  font-size: 0.85rem; font-weight: 700; color: var(--ink-soft);
  transition: background 150ms, color 150ms;
}
.nav-link:hover, .nav-link.active { background: var(--ink); color: var(--paper-2); }
.nav-actions { display: flex; align-items: center; gap: 12px; margin-left: 12px; }
.nav-avatar {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 12px; border: 1.5px solid var(--ink);
  background: var(--red); color: white;
  font-family: var(--mono); font-weight: 800; font-size: 0.8rem;
}

/* ── Main ─────────────────────────────────────────────────── */
.main { min-height: calc(100vh - 64px - 80px); padding: 32px 0; }

/* ── Auth ─────────────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 32px 16px;
  background:
    radial-gradient(circle at 20% 20%, rgba(239,158,167,0.3), transparent 20rem),
    radial-gradient(circle at 80% 10%, rgba(242,184,75,0.25), transparent 20rem),
    var(--paper);
}
.auth-card {
  width: min(420px, 100%);
  padding: 32px;
  border: 1.5px solid var(--ink);
  border-radius: var(--radius-lg);
  background: var(--paper-2);
  box-shadow: 8px 10px 0 rgba(23,18,15,0.08);
  text-align: center;
}
.auth-logo { border-radius: 18px; margin-bottom: 16px; }
.auth-headline { font-family: var(--display); font-size: 2rem; letter-spacing: -0.06em; margin: 0 0 8px; }
.auth-sub { color: var(--ink-soft); margin: 0 0 24px; line-height: 1.5; }
.auth-error { color: var(--red); font-weight: 700; font-size: 0.9rem; margin-bottom: 16px; }
.auth-error-note { color: var(--ink-soft); font-size: 0.8rem; margin: -10px 0 16px; line-height: 1.5; }
.auth-footer { margin-top: 20px; font-size: 0.85rem; color: var(--ink-soft); }
.auth-footer a { color: var(--red); font-weight: 700; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; justify-content: center; align-items: center;
  min-height: 48px; padding: 0 24px;
  border-radius: 999px; border: 1.5px solid var(--ink);
  font-weight: 800; letter-spacing: -0.02em;
  cursor: pointer; white-space: nowrap;
  transition: transform 150ms, box-shadow 150ms;
  box-shadow: 0 6px 0 rgba(23,18,15,0.1);
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 8px 0 rgba(23,18,15,0.1); }
.btn:active { transform: translateY(1px); box-shadow: 0 3px 0 rgba(23,18,15,0.1); }
.btn-primary { background: var(--red); border-color: var(--red); color: white; }
.btn-secondary { background: var(--ink); border-color: var(--ink); color: var(--paper-2); }
.btn-ghost { background: transparent; color: var(--ink); box-shadow: none; }
.btn-ghost:hover { background: var(--paper-3); }
.btn-full { width: 100%; }
.btn-sm { min-height: 38px; padding: 0 16px; font-size: 0.85rem; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  padding: 20px;
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper-2);
  box-shadow: 6px 7px 0 rgba(23,18,15,0.07);
}
.card:hover { box-shadow: 8px 10px 0 rgba(23,18,15,0.09); }

/* ── Forms ────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.label {
  display: block; margin-bottom: 6px;
  font-family: var(--mono); font-size: 0.75rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.input, .select {
  width: 100%; height: 48px; padding: 0 14px;
  border: 1.5px solid var(--ink); border-radius: var(--radius-sm);
  background: white; color: var(--ink); outline: none;
  box-shadow: 4px 4px 0 rgba(23,18,15,0.06);
  transition: transform 120ms, box-shadow 120ms;
  font-size: 16px; /* explicit, not just inherited — anything under 16px makes iOS Safari zoom in on focus */
}
.input:focus, .select:focus {
  transform: translateY(-1px);
  box-shadow: 5px 5px 0 rgba(23,18,15,0.08);
}
textarea.input { height: auto; padding: 12px 14px; resize: vertical; }

.checkbox-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-check {
  display: none;
}
.chip-label {
  display: inline-flex; align-items: center;
  padding: 8px 14px; border: 1.5px solid var(--line);
  border-radius: 999px; font-size: 0.85rem; font-weight: 700;
  cursor: pointer; transition: all 120ms;
  background: white;
}
.chip-check:checked + .chip-label {
  background: var(--ink); color: var(--paper-2); border-color: var(--ink);
}

/* ── Page headers ─────────────────────────────────────────── */
.page-header { margin-bottom: 28px; }
.page-header h1 {
  font-family: var(--display); font-size: clamp(2rem, 5vw, 3rem);
  letter-spacing: -0.07em; line-height: 0.95; margin: 0 0 8px;
}
.page-header p { color: var(--ink-soft); margin: 0; }

/* ── Partner card ─────────────────────────────────────────── */
.partner-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.partner-card {
  display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center;
  padding: 16px;
  border: 1.5px solid var(--ink); border-radius: var(--radius);
  background: var(--paper-2);
  box-shadow: 6px 7px 0 rgba(23,18,15,0.07);
  transition: transform 150ms;
}
.partner-card:hover { transform: translateY(-3px) rotate(-0.5deg); }
.avatar {
  width: 52px; height: 52px;
  border: 1.5px solid var(--ink); border-radius: 16px;
  display: grid; place-items: center;
  font-family: var(--mono); font-weight: 800; color: white;
}
.partner-name { font-weight: 800; letter-spacing: -0.03em; }
.partner-meta { font-size: 0.85rem; color: var(--ink-soft); margin-top: 2px; }
.tag-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.tag {
  padding: 4px 8px; border-radius: 999px;
  border: 1px solid var(--line); background: white;
  font-family: var(--mono); font-size: 0.7rem; font-weight: 700;
}

/* ── Chat ─────────────────────────────────────────────────── */
.convo-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer; transition: background 100ms;
}
.convo-item:hover, .convo-item.active { background: white; }
.convo-item.active { border-left: 3px solid var(--red); padding-left: 13px; }
.convo-item .avatar { width: 42px; height: 42px; font-size: 0.75rem; flex-shrink: 0; }
.convo-name { font-weight: 700; font-size: 0.9rem; }
.convo-preview { font-size: 0.8rem; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.convo-time { font-family: var(--mono); font-size: 0.7rem; color: var(--ink-soft); margin-left: auto; flex-shrink: 0; }
.unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); flex-shrink: 0; }

/* ── Chat app shell: sidebar list + active conversation pane, side by side ── */
.chat-app {
  display: flex;
  width: min(calc(100% - 32px), 1280px);
  margin-left: auto; margin-right: auto;
  margin-top: -32px; margin-bottom: -32px;
  height: calc(100dvh - 64px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: white;
}
.chat-sidebar { width: 320px; flex-shrink: 0; overflow-y: auto; border-right: 1px solid var(--line); background: var(--paper-2); }
.chat-sidebar-head { position: sticky; top: 0; padding: 20px 20px 14px; border-bottom: 1px solid var(--line); background: var(--paper-2); z-index: 1; }
.chat-sidebar-head h1 { font-family: var(--display); font-size: 1.4rem; letter-spacing: -0.03em; margin: 0; }
.chat-sidebar .empty-state { padding: 40px 20px; }

.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-main-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); position: relative; flex-shrink: 0; }
.chat-back { display: none; }
.chat-empty { flex: 1; display: grid; place-items: center; text-align: center; padding: 40px; color: var(--ink-soft); }
.chat-empty h2 { font-family: var(--display); font-size: 1.7rem; letter-spacing: -0.04em; color: var(--ink); margin-bottom: 8px; }

.chat-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 8px; }

.image-lightbox {
  display: none; position: fixed; inset: 0; z-index: 300;
  background: rgba(23,18,15,0.92);
  align-items: center; justify-content: center; padding: 24px;
}
.image-lightbox.open { display: flex; }
.image-lightbox img { max-width: 92vw; max-height: 88vh; border-radius: 10px; display: block; }
.image-lightbox-close {
  position: absolute; top: max(16px, env(safe-area-inset-top)); right: 16px;
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: rgba(255,255,255,0.15); color: white; font-size: 1.6rem; line-height: 1;
  cursor: pointer; display: grid; place-items: center;
}
.image-lightbox-close:hover { background: rgba(255,255,255,0.25); }
.message { max-width: 70%; padding: 10px 14px; border-radius: 16px; font-size: 0.92rem; line-height: 1.45; }
.message.sent { align-self: flex-end; background: var(--ink); color: var(--paper-2); border-bottom-right-radius: 4px; }
.message.received { align-self: flex-start; background: white; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.message-time { font-size: 0.7rem; color: var(--ink-soft); margin-top: 4px; }
.message.sent .message-time { color: rgba(255,248,236,0.6); }
.message.prompt-msg { background: var(--yellow); color: var(--ink); border: 1.5px solid var(--ink); align-self: center; max-width: 85%; text-align: center; border-radius: var(--radius); }

.message-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.message-actions .edit-toggle,
.message-actions .correct-toggle { flex-basis: auto; }
.message-actions .edit-toggle[open],
.message-actions .correct-toggle[open] { flex-basis: 100%; }
.message-action-btn {
  display: inline-block; font-size: 0.7rem; font-weight: 700; letter-spacing: -0.01em;
  color: var(--ink-soft); background: none; border: none; padding: 0; margin: 0;
  cursor: pointer; list-style: none;
}
.message-action-btn::-webkit-details-marker { display: none; }
.message-action-btn::marker { content: ''; }
.message-action-btn:hover { color: var(--ink); text-decoration: underline; }
button.message-action-btn:disabled { color: var(--green); cursor: default; }
button.message-action-btn:disabled:hover { text-decoration: none; }
.message-action-sep { font-size: 0.7rem; color: var(--ink-soft); opacity: 0.45; }
.message.sent .message-action-btn { color: rgba(255,248,236,0.55); }
.message.sent .message-action-btn:hover { color: var(--paper-2); }
.message.sent button.message-action-btn:disabled { color: #a9f0cd; }
.message.sent .message-action-sep { color: rgba(255,248,236,0.35); opacity: 1; }
.message-action-panel { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }

.voice-player { display: flex; align-items: center; gap: 8px; min-width: 170px; }
.voice-play-btn {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%; border: none; cursor: pointer;
  flex-shrink: 0; padding: 0; transition: transform 100ms;
}
.voice-play-btn:active { transform: scale(0.9); }
.voice-play-btn .icon-play { margin-left: 1px; }
.message.sent .voice-play-btn { background: var(--paper-2); color: var(--ink); }
.message.received .voice-play-btn { background: var(--ink); color: var(--paper-2); }
.voice-track { flex: 1; height: 4px; border-radius: 999px; cursor: pointer; }
.message.sent .voice-track { background: rgba(255,248,236,0.25); }
.message.received .voice-track { background: var(--line); }
.voice-progress { height: 100%; width: 0%; border-radius: 999px; background: var(--red); }
.voice-time { font-family: var(--mono); font-size: 0.7rem; flex-shrink: 0; min-width: 28px; text-align: right; opacity: 0.85; }

.icon-spin { animation: icon-spin 0.8s linear infinite; transform-origin: center; }
@keyframes icon-spin { to { transform: rotate(360deg); } }

.chat-input-bar {
  display: flex; gap: 8px; padding: 12px 16px;
  border-top: 1px solid var(--line); background: var(--paper-2);
}
.chat-input-bar .input { flex: 1; height: 44px; border-radius: 999px; min-width: 0; }
.chat-input-bar .btn { border-radius: 999px; min-height: 44px; }
.chat-input-bar .btn-icon { width: 44px; min-width: 44px; padding: 0; flex-shrink: 0; }

/* ── Prompt picker ────────────────────────────────────────── */
.prompt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.prompt-card {
  padding: 14px; border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: white; cursor: pointer; transition: all 120ms;
}
.prompt-card:hover { border-color: var(--ink); box-shadow: 4px 4px 0 rgba(23,18,15,0.06); }
.prompt-card.selected { border-color: var(--red); background: #fff0ec; }
.prompt-title { font-weight: 800; margin: 4px 0; }
.prompt-body { font-size: 0.85rem; color: var(--ink-soft); line-height: 1.45; }

/* ── Phrase shelf ─────────────────────────────────────────── */
.phrase-item {
  display: flex; justify-content: space-between; align-items: start; gap: 16px;
  padding: 14px 0; border-bottom: 1px solid var(--line);
}
.phrase-text { font-weight: 700; }
.phrase-translation { font-size: 0.85rem; color: var(--ink-soft); margin-top: 2px; }
.phrase-lang { font-family: var(--mono); font-size: 0.7rem; color: var(--green); font-weight: 700; }

/* ── Footer ───────────────────────────────────────────────── */
.footer { padding: 28px 0; border-top: 1px solid var(--line); }
.footer-inner { text-align: center; }
.footer small { color: var(--ink-soft); font-size: 0.8rem; }
.footer a { color: var(--ink-soft); text-decoration: underline; }

/* ── Utilities ────────────────────────────────────────────── */
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.gap-2 { gap: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--ink-soft); }
.empty-state h3 { font-family: var(--display); font-size: 1.6rem; letter-spacing: -0.05em; color: var(--ink); margin-bottom: 8px; }
.badge { display: inline-flex; padding: 3px 8px; border-radius: 999px; font-family: var(--mono); font-size: 0.7rem; font-weight: 700; }
.badge-green { background: rgba(40,108,85,0.12); color: var(--green); }
.badge-red { background: rgba(222,79,50,0.12); color: var(--red); }

.bottom-nav { display: none; }

@media (max-width: 768px) {
  .nav-links { display: none; }
  .partner-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }

  .main { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

  .chat-app {
    width: 100%;
    margin-left: 0; margin-right: 0;
    border-left: 0; border-right: 0; border-radius: 0;
    height: calc(100dvh - 64px - 72px - env(safe-area-inset-bottom));
    margin-bottom: calc(-1 * (72px + env(safe-area-inset-bottom)));
  }
  .chat-sidebar { width: 100%; border-right: 0; }
  .chat-app--convo-open .chat-sidebar { display: none; }
  .chat-app:not(.chat-app--convo-open) .chat-main { display: none; }
  .chat-back { display: inline-flex; }

  .bottom-nav {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 100;
    background: rgba(247, 239, 225, 0.95);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--line);
    padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
  }
  .bottom-nav a {
    flex: 1; text-align: center;
    padding: 6px 2px;
    font-family: var(--mono); font-size: 0.65rem; font-weight: 700;
    color: var(--ink-soft); text-decoration: none;
    border-radius: var(--radius-sm);
  }
  .bottom-nav a.active { color: var(--red); }
}
