:root {
  color-scheme: light;
  --ink: #151619;
  --muted: #626b70;
  --paper: #eff5f3;
  --panel: #fffdfa;
  --line: rgba(21, 22, 25, 0.12);
  --teal: #0b7477;
  --teal-dark: #09565a;
  --gold: #b87924;
  --rose: #a8323d;
  --mint: #a8d2bd;
  --steel: #33444d;
  --emotion: var(--gold);
  --success: #237a46;
  --shadow: 0 18px 50px rgba(21, 22, 25, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.42), rgba(247, 245, 239, 0) 260px),
    var(--paper);
}

html[data-emotion="confident"] {
  --emotion: #8fc49f;
}

html[data-emotion="warm"] {
  --emotion: #e79d46;
}

html[data-emotion="thinking"] {
  --emotion: #719abc;
}

html[data-emotion="strict"] {
  --emotion: var(--rose);
}

html[data-emotion="intense"] {
  --emotion: #df6035;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
  height: 100vh;
  padding: 24px;
  color: #f7f5ef;
  background: #121315;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 64px;
  height: 64px;
  border: 2px solid var(--gold);
  border-radius: 50%;
  color: var(--gold);
  background: #0d0e10;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  font-weight: 800;
}

.character-surface {
  display: grid;
  grid-template-columns: minmax(230px, 0.72fr) minmax(0, 1fr);
  grid-column: 1 / -1;
  gap: 20px;
  align-items: center;
  overflow: hidden;
  color: #fff;
  background:
    linear-gradient(135deg, #111417 0%, var(--steel) 54%, var(--teal-dark) 100%);
}

.character-surface h3 {
  color: #fff;
}

.character-controls {
  display: grid;
  gap: 14px;
}

.emotion-name {
  min-height: 28px;
  padding: 5px 10px;
  border-radius: 999px;
  color: #111417;
  background: var(--emotion);
  font-size: 0.78rem;
  font-weight: 900;
}

.emotion-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.emotion-grid .text-button {
  color: rgba(255, 255, 255, 0.84);
  background: rgba(255, 255, 255, 0.10);
  border-color: rgba(255, 255, 255, 0.10);
}

.emotion-grid .text-button.is-active {
  color: #111417;
  background: var(--emotion);
  border-color: transparent;
}

.web-avatar-stage {
  position: relative;
  min-height: 306px;
  perspective: 760px;
  transform-style: preserve-3d;
}

.avatar-shadow,
.avatar-body,
.avatar-neck,
.avatar-head,
.shirt-line,
.shirt-mark,
.avatar-head span {
  position: absolute;
  display: block;
}

.avatar-shadow {
  left: 50%;
  bottom: 23px;
  width: 218px;
  height: 34px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.28);
  filter: blur(5px);
  transform: translateX(-50%) rotateX(64deg);
}

.avatar-body {
  left: 50%;
  bottom: 34px;
  width: 220px;
  height: 166px;
  border-radius: 48% 48% 18px 18px;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.10), transparent 33%),
    radial-gradient(circle at 50% 0%, #1c2024 0 20%, #08090b 58%, #030405 100%);
  box-shadow:
    inset -24px -16px 30px rgba(0, 0, 0, 0.46),
    inset 18px 12px 24px rgba(255, 255, 255, 0.04);
  transform: translateX(-50%) rotateX(3deg);
}

.shirt-line {
  left: 36px;
  top: 106px;
  width: 60px;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
}

.shirt-mark {
  left: 52px;
  top: 78px;
  color: var(--emotion);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.15rem;
  font-weight: 900;
}

.avatar-neck {
  left: 50%;
  bottom: 164px;
  width: 56px;
  height: 54px;
  border-radius: 22px;
  background: linear-gradient(100deg, #9b7059, #d09b7a 46%, #875f4d);
  transform: translateX(-50%);
}

.avatar-head {
  left: 50%;
  bottom: 185px;
  width: 154px;
  height: 178px;
  border-radius: 44% 44% 48% 48%;
  background:
    radial-gradient(circle at 35% 28%, rgba(255, 255, 255, 0.42), transparent 18%),
    linear-gradient(105deg, #926a57, #d29b7c 43%, #a6765f 100%);
  box-shadow:
    inset -18px -12px 28px rgba(63, 32, 22, 0.38),
    inset 18px 10px 30px rgba(255, 230, 210, 0.18),
    0 22px 34px rgba(0, 0, 0, 0.18);
  transform: translateX(-50%) rotateY(-4deg);
}

.ear {
  top: 72px;
  width: 24px;
  height: 38px;
  border-radius: 50%;
  background: #b98267;
  z-index: -1;
}

.ear.left {
  left: -13px;
}

.ear.right {
  right: -13px;
}

.hair {
  background: #281106;
}

.hair.side {
  top: 27px;
  width: 32px;
  height: 78px;
  border-radius: 48% 42% 50% 34%;
  box-shadow: inset 8px 0 14px rgba(255, 180, 96, 0.14);
}

.hair.side.left {
  left: 2px;
  transform: rotate(7deg);
}

.hair.side.right {
  right: 3px;
  transform: rotate(-7deg);
}

.hair.cap {
  left: 22px;
  top: -4px;
  width: 112px;
  height: 64px;
  border-radius: 54% 60% 38% 38%;
  background: linear-gradient(120deg, #2a1107, #5f2b12 44%, #1f0d05);
}

.hair.lock {
  top: 3px;
  height: 37px;
  border-radius: 50%;
  background: linear-gradient(115deg, #6b3217, #2b1107);
}

.lock-a {
  left: 35px;
  width: 42px;
  transform: rotate(-12deg);
}

.lock-b {
  left: 62px;
  width: 50px;
  height: 42px;
  top: -3px;
  transform: rotate(-5deg);
}

.lock-c {
  right: 25px;
  width: 38px;
  transform: rotate(13deg);
}

.eye {
  top: 85px;
  width: 19px;
  height: 10px;
  border-radius: 50%;
  background: #191615;
  box-shadow: 0 0 0 2px rgba(255, 230, 210, 0.10);
}

.eye.left {
  left: 46px;
}

.eye.right {
  right: 44px;
}

.brow {
  top: 70px;
  width: 34px;
  height: 6px;
  border-radius: 999px;
  background: #241108;
}

.brow.left {
  left: 37px;
  transform: rotate(7deg);
}

.brow.right {
  right: 35px;
  transform: rotate(-7deg);
}

.nose {
  left: 50%;
  top: 94px;
  width: 18px;
  height: 30px;
  border-radius: 48% 48% 55% 55%;
  background: linear-gradient(105deg, #9d705b, #d2a083);
  transform: translateX(-50%);
}

.mouth {
  left: 50%;
  top: 132px;
  width: 42px;
  height: 6px;
  border-radius: 999px;
  background: #3a1110;
  transform: translateX(-50%);
}

.cheek {
  display: none;
  top: 118px;
  width: 25px;
  height: 10px;
  border-radius: 50%;
  background: rgba(203, 69, 54, 0.38);
}

.cheek.left {
  left: 28px;
}

.cheek.right {
  right: 28px;
}

html[data-emotion="warm"] .mouth {
  top: 127px;
  width: 52px;
  height: 22px;
  border-bottom: 6px solid #3a1110;
  border-radius: 0 0 48px 48px;
  background: transparent;
}

html[data-emotion="warm"] .cheek {
  display: block;
}

html[data-emotion="thinking"] .brow.left {
  top: 64px;
  transform: rotate(-14deg);
}

html[data-emotion="thinking"] .brow.right {
  top: 75px;
  transform: rotate(-2deg);
}

html[data-emotion="thinking"] .mouth {
  left: 54%;
  width: 32px;
  transform: translateX(-50%) rotate(-7deg);
}

html[data-emotion="strict"] .eye,
html[data-emotion="intense"] .eye {
  height: 7px;
}

html[data-emotion="strict"] .brow.left {
  transform: rotate(16deg);
}

html[data-emotion="strict"] .brow.right {
  transform: rotate(-16deg);
}

html[data-emotion="intense"] .brow.left {
  top: 74px;
  transform: rotate(25deg);
}

html[data-emotion="intense"] .brow.right {
  top: 74px;
  transform: rotate(-25deg);
}

html[data-emotion="intense"] .mouth {
  width: 38px;
  transform: translateX(-50%) rotate(-4deg);
}

html[data-emotion="confident"] .mouth {
  width: 45px;
  transform: translateX(-50%) rotate(8deg);
}

html[data-emotion="confident"] .brow.right {
  top: 66px;
  transform: rotate(12deg);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.7rem;
  line-height: 1;
}

h2 {
  margin-bottom: 0;
  font-size: 2.35rem;
  line-height: 1.05;
}

h3 {
  margin-bottom: 0;
  font-size: 1rem;
}

.identity-panel,
.tool-surface {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.identity-panel {
  display: grid;
  gap: 9px;
  padding: 14px;
  color: var(--ink);
}

label,
.metric-label,
.profile-list dt,
.message-meta,
.item-meta {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

input,
select {
  height: 42px;
  padding: 0 11px;
}

textarea {
  resize: vertical;
  padding: 11px;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(11, 116, 119, 0.15);
}

.inline-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 8px;
}

.primary-button,
.text-button,
.icon-button,
.nav-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  padding: 0 16px;
  color: #fff;
  background: var(--teal);
}

.primary-button:hover {
  background: var(--teal-dark);
}

.primary-button:disabled,
.icon-button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  padding: 0;
  color: var(--ink);
  background: #fff;
  border-color: var(--line);
  font-size: 1.25rem;
}

.icon-button:hover,
.text-button:hover {
  border-color: rgba(11, 116, 119, 0.45);
}

.text-button {
  min-height: 34px;
  padding: 0 12px;
  color: var(--teal);
  background: rgba(11, 116, 119, 0.08);
}

.side-nav {
  display: grid;
  gap: 8px;
}

.nav-button {
  width: 100%;
  padding: 0 14px;
  text-align: left;
  color: rgba(247, 245, 239, 0.76);
  background: transparent;
  border-color: rgba(255, 255, 255, 0.08);
}

.nav-button:hover,
.nav-button.is-active {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.16);
}

.backend-status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  color: rgba(247, 245, 239, 0.76);
  font-size: 0.86rem;
  font-weight: 700;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold);
}

.backend-status.is-ok .status-dot {
  background: var(--success);
}

.backend-status.is-error .status-dot {
  background: var(--rose);
}

.workspace {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

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

.notice {
  display: none;
  margin-bottom: 18px;
  padding: 12px 14px;
  border: 1px solid rgba(11, 116, 119, 0.2);
  border-radius: 8px;
  color: var(--teal-dark);
  background: rgba(11, 116, 119, 0.08);
  font-weight: 700;
}

.notice.is-visible {
  display: block;
}

.notice.is-error {
  color: var(--rose);
  border-color: rgba(168, 50, 61, 0.2);
  background: rgba(168, 50, 61, 0.08);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 26px;
}

.metric-card,
.item-card,
.message-bubble {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metric-card {
  min-height: 108px;
  padding: 16px;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  color: var(--ink);
  font-size: 2rem;
  line-height: 1;
}

.metric-card.accent {
  border-color: rgba(184, 121, 36, 0.35);
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.overview-grid,
.split-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 18px;
  margin-bottom: 24px;
}

.tool-surface {
  padding: 16px;
}

.tool-surface.character-surface {
  padding: 18px;
  color: #fff;
  background:
    linear-gradient(135deg, #111417 0%, var(--steel) 54%, var(--teal-dark) 100%);
}

.tool-surface.character-surface .section-heading {
  margin-bottom: 0;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.profile-list {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 10px 14px;
  margin: 0;
}

.profile-list dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.model-tile {
  display: flex;
  align-items: center;
  min-height: 110px;
  color: var(--teal-dark);
  font-size: 1.4rem;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.mind-surface {
  grid-column: 1 / -1;
}

.mind-status {
  display: grid;
  gap: 10px;
}

.mind-status.large {
  min-height: 220px;
  align-content: start;
}

.mind-heading {
  display: grid;
  gap: 4px;
}

.mind-heading strong {
  font-size: 1.35rem;
  line-height: 1.15;
}

.mind-heading span {
  color: var(--teal-dark);
  font-weight: 800;
}

.mind-status p {
  margin: 0;
  color: #2c3034;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.mind-meter-grid,
.mind-meter-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.mind-meter-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.mind-meter {
  min-width: 0;
}

.mind-meter-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.mind-meter-top strong {
  color: var(--ink);
}

.mind-meter.teal .progress span {
  background: var(--teal);
}

.mind-meter.gold .progress span {
  background: var(--gold);
}

.mind-meter.rose .progress span {
  background: var(--rose);
}

.mind-meter.steel .progress span {
  background: var(--steel);
}

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

.item-card {
  padding: 14px;
}

.item-card h4 {
  margin: 0 0 7px;
  font-size: 0.98rem;
}

.item-card p {
  margin-bottom: 0;
  color: #2c3034;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--teal-dark);
  background: rgba(11, 116, 119, 0.1);
}

.pill.rose {
  color: var(--rose);
  background: rgba(168, 50, 61, 0.1);
}

.empty-state {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.58);
}

.chat-layout {
  display: grid;
  grid-template-rows: minmax(360px, calc(100vh - 280px)) auto;
  gap: 14px;
}

.chat-stream {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 360px;
  padding: 2px 2px 14px;
  overflow: auto;
}

.message-bubble {
  width: min(760px, 88%);
  padding: 13px 14px;
  box-shadow: 0 10px 28px rgba(21, 22, 25, 0.06);
}

.message-bubble.is-user {
  align-self: flex-end;
  color: #fff;
  background: var(--teal);
  border-color: transparent;
}

.message-bubble.is-user .message-meta {
  color: rgba(255, 255, 255, 0.78);
}

.message-text {
  margin: 6px 0 0;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px 104px;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.voice-status {
  display: none;
  min-height: 34px;
  padding: 8px 11px;
  border: 1px solid rgba(11, 116, 119, 0.18);
  border-radius: 8px;
  color: var(--teal-dark);
  background: rgba(11, 116, 119, 0.07);
  font-size: 0.82rem;
  font-weight: 800;
}

.voice-status.is-visible {
  display: block;
}

.voice-status.is-error {
  color: var(--rose);
  border-color: rgba(168, 50, 61, 0.22);
  background: rgba(168, 50, 61, 0.08);
}

.voice-button.is-recording {
  color: #fff;
  background: var(--rose);
  border-color: var(--rose);
}

.memory-form {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr) 96px;
  gap: 12px;
  align-items: end;
  margin-bottom: 22px;
}

.field-row {
  display: grid;
  gap: 7px;
}

.progress {
  position: relative;
  height: 7px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(21, 22, 25, 0.09);
}

.progress span {
  display: block;
  height: 100%;
  width: var(--value, 0%);
  background: var(--gold);
}

.inbox-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 18px;
  }

  .side-nav {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-button {
    flex: 0 0 auto;
    width: auto;
    white-space: nowrap;
  }

  .backend-status {
    margin-top: 0;
  }

  .workspace {
    padding: 22px 16px 28px;
  }

  .metrics-grid,
  .overview-grid,
  .split-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .memory-form {
    grid-template-columns: 1fr;
  }

  .character-surface {
    grid-template-columns: 1fr;
  }

  .web-avatar-stage {
    min-height: 270px;
  }
}

@media (max-width: 640px) {
  .brand-mark {
    width: 54px;
    height: 54px;
    font-size: 19px;
  }

  h1 {
    font-size: 1.45rem;
  }

  h2 {
    font-size: 1.7rem;
  }

  .metrics-grid,
  .overview-grid,
  .split-grid {
    grid-template-columns: 1fr;
  }

  .mind-meter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar {
    align-items: center;
  }

  .profile-list {
    grid-template-columns: 1fr;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) 46px;
  }

  .composer .primary-button {
    grid-column: 1 / -1;
    width: 100%;
  }

  .message-bubble {
    width: 96%;
  }
}
