@font-face {
  font-family: "Inter";
  src: url("./fonts/Inter-V.ttf") format("truetype");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #101114;
  --bg-deep: #0b0c0f;
  --surface: #181a1f;
  --surface-2: #202329;
  --surface-3: #2a2e36;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f1f2f5;
  --muted: #9b9fa8;
  --faint: #676b74;
  --accent: #a8e85f;
  --accent-strong: #c2ff7d;
  --accent-ink: #1b2910;
  --danger: #ff777a;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.34);
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body, #app { min-height: 100%; margin: 0; }
body { min-height: 100vh; overflow-x: hidden; }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
button, [role="button"] { -webkit-tap-highlight-color: transparent; }

.noise {
  position: fixed;
  z-index: -1;
  inset: 0;
  pointer-events: none;
  opacity: .18;
  background-image: radial-gradient(rgba(255,255,255,.13) .55px, transparent .7px);
  background-size: 5px 5px;
  mask-image: linear-gradient(to bottom, black, transparent 80%);
}

.app-shell { min-height: 100vh; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 15px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  color: var(--text);
  background: rgba(255,255,255,.04);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: transform .16s ease, background .16s ease, border-color .16s ease, color .16s ease;
}
.button:hover { background: rgba(255,255,255,.09); border-color: rgba(255,255,255,.27); }
.button:active { transform: translateY(1px) scale(.98); }
.button:focus-visible, .icon-button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.button.primary { border-color: var(--accent); color: var(--accent-ink); background: var(--accent); }
.button.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.button.danger { color: var(--danger); }
.button.ghost { border-color: transparent; background: transparent; }
.button.ghost:hover { background: rgba(255,255,255,.07); }
.button:disabled { cursor: not-allowed; opacity: .48; transform: none; }

.icon-button {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 11px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  transition: .16s ease;
}
.icon-button:hover { color: var(--text); background: rgba(255,255,255,.075); border-color: var(--line); }
.icon { width: 18px; height: 18px; display: block; }
.mobile-only { display: none; }

/* Character lobby */
.lobby { width: min(1160px, calc(100% - 48px)); min-height: 100vh; margin: 0 auto; padding: 34px 0 84px; }
.lobby-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 68px; }
.brand { display: flex; align-items: center; gap: 11px; letter-spacing: -.03em; font-size: 18px; font-weight: 750; }
.brand-mark { display: grid; place-items: center; width: 31px; height: 31px; border-radius: 10px; color: var(--accent-ink); background: var(--accent); }
.brand-mark .icon { width: 17px; }
.header-actions { display: flex; gap: 6px; }
.lobby-intro { max-width: 600px; margin: 0 auto 37px; text-align: center; }
.eyebrow { margin: 0 0 12px; color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 14px; letter-spacing: -.055em; font-size: clamp(32px, 4vw, 52px); line-height: 1.04; }
.intro-text { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.6; }
.character-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.character-card { position: relative; min-height: 251px; overflow: hidden; padding: 16px; border: 1px solid var(--line); border-radius: 18px; color: var(--text); background: var(--surface); cursor: pointer; text-align: left; transition: transform .2s ease, border-color .2s ease, background .2s ease; }
.character-card:hover { transform: translateY(-3px); border-color: rgba(168,232,95,.55); background: #1d2024; }
.character-card .avatar { width: 76px; height: 76px; margin-bottom: 58px; }
.card-arrow { position: absolute; top: 15px; right: 15px; color: var(--faint); }
.character-card:hover .card-arrow { color: var(--accent); }
.character-name { display: block; margin-bottom: 7px; font-size: 17px; font-weight: 700; letter-spacing: -.03em; }
.character-title { display: -webkit-box; overflow: hidden; color: var(--muted); font-size: 12px; line-height: 1.45; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.empty-state { display: grid; place-items: center; min-height: 410px; padding: 32px; border: 1px dashed var(--line-strong); border-radius: 22px; background: linear-gradient(145deg, rgba(255,255,255,.035), rgba(255,255,255,.012)); text-align: center; }
.empty-symbol { display: grid; place-items: center; width: 70px; height: 70px; margin: 0 auto 20px; border: 1px solid rgba(168,232,95,.3); border-radius: 23px; color: var(--accent); background: rgba(168,232,95,.08); }
.empty-symbol .icon { width: 30px; height: 30px; }
.empty-state h2 { margin-bottom: 10px; font-size: 23px; letter-spacing: -.04em; }
.empty-state p { max-width: 380px; margin: 0 auto 24px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.fab { position: fixed; z-index: 5; right: 28px; bottom: 28px; width: 64px; height: 64px; display: grid; place-items: center; border: 1px solid var(--accent); border-radius: 50%; color: var(--accent-ink); background: var(--accent); box-shadow: 0 11px 30px rgba(116,174,54,.24); cursor: pointer; transition: transform .2s ease, background .2s ease; }
.fab:hover { transform: translateY(-3px) rotate(8deg); background: var(--accent-strong); }
.fab .icon { width: 25px; height: 25px; }

/* Shared avatar */
.avatar { overflow: hidden; display: grid; place-items: center; flex: 0 0 auto; border: 1px solid rgba(255,255,255,.10); border-radius: 50%; color: #d6eebf; background: #303b28; font-size: 18px; font-weight: 700; text-transform: uppercase; }
.avatar img { width: 100%; height: 100%; display: block; object-fit: cover; }

/* Chat */
.chat-layout { height: 100vh; display: grid; grid-template-columns: 272px minmax(0, 1fr); }
.chat-sidebar { display: flex; flex-direction: column; min-width: 0; padding: 20px 14px; border-right: 1px solid var(--line); background: rgba(10,11,14,.62); }
.sidebar-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 29px; padding: 0 4px; }
.sidebar-persona { display: grid; justify-items: center; padding: 16px 12px 23px; border-bottom: 1px solid var(--line); text-align: center; }
.sidebar-persona .avatar { width: 86px; height: 86px; margin-bottom: 14px; }
.sidebar-persona h2 { margin-bottom: 5px; font-size: 16px; letter-spacing: -.03em; }
.sidebar-persona p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.sidebar-nav { padding: 17px 0; }
.sidebar-link { width: 100%; display: flex; align-items: center; gap: 10px; padding: 11px 12px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; cursor: pointer; text-align: left; font-size: 13px; }
.sidebar-link:hover { color: var(--text); background: rgba(255,255,255,.055); }
.sidebar-link .icon { width: 16px; }
.sidebar-foot { margin-top: auto; padding: 14px 4px 1px; color: var(--faint); font-size: 11px; line-height: 1.5; }
.chat-main { min-width: 0; display: flex; flex-direction: column; background: linear-gradient(150deg, rgba(255,255,255,.018), transparent 40%); }
.chat-topbar { height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 30px; border-bottom: 1px solid var(--line); }
.chat-heading { min-width: 0; }
.chat-heading span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 650; }
.chat-heading small { color: var(--muted); font-size: 11px; }
.status { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(168,232,95,.11); }
.chat-log { width: min(820px, 100%); flex: 1; margin: 0 auto; padding: 42px 30px 26px; overflow-y: auto; scroll-behavior: smooth; }
.message { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 12px; margin-bottom: 26px; }
.message .avatar { width: 34px; height: 34px; font-size: 12px; }
.message-content { min-width: 0; }
.message-meta { display: flex; align-items: baseline; gap: 9px; margin: 2px 0 7px; }
.message-name { font-size: 13px; font-weight: 700; }
.message-time { color: var(--faint); font-size: 11px; }
.message-text { color: #dde0e6; font-size: 14px; line-height: 1.68; overflow-wrap: anywhere; }
.message-text p { margin: 0 0 10px; }
.message-text p:last-child { margin-bottom: 0; }
.message.user { grid-template-columns: minmax(0, 1fr); margin-left: 58px; }
.message.user .message-content { max-width: 590px; justify-self: end; padding: 12px 15px; border: 1px solid rgba(255,255,255,.08); border-radius: 15px 15px 3px 15px; background: var(--surface-2); }
.message.user .message-meta { margin-top: 0; }
.message.error .message-content { color: #ffd6d7; }
.thinking { display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); background: rgba(255,255,255,.025); }
.thinking i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: bounce 1.1s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: .14s; }.thinking i:nth-child(3) { animation-delay: .28s; }
@keyframes bounce { 0%, 65%, 100% { transform: translateY(0); opacity: .34; } 32% { transform: translateY(-3px); opacity: 1; } }
.composer-wrap { width: min(880px, 100%); margin: 0 auto; padding: 0 30px 25px; }
.composer { display: flex; align-items: end; gap: 11px; padding: 10px 11px 10px 16px; border: 1px solid var(--line-strong); border-radius: 17px; background: #1a1c20; box-shadow: 0 14px 40px rgba(0,0,0,.18); }
.composer:focus-within { border-color: rgba(168,232,95,.58); box-shadow: 0 0 0 3px rgba(168,232,95,.08), 0 14px 40px rgba(0,0,0,.18); }
.composer textarea { width: 100%; min-height: 24px; max-height: 180px; padding: 3px 0; resize: none; border: 0; outline: none; color: var(--text); background: transparent; font-size: 14px; line-height: 1.55; }
.composer textarea::placeholder { color: var(--faint); }
.send-button { width: 37px; height: 37px; display: grid; place-items: center; flex: 0 0 37px; border: 0; border-radius: 11px; color: var(--accent-ink); background: var(--accent); cursor: pointer; }
.send-button:hover { background: var(--accent-strong); }.send-button:disabled { cursor: not-allowed; color: var(--faint); background: #32353b; }
.send-button .icon { width: 18px; }
.composer-note { margin: 9px 0 0; color: var(--faint); font-size: 10px; text-align: center; }

/* Modal/editor */
.modal-backdrop { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 22px; background: rgba(4,5,7,.74); backdrop-filter: blur(8px); animation: appear .18s ease; }
@keyframes appear { from { opacity: 0; } to { opacity: 1; } }
.modal { width: min(950px, 100%); max-height: calc(100vh - 44px); overflow: auto; border: 1px solid var(--line-strong); border-radius: 20px; background: #17191d; box-shadow: var(--shadow); }
.modal-header { position: sticky; z-index: 2; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 20px 24px; border-bottom: 1px solid var(--line); background: rgba(23,25,29,.93); backdrop-filter: blur(12px); }
.modal-header h2 { margin: 0; font-size: 18px; letter-spacing: -.04em; }
.modal-body { padding: 25px; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) 270px; gap: 31px; }
.form-stack { display: grid; gap: 18px; }
.field { display: block; }
.field > span, .field-label { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 8px; color: #d9dce0; font-size: 12px; font-weight: 650; }
.field-hint { color: var(--faint); font-weight: 500; }
input[type="text"], input[type="url"], input[type="number"], textarea, select { width: 100%; border: 1px solid var(--line-strong); border-radius: 10px; outline: none; color: var(--text); background: #111216; transition: border-color .16s ease, box-shadow .16s ease; }
input[type="text"], input[type="url"], input[type="number"], select { height: 42px; padding: 0 12px; font-size: 13px; }
textarea { min-height: 105px; padding: 11px 12px; resize: vertical; font-size: 13px; line-height: 1.52; }
input:focus, textarea:focus, select:focus { border-color: rgba(168,232,95,.62); box-shadow: 0 0 0 3px rgba(168,232,95,.08); }
.avatar-editor { display: grid; justify-items: center; align-content: start; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.02); }
.crop-area { position: relative; width: 100%; aspect-ratio: 1; overflow: hidden; border-radius: 12px; background: #0c0d10; touch-action: none; cursor: grab; }
.crop-area.dragging { cursor: grabbing; }
.crop-area canvas { width: 100%; height: 100%; display: block; }
.crop-area::after { position: absolute; inset: 0; border: 1px solid rgba(255,255,255,.22); border-radius: inherit; content: ""; pointer-events: none; }
.avatar-placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--faint); font-size: 12px; text-align: center; }
.file-control { width: 100%; position: relative; overflow: hidden; }
.file-control input { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }
.file-control .button { width: 100%; pointer-events: none; }
.range-line { width: 100%; display: grid; grid-template-columns: 17px 1fr 17px; align-items: center; gap: 8px; color: var(--faint); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.crop-help { margin: 0; color: var(--faint); font-size: 10px; line-height: 1.4; text-align: center; }
.modal-footer { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line); }
.modal-footer .right-actions { display: flex; gap: 8px; margin-left: auto; }

/* Settings */
.settings-modal { width: min(760px, 100%); }
.settings-section + .settings-section { margin-top: 28px; padding-top: 26px; border-top: 1px solid var(--line); }
.settings-section h3 { margin-bottom: 5px; letter-spacing: -.025em; font-size: 15px; }
.settings-section > p { margin-bottom: 17px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 15px; }
.settings-grid.generation { grid-template-columns: repeat(3, minmax(0,1fr)); }
.inline-help { margin: 15px 0 0; color: var(--faint); font-size: 11px; line-height: 1.55; }
.connection-status { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 17px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.025); color: var(--muted); font-size: 12px; }
.connection-status .status-dot { flex: 0 0 auto; background: var(--faint); box-shadow: none; }.connection-status.ok .status-dot { background: var(--accent); }.connection-status.error .status-dot { background: var(--danger); }

.toast { position: fixed; z-index: 30; left: 50%; bottom: 25px; transform: translate(-50%, 12px); min-width: min(370px, calc(100% - 32px)); padding: 12px 15px; border: 1px solid var(--line-strong); border-radius: 11px; color: var(--text); background: #25282e; box-shadow: var(--shadow); font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease; text-align: center; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }.toast.error { border-color: rgba(255,119,122,.44); color: #ffdadd; }

@media (max-width: 720px) {
  .lobby { width: min(100% - 32px, 1160px); padding-top: 18px; }.lobby-header { margin-bottom: 52px; }.lobby-intro { text-align: left; }.character-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }.character-card { min-height: 215px; }.character-card .avatar { margin-bottom: 39px; }.fab { right: 18px; bottom: 18px; }
  .chat-layout { display: block; height: 100vh; }.chat-sidebar { display: none; }.chat-topbar { height: 63px; padding: 0 14px; }.mobile-only { display: grid; }.chat-log { padding: 27px 16px 20px; }.composer-wrap { padding: 0 13px 18px; }.message.user { margin-left: 18px; }.status { font-size: 0; }.status-dot { width: 8px; height: 8px; }.modal-backdrop { padding: 0; align-items: end; }.modal { max-height: min(92vh, 100%); border-radius: 20px 20px 0 0; }.modal-header { padding: 18px; }.modal-body { padding: 19px 18px; }.form-grid { grid-template-columns: 1fr; gap: 20px; }.avatar-editor { max-width: 270px; }.settings-grid, .settings-grid.generation { grid-template-columns: 1fr 1fr; }.modal-footer { align-items: stretch; flex-wrap: wrap; }.modal-footer .right-actions { width: 100%; }.modal-footer .right-actions .button { flex: 1; }
}

@media (max-width: 390px) { .character-grid { grid-template-columns: 1fr; }.settings-grid, .settings-grid.generation { grid-template-columns: 1fr; } }
