@font-face {
  font-family: "Figtree";
  src: url("fonts/figtree_extrabold.ttf") format("truetype");
  font-weight: 800;
  font-display: swap;
}
@font-face {
  font-family: "Figtree";
  src: url("fonts/figtree_black.ttf") format("truetype");
  font-weight: 900;
  font-display: swap;
}
@font-face {
  font-family: "Roboto";
  src: url("fonts/roboto_regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Roboto";
  src: url("fonts/roboto_medium.ttf") format("truetype");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Roboto";
  src: url("fonts/roboto_bold.ttf") format("truetype");
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: "Roboto";
  src: url("fonts/roboto_bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

:root {
  --background: #FFFFFF;
  --surface: #FFFFFF;
  --surface-variant: #F4F4F6;
  --outline: rgba(0, 0, 0, 0.1);
  --on-surface: #17171A;
  --on-surface-variant: #6B6B76;
  --primary: #2F6BFF;
  --on-primary: #FFFFFF;
  --bubble-own: #2F6BFF;
  --bubble-other: #F1F1F4;
  --header-icon: #8C99B0;
  --status-online: #1E9E5A;
  --record-red: #FF3B30;
  --brand: "Figtree", "Roboto", system-ui, sans-serif;
  --body: "Roboto", system-ui, sans-serif;
  --gutter: 12px;
  --sidebar-w: 360px;
  --add-h: 66px;
  --radius: 18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #1A1A1F;
    --surface: #1A1A1F;
    --surface-variant: #24242B;
    --outline: rgba(255, 255, 255, 0.12);
    --on-surface: #F2F2F5;
    --on-surface-variant: #9A9AA6;
    --primary: #6D95FF;
    --on-primary: #0B1220;
    --bubble-own: #3D6FE0;
    --bubble-other: #26262E;
    --header-icon: #96A2BB;
    --status-online: #34D399;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--body);
  background: var(--background);
  color: var(--on-surface);
  overflow: hidden;
}

#app {
  display: flex;
  height: 100dvh;
}

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--background);
  border-right: 1px solid var(--outline);
  z-index: 20;
}

.side-head {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 8px 6px 12px var(--gutter);
}

.side-title {
  font-family: var(--brand);
  font-weight: 900;
  font-size: 20px;
  line-height: 26px;
  letter-spacing: -0.5px;
  padding-top: 12px;
}

.pop {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transform-origin: center;
  will-change: transform;
}

.icon-pop {
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center;
  will-change: transform;
}

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--header-icon);
  width: 51px;
  height: 51px;
  font-size: 22px;
  font-weight: 800;
  font-family: var(--brand);
  cursor: pointer;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 120ms ease;
}

.icon-btn:hover { background: var(--surface-variant); }
.icon-btn:active { transform: scale(0.88); }

.side-head .icon-btn {
  position: absolute;
  right: var(--gutter);
  top: 8px;
}

.side-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#roster {
  list-style: none;
  margin: auto 0 0;
  padding: 4px 0 14px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.roster-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  padding: 10px 10px 10px 16px;
  min-height: 145px;
  font-family: inherit;
}

.roster-row:hover { background: var(--surface-variant); }

.avatar {
  position: relative;
  width: 118px;
  height: 118px;
  min-width: 118px;
  border-radius: 50%;
  background: var(--surface-variant);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--brand);
  font-weight: 900;
  font-size: 40px;
  color: var(--on-surface-variant);
  overflow: visible;
}

.avatar-art {
  width: 100%;
  height: 100%;
  display: flex;
}

.avatar-art svg {
  width: 100%;
  height: 100%;
  display: block;
}

.roster-row:hover .avatar { background: var(--surface); }

.avatar .dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--status-online);
  border: 2px solid var(--surface);
}

.roster-main { flex: 1; min-width: 0; }

.roster-top {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.roster-name {
  font-weight: 600;
  font-size: 22px;
  line-height: 29px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.roster-time {
  margin-left: auto;
  font-size: 16px;
  line-height: 21px;
  color: var(--on-surface-variant);
  opacity: 0.72;
  white-space: nowrap;
}

.roster-preview {
  margin: 2px 6px 0 0;
  font-size: 17px;
  line-height: 22px;
  color: var(--on-surface-variant);
  opacity: 0.72;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.roster-sep {
  margin-left: 146px;
  height: 1px;
  background: var(--outline);
}

.side-foot { padding: 0 var(--gutter) 14px; }

.invite-panel {
  display: flex;
  gap: 10px;
  align-items: stretch;
  margin-bottom: 10px;
}

.invite-card {
  flex: 1;
  background: var(--surface-variant);
  border-radius: var(--radius);
  padding: 18px 22px;
}

.invite-label {
  font-family: var(--brand);
  font-weight: 800;
  font-size: 15px;
  line-height: 19px;
}

.invite-link {
  font-family: var(--brand);
  font-weight: 900;
  font-size: 21px;
  line-height: 25px;
  color: var(--primary);
  margin-top: 8px;
  user-select: all;
  overflow-wrap: anywhere;
}

.copy-btn {
  border: 0;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--on-primary);
  font-family: var(--brand);
  font-weight: 900;
  font-size: 21px;
  padding: 0 28px;
  cursor: pointer;
  transition: transform 120ms ease;
}

.copy-btn:active { transform: scale(0.93); }

.add-friend {
  width: 100%;
  height: var(--add-h);
  border: 0;
  border-radius: var(--radius);
  background: var(--surface-variant);
  color: var(--on-surface);
  font-family: var(--brand);
  font-weight: 900;
  font-size: 21px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition: transform 120ms ease;
}

.add-friend:active { transform: scale(0.985); }

.add-icon {
  font-size: 26px;
  line-height: 1;
  font-weight: 900;
  display: inline-block;
  transition: transform 200ms ease;
}

.add-friend.open .add-icon { transform: rotate(45deg); }

#canvas {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--background);
}

.settings {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.style-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: var(--gutter);
}

.style-circle {
  width: 260px;
  height: 260px;
  max-width: 72vw;
  max-height: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--surface-variant);
  display: flex;
  overflow: hidden;
}

.style-foot {
  padding: 0 var(--gutter) 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.big-btn {
  flex: 1 1 0%;
  height: 66px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface-variant);
  color: var(--on-surface);
  font-family: var(--brand);
  font-weight: 900;
  font-size: 21px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition: transform 120ms ease;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

.big-btn:active { transform: scale(0.985); }

.btn-icon {
  font-size: 26px;
  line-height: 1;
}

.save-btn {
  flex: 0 1 0%;
  height: 66px;
  border: 0;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--on-primary);
  font-family: var(--brand);
  font-weight: 900;
  font-size: 21px;
  cursor: pointer;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

#nameInput {
  flex: 1;
  height: 66px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface-variant);
  color: var(--on-surface);
  font-family: var(--body);
  font-weight: 300;
  font-size: 20px;
  padding: 0 22px;
  outline: none;
  min-width: 0;
}

#nameInput::placeholder { color: var(--on-surface-variant); }

.thread {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.thread-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px var(--gutter) 10px;
  min-height: 67px;
}

.back-btn {
  position: absolute;
  left: var(--gutter);
  top: 8px;
  font-size: 30px;
  font-weight: 400;
  display: none;
}

.thread-title {
  font-family: var(--brand);
  font-weight: 900;
  font-size: 20px;
  max-width: calc(100% - 130px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.thread-loc {
  font-family: var(--body);
  font-weight: 400;
  font-size: 15px;
  color: var(--on-surface-variant);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px var(--gutter) 12px;
  display: flex;
  flex-direction: column;
}

.msg-row { display: flex; margin-top: 10px; }
.msg-row.own { justify-content: flex-end; }

.msg-avatar {
  width: 64px;
  height: 64px;
  min-width: 64px;
  font-size: 22px;
  margin-right: 8px;
}

.msg-col { max-width: 74%; display: flex; flex-direction: column; }
.msg-row.own .msg-col { align-items: flex-end; }

.msg-time {
  font-size: 11px;
  line-height: 14px;
  font-weight: 600;
  color: var(--on-surface-variant);
  margin: 0 0 2px 12px;
}

.bubble {
  padding: 8px 12px;
  font-size: 15px;
  line-height: 21px;
  overflow-wrap: anywhere;
}

.msg-row.own .bubble {
  background: var(--bubble-own);
  color: #fff;
  border-radius: 19px 19px 5px 19px;
}

.bubble code {
  font-family: ui-monospace, monospace;
  background: rgba(128, 128, 128, 0.15);
  border-radius: 4px;
  padding: 0 4px;
}

.msg-row.theirs .bubble {
  background: var(--bubble-other);
  color: var(--on-surface);
  border-radius: 5px 19px 19px 19px;
}

@media (prefers-color-scheme: dark) {
  .msg-row.own .bubble { color: #fff; }
}

.composer-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px var(--gutter) 14px;
}

.composer-pill {
  flex: 1 1 0%;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 66px;
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--radius);
  padding: 4px 9px 4px 14px;
  min-width: 0;
}

#composerInput {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--on-surface);
  font-family: var(--body);
  font-size: 15px;
  padding: 6px 0;
  min-width: 0;
}

#composerInput::placeholder { color: var(--on-surface-variant); opacity: 0.6; }

.mic-btn {
  width: 48px;
  height: 48px;
  min-width: 48px;
  border: 0;
  border-radius: 14px;
  background: var(--surface-variant);
  color: var(--on-surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 120ms ease;
}

.mic-btn:active { transform: scale(0.9); }
.mic-btn.rec { background: var(--record-red); color: #fff; }

.send-btn {
  flex: 0 1 0%;
  height: 66px;
  border: 0;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--on-primary);
  font-family: var(--brand);
  font-weight: 900;
  font-size: 21px;
  padding: 0 28px;
  cursor: pointer;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 70px;
  transform: translateX(-50%);
  background: var(--on-surface);
  color: var(--background);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 50;
}

@media (max-width: 800px) {
  #app {
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
  }
  #app::-webkit-scrollbar { display: none; }
  #sidebar, #canvas {
    min-width: 100%;
    width: 100%;
    scroll-snap-align: start;
    scroll-snap-stop: always;
  }
  #sidebar { border-right: 0; }
  .back-btn { display: flex; }
}
