:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17212b;
  --muted: #687583;
  --line: #d8e0e8;
  --user: #0f766e;
  --user-bubble: #d8f7f1;
  --assistant: #385089;
  --assistant-bubble: #eef2ff;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --shadow: 0 18px 50px rgba(28, 41, 61, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  padding: 0.7rem 0.9rem;
}

button:hover {
  border-color: #a9b7c7;
}

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

button.primary:hover {
  background: var(--accent-dark);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 1rem;
  min-height: 100vh;
  max-width: 1460px;
  margin: 0 auto;
  padding: 1rem;
}

.chat-panel,
.controls {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) minmax(180px, 26vh);
  min-width: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  padding: 1rem;
}

.eyebrow {
  margin: 0 0 0.2rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 1.35rem;
}

.file-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  min-width: 142px;
  padding: 0.7rem 0.9rem;
}

.file-picker input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  overflow-y: auto;
  padding: 1.1rem;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: min(760px, 88%);
}

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

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

.speaker {
  margin: 0 0 0.25rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.bubble {
  border-radius: 8px;
  padding: 0.85rem 1rem;
  line-height: 1.48;
  overflow-wrap: anywhere;
}

.user .bubble {
  background: var(--user-bubble);
  border: 1px solid rgba(15, 118, 110, 0.22);
}

.assistant .bubble {
  background: var(--assistant-bubble);
  border: 1px solid rgba(56, 80, 137, 0.2);
}

.system .bubble {
  background: #f5f7fa;
  border: 1px solid var(--line);
}

.message.current .bubble {
  outline: 3px solid rgba(37, 99, 235, 0.25);
}

.bubble > :first-child {
  margin-top: 0;
}

.bubble > :last-child {
  margin-bottom: 0;
}

.bubble pre {
  overflow-x: auto;
  border-radius: 8px;
  background: #111827;
  color: #eef2ff;
  padding: 0.8rem;
}

.bubble code {
  border-radius: 5px;
  background: rgba(17, 24, 39, 0.08);
  padding: 0.12rem 0.28rem;
}

.bubble pre code {
  background: transparent;
  padding: 0;
}

.composer {
  border-top: 1px solid var(--line);
  background: #fbfcfe;
  padding: 0.85rem;
}

.composer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.composer label,
.control-block label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

textarea {
  width: 100%;
  height: calc(100% - 3rem);
  min-height: 110px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  padding: 0.75rem;
  line-height: 1.45;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: sticky;
  top: 1rem;
  align-self: start;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  padding: 1rem;
}

.status-card,
.metrics {
  display: grid;
  gap: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 0.9rem;
}

.status-card {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.state {
  border-radius: 999px;
  background: #e9eef5;
  color: #405064;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.28rem 0.6rem;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.control-block {
  display: grid;
  gap: 0.7rem;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
  padding: 0;
}

.speed-block {
  justify-items: center;
}

.speed-block label {
  justify-self: start;
}

.speed-knob {
  --angle: 0deg;
  --fill: 50%;
  position: relative;
  display: grid;
  place-items: center;
  width: 154px;
  height: 154px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background:
    radial-gradient(circle at center, #fff 0 57%, transparent 58%),
    conic-gradient(from 225deg, var(--accent) 0 var(--fill), #e8edf4 0 75%, transparent 0);
  box-shadow: inset 0 2px 8px rgba(28, 41, 61, 0.12);
  cursor: grab;
  user-select: none;
}

.speed-knob:active {
  cursor: grabbing;
}

.speed-knob:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.32);
  outline-offset: 4px;
}

.speed-knob strong {
  font-size: 1.55rem;
  line-height: 1;
}

.speed-knob small {
  margin-top: 2.2rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  position: absolute;
}

.dial-pointer {
  position: absolute;
  inset: 16px;
  transform: rotate(var(--angle));
}

.dial-pointer::before {
  position: absolute;
  top: 0;
  left: calc(50% - 3px);
  width: 6px;
  height: 43px;
  border-radius: 999px;
  background: var(--accent);
  content: "";
}

.dial-range {
  width: 154px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.dial-range span:nth-child(2) {
  text-align: center;
}

.dial-range span:last-child {
  text-align: right;
}

.range-row,
.button-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
}

.button-row button {
  flex: 1;
}

.range-row {
  color: var(--muted);
  font-size: 0.82rem;
}

.range-row strong {
  color: var(--ink);
}

.note {
  margin: auto 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

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

  .chat-panel {
    min-height: 72vh;
  }

  .controls {
    position: sticky;
    top: auto;
    bottom: 0;
    z-index: 2;
    max-height: none;
    box-shadow: 0 -12px 30px rgba(28, 41, 61, 0.12);
  }
}

@media (min-width: 1180px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr) 315px;
    gap: 0.85rem;
  }

  .chat-panel {
    grid-template-rows: auto minmax(330px, 1fr) minmax(150px, 22vh);
  }

  .topbar,
  .controls {
    padding: 0.85rem;
  }

  .chat-log {
    gap: 0.65rem;
    padding: 0.85rem;
  }

  .bubble {
    padding: 0.68rem 0.82rem;
    line-height: 1.42;
  }

  .message {
    max-width: min(720px, 82%);
  }

  .composer {
    padding: 0.7rem;
  }

  textarea {
    min-height: 92px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 0;
  }

  .chat-panel,
  .controls {
    border-radius: 0;
    box-shadow: none;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .file-picker {
    width: 100%;
  }

  .message {
    max-width: 96%;
  }
}
