:root {
  color-scheme: dark;
  --bg: #07070a;
  --surface: #101016;
  --surface-2: #171720;
  --surface-3: #20202b;
  --text: #fbf8fb;
  --muted: #aaa7b6;
  --soft: #d7d2df;
  --line: #2d2c38;
  --line-2: #3a3344;
  --accent: #ff4f8d;
  --accent-2: #ff9f64;
  --violet: #7c5cff;
  --good: #8effa6;
  --warn: #ffd166;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif;
  background:
    radial-gradient(circle at 18% 0%, rgba(255, 79, 141, .16), transparent 28rem),
    radial-gradient(circle at 82% 8%, rgba(124, 92, 255, .13), transparent 24rem),
    var(--bg);
  color: var(--text);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }

.app {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: .55rem;
  height: 100vh;
  padding: 1.1rem;
  border-right: 1px solid var(--line);
  background: rgba(8, 8, 12, .86);
  backdrop-filter: blur(18px);
}

.brand {
  display: grid;
  gap: .15rem;
  margin-bottom: 1.4rem;
  color: var(--text);
  text-decoration: none;
}
.brand span {
  color: var(--muted);
  font-size: .82rem;
}
.brand strong {
  font-size: 1.65rem;
  line-height: 1;
}

.nav-btn, .chip, .setup button, .chat button {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(23, 23, 32, .86);
  padding: .72rem .85rem;
}
.nav-btn {
  text-align: left;
}
.nav-btn:hover, .chip:hover, .setup button:hover, .chat button:hover {
  border-color: var(--line-2);
  background: rgba(32, 32, 43, .95);
}
.nav-btn.active, .chip.active {
  border-color: rgba(255, 79, 141, .72);
  background: linear-gradient(135deg, rgba(255, 79, 141, .2), rgba(124, 92, 255, .12));
}
.rail-note {
  margin-top: auto;
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.45;
}

.home {
  min-width: 0;
  padding: 1.15rem 1.55rem 2.5rem;
  overflow: auto;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 780px) auto;
  gap: 1rem;
  align-items: end;
  padding: 1.15rem 0 1rem;
}
.topbar p {
  margin: 0 0 .45rem;
  color: var(--warn);
  font-size: .78rem;
  font-weight: 800;
  text-transform: uppercase;
}
.topbar h1 {
  margin: 0;
  max-width: 820px;
  font-size: clamp(2.35rem, 5vw, 5.2rem);
  line-height: .92;
  letter-spacing: 0;
}
.primary {
  border: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #16070d;
  font-weight: 900;
}

.filters {
  display: flex;
  gap: .55rem;
  overflow-x: auto;
  padding: .35rem 0 1.2rem;
}
.chip {
  min-width: 4.4rem;
  white-space: nowrap;
  padding: .55rem .8rem;
}

.discover-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 1rem;
  align-items: start;
}
.character-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: .85rem;
}
.character-card {
  position: relative;
  display: grid;
  grid-template-columns: 5.4rem minmax(0, 1fr);
  gap: .85rem;
  min-height: 11.6rem;
  padding: .9rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(26, 26, 36, .95), rgba(13, 13, 19, .96));
  color: var(--text);
  text-align: left;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}
.character-card:hover {
  border-color: rgba(255, 79, 141, .72);
  transform: translateY(-2px);
  background: linear-gradient(180deg, rgba(35, 31, 44, .98), rgba(15, 15, 22, .98));
}
.avatar {
  display: grid;
  place-items: center;
  width: 5.4rem;
  height: 8rem;
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 79, 141, .78), rgba(255, 159, 100, .64)),
    var(--surface-3);
  color: #14070d;
  font-size: 2.3rem;
  font-weight: 950;
  overflow: hidden;
}
.avatar.has-image {
  background: var(--surface-3);
}
.avatar img,
.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.avatar.has-image img,
.profile-avatar.has-image img {
  object-fit: contain !important;
}
.card-copy {
  display: grid;
  gap: .42rem;
  min-width: 0;
}
.card-meta {
  width: fit-content;
  color: var(--good);
  font-size: .72rem;
}
.card-copy strong {
  font-size: 1.12rem;
  line-height: 1.12;
}
.card-copy em {
  color: #ffd4e2;
  font-style: normal;
  font-size: .88rem;
  line-height: 1.35;
}
.card-copy span:last-child {
  color: var(--muted);
  font-size: .84rem;
  line-height: 1.45;
}

.ad-slot {
  width: 100%;
  min-height: 1px;
  overflow: hidden;
  text-align: center;
}
.ad-slot-top {
  display: grid;
  place-items: center;
  min-height: 96px;
  margin: .25rem auto .75rem;
}
.ad-slot-top.compact {
  min-height: 0;
  margin: .75rem 0 0;
}
.ad-slot-native {
  margin-top: 1.25rem;
}
.ad-slot-native.compact {
  margin: .35rem 0 .65rem;
}
.ad-rail {
  min-width: 160px;
}
.ad-rail-sticky {
  position: sticky;
  top: 1rem;
  width: 160px;
  min-height: 600px;
  margin: 0 auto;
}

.setup, .chat {
  border-left: 1px solid var(--line);
  background: rgba(9, 9, 14, .9);
}
.setup {
  display: none;
  grid-column: 2;
  max-height: 100vh;
  padding: 1.15rem;
  overflow: auto;
}
.panel-head, .chat header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}
.panel-head span, .chat header span {
  display: block;
  margin-top: .18rem;
  color: var(--muted);
  font-size: .8rem;
}
.panel-head strong, .chat header strong {
  font-size: 1.18rem;
}

label {
  display: grid;
  gap: .4rem;
  margin: .85rem 0;
  color: var(--soft);
  font-size: .86rem;
}
.names {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 16, 22, .92);
  color: var(--text);
  padding: .72rem .78rem;
  outline: none;
}
textarea {
  resize: vertical;
  line-height: 1.45;
}
input:focus, select:focus, textarea:focus {
  border-color: rgba(255, 79, 141, .82);
  box-shadow: 0 0 0 3px rgba(255, 79, 141, .12);
}
.tiny {
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.45;
}

.chat {
  display: none;
  grid-column: 2;
  grid-template-columns: 300px minmax(0, 1fr);
  min-width: 0;
  min-height: 100vh;
}
.chat-profile {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow: hidden;
  padding: 1rem;
  border-right: 1px solid var(--line);
  background: rgba(13, 13, 19, .94);
}
.back-btn {
  margin-bottom: .7rem;
}
.profile-avatar {
  display: grid;
  place-items: center;
  width: 100%;
  max-height: min(42vh, 23rem);
  aspect-ratio: 3 / 4;
  margin-bottom: .75rem;
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 79, 141, .78), rgba(255, 159, 100, .64)),
    var(--surface-3);
  color: #14070d;
  font-size: 4.8rem;
  font-weight: 950;
  overflow: hidden;
}
.profile-avatar.has-image {
  background: var(--surface-3);
}
.profile-tags {
  margin: 0 0 .4rem;
  color: var(--good);
  font-size: .76rem;
}
.chat-profile h2 {
  margin: 0 0 .45rem;
  font-size: 1.35rem;
  line-height: 1.05;
}
.chat-profile strong {
  display: block;
  margin-bottom: .55rem;
  color: #ffd4e2;
  line-height: 1.35;
}
.chat-profile p {
  color: var(--muted);
  line-height: 1.42;
  margin: 0;
}
.profile-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .55rem;
  margin-top: .8rem;
}
.chat-main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 100vh;
  padding: .9rem 1rem;
}
.chat header {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: -.9rem -1rem 0;
  padding: .9rem 1rem;
  background: rgba(7, 7, 10, .88);
  backdrop-filter: blur(18px);
}
.messages {
  display: flex;
  flex-direction: column;
  gap: .7rem;
  overflow: auto;
  padding: 1rem 0 1.1rem;
}
.empty {
  color: var(--muted);
  padding: 2rem;
  text-align: center;
}
.msg {
  max-width: 850px;
  margin: 0;
  padding: .9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(21, 21, 29, .72);
  line-height: 1.62;
}
.msg.assistant {
  border-color: rgba(255, 255, 255, .08);
  background: rgba(24, 24, 33, .82);
}
.msg.user {
  align-self: flex-end;
  max-width: min(760px, 86%);
  background: linear-gradient(135deg, rgba(255, 79, 141, .17), rgba(124, 92, 255, .1));
  border-color: rgba(255, 79, 141, .34);
}
.msg.system {
  align-self: stretch;
  max-width: none;
  color: #ffdbe7;
  padding: .7rem .9rem;
  background: rgba(255, 79, 141, .06);
  border-color: rgba(255, 79, 141, .18);
  font-size: .92rem;
}
.msg.loading {
  color: var(--muted);
}
.msg.loading::after {
  content: '';
  display: inline-block;
  width: 1.1rem;
  margin-left: .25rem;
  animation: dots 1.1s steps(4, end) infinite;
}
.rp-block {
  margin: 0 0 .82rem;
}
.rp-block:last-child {
  margin-bottom: 0;
}
.msg em {
  color: #c6c1cc;
  font-style: italic;
}
.msg strong {
  color: #fff;
  font-weight: 850;
}
.msg .speaker {
  margin-right: .25rem;
  color: #fff;
}
.rp-block.meter,
.rp-block.thought {
  display: block;
  padding: .55rem .65rem;
  border: 1px solid rgba(255, 79, 141, .18);
  border-radius: 8px;
  background: rgba(255, 79, 141, .06);
  color: #ffd4e2;
  font-size: .92rem;
}
.rp-block.thought {
  border-color: rgba(124, 92, 255, .2);
  background: rgba(124, 92, 255, .08);
  color: #ded8ff;
}
.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .6rem;
  align-items: end;
  padding: .65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(14, 14, 20, .9);
  box-shadow: 0 -14px 36px rgba(0, 0, 0, .2);
}
.composer textarea {
  min-height: 3rem;
  max-height: 7.5rem;
  border: 0;
  background: transparent;
  padding: .65rem .7rem;
  line-height: 1.45;
}
.composer textarea:focus {
  border-color: transparent;
  box-shadow: none;
}
.composer .primary {
  min-width: 5.4rem;
  height: 3rem;
  padding: 0 1rem;
}

body[data-view="create"] .home,
body[data-view="chat"] .home {
  display: none;
}
body[data-view="create"] .setup { display: block; }
body[data-view="create"] .chat { display: none; }
body[data-view="chat"] .chat { display: grid; }
body[data-view="discover"] .setup { display: none; }
body[data-view="discover"] .chat { display: none; }

@keyframes dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75%, 100% { content: '...'; }
}

@media (max-width: 1180px) {
  .discover-layout {
    grid-template-columns: 1fr;
  }
.ad-rail {
    display: none;
  }
  .chat {
    grid-template-columns: 280px minmax(0, 1fr);
  }
}

@media (max-width: 880px) {
  .app {
    grid-template-columns: 1fr;
  }
  .rail {
    position: sticky;
    z-index: 5;
    flex-direction: row;
    align-items: center;
    height: auto;
    padding: .7rem;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .brand {
    margin: 0 auto 0 0;
  }
  .brand strong {
    font-size: 1.1rem;
  }
  .brand span, .rail-note {
    display: none;
  }
  .nav-btn {
    padding: .55rem .7rem;
  }
  .home, .setup, .chat {
    grid-column: 1;
    grid-row: auto;
    border-left: 0;
  }
  .topbar {
    grid-template-columns: 1fr;
    align-items: start;
  }
  .chat {
    grid-template-columns: 1fr;
  }
  .chat header {
    top: 3.85rem;
  }
  .chat-profile {
    position: relative;
    height: auto;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .profile-avatar {
    max-width: 13rem;
    max-height: 17rem;
  }
}

@media (max-width: 620px) {
  .home, .setup, .chat-main, .chat-profile {
    padding-left: .8rem;
    padding-right: .8rem;
  }
  .topbar h1 {
    font-size: 2.35rem;
  }
  .character-grid {
    grid-template-columns: 1fr;
  }
  .character-card {
    grid-template-columns: 4.6rem minmax(0, 1fr);
  }
  .avatar {
    width: 4.6rem;
    height: 6.1rem;
  }
  .names, .composer {
    grid-template-columns: 1fr;
  }
  .composer .primary {
    width: 100%;
  }
  .msg.user {
    max-width: 100%;
  }
}
