:root {
  color-scheme: dark;
  --bg: #10141b;
  --surface: #171c24;
  --surface-high: #202630;
  --surface-higher: #29313c;
  --text: #edf1f8;
  --muted: #aeb7c5;
  --outline: #3f4855;
  --primary: #9fc9ff;
  --on-primary: #09233f;
  --primary-container: #294b6d;
  --secondary-container: #314756;
  --danger: #ffb4ab;
  --radius: 20px;
  font-family: "Roboto", "Noto Sans JP", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

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

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 360px;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
}

.rail,
.settings-panel {
  background: var(--surface);
  border-color: var(--outline);
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  border-right: 1px solid var(--outline);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.brand img {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: #fff;
}

.brand div,
.topbar-title,
.panel-header div {
  display: grid;
  gap: 2px;
}

.brand span,
.topbar-title span,
.panel-header span,
.helper-text,
.rate-limit {
  color: var(--muted);
  font-size: 12px;
}

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

.persona-list {
  display: grid;
  gap: 6px;
  overflow: auto;
  padding-bottom: 12px;
}

.persona-item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  padding: 10px;
  border-radius: 16px;
  color: var(--text);
  background: transparent;
  text-align: left;
}

.persona-item:hover,
.persona-item.active {
  background: var(--surface-high);
}

.avatar {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary-container);
  color: var(--primary);
  font-weight: 700;
}

.persona-copy {
  min-width: 0;
}

.persona-copy strong,
.persona-copy span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.persona-copy span {
  color: var(--muted);
  font-size: 13px;
}

.chat-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: max(14px, env(safe-area-inset-top)) 18px 12px;
  background: rgba(16, 20, 27, 0.92);
  border-bottom: 1px solid var(--outline);
  backdrop-filter: blur(16px);
}

.topbar-title {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.topbar-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
  padding: 20px min(5vw, 54px);
}

.empty-state {
  display: grid;
  gap: 12px;
  max-width: 560px;
  margin-top: 24px;
}

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

.suggestions button,
.tonal-button,
.model-chip {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface-high);
  color: var(--text);
}

.message {
  display: grid;
  gap: 4px;
  max-width: min(72ch, 82%);
}

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
}

.message-label {
  padding: 0 4px;
  color: var(--muted);
  font-size: 12px;
}

.bubble {
  white-space: pre-wrap;
  line-height: 1.62;
  padding: 12px 15px;
  border-radius: 20px;
  background: var(--surface-high);
}

.message.user .bubble {
  background: var(--primary);
  color: var(--on-primary);
}

.message.system .bubble {
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--outline);
}

.composer {
  padding: 10px 14px max(12px, env(safe-area-inset-bottom));
  background: var(--surface-high);
  border-top-left-radius: 28px;
  border-top-right-radius: 28px;
  box-shadow: 0 -12px 32px rgba(0, 0, 0, 0.18);
}

.composer-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto 48px;
  gap: 8px;
  align-items: end;
}

.composer textarea {
  min-height: 44px;
  max-height: 180px;
  resize: none;
  border: 0;
  outline: 0;
  border-radius: 18px;
  padding: 12px 4px;
  background: transparent;
  color: var(--text);
}

.attachment-strip {
  display: flex;
  gap: 8px;
  overflow: auto;
  margin-bottom: 6px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 240px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.icon-button,
.send-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
}

.icon-button:hover {
  background: var(--surface-high);
}

.icon-button span,
.send-icon,
.cloud-mark {
  display: block;
  position: relative;
}

#menuButton span,
#settingsButton span {
  width: 20px;
  height: 2px;
  background: currentColor;
  box-shadow: 0 7px 0 currentColor, 0 -7px 0 currentColor;
}

#settingsButton span {
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: 50%;
  background: transparent;
  box-shadow: none;
}

.send-button {
  position: relative;
  background: var(--primary);
  color: var(--on-primary);
}

.send-icon {
  width: 0;
  height: 0;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-left: 16px solid currentColor;
  transform: translateX(2px);
}

.send-loader {
  position: absolute;
  inset: 3px;
  display: none;
  border: 2px solid rgba(9, 35, 63, 0.25);
  border-top-color: var(--on-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.send-button.loading .send-icon {
  opacity: 0;
}

.send-button.loading .send-loader {
  display: block;
}

.cloud-mark {
  width: 18px;
  height: 12px;
  border-radius: 999px;
  background: currentColor;
}

.cloud-mark::before,
.cloud-mark::after {
  content: "";
  position: absolute;
  bottom: 4px;
  border-radius: 50%;
  background: currentColor;
}

.cloud-mark::before {
  left: 2px;
  width: 9px;
  height: 9px;
}

.cloud-mark::after {
  right: 2px;
  width: 11px;
  height: 11px;
}

.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 190px;
}

.model-chip span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-panel {
  overflow: auto;
  padding: 18px;
  border-left: 1px solid var(--outline);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.settings-section {
  display: grid;
  gap: 12px;
  padding: 14px 0;
  border-top: 1px solid var(--outline);
}

.settings-section h2 {
  margin: 0;
  font-size: 15px;
}

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

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--outline);
  border-radius: 14px;
  outline: 0;
  padding: 11px 12px;
  background: var(--surface-high);
  color: var(--text);
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
}

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

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: 18px;
  background: var(--surface-high);
}

.segmented button {
  min-height: 38px;
  border-radius: 14px;
  color: var(--muted);
  background: transparent;
}

.segmented button.active {
  color: var(--text);
  background: var(--surface-higher);
}

.filled-button {
  min-height: 44px;
  border-radius: 999px;
  color: var(--on-primary);
  background: var(--primary);
}

.check-row {
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: center;
}

.check-row input {
  width: 18px;
  height: 18px;
}

.rate-limit {
  margin: 0;
}

.sheet-backdrop,
.mobile-sheet {
  display: none;
}

.only-mobile {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

  .rail {
    display: none;
  }

  .settings-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    width: min(420px, 92vw);
    transform: translateX(100%);
    transition: transform 180ms ease;
  }

  .settings-panel.open {
    transform: translateX(0);
  }

  .only-mobile {
    display: grid;
  }

  .sheet-backdrop.open,
  .mobile-sheet.open {
    display: block;
  }

  .sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(0, 0, 0, 0.42);
  }

  .mobile-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    max-height: 72vh;
    overflow: auto;
    padding: 16px;
    border-top-left-radius: 28px;
    border-top-right-radius: 28px;
    background: var(--surface);
  }
}

@media (max-width: 700px) {
  .topbar {
    min-height: 64px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .messages {
    padding: 14px 12px;
  }

  .message {
    max-width: 92%;
  }

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

  .model-chip {
    grid-column: 2 / 4;
    justify-content: center;
    max-width: none;
    min-height: 36px;
  }
}
