@import url("https://fonts.googleapis.com/css2?family=Fira+Sans:wght@400;500;700&display=swap");

:root {
  color-scheme: dark;
  --bg: #0f1419;
  --surface: #17212b;
  --surface-2: #1d2a36;
  --line: #273646;
  --text: #e5edf6;
  --muted: #99a8bb;
  --accent: #4ea2ff;
  --bubble-me: #254560;
  --bubble-other: #1b2a39;
  --danger: #ea7676;
  --success: #6fd6a4;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Fira Sans", "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

/* Landing Page */
.landing-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.hero {
  display: grid;
  gap: 2rem;
  justify-items: center;
}

.hero-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.landing-logo {
  width: 132px;
  height: 132px;
  object-fit: fit;
}

.landing-title {
  margin: 0;
  font-size: 3.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #ffff;
}

.landing-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  max-width: 360px;
  margin: 0 auto;
  width: 100%;
  padding: 0 1rem;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal[hidden] {
  display: none;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.5rem;
  max-width: 460px;
  width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  position: relative;
}

.modal-content h2 {
  margin: 0 0 1rem;
  font-size: 1.5rem;
}

.modal-close {
  position: absolute;
  top: 0.8rem;
  right: 0.8rem;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.8rem;
  cursor: pointer;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: var(--accent);
}

form {
  display: grid;
  gap: 0.75rem;
}

.stack-form {
  display: grid;
  gap: 0.75rem;
}

label {
  color: var(--muted);
  font-size: 0.88rem;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #111923;
  color: var(--text);
  padding: 0.72rem 0.78rem;
}

input:focus {
  outline: none;
  border-color: var(--accent);
}

.btn-primary,
.btn-secondary {
  border: 0;
  border-radius: 11px;
  font-weight: 700;
  padding: 0.72rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: #03111f;
}

.btn-primary:hover:not(:disabled) {
  opacity: 0.9;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Avatar Grid (step 2) */
.avatar-grid-large {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
  margin: 1.2rem 0;
  max-height: min(46vh, 340px);
  overflow-y: auto;
  padding-right: 0.75rem;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: #3d546c #111923;
}

.avatar-grid-large::-webkit-scrollbar {
  width: 10px;
}

.avatar-grid-large::-webkit-scrollbar-track {
  background: #111923;
  border-radius: 999px;
}

.avatar-grid-large::-webkit-scrollbar-thumb {
  background: #3d546c;
  border-radius: 999px;
  border: 2px solid #111923;
}

.avatar-grid-large::-webkit-scrollbar-thumb:hover {
  background: #4d6885;
}

.avatar-item-large {
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #111923;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  display: block;
  line-height: 0;
  cursor: pointer;
  transition: all 0.2s;
  overflow: hidden;
}

.avatar-item-large:hover {
  border-color: var(--accent);
  transform: scale(1.05);
}

.avatar-item-large.active {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(78, 162, 255, 0.3);
}

.avatar-item-large img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.error {
  color: var(--danger);
  font-size: 0.88rem;
  margin-top: 0.5rem;
}

.warning-anon {
  margin: 0;
  color: var(--danger);
  font-size: 0.85rem;
  line-height: 1.35;
}

/* Chat Layout */
.app-shell {
  width: min(760px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100dvh;
  border-inline: 1px solid var(--line);
}

.chat-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0.7rem 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  object-fit: fit;
}

.chat-header h1 {
  margin: 0;
  font-size: 1.03rem;
  letter-spacing: 0.02em;
}

.chat-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.79rem;
}

.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  cursor: pointer;
}

.ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  line-height: 1;
}

.settings-list {
  display: grid;
  gap: 0.75rem;
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  background: #111923;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  color: var(--text);
}

.settings-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.settings-help {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.chat-user {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.7rem;
  padding: 0.9rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.avatar.large {
  width: 48px;
  height: 48px;
}

.chat-user strong {
  display: block;
  font-size: 0.97rem;
}

.chat-user p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.messages {
  padding: 0.95rem;
  overflow-y: auto;
  display: grid;
  gap: 0.55rem;
  align-content: start;
  background: #10171f;
}

.msg {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 0.55rem;
  align-items: start;
}

.msg.bubble-me {
  justify-self: end;
  max-width: min(100%, 560px);
}

.msg.bubble-me .msg-body {
  background: var(--bubble-me);
}

.msg.bubble-other .msg-body {
  background: var(--bubble-other);
}

.msg-avatar {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  object-fit: cover;
}

.msg-body {
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 0.52rem 0.65rem;
  line-height: 1.32;
}

.reply-quote {
  border-left: 3px solid var(--accent);
  background: rgba(14, 29, 43, 0.55);
  border-radius: 8px;
  padding: 0.3rem 0.45rem;
  margin: 0 0 0.35rem;
}

.reply-quote-user {
  margin: 0;
  font-size: 0.77rem;
  color: #9fcbf8;
  font-weight: 700;
}

.reply-quote-text {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.msg-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.28rem;
}

.msg-user {
  font-weight: 700;
  font-size: 0.84rem;
}

.msg-time {
  font-size: 0.73rem;
  color: var(--muted);
}

.msg-text {
  font-size: 0.95rem;
  word-break: break-word;
}

.msg-text a {
  color: #9cd0ff;
}

.system-note {
  justify-self: center;
  color: var(--muted);
  font-size: 0.82rem;
  background: #1b2530;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0.35rem 0.65rem;
}

.reply-preview {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.75rem;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.reply-preview[hidden] {
  display: none;
}

.reply-preview-main {
  border-left: 3px solid var(--accent);
  padding-left: 0.5rem;
  min-width: 0;
}

.reply-preview-label {
  margin: 0;
  font-size: 0.74rem;
  color: #9fcbf8;
  font-weight: 700;
}

.reply-preview-user {
  margin: 0.05rem 0 0;
  font-size: 0.78rem;
  color: var(--text);
  font-weight: 700;
}

.reply-preview-text {
  margin: 0.1rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-cancel-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.reply-cancel-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

.composer {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem;
  padding: 0.75rem;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.composer input {
  background: #0f171f;
}

.composer button {
  background: var(--accent);
  color: #03111f;
  border: 0;
  border-radius: 11px;
  font-weight: 700;
  width: 44px;
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.composer button img {
  width: 18px;
  height: 18px;
  display: block;
  object-fit: contain;
}

@media (min-width: 720px) {
  .app-shell {
    min-height: calc(100dvh - 2rem);
    margin: 1rem auto;
    border-radius: 16px;
    overflow: hidden;
  }

  .landing-title {
    font-size: 4rem;
  }

  .landing-buttons {
    max-width: 420px;
  }
}
