.app {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: min(100vw, 820px);
  height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
}

body.has-session-background {
  background:
    linear-gradient(rgba(248, 246, 241, 0.72), rgba(248, 246, 241, 0.72)),
    var(--session-bg-image) center / cover fixed,
    var(--bg);
}

body.has-session-background .app,
body.has-session-background .messages,
body.has-session-background .roundtable-workspace {
  background:
    linear-gradient(rgba(255, 253, 250, 0.82), rgba(255, 253, 250, 0.82)),
    var(--session-bg-image) center / cover fixed,
    var(--bg);
}

.topbar {
  z-index: 5;
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 54px;
  padding: max(env(safe-area-inset-top), 7px) 10px 7px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 250, 0.94);
  backdrop-filter: blur(18px);
  transition:
    background-color var(--motion-soft),
    border-color var(--motion-soft),
    box-shadow var(--motion-soft);
}

.topbar h1 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 21px;
  font-weight: 500;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  gap: 6px;
}

.source-link {
  display: inline-grid;
  place-items: center;
  min-width: 74px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(36, 36, 36, 0.12);
  border-radius: 999px;
  color: #1f2933;
  background: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}

.source-link:hover,
.source-link:focus-visible {
  background: rgba(32, 33, 36, 0.06);
}

.article-link {
  border-color: rgba(141, 107, 49, 0.28);
  color: #5f4520;
  background: #fff7e6;
}

.icon-button,
.round-button {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #242424;
  font-size: 21px;
  transform-origin: center;
}

.icon-button:hover,
.round-button:hover,
.icon-button:focus-visible,
.round-button:focus-visible {
  background: rgba(32, 33, 36, 0.06);
}

.icon-button:active,
.round-button:active {
  scale: 0.94;
}

.roundtable-entry {
  position: relative;
  border: 1px solid #d8c8a9;
  color: #2f2b24;
  background: #fff7e6;
  font-size: 16px;
  font-weight: 700;
}

.composer .round-button {
  width: var(--tool-button-size);
  height: var(--tool-button-size);
  font-size: 15px;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 12px var(--message-side-padding) calc(var(--composer-height) + 12px);
  background: var(--bg);
  scroll-behavior: smooth;
}

.messages:not([hidden]) {
  animation: workspace-enter 180ms ease-out both;
}

.roundtable-workspace {
  min-height: 0;
  overflow-y: auto;
  padding: 10px 10px calc(var(--composer-height) + 92px);
  background: var(--bg);
  scroll-behavior: smooth;
}

.roundtable-workspace:not([hidden]) {
  animation: workspace-enter 220ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.roundtable-mode .topbar {
  border-bottom-color: var(--line);
  background: rgba(248, 246, 241, 0.95);
  box-shadow: 0 8px 28px rgba(45, 40, 33, 0.035);
}

.roundtable-mode .roundtable-entry {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
  box-shadow: 0 10px 24px rgba(32, 32, 32, 0.14);
  animation: roundtable-entry-awake 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.roundtable-mode .composer {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.composer-focused .composer {
  border-color: rgba(34, 34, 34, 0.16);
  box-shadow:
    0 14px 34px rgba(31, 28, 23, 0.11),
    0 0 0 4px rgba(34, 34, 34, 0.035);
}

@keyframes workspace-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes roundtable-entry-awake {
  0% {
    scale: 0.82;
    rotate: -8deg;
  }

  62% {
    scale: 1.07;
    rotate: 2deg;
  }

  100% {
    scale: 1;
    rotate: 0deg;
  }
}

.message-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 8px 0 var(--message-gap);
  animation: message-arrive 240ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.message-row.user {
  align-items: flex-end;
}

.message-row.assistant {
  align-items: flex-start;
  padding-left: var(--assistant-left);
}

@keyframes message-arrive {
  from {
    opacity: 0;
    transform: translateY(5px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}
