:root {
  color-scheme: dark;
  --bg: #0e1621;
  --panel: #17212b;
  --bubble: #182533;
  --accent: #2aabee;
  --accent-hover: #229ed9;
  --text: #f5f5f5;
  --muted: #8b98a5;
  --border: #242f3d;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body {
  min-height: 100dvh;
}

.app {
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.back-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--accent);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.back-btn:active {
  background: rgba(42, 171, 238, 0.12);
}

.hidden { display: none !important; }

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 12px calc(16px + var(--safe-bottom));
  gap: 12px;
}

.message {
  margin: 0;
  padding: 12px 14px;
  background: var(--bubble);
  border-radius: 12px 12px 12px 4px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.98rem;
}

.message.message--html {
  white-space: normal;
}

.message.message--html p {
  margin: 0 0 0.75em;
}

.message.message--html p:last-child {
  margin-bottom: 0;
}

.message.message--html ul,
.message.message--html ol {
  margin: 0.5em 0;
  padding-left: 1.4em;
}

.message.message--html code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: rgba(255, 255, 255, 0.08);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.message.message--html pre {
  margin: 0.75em 0;
  padding: 10px 12px;
  overflow-x: auto;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
}

.message.message--html pre code {
  padding: 0;
  background: transparent;
}

.message.message--html blockquote {
  margin: 0.75em 0;
  padding-left: 12px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

.message.message--html h1,
.message.message--html h2,
.message.message--html h3 {
  margin: 0.75em 0 0.35em;
  font-size: 1rem;
  line-height: 1.3;
}

.message.message--html h1 { font-size: 1.15rem; }
.message.message--html h2 { font-size: 1.08rem; }

.message a {
  color: #6ecbff;
  word-break: break-all;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.menu.hidden {
  display: none;
}

.message:empty {
  display: none;
}

.menu-btn {
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.menu-btn:active {
  background: #1f2c3a;
  border-color: var(--accent);
}

.menu-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.loading {
  color: var(--muted);
  padding: 8px 4px;
}

@media (min-width: 481px) {
  .app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.35);
  }
}
