@font-face {
  font-family: "Manrope";
  src: url("/static/fonts/manrope-variable.ttf") format("truetype");
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
}

@font-face {
  font-family: "Source Serif 4";
  src: url("/static/fonts/source-serif-4-variable.ttf") format("truetype");
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
}

:root {
  --ink: #14212b;
  --muted: #5b6b78;
  --line: #d5dee6;
  --panel: #f4f7fa;
  --paper: #eef3f7;
  --surface: #ffffff;
  --accent: #0f766e;
  --accent-ink: #083b38;
  --danger: #9f1239;
  --shadow: 0 18px 40px rgba(20, 33, 43, 0.08);
  --radius: 16px;
  --sans: "Manrope", "Segoe UI", sans-serif;
  --serif: "Source Serif 4", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  color: var(--ink);
  font-family: var(--sans);
  background:
    radial-gradient(900px 420px at 0% 0%, #dceeea 0%, transparent 55%),
    radial-gradient(800px 480px at 100% 100%, #d9e4f0 0%, transparent 50%),
    var(--paper);
}

.shell {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(300px, 360px) 1fr;
  gap: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.35rem 1.15rem 1.15rem;
  background: color-mix(in srgb, var(--panel) 82%, white);
  border-right: 1px solid var(--line);
  min-height: 0;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
}
.sidebar-head { display: none; }
.icon-button {
  width: 42px;
  height: 42px;
  display: none;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--accent-ink);
  cursor: pointer;
  font: inherit;
  font-size: 1.4rem;
  line-height: 1;
}
.icon-button:hover { border-color: var(--accent); color: var(--accent); }
.icon-button:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 45%, white); }

.sidebar-head { padding: 0 0.2rem; }
.new-chat {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.95rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.pair {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0.45rem;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.field select,
.field input,
.compose textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fbfcfd;
  color: var(--ink);
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
}

.field select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 12px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 2rem;
}

.field select:focus,
.field input:focus,
.compose textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, white);
  border-color: var(--accent);
}

.swap {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--accent-ink);
  font-size: 1.05rem;
  cursor: pointer;
  margin-bottom: 1px;
}
.swap:hover { border-color: var(--accent); color: var(--accent); }

.primary,
.ghost {
  border: 0;
  border-radius: 12px;
  padding: 0.8rem 1rem;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}
.primary {
  background: var(--accent);
  color: white;
}
.primary:hover { filter: brightness(1.05); }
.primary:disabled { opacity: 0.55; cursor: wait; }
.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
}
.ghost.danger:hover {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, white);
}

.list-label {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 0.2rem;
}

.chat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-height: 0;
  flex: 1;
}

.chat-card {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 14px;
  overflow: hidden;
}
.chat-card:hover,
.chat-card.active {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  box-shadow: inset 3px 0 0 var(--accent);
}
.chat-list .chat-select {
  flex: 1;
  min-width: 0;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0.85rem 0.9rem;
  cursor: pointer;
  font: inherit;
}
.chat-list .chat-select:hover,
.chat-list .chat-select:focus-visible {
  outline: none;
}
.chat-delete {
  align-self: center;
  flex: 0 0 auto;
  margin: 0 0.45rem 0 0;
  padding: 0.45rem 0.55rem;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 750;
}
.chat-delete:hover,
.chat-delete:focus-visible {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, white);
  outline: none;
}
.chat-list .title {
  font-weight: 750;
  font-size: 0.98rem;
}
.chat-list .meta {
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.main {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.chat-view {
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-rows: 1fr auto;
}
.chat-view[hidden],
#no-chat[hidden] {
  display: none !important;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, white 70%, transparent);
  backdrop-filter: blur(8px);
}
@media (min-width: 861px) {
  .top { display: none; }
  .main { grid-template-rows: minmax(0, 1fr); }
}

.messages {
  overflow: auto;
  padding: 1.35rem 1.5rem 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: stretch;
  min-height: 0;
}

.empty {
  margin: auto;
  max-width: 420px;
  padding: 1.4rem 1.5rem;
  border: 1px dashed var(--line);
  border-radius: 18px;
  background: color-mix(in srgb, white 75%, transparent);
  color: var(--muted);
  flex: 0 0 auto;
}
.empty strong {
  display: block;
  color: var(--ink);
  font-size: 1.05rem;
  margin-bottom: 0.7rem;
}
.empty ol {
  margin: 0;
  padding-left: 1.15rem;
  line-height: 1.55;
  font-weight: 600;
}

.turn {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  flex: 0 0 auto;
  min-height: auto;
}
.turn-grid {
  display: grid;
  grid-template-columns: 1fr;
  align-items: start;
}
@media (min-width: 980px) {
  .turn-grid.dual { grid-template-columns: 1fr 1fr; }
}
.turn-block {
  padding: 1rem 1.1rem 1.15rem;
  min-width: 0;
}
.turn-block + .turn-block {
  border-top: 1px solid var(--line);
}
@media (min-width: 980px) {
  .turn-grid.dual .turn-block + .turn-block {
    border-top: 0;
    border-left: 1px solid var(--line);
  }
}
.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.55rem;
  flex: 0 0 auto;
}
.block-head h3,
.block-label {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 800;
}
.turn-block .body,
.source-body {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--ink);
  font-weight: 400;
  overflow-wrap: anywhere;
  min-height: 1.55em;
}
.source-body {
  font-size: 1rem;
  font-weight: 600;
}
.turn-source {
  padding: 0.85rem 1.1rem 1rem;
  background: #f7fafc;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.copy-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}
.copy-btn:hover {
  color: var(--accent-ink);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
}
.copy-btn.copied {
  color: var(--accent);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, white);
}
.copy-btn:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, white);
}

.compose {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem 1.5rem 1.25rem;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, white 88%, var(--panel));
}
.compose[hidden] {
  display: none !important;
}
.compose-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.compose-style {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.compose-style select {
  min-width: 13.5rem;
  border: 1px solid var(--line);
  background: #fbfcfd;
  color: var(--ink);
  border-radius: 10px;
  padding: 0.45rem 1.8rem 0.45rem 0.7rem;
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0;
  text-transform: none;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 16px) calc(50% - 2px),
    calc(100% - 10px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
.compose-style select:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, white);
  border-color: var(--accent);
}
.compose textarea {
  min-height: 120px;
  resize: vertical;
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 400;
  line-height: 1.5;
}
.compose-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.compose-hint {
  color: var(--muted, #64748b);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.3;
}

.error {
  color: #9f1239;
  background: #fff1f2;
  border: 1px solid #fecdd3;
  border-radius: 14px;
  padding: 0.9rem 1rem;
  font-weight: 650;
}

@media (max-width: 860px) {
  html, body, .shell { min-height: 100%; height: auto; }
  .shell { display: block; }
  .main { min-height: 100dvh; }
  .sidebar {
    position: fixed;
    z-index: 20;
    inset: 0 auto 0 0;
    width: min(88vw, 360px);
    height: 100dvh;
    min-height: 0;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    box-shadow: 18px 0 40px rgba(20, 33, 43, 0.16);
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar-head { display: flex; }
  .sidebar-backdrop {
    position: fixed;
    z-index: 10;
    inset: 0;
    background: rgba(20, 33, 43, 0.4);
    backdrop-filter: blur(2px);
  }
  .sidebar-backdrop[hidden] { display: none; }
  .icon-button { display: inline-flex; }
  .menu-button { font-size: 1.25rem; }
  .pair { grid-template-columns: 1fr; }
  .swap { width: 100%; border-radius: 12px; }
  .compose-actions { flex-direction: column; align-items: stretch; }
  .compose-hint { display: none; }
  .compose-style { margin-left: 0; width: 100%; }
  .compose-style select { width: 100%; min-width: 0; }
  .top { padding: 0.7rem 1rem; }
  .messages { padding: 1rem; }
  .compose { padding: 0.9rem 1rem calc(1rem + env(safe-area-inset-bottom)); }
  .compose textarea { min-height: 132px; }
  .turn-block, .turn-source { padding-left: 0.9rem; padding-right: 0.9rem; }
}
