:root {
  --cream: #FFF7EC;
  --cream-2: #FFF0DC;
  --card: #FFFFFF;
  --peach: #FF9466;
  --peach-dark: #F2703D;
  --yellow: #FFC94A;
  --mint: #4FBDA6;
  --mint-dark: #2E9C87;
  --text: #4A3A2F;
  --text-soft: #8A7A6D;
  --border: #F0E2D0;
  --danger: #E76F51;
  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --shadow: 0 8px 24px rgba(180, 130, 90, 0.14);
  --shadow-sm: 0 3px 10px rgba(180, 130, 90, 0.10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--cream);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  background: var(--cream);
  position: relative;
}

@media (min-width: 560px) {
  #app {
    min-height: 100vh;
    box-shadow: var(--shadow);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

a { color: inherit; text-decoration: none; }

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px 20px 90px;
  animation: fadein .25s ease;
}
.screen.no-pad-bottom { padding-bottom: 24px; }

@keyframes fadein { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: translateY(0);} }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 26px;
  font-weight: 800;
  color: var(--peach-dark);
  margin-bottom: 4px;
}
.brand .logo-dot { font-size: 22px; }

.subtitle { color: var(--text-soft); font-size: 14px; margin-bottom: 24px; }

h1.page-title {
  font-size: 22px;
  font-weight: 800;
  margin: 0 0 4px;
  color: var(--text);
}
p.page-desc { color: var(--text-soft); font-size: 14px; margin: 0 0 20px; line-height: 1.5; }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-soft);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--card);
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--peach);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .1s, box-shadow .15s, opacity .15s;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: linear-gradient(135deg, var(--peach), var(--peach-dark));
  color: white;
  box-shadow: 0 6px 16px rgba(242, 112, 61, 0.35);
}
.btn-secondary {
  background: var(--card);
  color: var(--peach-dark);
  border: 2px solid var(--peach);
}
.btn-mint {
  background: linear-gradient(135deg, var(--mint), var(--mint-dark));
  color: white;
  box-shadow: 0 6px 16px rgba(46, 156, 135, 0.3);
}
.btn-ghost {
  background: transparent;
  color: var(--text-soft);
  font-weight: 700;
}
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-sm { padding: 9px 14px; font-size: 13px; width: auto; border-radius: var(--radius-sm); }

.link-row { text-align: center; margin-top: 18px; font-size: 14px; color: var(--text-soft); }
.link-row button.link, button.link { background: none; border: none; color: var(--peach-dark); font-weight: 800; cursor: pointer; padding: 0; font-size: 14px; }

.error-box {
  background: #FFF0EC;
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 14px;
  border: 1px solid #FADBD3;
}
.hint-box {
  background: #FFF7E0;
  color: #8A6B1E;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 14px;
}

.card {
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

.level-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.level-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--card);
  cursor: pointer;
}
.level-option.selected { border-color: var(--peach); background: #FFF3EC; }
.level-badge {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--yellow); color: #6B4A00;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px; flex-shrink: 0;
}
.level-text b { display: block; font-size: 14px; }
.level-text span { font-size: 12px; color: var(--text-soft); }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--cream);
  padding: 18px 20px 10px;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; column-gap: 10px;
}
.topbar .title { font-size: 20px; font-weight: 800; }
.topbar-right { display: flex; align-items: center; gap: 10px; justify-self: end; }
.topbar-brand { display: flex; align-items: center; gap: 4px; font-size: 15px; font-weight: 800; color: var(--peach-dark); white-space: nowrap; justify-self: start; }
.page-tag { display: flex; align-items: center; gap: 4px; font-size: 14px; font-weight: 700; color: var(--text); white-space: nowrap; justify-self: center; }
.topbar .lang-pill {
  background: var(--card); border-radius: 20px; padding: 6px 12px;
  font-size: 12px; font-weight: 700; color: var(--peach-dark);
  box-shadow: var(--shadow-sm);
}
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--card); border: none; box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: center; font-size: 17px; cursor: pointer;
}

.profile-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: none; box-shadow: var(--shadow-sm);
  border-radius: 22px; padding: 5px 6px 5px 14px; cursor: pointer;
}
.profile-chip-name {
  font-size: 13.5px; font-weight: 800; color: var(--text);
  max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.profile-chip-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  background: var(--cream-2); display: flex; align-items: center; justify-content: center;
  font-size: 16px; overflow: hidden;
}
.profile-chip-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* conversation list */
.conv-list { padding: 4px 20px 100px; display: flex; flex-direction: column; gap: 10px; }
.conv-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: var(--radius-md);
  padding: 12px 14px; box-shadow: var(--shadow-sm); cursor: pointer;
}
.avatar {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--cream-2); display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}
.conv-info { flex: 1; min-width: 0; }
.conv-name-row { display: flex; align-items: center; gap: 6px; }
.conv-name { font-weight: 800; font-size: 15px; }
.conv-lang-tag { font-size: 11px; color: var(--mint-dark); background: #E6F7F3; padding: 2px 7px; border-radius: 10px; font-weight: 700; }
.conv-last { font-size: 13px; color: var(--text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.conv-time { font-size: 11px; color: var(--text-soft); flex-shrink: 0; }
.empty-state { text-align: center; color: var(--text-soft); padding: 40px 20px; font-size: 14px; line-height: 1.6; }
.empty-state .emoji { font-size: 40px; display: block; margin-bottom: 10px; }

/* friend list */
.friend-list { padding: 4px 20px calc(100px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
.friend-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border-radius: var(--radius-md);
  padding: 14px; box-shadow: var(--shadow-sm); cursor: pointer;
}
.friend-avatar {
  width: 56px; height: 56px; border-radius: 50%; flex-shrink: 0;
  background: var(--cream-2); display: flex; align-items: center; justify-content: center;
  font-size: 26px; overflow: hidden;
}
.friend-avatar img { width: 100%; height: 100%; object-fit: cover; }
.friend-info { flex: 1; min-width: 0; }
.friend-name { font-weight: 800; font-size: 15.5px; margin-bottom: 6px; }
.friend-langs { display: flex; gap: 6px; flex-wrap: wrap; }
.lang-badge { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 10px; }
.lang-badge.native { color: var(--peach-dark); background: #FFF0E5; }
.lang-badge.learning { color: var(--mint-dark); background: #E6F7F3; }

.action-row { display: flex; gap: 10px; padding: 4px 20px 14px; }
.action-chip {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--card); border-radius: var(--radius-sm); padding: 12px; font-size: 13px; font-weight: 800;
  box-shadow: var(--shadow-sm); cursor: pointer; color: var(--peach-dark); border: none;
}

/* bottom tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  max-width: 480px; margin: 0 auto;
  background: var(--card);
  display: flex; justify-content: space-around; align-items: center;
  padding: 10px 6px calc(10px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 18px rgba(180,130,90,0.12);
  border-top-left-radius: 22px; border-top-right-radius: 22px;
  z-index: 10;
}
.tab-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: none; cursor: pointer; color: var(--text-soft);
  font-size: 10px; font-weight: 700; padding: 4px 10px; border-radius: 14px;
}
.tab-item .tab-glyph {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px; background: var(--cream-2); color: var(--text-soft);
}
.tab-item.active { color: var(--peach-dark); }
.tab-item.active .tab-glyph { background: linear-gradient(135deg, var(--peach), var(--peach-dark)); color: white; }

/* chat */
.chat-header {
  position: sticky; top: 0; z-index: 5;
  background: var(--cream);
  padding: 16px 16px 10px;
  display: flex; align-items: center; gap: 10px;
}
.chat-header .name { font-weight: 800; font-size: 16px; flex: 1; }
.chat-header .lang-pill {
    background: var(--card); border: none; border-radius: 20px; padding: 6px 12px;
    font-size: 12px; font-weight: 700; color: var(--peach-dark); box-shadow: var(--shadow-sm);
}
.chat-header .lang-pill.clickable { cursor: pointer; }
.chat-header .leave-btn {
    background: none; border: none; color: var(--peach-dark); font-size: 13px;
    font-weight: 700; cursor: pointer; padding: 6px 4px;
}
/* Bottom padding leaves room for .chat-input-bar, which is position:fixed and
   sits on top of the page rather than taking up flex space - without this the
   last message (or two) end up hidden behind the input bar. */
.chat-body { flex: 1; padding: 8px 16px calc(84px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }
.msg-row { display: flex; flex-direction: column; max-width: 82%; }
.msg-row.mine { align-self: flex-end; align-items: flex-end; }
.msg-row.theirs { align-self: flex-start; align-items: flex-start; }
.msg-bubble {
  border-radius: var(--radius-md); padding: 10px 14px; font-size: 14.5px; line-height: 1.5;
  box-shadow: var(--shadow-sm);
}
.msg-row.mine .msg-bubble { background: linear-gradient(135deg, var(--peach), var(--peach-dark)); color: white; border-bottom-right-radius: 4px; }
.msg-row.theirs .msg-bubble { background: var(--card); color: var(--text); border-bottom-left-radius: 4px; }
.msg-native {
  font-size: 12px; margin-top: 4px; padding: 0 4px; color: var(--text-soft);
}
.msg-row.mine .msg-native { text-align: right; }
.word-token { cursor: pointer; border-radius: 4px; }
.word-token:active, .word-token.word-active { background: rgba(255,255,255,0.35); }
.msg-row.theirs .word-token.word-active { background: var(--yellow); }

.vocab-popover {
  position: fixed; z-index: 40; background: var(--text); color: white;
  border-radius: 14px; padding: 10px 14px; font-size: 13px; box-shadow: var(--shadow);
  max-width: 260px;
}
.vocab-popover .add-vocab-btn {
  margin-top: 8px; background: var(--yellow); color: #5A3E00; border: none;
  border-radius: 10px; padding: 6px 10px; font-weight: 800; font-size: 12px; cursor: pointer; width: 100%;
}

.chat-input-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  max-width: 480px; margin: 0 auto;
  background: var(--card); padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  display: flex; gap: 8px; align-items: center;
  box-shadow: 0 -4px 18px rgba(180,130,90,0.12);
  border-top-left-radius: 22px; border-top-right-radius: 22px;
}
.mode-toggle {
  display: flex; border-radius: 20px; background: var(--cream-2); padding: 3px; flex-shrink: 0;
}
.mode-toggle button {
  border: none; background: none; font-size: 11px; font-weight: 800; padding: 7px 10px; border-radius: 16px; cursor: pointer; color: var(--text-soft);
}
.mode-toggle button.active { background: var(--mint); color: white; }
.chat-input-bar input {
  flex: 1; border: none; background: var(--cream-2); border-radius: 20px; padding: 11px 16px; font-size: 14px; outline: none; font-family: inherit;
}
.send-btn {
  width: 40px; height: 40px; border-radius: 50%; border: none; flex-shrink: 0;
  background: linear-gradient(135deg, var(--peach), var(--peach-dark)); color: white; font-size: 16px; cursor: pointer;
}
.send-btn[disabled] { opacity: .5; }

.lang-modal-backdrop {
  position: fixed; inset: 0; background: rgba(74,58,47,0.4); z-index: 30;
  display: flex; align-items: flex-end; justify-content: center;
}
.lang-modal {
  background: var(--cream); width: 100%; max-width: 480px; border-top-left-radius: 26px; border-top-right-radius: 26px;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom)); max-height: 80vh; overflow-y: auto;
}

/* vocabulary */
.vocab-date-heading { font-weight: 800; font-size: 14px; color: var(--peach-dark); margin: 18px 0 8px; }
.vocab-card { position: relative; background: var(--card); border-radius: var(--radius-md); padding: 14px 40px 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow-sm); }
.vocab-word-line { font-weight: 800; font-size: 15px; margin-bottom: 6px; }
.vocab-meta { font-size: 12.5px; color: var(--text-soft); margin-top: 2px; line-height: 1.5; }
.vocab-delete-btn {
  position: absolute; top: 10px; right: 10px; width: 26px; height: 26px;
  border: none; border-radius: 50%; background: var(--cream-2); color: var(--text-soft);
  font-size: 13px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.vocab-delete-btn:hover { background: var(--peach); color: white; }
.vocab-delete-btn:disabled { opacity: 0.5; cursor: default; }

.center-flex { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 10px; padding: 40px 20px; }
.center-flex .big-emoji { font-size: 52px; }
.center-flex h2 { margin: 0; font-size: 18px; }
.center-flex p { margin: 0; color: var(--text-soft); font-size: 14px; }

.toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: white; padding: 10px 18px; border-radius: 20px; font-size: 13px; box-shadow: var(--shadow);
}
.msg-toast {
  border-radius: 14px; padding: 12px 16px; max-width: 320px; width: calc(100% - 32px);
  text-align: left; cursor: pointer;
}
.msg-toast b { display: block; font-size: 13px; margin-bottom: 3px; color: var(--yellow); }
.msg-toast div { font-size: 13.5px; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.stepper { display: flex; gap: 6px; margin-bottom: 20px; }
.stepper .dot { flex: 1; height: 5px; border-radius: 3px; background: var(--border); }
.stepper .dot.done { background: var(--peach); }

.spinner {
  width: 16px; height: 16px; border-radius: 50%; border: 2.5px solid rgba(255,255,255,0.5); border-top-color: white;
  display: inline-block; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.typing-dots { display: inline-flex; gap: 3px; padding: 12px 14px; }
.typing-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-soft); display: inline-block; animation: bounce 1s infinite; }
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5;} 30% { transform: translateY(-4px); opacity: 1; } }
