:root {
  --bg: #0b0c12;
  --panel: #11131b;
  --panel-strong: #171a24;
  --line: #272a36;
  --text: #f4f4f6;
  --muted: #9a9dab;
  --accent: #ff4f8b;
  --accent-strong: #e83b77;
  --danger: #ff7f91;
  --sidebar: 320px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 80% -10%, rgba(255, 79, 139, 0.12), transparent 32rem),
    var(--bg);
  color: var(--text);
  font-size: 16px;
}

button, input, textarea, select { font: inherit; }
button { color: inherit; }

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.muted { color: var(--muted); line-height: 1.55; }
.eyebrow { margin: 0 0 6px; color: var(--accent); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.16em; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 410px);
  display: grid;
  gap: 24px;
  padding: 38px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(17, 19, 27, 0.94);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.4);
}

.login-card h1 { margin: 0; font-size: clamp(1.8rem, 6vw, 2.45rem); letter-spacing: -0.04em; }
.login-card p { margin: 7px 0 0; }
.login-language { justify-self: end; }

.language-control { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.language-control select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 30px 0 10px;
  outline: none;
  background: #11131a;
  color: var(--text);
  cursor: pointer;
}
.language-control select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 79, 139, 0.13); }

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: linear-gradient(145deg, #ff6a9e, #d72f6b);
  box-shadow: 0 12px 34px rgba(255, 79, 139, 0.28);
  color: white;
  font-size: 1.45rem;
  font-weight: 900;
}

.brand-mark.small { width: 34px; height: 34px; border-radius: 11px; font-size: 1rem; }

.login-form { display: grid; gap: 16px; }
.login-form label { display: grid; gap: 8px; color: #d8d9df; font-size: 0.9rem; font-weight: 650; }

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 13px;
  outline: none;
  background: #0d0f16;
  color: var(--text);
  transition: border-color 150ms, box-shadow 150ms;
}

input { min-height: 48px; padding: 0 14px; }
textarea { min-height: 48px; max-height: 150px; resize: none; padding: 13px 52px 12px 15px; line-height: 1.4; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 79, 139, 0.13); }

.primary-button {
  min-height: 48px;
  border: 0;
  border-radius: 13px;
  padding: 0 20px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  cursor: pointer;
  transition: background 150ms, transform 150ms;
}
.primary-button:hover { background: var(--accent-strong); }
.primary-button:active { transform: translateY(1px); }
.primary-button:disabled { cursor: wait; opacity: 0.58; }
.primary-button.wide { width: 100%; }

.form-error { color: var(--danger); font-size: 0.9rem; line-height: 1.4; }
.login-note { color: #777b89; font-size: 0.8rem; text-align: center; }

.app-shell { min-height: 100vh; }
.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 12, 18, 0.9);
  backdrop-filter: blur(16px);
}

.brand-button, .text-button, .sidebar-tab {
  border: 0;
  background: transparent;
  cursor: pointer;
}
.brand-button { display: flex; align-items: center; gap: 11px; padding: 0; font-size: 1.05rem; font-weight: 850; }
.account-area { display: flex; align-items: center; gap: 14px; }
.account-name { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #c8cad3; font-size: 0.88rem; }
.text-button { padding: 8px 10px; color: var(--muted); border-radius: 9px; }
.text-button:hover { color: var(--text); background: var(--panel-strong); }

.workspace { height: calc(100vh - 64px); min-height: 0; display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); overflow: hidden; }
.sidebar { height: calc(100vh - 64px); min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); border-right: 1px solid var(--line); background: rgba(15, 17, 24, 0.78); }
.sidebar-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; padding: 14px; }
.sidebar-tab { min-height: 40px; border-radius: 10px; color: var(--muted); font-size: 0.92rem; font-weight: 700; }
.sidebar-tab.active { color: var(--text); background: var(--panel-strong); }
.count-badge { display: inline-grid; min-width: 20px; min-height: 20px; place-items: center; margin-left: 3px; padding: 0 5px; border-radius: 10px; background: #282b37; font-size: 0.72rem; }
.sidebar-panel { min-height: 0; overflow-y: auto; padding: 0 12px 18px; }
.search-field { display: block; padding: 0 2px 10px; }
.search-field input { min-height: 42px; background: #11131a; }
.item-list { display: grid; gap: 4px; }

.list-item {
  width: 100%;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 13px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.list-item:hover { background: #171923; }
.list-item.active { border-color: #3b3040; background: rgba(255, 79, 139, 0.09); }
.list-avatar, .mini-avatar { display: grid; place-items: center; flex: 0 0 auto; overflow: hidden; background: var(--avatar-color, #6e6380); color: white; }
.list-avatar img, .mini-avatar img, .character-avatar img { width: 100%; height: 100%; display: block; object-fit: cover; object-position: center 20%; }
.list-avatar { width: 46px; height: 46px; border-radius: 14px; font-size: 1.45rem; }
.list-copy { min-width: 0; }
.list-title, .list-subtitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-title { display: block; margin-bottom: 4px; font-weight: 760; }
.list-subtitle { display: block; color: var(--muted); font-size: 0.8rem; }
.empty-list { padding: 30px 12px; color: var(--muted); text-align: center; line-height: 1.6; }

.content-area { min-width: 0; height: calc(100vh - 64px); overflow-y: auto; }
.welcome-view { min-height: calc(100vh - 64px); display: grid; place-content: center; justify-items: center; padding: 30px; text-align: center; }
.welcome-view h2 { margin: 22px 0 6px; font-size: 1.7rem; }
.welcome-view p { margin: 0; color: var(--muted); }
.welcome-orbit { display: flex; gap: 8px; }
.welcome-orbit span { width: 54px; height: 54px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 18px; background: var(--panel-strong); font-size: 1.6rem; }
.welcome-orbit span:nth-child(2) { transform: translateY(-16px); border-color: rgba(255, 79, 139, 0.45); }

.character-view { max-width: 900px; margin: 0 auto; padding: clamp(20px, 5vw, 64px); }
.character-hero { min-height: 260px; display: flex; align-items: flex-end; gap: 26px; padding: 34px; border: 1px solid var(--line); border-radius: 24px; background: linear-gradient(135deg, color-mix(in srgb, var(--hero-color) 30%, #171923), #10121a 70%); }
.character-avatar { width: 132px; height: 132px; display: grid; place-items: center; flex: 0 0 auto; overflow: hidden; border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 38px; background: color-mix(in srgb, var(--hero-color) 76%, #11131b); box-shadow: 0 22px 44px rgba(0, 0, 0, 0.3); font-size: 4rem; }
.character-heading h2 { margin: 0; font-size: clamp(2.2rem, 7vw, 4.6rem); line-height: 0.95; letter-spacing: -0.06em; }
.character-body { max-width: 680px; margin: 34px auto 0; }
.character-description { color: #d4d5db; line-height: 1.75; font-size: 1.06rem; }
.tag-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 28px; }
.tag { padding: 7px 11px; border: 1px solid var(--line); border-radius: 999px; color: #b8bac4; background: #11131a; font-size: 0.8rem; }
.opening-card { margin-bottom: 22px; padding: 20px; border-left: 3px solid var(--accent); border-radius: 4px 14px 14px 4px; background: var(--panel); }
.opening-card p { margin: 9px 0 0; color: #d6d7dc; line-height: 1.7; white-space: pre-line; }
.section-label { color: var(--muted); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.1em; }

.chat-view { height: calc(100vh - 64px); display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.chat-header { min-height: 72px; display: flex; align-items: center; gap: 12px; padding: 10px clamp(16px, 4vw, 34px); border-bottom: 1px solid var(--line); }
.mini-avatar { width: 44px; height: 44px; border-radius: 14px; font-size: 1.35rem; }
.chat-header h2 { margin: 0; font-size: 1.05rem; }
.chat-header p { margin: 3px 0 0; color: var(--muted); font-size: 0.78rem; }
.chat-actions { display: flex; align-items: center; gap: 8px; min-width: 0; margin-left: auto; }
.voice-tool-button, .voice-input-button { display: grid; place-items: center; border: 1px solid var(--line); background: #151722; color: #d8d9df; cursor: pointer; }
.voice-tool-button { width: 38px; height: 38px; border-radius: 50%; font-size: 1rem; }
.voice-tool-button.active { border-color: #ff526d; background: #6b1e2e; color: white; animation: pulse-call 1.4s infinite; }
.voice-tool-button:disabled, .voice-input-button:disabled { cursor: wait; opacity: 0.5; }
@keyframes pulse-call { 50% { box-shadow: 0 0 0 7px rgba(255, 82, 109, 0.08); } }
.message-list { overflow-y: auto; scroll-behavior: smooth; padding: 26px clamp(16px, 7vw, 90px) 38px; }
.message-row { display: flex; margin: 0 auto 18px; max-width: 820px; }
.message-row.user { justify-content: flex-end; }
.message-bubble { max-width: min(78%, 620px); padding: 12px 16px; border-radius: 16px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-row.assistant .message-bubble { border: 1px solid var(--line); border-bottom-left-radius: 5px; background: var(--panel-strong); color: #e2e3e8; }
.message-row.user .message-bubble { border-bottom-right-radius: 5px; background: var(--accent); color: white; }
.message-stack { width: min(82%, 660px); display: grid; gap: 8px; }
.message-stack > .message-bubble { max-width: 100%; }
.message-opening-image { width: min(100%, 390px); height: auto; max-height: min(68vh, 680px); object-fit: contain; object-position: left; border-radius: 16px; }
.message-block { padding: 10px 14px; border-radius: 14px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-block.voiceover { border: 1px solid #292c36; background: #101118; color: #aaaebb; font-style: italic; }
.message-block.dialog { border: 1px solid var(--line); border-bottom-left-radius: 5px; background: var(--panel-strong); color: #e2e3e8; }
.message-block.thought { border-left: 2px solid #555a6a; border-radius: 3px 12px 12px 3px; background: rgba(255, 255, 255, 0.025); color: #8f93a1; }
.message-speaker { display: flex; align-items: center; gap: 7px; margin-bottom: 6px; color: var(--accent); font-size: 0.72rem; font-weight: 800; }
.message-speaker-avatar { display: grid; flex: 0 0 auto; width: 24px; height: 24px; place-items: center; overflow: hidden; border-radius: 50%; background: var(--avatar-color, #6e6380); font-size: 0.72rem; }
.message-speaker-avatar img { width: 100%; height: 100%; object-fit: cover; }
.speech-button { display: grid; width: 26px; height: 26px; margin-left: auto; padding: 0; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: #151722; color: var(--accent); font-size: 0.68rem; cursor: pointer; }
.speech-button:hover { border-color: rgba(255, 79, 139, 0.55); color: white; }
.speech-button:disabled { cursor: wait; opacity: 0.55; }
.message-media-actions { display: flex; margin-top: 9px; white-space: normal; }
.generate-image-button { border: 1px solid rgba(255, 79, 139, 0.35); border-radius: 999px; padding: 6px 10px; background: rgba(255, 79, 139, 0.08); color: #ff9bbb; font: inherit; font-size: 0.72rem; font-weight: 750; cursor: pointer; }
.generate-image-button:hover { border-color: rgba(255, 79, 139, 0.7); background: rgba(255, 79, 139, 0.14); color: white; }
.generate-image-button:disabled { cursor: default; opacity: 0.7; }
.generate-image-button.pending { cursor: wait; }
.generate-image-button.completed { border-color: rgba(92, 211, 151, 0.35); background: rgba(92, 211, 151, 0.08); color: #8be2b5; }
.generate-image-button.failed { border-color: rgba(255, 105, 126, 0.35); background: rgba(255, 105, 126, 0.08); color: #ff9aaa; }
.generated-image-card { width: min(76%, 390px); margin: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: var(--panel-strong); box-shadow: 0 16px 40px rgba(0, 0, 0, 0.22); }
.generated-image-card img, .generated-image-card video { display: block; width: 100%; max-height: min(68vh, 680px); object-fit: contain; background: #090a0f; }
.generated-image-card figcaption { padding: 10px 13px 12px; color: #aeb1bb; font-size: 0.78rem; line-height: 1.45; }
.message-bubble.streaming::after { content: ""; display: inline-block; width: 7px; height: 1em; margin-left: 4px; border-radius: 2px; vertical-align: -2px; background: var(--accent); animation: blink 900ms infinite; }
.message-block-text.streaming::after { content: ""; display: inline-block; width: 7px; height: 1em; margin-left: 4px; border-radius: 2px; vertical-align: -2px; background: var(--accent); animation: blink 900ms infinite; }
.message-bubble.failed { border: 1px solid #a54b59; color: #f0a4af; }
@keyframes blink { 50% { opacity: 0.2; } }

.composer-wrap { padding: 10px clamp(16px, 7vw, 90px) 16px; border-top: 1px solid var(--line); background: rgba(11, 12, 18, 0.95); }
.composer, .reply-choices { max-width: 820px; margin: 0 auto; }
.composer { position: relative; }
.composer:has(.voice-input-button:not([hidden])) textarea { padding-left: 48px; }
.voice-input-button { position: absolute; z-index: 1; left: 7px; bottom: 7px; width: 36px; height: 36px; border-radius: 11px; color: var(--accent); font-size: 0.85rem; }
.voice-input-button.recording { border-color: #ff526d; background: #6b1e2e; color: white; animation: blink 900ms infinite; }
.send-button { position: absolute; right: 7px; bottom: 7px; width: 36px; height: 36px; border: 0; border-radius: 11px; background: var(--accent); color: white; font-size: 1.18rem; font-weight: 900; cursor: pointer; }
.send-button:disabled { cursor: wait; opacity: 0.45; }
.reply-choices { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 9px; }
.choice-button { flex: 0 0 auto; border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; background: #12141c; color: #cfd0d7; font-size: 0.82rem; cursor: pointer; }
.choice-button:hover { border-color: rgba(255, 79, 139, 0.55); color: white; }
.composer-footer { display: flex; align-items: center; justify-content: center; gap: 12px; max-width: 820px; margin: 6px auto 0; color: #6f7280; font-size: 0.72rem; }
.composer-hint { margin: 0; }
.voice-language-control { display: flex; align-items: center; gap: 5px; }
.voice-language-control select { max-width: 145px; border: 1px solid var(--line); border-radius: 7px; padding: 3px 6px; background: #11131a; color: #aeb1bc; font: inherit; }

.mobile-back { display: none; }
.error-view { min-height: calc(100vh - 64px); display: grid; place-content: center; justify-items: center; padding: 30px; text-align: center; }
.error-view h2 { margin: 0 0 8px; }
.error-view p { max-width: 520px; margin: 0 0 20px; color: var(--muted); }
.toast { position: fixed; z-index: 20; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(90vw, 520px); padding: 11px 16px; border: 1px solid #4a3944; border-radius: 12px; background: #20151c; box-shadow: 0 16px 50px rgba(0, 0, 0, 0.4); color: #ffdbe7; font-size: 0.9rem; }

.video-call-overlay { position: fixed; z-index: 30; inset: 0; display: grid; place-items: center; padding: 18px; background: rgba(4, 5, 9, 0.9); backdrop-filter: blur(12px); }
.video-call-overlay[hidden] { display: none; }
.video-call-card { position: relative; width: min(92vw, 720px); height: min(88vh, 900px); overflow: hidden; border: 1px solid #353846; border-radius: 28px; background: #080910; box-shadow: 0 30px 90px rgba(0, 0, 0, 0.65); }
.video-call-remote { width: 100%; height: 100%; object-fit: cover; background: radial-gradient(circle at 50% 35%, #242735, #090a10 70%); }
.video-call-local { position: absolute; z-index: 2; top: 20px; right: 20px; width: min(24%, 150px); aspect-ratio: 3 / 4; object-fit: cover; border: 1px solid rgba(255, 255, 255, 0.28); border-radius: 18px; background: #151722; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.38); }
.video-call-shade { position: absolute; inset: 0; pointer-events: none; background: linear-gradient(to bottom, rgba(0, 0, 0, 0.48), transparent 24%, transparent 65%, rgba(0, 0, 0, 0.74)); }
.video-call-header { position: absolute; z-index: 3; top: 0; right: 0; left: 0; padding: 24px 190px 24px 26px; }
.video-call-header h2 { margin: 0; color: white; font-size: 1.35rem; }
.video-call-header p { margin: 6px 0 0; color: #d3d5de; font-size: 0.86rem; }
.video-call-footer { position: absolute; z-index: 3; right: 0; bottom: 0; left: 0; display: grid; place-items: center; padding: 28px; }
.video-call-end { width: auto; min-width: 150px; padding: 12px 22px; border: 0; border-radius: 999px; background: #cf334d; color: white; font-weight: 800; cursor: pointer; }

@media (max-width: 760px) {
  :root { --sidebar: 100%; }
  .topbar { height: 58px; padding: 0 14px; }
  .account-name { max-width: 150px; }
  .language-control.compact select { width: 112px; padding-left: 8px; }
  .workspace { height: auto; min-height: calc(100vh - 58px); display: block; overflow: visible; }
  .sidebar { height: calc(100vh - 58px); border-right: 0; }
  .content-area { height: auto; min-height: calc(100vh - 58px); overflow: visible; }
  .app-shell.detail-open .sidebar { display: none; }
  .app-shell:not(.detail-open) .content-area { display: none; }
  .mobile-back { display: inline-flex; margin: 8px 10px 0; }
  .character-view { padding: 10px 14px 30px; }
  .character-hero { min-height: 230px; display: grid; align-content: end; padding: 24px; }
  .character-avatar { width: 90px; height: 90px; border-radius: 26px; font-size: 3rem; }
  .character-heading h2 { font-size: 2.6rem; }
  .character-body { margin-top: 24px; }
  .chat-view { height: calc(100vh - 96px); }
  .chat-header { padding: 8px 14px; }
  .message-list { padding: 20px 14px 28px; }
  .message-bubble { max-width: 88%; }
  .generated-image-card { width: min(88%, 390px); }
  .message-stack { width: 92%; }
  .composer-wrap { padding: 9px 10px 10px; }
  .composer-hint { display: none; }
  .login-card { padding: 28px 22px; border-radius: 20px; }
  .video-call-overlay { padding: 0; }
  .video-call-card { width: 100vw; height: 100vh; border: 0; border-radius: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; }
}

/* Rating badge: adult (limitless) vs all ages (limited). */
.tag.rating-tag { font-weight: 600; }
.tag.rating-limitless { background: rgba(255, 77, 109, 0.18); color: #ff8fa3; border-color: rgba(255, 77, 109, 0.45); }
.tag.rating-limited { background: rgba(80, 200, 140, 0.14); color: #7ddcaa; border-color: rgba(80, 200, 140, 0.4); }
.chat-model-control { display: grid; gap: 4px; min-width: 0; width: 240px; max-width: 100%; font-size: 11px; color: var(--muted); }
.chat-model-control select { width: 100%; min-width: 0; padding: 7px; border-radius: 8px; border: 1px solid #ffffff26; background: #25232e; color: #fff; font: inherit; font-size: 12px; }
.chat-model-description { line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; }
@media (max-width: 600px) { .chat-header { flex-wrap: wrap; } .chat-actions { width: 100%; } .chat-model-control { flex: 1; width: auto; } }
