:root {
  color-scheme: dark;
  --bg: #07080b;
  --panel: #11141a;
  --panel-2: #171b23;
  --line: #2a303c;
  --text: #f4f0f3;
  --muted: #a6adba;
  --red: #e84a5f;
  --cyan: #74d7df;
  --violet: #b196ff;
  --green: #8adf9a;
  --danger: #ff7a7a;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  background:
    linear-gradient(135deg, rgba(232, 74, 95, 0.2), transparent 34%),
    radial-gradient(circle at 90% 20%, rgba(116, 215, 223, 0.14), transparent 28%),
    var(--bg);
  color: var(--text);
  margin: 0;
}

body[data-view="conversation"] {
  overflow: hidden;
}

#appView {
  min-height: 100vh;
}

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

button {
  background: var(--red);
  border: 1px solid transparent;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  font-weight: 700;
  min-height: 40px;
  padding: 0 16px;
}

button:disabled,
label.file-button.disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

input,
select,
textarea {
  background: #0d1016;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  outline: none;
  padding: 11px 12px;
  width: 100%;
}

textarea {
  line-height: 1.65;
  resize: vertical;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  gap: 8px;
}

.provider-form,
.story-create,
.story-continue {
  display: grid;
  gap: 14px;
}

.form-error {
  color: var(--danger);
  margin: 14px 0 0;
}

.home-view {
  display: grid;
  gap: 24px;
  min-height: 100vh;
  padding: 28px;
}

.home-head {
  align-items: center;
  display: flex;
  gap: 18px;
  justify-content: space-between;
}

.home-head p {
  color: var(--muted);
  font-size: 14px;
  margin-top: 6px;
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.people-grid {
  align-content: start;
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.people-card {
  align-items: start;
  background: rgba(17, 20, 26, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  display: grid;
  gap: 14px;
  grid-template-columns: 82px 1fr;
  min-height: 190px;
  padding: 14px;
  text-align: left;
}

.people-card:hover {
  border-color: var(--red);
}

.people-card > img {
  aspect-ratio: 1;
  border-radius: 8px;
  height: 82px;
  object-fit: cover;
  width: 82px;
}

.people-card strong {
  display: block;
  font-size: 18px;
}

.people-card span span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  line-height: 1.45;
  margin-top: 5px;
}

.people-card small {
  color: var(--cyan);
  display: block;
  font-size: 11px;
  margin-top: 8px;
}

.people-card-assets {
  display: grid;
  gap: 8px;
  grid-column: 1 / -1;
  grid-template-columns: repeat(3, 1fr);
}

.people-card-assets img {
  aspect-ratio: 1.4;
  border-radius: 6px;
  height: auto;
  object-fit: cover;
  width: 100%;
}

.stream-view {
  display: grid;
  gap: 18px;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100vh;
  padding: 22px;
}

.stream-head {
  align-items: center;
  background: rgba(12, 14, 19, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  padding: 16px 18px;
}

.stream-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.stream-main {
  align-content: start;
  background: rgba(12, 14, 19, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 18px;
  justify-self: center;
  max-width: 780px;
  padding: 18px;
  width: min(100%, 780px);
}

.workspace-head,
.stream-head,
.settings-head,
.section-title,
.conversation-title,
.composer-actions,
.dialog-actions {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 20px;
}

.stream-head p,
.workspace-head p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.ghost-button,
.small-button {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
}

.friend-section,
.history-section {
  min-height: 0;
}

.friend-list {
  display: grid;
  gap: 8px;
}

.friend-item {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  display: grid;
  gap: 12px;
  grid-template-columns: 56px 1fr;
  min-height: 72px;
  padding: 8px;
  text-align: left;
  width: 100%;
}

.friend-item.active {
  border-color: var(--red);
  background: rgba(232, 74, 95, 0.12);
}

.friend-item img {
  aspect-ratio: 1;
  border-radius: 8px;
  height: 56px;
  object-fit: cover;
  width: 56px;
}

.friend-item strong,
.history-item strong {
  display: block;
  font-size: 14px;
}

.friend-item span,
.history-item span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  line-height: 1.4;
  margin-top: 3px;
}

.select-row {
  gap: 7px;
}

.section-title {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 11px;
  text-align: left;
  width: 100%;
}

.history-item.active {
  border-color: var(--cyan);
  background: rgba(116, 215, 223, 0.08);
}

.history-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  padding: 14px;
}

.conversation-view {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.workspace-head {
  border-bottom: 1px solid var(--line);
  padding: 18px 22px;
}

.conversation-title {
  min-width: 0;
}

.conversation-layout,
.story-layout {
  display: grid;
  gap: 16px;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  padding: 18px 22px 22px;
}

.empty-workspace {
  align-items: center;
  color: var(--muted);
  display: grid;
  min-height: 0;
  padding: 22px;
}

.empty-workspace > div {
  border: 1px dashed var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  justify-items: start;
  margin: auto;
  max-width: 420px;
  padding: 24px;
}

.empty-workspace h3 {
  color: var(--text);
  font-size: 18px;
  margin: 0;
}

.empty-workspace p {
  line-height: 1.6;
}

.message-list,
.story-reader {
  min-height: 0;
  overflow: auto;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 6px 0;
}

.message-row {
  display: flex;
  width: 100%;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.assistant {
  justify-content: flex-start;
}

.message {
  border: 1px solid transparent;
  border-radius: 18px;
  line-height: 1.7;
  max-width: min(680px, 82%);
  padding: 10px 14px;
  white-space: pre-wrap;
}

.message.user {
  background: var(--red);
  border-bottom-right-radius: 6px;
  color: white;
}

.message.assistant {
  background: rgba(23, 27, 35, 0.98);
  border-bottom-left-radius: 6px;
  border-color: var(--line);
}

.message img {
  border-radius: 8px;
  display: block;
  margin-top: 10px;
  max-height: 240px;
  max-width: 100%;
  object-fit: contain;
}

.composer {
  background: rgba(17, 20, 26, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  padding: 12px;
}

.composer-actions {
  flex-wrap: wrap;
}

.file-button {
  align-items: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  font-weight: 700;
  min-height: 40px;
  padding: 0 14px;
}

.attachment-preview {
  color: var(--cyan);
  font-size: 13px;
}

.story-layout {
  grid-template-rows: auto minmax(0, 1fr);
  overflow: auto;
}

.story-create,
.story-continue {
  background: rgba(17, 20, 26, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.story-opening,
.story-segment {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  line-height: 1.8;
  margin-bottom: 12px;
  padding: 15px;
  white-space: pre-wrap;
}

.story-opening {
  border-color: rgba(116, 215, 223, 0.44);
}

.settings-panel {
  background: rgba(0, 0, 0, 0.58);
  inset: 0;
  position: fixed;
  z-index: 10;
}

.settings-inner {
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: grid;
  gap: 18px;
  height: 100%;
  margin-left: auto;
  max-width: 480px;
  overflow: auto;
  padding: 20px;
  width: min(100%, 480px);
}

.scenario-inner {
  max-width: 640px;
  width: min(100%, 640px);
}

#personProfilePanel .settings-inner {
  max-width: 760px;
  width: min(100%, 760px);
}

.capability-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.capability-grid label {
  align-items: center;
  background: #0d1016;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  padding: 10px;
}

.capability-grid input {
  margin-right: 8px;
  width: auto;
}

.provider-list {
  display: grid;
  gap: 10px;
}

.provider-row {
  background: #0d1016;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  padding: 12px;
}

.provider-row-actions {
  display: flex;
  gap: 8px;
}

.image-dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  max-width: 560px;
  width: calc(100% - 32px);
}

.image-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.image-dialog form {
  display: grid;
  gap: 14px;
}

.image-result-list {
  display: grid;
  gap: 10px;
}

.image-result-list img {
  border-radius: 8px;
  max-width: 100%;
}

.toast {
  background: #11141a;
  border: 1px solid var(--line);
  border-radius: 8px;
  bottom: 18px;
  box-shadow: var(--shadow);
  color: var(--text);
  left: 50%;
  padding: 12px 16px;
  position: fixed;
  transform: translateX(-50%);
  z-index: 20;
}

@media (max-width: 840px) {
  .home-view {
    padding: 18px;
  }

  .home-head {
    align-items: flex-start;
    display: grid;
  }

  .stream-view {
    padding: 14px;
  }

  .stream-head {
    align-items: flex-start;
    display: grid;
  }

  .stream-main {
    max-width: none;
  }

  .friend-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .friend-item {
    flex: 0 0 250px;
  }

  .conversation-layout,
  .story-layout {
    min-height: 0;
    padding: 14px;
  }

  .workspace-head {
    padding: 14px;
  }

  .composer-actions {
    align-items: stretch;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .composer-actions button,
  .composer-actions .file-button {
    justify-content: center;
    width: 100%;
  }
}

@media (max-width: 520px) {
  .stream-head,
  .workspace-head,
  .settings-head {
    align-items: flex-start;
  }

  .composer-actions {
    grid-template-columns: 1fr;
  }

  .capability-grid {
    grid-template-columns: 1fr;
  }
}
