:root {
  color-scheme: light dark;
  --paper: #f7f4ed;
  --ink: #313127;
  --muted: #646462;
  --rule: #dddacf;
  --green: #627753;
  --green-fill: #62775318;
  --gutter: 34px;
  --stop-size: 44px;
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.65;
  font-weight: 400;
  background: var(--paper);
  color: var(--ink);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1c1b18;
    --ink: #eeebdf;
    --muted: #a3a39c;
    --rule: #37362f;
    --green: #9cb589;
    --green-fill: #9cb58918;
  }
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
button { border: 0; border-radius: 0; background: transparent; padding: 0; text-align: left; cursor: pointer; }
button:hover { color: var(--green); }
button:disabled { cursor: default; opacity: .35; }
button:disabled:hover { color: inherit; }
button:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 5px;
}
h1, h2, p { margin: 0; }
h1, h2 { font-weight: 400; }
[hidden] { display: none !important; }
::selection { background: var(--green); color: var(--paper); }

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 73px;
  margin: 0 var(--gutter);
  padding: 8px 0;
  border-bottom: 1px solid var(--rule);
}
.brand {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  font-size: 17px;
  font-weight: 500;
  letter-spacing: .03em;
}
.brand-mark { display: block; width: 29px; height: 29px; flex-shrink: 0; }
.logo-outline { fill: none; stroke: currentColor; stroke-width: .65; opacity: .55; }
.logo-ring { fill: none; stroke: var(--rule); stroke-width: .45; }
.logo-axis { stroke: var(--rule); stroke-width: .45; }
.logo-profile { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; }
.brand-mark .logo-profile { fill: var(--green-fill); stroke: var(--green); stroke-width: 1.3; }

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.setup {
  width: 100%;
  max-width: 1120px;
  padding: 40px 50px 56px;
  margin: 0 auto;
}
.setup-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(290px, 1fr); gap: 60px; }
.mood-editor { min-width: 0; }
.mood-editor h1 { font-size: 23px; line-height: 1.4; }
.empty-history { color: var(--muted); font-size: 12px; }
.mood-controls { margin: 22px 0 24px; }
.graph-holder { display: block; width: 64px; flex-shrink: 0; pointer-events: none; }
.mood-graph { display: block; width: 100%; aspect-ratio: 1; }
.mood-graph * { vector-effect: non-scaling-stroke; }
.graph-ring { fill: none; stroke: var(--rule); stroke-width: 1; }
.graph-axis { stroke: var(--rule); stroke-width: 1; }
.graph-profile { fill: var(--green-fill); stroke: var(--green); stroke-width: 1.6; stroke-linejoin: round; }
.control-list { max-width: 460px; margin: 0 auto; }
.control-row { display: flex; align-items: center; justify-content: space-between; min-height: 44px; gap: 12px; flex-wrap: wrap; }
.emotion { font-size: 12px; }
.mood-stops { display: flex; align-items: center; gap: 3px; flex-shrink: 0; position: relative; }
.mood-stops::before {
  content: '';
  position: absolute;
  left: calc(var(--stop-size) / 2);
  right: calc(var(--stop-size) / 2);
  height: 1px;
  background: var(--rule);
  pointer-events: none;
}
.mood-stop { display: flex; align-items: center; justify-content: center; width: var(--stop-size); height: 44px; position: relative; cursor: pointer; }
.mood-stop input {
  appearance: none;
  -webkit-appearance: none;
  width: 9px;
  height: 9px;
  display: block;
  margin: 0;
  background: var(--paper);
  border: 1px solid var(--muted);
  border-radius: 50%;
  position: relative;
  cursor: pointer;
}
.mood-stop input:checked { background: var(--green); border-color: var(--green); box-shadow: 0 0 0 3px var(--paper), 0 0 0 4px var(--green); }
.mood-stop:hover input { border-color: var(--green); }
.mood-stop input:focus-visible { outline: 2px solid var(--green); outline-offset: 7px; }
.start-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  max-width: 460px;
  min-height: 44px;
  margin: 0 auto;
  padding: 12px 16px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
}
.start-chat:hover { border-color: var(--green); background: var(--green-fill); color: var(--ink); }
.start-chat:focus-visible { outline-offset: 4px; }
.start-chat-label { font-size: 14px; line-height: 1.5; white-space: nowrap; }
.start-chat-name { font-size: 17px; font-weight: 500; letter-spacing: .03em; white-space: nowrap; }
.history h2 { font-size: 13px; font-weight: 700; color: var(--ink); }
.history { padding-top: 2px; min-width: 0; }
.history h2 { margin-bottom: 20px; }
.history-list { display: flex; flex-direction: column; }
.history-item { display: block; width: 100%; padding: 18px 0; border-top: 1px solid var(--rule); }
.history-title { display: block; overflow-wrap: anywhere; line-height: 1.5; }
.history-meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 6px; font-size: 11px; color: var(--muted); }
.mini-profile { display: block; width: 22px; height: 22px; flex-shrink: 0; }

@media (min-width: 701px) {
  .history-list {
    max-height: 425px;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--rule) transparent;
  }
  .history-item { flex-shrink: 0; }
  .history-item:focus-visible { outline-offset: -2px; }
}

.chat-view {
  display: flex;
  flex: 1;
  flex-direction: column;
  width: 100%;
  max-width: 790px;
  min-width: 0;
  margin: 0 auto;
  padding: 43px 50px 30px;
}
.chat-title { min-width: 0; margin-left: auto; font-size: 13px; font-weight: 700; text-align: right; overflow-wrap: anywhere; }
.transcript { display: flex; flex-direction: column; flex: 1; gap: 28px; min-width: 0; }
.reply-status { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; min-height: 22px; margin-top: 24px; color: var(--muted); font-size: 11px; }
.retry-button { min-height: 32px; color: var(--green); text-decoration: underline; text-underline-offset: 3px; }
.message-note { display: block; margin-top: 7px; color: var(--muted); font-size: 11px; }
.message { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 10px; }
.speaker { font-size: 11px; color: var(--muted); padding-top: 3px; }
.message-text { line-height: 1.9; overflow-wrap: anywhere; white-space: pre-wrap; }
.composer {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-top: 10px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--ink) 28%, var(--paper));
  border-radius: 18px;
  background: var(--green-fill);
  box-shadow: 0 2px 8px #00000008;
}
.composer:focus-within { border-color: var(--green); box-shadow: 0 0 0 2px var(--green-fill); }
.composer textarea {
  display: block;
  min-width: 0;
  width: 100%;
  min-height: 44px;
  max-height: 180px;
  padding: 10px 2px;
  border: 0;
  border-radius: 0;
  background: transparent;
  resize: none;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.65;
}
.composer textarea::placeholder { color: var(--muted); opacity: 1; }
.composer textarea:focus { outline: none; }
.composer textarea:disabled { opacity: .5; }
.send-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--green);
  color: var(--paper);
}
.send-button:hover:not(:disabled) { background: var(--ink); color: var(--paper); }
.send-button:disabled, .send-button:disabled:hover { background: var(--rule); color: var(--muted); opacity: 1; }
.send-button:focus-visible { outline-offset: 3px; }
.send-button svg { display: block; width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 900px) {
  .setup { padding: 36px 30px 48px; }
  .setup-layout { gap: 40px; grid-template-columns: minmax(0, 1fr) minmax(250px, 1fr); }
}

@media (max-width: 700px) {
  :root { --gutter: 20px; --stop-size: 44px; font-size: 12px; }
  .topbar { min-height: 63px; }
  .setup { padding: 27px 20px 40px; }
  .setup-layout { grid-template-columns: 1fr; gap: 39px; }
  .mood-editor h1 { font-size: 22px; }
  .mood-controls { margin: 18px 0 22px; }
  .start-chat { gap: 12px; }
  .graph-holder { width: 56px; }
  .control-row { min-height: 44px; gap: 0; flex-wrap: wrap; }
  .mood-stops { gap: 0; }
  .mood-stop { height: 44px; }
  .history h2 { margin-bottom: 8px; }
  .history-item { padding: 13px 0; min-height: 44px; }
  .chat-view { padding: 30px 20px max(20px, env(safe-area-inset-bottom)); }
  .message { grid-template-columns: 1fr; gap: 4px; }
  .speaker { padding: 0; }
  .message-text { font-size: 13px; }
  .composer textarea { font-size: 16px; }
}

@media (pointer: coarse) {
  :root { --stop-size: 44px; }
  .mood-stops { gap: 0; }
  .mood-stop { height: 44px; }
  .control-row { min-height: 44px; flex-wrap: wrap; }
}

@media (max-width: 359px) {
  .start-chat { padding-inline: 12px; }
  .emotion { width: 100%; }
  .control-row { margin-bottom: 7px; }
  .mood-stops { margin-left: auto; }
}
