:root {
  color-scheme: light dark;
  --background: #f7f6f2;
  --surface: #ffffff;
  --surface-soft: #eeeee7;
  --text: #252d29;
  --muted: #59655e;
  --border: #cbd2ca;
  --accent: #315e4b;
  --accent-text: #ffffff;
  --user-bubble: #e1ecdf;
  --persona-bubble: #ffffff;
  --banner: #f4ebcf;
  --danger: #953b37;
  --focus: #326baf;
  --sonnet: #446f83;
  --haiku: #aa7043;
  --grid: #dce1da;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
  background: var(--background);
  color: var(--text);
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #191f1c;
    --surface: #232b26;
    --surface-soft: #2d3730;
    --text: #e8ece6;
    --muted: #b4beb5;
    --border: #48574b;
    --accent: #b0cfb8;
    --accent-text: #17251c;
    --user-bubble: #344d3a;
    --persona-bubble: #252f29;
    --banner: #413b28;
    --danger: #f0a49e;
    --focus: #98c5fa;
    --sonnet: #8dbbd0;
    --haiku: #e1ae7c;
    --grid: #3b473e;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 0;
}

.shell {
  width: 100%;
  max-width: 792px;
  margin-inline: auto;
  padding-inline: 16px;
}

.app-header {
  padding-top: 20px;
  padding-bottom: 16px;
}

.app-header h1 {
  margin: 0 0 12px;
  font-size: 1.55rem;
  letter-spacing: -0.035em;
}

main {
  padding-top: 8px;
  padding-bottom: 48px;
}

section,
form,
fieldset,
.card,
.stack,
.field {
  min-width: 0;
}

h2,
h3,
p {
  overflow-wrap: anywhere;
}

h2 {
  margin: 0 0 16px;
  font-size: 1.4rem;
  line-height: 1.3;
}

h3 {
  margin: 0 0 12px;
  font-size: 1.08rem;
}

p {
  margin: 0 0 12px;
}

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

button,
input,
select,
textarea,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  min-height: 44px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  line-height: 1.3;
  white-space: normal;
  overflow-wrap: anywhere;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--surface-soft);
}

button:disabled {
  opacity: 0.6;
  cursor: wait;
}

button.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

button.primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

button.danger {
  color: var(--danger);
}

button.small {
  padding: 6px 11px;
  font-size: 0.85rem;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 104px;
}

input[type="checkbox"],
input[type="radio"] {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 1;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 100%;
}

.tabs button {
  flex: 0 1 auto;
}

.tabs button[aria-selected="true"],
.tabs button[aria-selected="true"]:hover {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
}

.field > span {
  font-weight: 600;
}

.row,
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.row > *,
.actions > * {
  min-width: 0;
}

.card,
fieldset {
  margin: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface);
}

fieldset legend {
  padding-inline: 6px;
  font-weight: 600;
}

.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding-block: 8px;
}

.choice span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.choice small {
  display: block;
  color: var(--muted);
}

.muted,
.empty,
.date {
  color: var(--muted);
}

.empty {
  padding-block: 16px;
}

.banner {
  width: calc(100% - 32px);
  max-width: 760px;
  margin-bottom: 16px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--banner);
  overflow-wrap: anywhere;
}

.chat-history {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 180px;
  max-height: 58vh;
  max-height: 58dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 4px 16px;
  margin-bottom: 12px;
}

.bubble {
  width: fit-content;
  max-width: 90%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--persona-bubble);
  overflow-wrap: anywhere;
}

.bubble.user {
  margin-inline-start: auto;
  background: var(--user-bubble);
}

.bubble.assistant {
  margin-inline-end: auto;
}

.bubble-label {
  margin-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 650;
  color: var(--muted);
}

.bubble-text,
.saved-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble .actions {
  margin-top: 10px;
}

.thinking .bubble-text {
  color: var(--muted);
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.composer .actions {
  justify-content: flex-end;
}

.composer textarea {
  min-height: 100px;
}

.goal-title {
  flex: 1;
  font-weight: 600;
}

.goal-meta {
  margin-block: 8px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

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

.moods button {
  flex: 1 1 44px;
}

.moods [aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.date {
  display: block;
  margin-bottom: 8px;
  font-size: 0.85rem;
}

details {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding: 12px 16px;
}

summary {
  min-height: 44px;
  display: list-item;
  align-content: center;
  cursor: pointer;
  font-weight: 600;
}

details[open] > summary {
  margin-bottom: 12px;
}

.file-input {
  max-width: 100%;
}

.spend-total {
  font-size: 1.15rem;
  font-weight: 600;
}

.spend-chart {
  display: block;
  width: 100%;
  height: auto;
  overflow: hidden;
}

.chart-label {
  fill: var(--muted);
  font-family: inherit;
  font-size: 12px;
}

.chart-grid {
  stroke: var(--grid);
  stroke-width: 1;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-block: 8px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
}

.swatch.sonnet {
  background: var(--sonnet);
}

.swatch.haiku {
  background: var(--haiku);
}

dialog {
  width: calc(100% - 32px);
  max-width: 620px;
  max-height: 90vh;
  max-height: 90dvh;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  overflow-y: auto;
}

dialog::backdrop {
  background: rgb(0 0 0 / 48%);
}

dialog ul {
  padding-inline-start: 22px;
}

dialog li + li {
  margin-top: 12px;
}

.message-preview {
  min-height: 180px;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 16px;
  z-index: 10;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

@media (min-width: 640px) {
  .app-header {
    padding-top: 32px;
  }

  .bubble {
    max-width: 82%;
  }

  .card {
    padding: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}

