/* ============================================================
   AniChat — Design System
   Palette: ink navy base, warm paper accents, plum-coral signature
   Type: Fraunces (display) + Inter (UI) + JetBrains Mono (meta)
   Signature element: "presence aura" — a breathing gradient halo
   behind every character portrait, color-keyed per character.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,500;0,9..144,600;0,9..144,700;1,9..144,500&family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* ---- Base ink palette ---- */
  --ink-950: #0c0c14;
  --ink-900: #121220;
  --ink-850: #181826;
  --ink-800: #1d1d2e;
  --ink-700: #262638;
  --ink-600: #34344a;
  --paper: #f3ede2;
  --paper-dim: rgba(243, 237, 226, 0.08);

  /* ---- Signature accent (plum-coral) ---- */
  --signature: #d97a93;
  --signature-soft: rgba(217, 122, 147, 0.18);
  --signature-glow: rgba(217, 122, 147, 0.4);

  /* ---- Text ---- */
  --text: #f2efe9;
  --text-muted: rgba(242, 239, 233, 0.58);
  --text-dim: rgba(242, 239, 233, 0.34);

  /* ---- Per-character accent (set dynamically via JS) ---- */
  --char: #d97a93;
  --char-g: rgba(217, 122, 147, 0.4);
  --char-a: #d97a93;
  --char-b: #f0a8b8;
  --char-r: 217;
  --char-gr: 122;
  --char-bl: 147;

  /* ---- Type ---- */
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --msg-fs: 14.5px;

  /* ---- Radii & shadow ---- */
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 28px;
  --shadow-deep: 0 24px 70px rgba(0, 0, 0, 0.5);

  /* ---- Layout ---- */
  --sidebar-w: 320px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-body);
  background: var(--ink-950);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

::selection { background: var(--signature-soft); color: var(--text); }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

/* ============================================================
   AMBIENT BACKGROUND — soft ink wash + grain, no glassmorphism
   ============================================================ */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 900px 600px at 12% -10%, rgba(217,122,147,0.10), transparent 60%),
    radial-gradient(ellipse 700px 500px at 105% 10%, var(--char-g), transparent 55%),
    radial-gradient(ellipse 900px 700px at 50% 120%, rgba(217,122,147,0.06), transparent 60%);
  transition: background 0.6s ease;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.035;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ============================================================
   APP SHELL
   ============================================================ */
#app {
  position: relative;
  z-index: 1;
  display: flex;
  height: 100vh;
  height: 100dvh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--ink-900), var(--ink-850));
  border-right: 1px solid rgba(255,255,255,0.06);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  position: relative;
  z-index: 20;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 16px;
}

.logo-icon {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--signature), #b8597a);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px rgba(217,122,147,0.35);
  flex-shrink: 0;
}

.logo-text {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.28rem;
  letter-spacing: -0.01em;
}

.logo-badge {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--signature);
  background: var(--signature-soft);
  border: 1px solid rgba(217,122,147,0.3);
  border-radius: 6px;
  padding: 2px 6px;
  margin-left: auto;
}

.sidebar-search { padding: 0 20px 14px; }

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 13px;
  color: var(--text-dim);
  pointer-events: none;
}

#search-input {
  width: 100%;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: var(--r-md);
  padding: 10px 12px 10px 36px;
  color: var(--text);
  font-size: 0.86rem;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}
#search-input::placeholder { color: var(--text-dim); }
#search-input:focus {
  border-color: rgba(217,122,147,0.45);
  background: rgba(255,255,255,0.06);
}

.cat-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 20px 14px;
}

.cat-tab {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.2s;
}
.cat-tab:hover { color: var(--text); border-color: rgba(255,255,255,0.14); }

#tab-waifu.active {
  background: rgba(217,122,147,0.18);
  border-color: rgba(217,122,147,0.4);
  color: #f5c4d2;
}
#tab-husbu.active {
  background: rgba(122,166,217,0.18);
  border-color: rgba(122,166,217,0.4);
  color: #b9d4f5;
}

.char-count-badge {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
  padding: 3px 7px;
}

.character-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.char-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}
.char-item:hover { background: rgba(255,255,255,0.045); }
.char-item.active {
  background: linear-gradient(90deg, rgba(var(--char-r),var(--char-gr),var(--char-bl),0.16), rgba(var(--char-r),var(--char-gr),var(--char-bl),0.04));
}
.char-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 14%; bottom: 14%;
  width: 3px;
  border-radius: 3px;
  background: rgb(var(--char-r),var(--char-gr),var(--char-bl));
}

.char-avatar {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  position: relative;
  overflow: hidden;
}
.char-avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
}

.avatar-fallback-emoji {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 1.1em;
  line-height: 1;
}

.online-dot {
  position: absolute;
  bottom: 1px; right: 1px;
  width: 9px; height: 9px;
  background: #6ee7a7;
  border: 2px solid var(--ink-900);
  border-radius: 50%;
}

.char-info { flex: 1; min-width: 0; }
.char-name {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.char-anime {
  font-size: 0.74rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.char-rel-badge {
  font-size: 0.62rem;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 999px;
  flex-shrink: 0;
  white-space: nowrap;
}
.rel-dating { background: rgba(217,122,147,0.18); color: #f5b4c7; }
.rel-married { background: rgba(244,196,72,0.18); color: #f4d27a; }
.rel-family { background: rgba(122,217,166,0.18); color: #95e3b6; }
.rel-aff { background: rgba(255,255,255,0.06); color: var(--text-dim); }

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,0.06);
  padding: 14px 18px calc(14px + var(--safe-bottom));
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background 0.15s;
}
.sidebar-user:hover { background: rgba(255,255,255,0.04); }

.sidebar-user-avatar {
  width: 30px; height: 30px;
  border-radius: 10px;
  background: var(--signature-soft);
  color: var(--signature);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.sidebar-user-name {
  font-weight: 600;
  font-size: 0.84rem;
  flex: 1;
}

.sidebar-user-edit { color: var(--text-dim); }

.sidebar-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.sidebar-action-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--r-sm);
  padding: 9px 4px;
  color: var(--text-muted);
  font-size: 0.66rem;
  font-weight: 600;
  transition: all 0.15s;
}
.sidebar-action-btn:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.sidebar-action-btn.danger:hover { background: rgba(248,113,113,0.12); color: #f87171; }

/* ============================================================
   MOBILE SIDEBAR + OVERLAY
   ============================================================ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
  z-index: 19;
}

@media (max-width: 880px) {
  #sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.32,0.72,0,1);
    width: min(86vw, 340px);
    box-shadow: var(--shadow-deep);
  }
  #sidebar.open { transform: translateX(0); }
  .sidebar-overlay:not(.hidden) { display: block; }
}

/* ============================================================
   MAIN AREA
   ============================================================ */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

/* ---- Header ---- */
#chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  padding-top: calc(14px + var(--safe-top));
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(12,12,20,0.7);
  backdrop-filter: blur(14px);
  position: relative;
  z-index: 10;
  min-height: 68px;
}

.header-skeleton { display: flex; align-items: center; gap: 12px; width: 100%; }
.skeleton {
  background: linear-gradient(90deg, rgba(255,255,255,0.04), rgba(255,255,255,0.09), rgba(255,255,255,0.04));
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 8px;
}
.skel-avatar { width: 42px; height: 42px; border-radius: 13px; }
.header-skel-info { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.skel-name { height: 13px; width: 40%; border-radius: 5px; }
.skel-sub { height: 10px; width: 26%; border-radius: 5px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

#menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  width: 36px; height: 36px;
  align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  flex-shrink: 0;
}
@media (max-width: 880px) { #menu-toggle { display: flex; } }

.header-avatar {
  width: 42px; height: 42px;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--char-a), var(--char-b));
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  font-size: 1.1rem;
  position: relative;
  transition: box-shadow 0.3s;
}
.header-avatar img { width: 100%; height: 100%; object-fit: cover; }
.header-avatar.typing-glow {
  box-shadow: 0 0 0 3px rgba(var(--char-r),var(--char-gr),var(--char-bl),0.3), 0 0 22px var(--char-g);
  animation: pulseGlow 1.4s ease-in-out infinite;
}
@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 3px rgba(var(--char-r),var(--char-gr),var(--char-bl),0.25), 0 0 16px var(--char-g); }
  50% { box-shadow: 0 0 0 5px rgba(var(--char-r),var(--char-gr),var(--char-bl),0.4), 0 0 28px var(--char-g); }
}

.header-info { flex: 1; min-width: 0; }
.header-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.02rem;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.header-sub {
  font-size: 0.76rem;
  color: var(--text-dim);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-rel-tag {
  font-family: var(--font-body);
  font-size: 0.64rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
}
.header-rel-dating { background: rgba(217,122,147,0.18); color: #f5b4c7; }
.header-rel-married { background: rgba(244,196,72,0.18); color: #f4d27a; }
.header-rel-family { background: rgba(122,217,166,0.18); color: #95e3b6; }

.online-badge {
  font-size: 0.62rem;
  font-weight: 600;
  color: #6ee7a7;
  display: none;
}
@media (min-width: 560px) { .online-badge { display: inline; } }

.header-actions { display: flex; gap: 4px; flex-shrink: 0; }
@media (max-width: 640px) { .header-actions { display: none; } }

.header-btn {
  width: 34px; height: 34px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.header-btn:hover { background: rgba(255,255,255,0.09); color: var(--text); }

/* ---- Chat area ---- */
#chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 22px 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

@media (min-width: 700px) {
  #chat-area, #chat-input-area, .relationship-bar, .quick-chips {
    max-width: 760px;
    width: 100%;
    margin: 0 auto;
  }
}

/* ---- Welcome screen ---- */
#welcome-screen {
  margin: auto;
  text-align: center;
  max-width: 420px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.welcome-avatar {
  width: 92px; height: 92px;
  border-radius: 26px;
  background: linear-gradient(135deg, var(--char-a), var(--char-b));
  display: flex; align-items: center; justify-content: center;
  font-size: 2.4rem;
  overflow: hidden;
  margin-bottom: 18px;
  position: relative;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08), 0 20px 50px rgba(var(--char-r),var(--char-gr),var(--char-bl),0.25);
}
.welcome-avatar::before {
  content: '';
  position: absolute;
  inset: -16px;
  border-radius: 38px;
  background: radial-gradient(circle, var(--char-g), transparent 70%);
  z-index: -1;
  animation: auraBreath 4s ease-in-out infinite;
}
@keyframes auraBreath {
  0%, 100% { transform: scale(0.94); opacity: 0.7; }
  50% { transform: scale(1.08); opacity: 1; }
}
.welcome-avatar img { width: 100%; height: 100%; object-fit: cover; }

.welcome-name {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 2px;
}
.welcome-anime {
  font-size: 0.8rem;
  color: var(--char);
  font-weight: 600;
  margin-bottom: 12px;
}
.welcome-desc {
  font-size: 0.86rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 22px;
}

.welcome-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: center;
}
.suggestion-chip {
  background: rgba(255,255,255,0.045);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.78rem;
  color: var(--text-muted);
  transition: all 0.15s;
  cursor: pointer;
}
.suggestion-chip:hover {
  border-color: rgba(var(--char-r),var(--char-gr),var(--char-bl),0.5);
  color: var(--text);
  background: rgba(var(--char-r),var(--char-gr),var(--char-bl),0.1);
}

/* ---- Messages ---- */
.message {
  display: flex;
  gap: 10px;
  max-width: 84%;
  animation: msgIn 0.32s cubic-bezier(0.2,0.9,0.3,1);
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.ai { align-self: flex-start; }

.msg-avatar {
  width: 32px; height: 32px;
  border-radius: 10px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.95rem;
  overflow: hidden;
  margin-top: 2px;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }

.msg-content { display: flex; flex-direction: column; min-width: 0; }
.message.user .msg-content { align-items: flex-end; }

.msg-bubble {
  font-size: var(--msg-fs);
  line-height: 1.55;
  padding: 11px 15px;
  border-radius: var(--r-lg);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.message.ai .msg-bubble {
  background: var(--ink-800);
  border: 1px solid rgba(255,255,255,0.06);
  border-top-left-radius: 6px;
  color: var(--text);
}
.message.user .msg-bubble {
  background: linear-gradient(135deg, rgb(var(--char-r),var(--char-gr),var(--char-bl)), color-mix(in srgb, var(--char) 70%, #fff 10%));
  background: linear-gradient(135deg, var(--char-a), var(--char-b));
  color: #1a1014;
  border-top-right-radius: 6px;
  font-weight: 500;
}

.char-action {
  color: var(--char);
  font-style: italic;
  opacity: 0.92;
}
.message.user .char-action { color: rgba(20,12,16,0.7); }

.msg-bubble code {
  background: rgba(0,0,0,0.3);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.85em;
}
.msg-bubble pre {
  background: rgba(0,0,0,0.3);
  padding: 10px 12px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 6px 0;
}
.msg-bubble pre code { background: none; padding: 0; }

.msg-time {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  padding: 0 4px;
}
.msg-copy {
  display: inline-flex;
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.15s;
  color: var(--text-dim);
}
.message.ai:hover .msg-copy { opacity: 1; }
.msg-copy:hover { color: var(--char); }

/* ---- Narration ---- */
.message.narration {
  align-self: center;
  max-width: 70%;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.narration-bubble {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.84rem;
  color: var(--text-muted);
  text-align: center;
}
.narration-dash { color: var(--char); opacity: 0.6; }
.narration-time {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-dim);
  margin-top: 3px;
}

/* ---- Typing indicator ---- */
.typing-indicator {
  display: flex;
  gap: 10px;
  align-self: flex-start;
  align-items: center;
  animation: msgIn 0.25s ease;
}
.typing-bubble {
  background: var(--ink-800);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--r-lg);
  border-top-left-radius: 6px;
  padding: 13px 16px;
  display: flex;
  gap: 4px;
}
.typing-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--char);
  opacity: 0.6;
  animation: typingBounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ============================================================
   RELATIONSHIP BAR
   ============================================================ */
.relationship-bar {
  padding: 0 20px 10px;
}

.affection-bar-wrap, .marriage-bar-wrap {
  background: var(--ink-850);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--r-md);
  padding: 11px 14px;
  margin-bottom: 6px;
}
.affection-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 7px;
}
.affection-pct { font-family: var(--font-mono); font-weight: 700; }
.affection-track {
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 999px;
  overflow: hidden;
}
.affection-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.5s cubic-bezier(0.2,0.8,0.2,1);
}
.affection-hint {
  font-size: 0.68rem;
  color: var(--text-dim);
  margin-top: 6px;
}

.rel-status-wrap {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--ink-850);
  border: 1px solid rgba(var(--char-r),var(--char-gr),var(--char-bl),0.25);
  border-radius: var(--r-md);
  padding: 12px 14px;
}
.rel-icon-big { font-size: 1.3rem; }
.rel-status-label { font-weight: 600; font-size: 0.84rem; }

.kids-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.kid-chip {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.72rem;
  cursor: pointer;
  transition: all 0.15s;
}
.kid-chip:hover { background: rgba(var(--char-r),var(--char-gr),var(--char-bl),0.15); }

/* ============================================================
   QUICK CHIPS
   ============================================================ */
.quick-chips {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 0 20px 10px;
  scrollbar-width: none;
}
.quick-chips::-webkit-scrollbar { display: none; }
.quick-chip {
  flex-shrink: 0;
  background: var(--ink-850);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.78rem;
  white-space: nowrap;
  color: var(--text-muted);
  transition: all 0.15s;
  cursor: pointer;
}
.quick-chip:hover {
  border-color: rgba(var(--char-r),var(--char-gr),var(--char-bl),0.5);
  color: var(--text);
  background: rgba(var(--char-r),var(--char-gr),var(--char-bl),0.12);
}

/* ============================================================
   INPUT AREA
   ============================================================ */
#chat-input-area {
  padding: 10px 20px calc(14px + var(--safe-bottom));
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.input-icon-btn {
  width: 42px; height: 42px;
  flex-shrink: 0;
  background: var(--ink-850);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: var(--r-md);
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.input-icon-btn:hover, .input-icon-btn.active {
  color: var(--char);
  border-color: rgba(var(--char-r),var(--char-gr),var(--char-bl),0.4);
  background: rgba(var(--char-r),var(--char-gr),var(--char-bl),0.1);
}

.input-box {
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: var(--ink-850);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--r-lg);
  padding: 4px 4px 4px 16px;
  transition: border-color 0.2s;
}
.input-box:focus-within { border-color: rgba(var(--char-r),var(--char-gr),var(--char-bl),0.5); }

#message-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  padding: 10px 0;
  resize: none;
  max-height: 130px;
  font-family: inherit;
}
#message-input::placeholder { color: var(--text-dim); }
#message-input::-webkit-scrollbar { width: 3px; }

#send-btn {
  width: 38px; height: 38px;
  flex-shrink: 0;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--char-a), var(--char-b));
  color: #1a1014;
  display: flex; align-items: center; justify-content: center;
  margin: 2px;
  transition: transform 0.12s, opacity 0.15s;
}
#send-btn:hover { transform: scale(1.07); opacity: 0.92; }
#send-btn:active { transform: scale(0.93); }
#send-btn:disabled { opacity: 0.3; cursor: not-allowed; transform: none; }

.input-hint {
  text-align: center;
  font-size: 0.66rem;
  color: var(--text-dim);
  margin-top: 8px;
  font-family: var(--font-mono);
}

/* ============================================================
   STICKER PANEL
   ============================================================ */
.sticker-panel {
  background: var(--ink-850);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--r-lg);
  margin-bottom: 8px;
  max-height: 260px;
  overflow-y: auto;
  animation: msgIn 0.2s ease;
}
.sticker-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  position: sticky;
  top: 0;
  background: var(--ink-850);
}
.sticker-panel-title { font-weight: 600; font-size: 0.82rem; }
.sticker-close-btn {
  width: 24px; height: 24px;
  border-radius: 7px;
  background: rgba(255,255,255,0.05);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  color: var(--text-dim);
}
.sticker-panel-body { padding: 10px 14px 14px; }
.sticker-cat-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin: 10px 0 6px;
}
.sticker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.sticker-item {
  aspect-ratio: 1;
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  transition: transform 0.12s, background 0.15s;
}
.sticker-item:hover { transform: scale(1.06); background: rgba(255,255,255,0.06); }
.sticker-thumb { width: 100%; height: 100%; object-fit: contain; }

.sticker-wa { width: 130px; }
.sticker-wa-img { width: 100%; border-radius: 14px; }
.message.sticker-msg .msg-content { align-items: flex-end; }

/* ============================================================
   TOAST
   ============================================================ */
#toast-container {
  position: fixed;
  top: calc(16px + var(--safe-top));
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(90vw, 340px);
}

.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--ink-800);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--r-md);
  padding: 12px 15px;
  font-size: 0.82rem;
  box-shadow: var(--shadow-deep);
  animation: toastIn 0.3s cubic-bezier(0.2,0.9,0.3,1);
}
.toast.out { animation: toastOut 0.3s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(30px); } }

.toast.success { border-color: rgba(110,231,167,0.35); }
.toast.error { border-color: rgba(248,113,113,0.35); }
.toast.info { border-color: rgba(122,166,217,0.35); }
.toast-icon { font-size: 1rem; }

/* ============================================================
   SETTINGS MODAL
   ============================================================ */
#settings-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#settings-modal.open { display: flex; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
}

.modal-box {
  position: relative;
  background: linear-gradient(165deg, var(--ink-850), var(--ink-900));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--r-xl);
  max-width: 420px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 22px;
  box-shadow: var(--shadow-deep);
  animation: modalIn 0.3s cubic-bezier(0.34,1.4,0.64,1);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.modal-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--signature);
}
.modal-close {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: rgba(255,255,255,0.05);
  border: none;
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: rgba(255,255,255,0.1); color: var(--text); }

.setting-group { margin-bottom: 18px; }
.setting-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.setting-row:last-child { border-bottom: none; }
.setting-row.clickable { cursor: pointer; transition: opacity 0.15s; }
.setting-row.clickable:hover { opacity: 0.75; }

.setting-row-info {
  font-size: 0.86rem;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.setting-row-info span {
  font-size: 0.72rem;
  color: var(--text-dim);
  font-weight: 400;
}

.danger-row .danger-text { color: #f87171; }

.range-wrap { display: flex; align-items: center; gap: 8px; }
#fs-range { accent-color: var(--signature); width: 100px; }
.range-val {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-dim);
  min-width: 32px;
}

.toggle { position: relative; width: 38px; height: 22px; flex-shrink: 0; cursor: pointer; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
  position: absolute; inset: 0;
  background: rgba(255,255,255,0.12);
  border-radius: 999px;
  transition: background 0.2s;
}
.toggle-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle input:checked + .toggle-track { background: var(--signature); }
.toggle input:checked ~ .toggle-thumb { transform: translateX(16px); }

.about-box {
  background: rgba(255,255,255,0.03);
  border-radius: var(--r-md);
  padding: 16px;
  text-align: center;
}
.about-logo {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--signature);
}
.about-version {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  margin: 3px 0 8px;
}
.about-desc { font-size: 0.78rem; color: var(--text-muted); }

/* ============================================================
   GENERIC OVERLAY MODALS (username, child, etc — styled in JS)
   shared keyframe used by inline-styled modals in app.js
   ============================================================ */
@keyframes modalPop {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ============================================================
   ANIME SCHEDULE CARDS (AniList)
   ============================================================ */
.anime-card-bubble { padding: 0 !important; background: none !important; border: none !important; }
.anic-card {
  background: var(--ink-800);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: var(--r-lg);
  overflow: hidden;
  min-width: 280px;
  max-width: 360px;
}
.anic-header {
  padding: 12px 14px;
  font-weight: 700;
  font-size: 0.86rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.anic-date { font-size: 0.68rem; font-weight: 400; color: var(--text-dim); }
.anic-list { max-height: 320px; overflow-y: auto; }
.anic-day-header {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--char);
  padding: 8px 14px 4px;
}
.anic-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.anic-row.anic-passed { opacity: 0.45; }
.anic-row-cover { width: 38px; height: 52px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.anic-row-body { flex: 1; min-width: 0; }
.anic-row-title { font-size: 0.8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.anic-row-sub { font-size: 0.68rem; color: var(--text-dim); }
.anic-row-right { text-align: right; flex-shrink: 0; }
.anic-time-big { font-family: var(--font-mono); font-size: 0.78rem; font-weight: 700; }
.anic-countdown { font-size: 0.64rem; color: var(--char); font-weight: 600; }
.anic-countdown.passed { color: var(--text-dim); }
.anic-countdown.upcoming { color: #95c8f5; }
.anic-empty { padding: 24px; text-align: center; color: var(--text-dim); font-size: 0.82rem; }
.anic-footer { padding: 9px 14px; font-size: 0.62rem; color: var(--text-dim); text-align: center; font-family: var(--font-mono); }

.anic-wib-full { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }
.anic-upcoming-row { align-items: flex-start; }

.anic-detail-card { max-width: 380px; }
.anic-detail-hero { display: flex; gap: 12px; padding: 14px; }
.anic-detail-cover { width: 76px; height: 108px; object-fit: cover; border-radius: 10px; flex-shrink: 0; }
.anic-detail-meta { min-width: 0; }
.anic-detail-title { font-family: var(--font-display); font-weight: 600; font-size: 0.98rem; line-height: 1.2; }
.anic-detail-alt { font-size: 0.68rem; color: var(--text-dim); margin-top: 2px; }
.anic-meta-row { font-size: 0.72rem; color: var(--char); margin-top: 6px; font-weight: 600; }
.anic-meta-row2 { font-size: 0.7rem; color: var(--text-muted); margin-top: 3px; }
.anic-score { font-size: 0.72rem; color: var(--text-muted); margin-top: 4px; }
.anic-desc { padding: 0 14px 12px; font-size: 0.76rem; color: var(--text-muted); line-height: 1.5; }
.anic-sched-section { padding: 0 14px 12px; }
.anic-sched-title { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; color: var(--text-dim); margin-bottom: 8px; }
.anic-sched-block {
  background: rgba(255,255,255,0.03);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
}
.anic-sched-block.upcoming { opacity: 0.7; }
.anic-sched-block.finished { opacity: 0.6; }
.anic-sched-label { font-size: 0.72rem; font-weight: 700; }
.anic-countdown-big { font-family: var(--font-mono); font-size: 0.94rem; font-weight: 700; color: var(--char); margin-top: 3px; }
.anic-countdown-small { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-dim); margin-top: 2px; }

/* ============================================================
   ACCESSIBILITY
   ============================================================ */
a:focus-visible, button:focus-visible, input:focus-visible,
textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--signature);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ============================================================
   RESPONSIVE TWEAKS
   ============================================================ */
@media (max-width: 880px) {
  #chat-header { padding: 12px 14px; padding-top: calc(12px + var(--safe-top)); }
  #chat-area { padding: 16px 14px 10px; }
  .relationship-bar, .quick-chips { padding-left: 14px; padding-right: 14px; }
  #chat-input-area { padding: 8px 14px calc(12px + var(--safe-bottom)); }
  .message { max-width: 92%; }
}

@media (max-width: 380px) {
  .sticker-grid { grid-template-columns: repeat(3, 1fr); }
}
