:root {
  --paper: #f4f0e8;
  --ink: #20201d;
  --muted: #706a5f;
  --line: #d8d0c0;
  --panel: #fffaf0;
  --accent: #b88b2d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  width: 100vw;
  height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: "Aptos", "Segoe UI", sans-serif;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.tetraShell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.tetraTopbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #ebe4d7;
  min-width: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-family: Georgia, serif;
  font-size: 21px;
}

h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0;
  color: var(--muted);
}

#status {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.tetraControls {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

select,
input,
button,
.linkButton {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  padding: 7px 10px;
}

select {
  max-width: 300px;
}

input {
  width: 220px;
}

button,
.linkButton {
  cursor: pointer;
  text-decoration: none;
}

button:hover,
.linkButton:hover {
  border-color: var(--accent);
}

.tetraWorkspace {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(460px, 34vw, 620px);
  overflow: hidden;
}

.canvasWrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: #171713;
}

#graph-canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #171713;
}

.canvasNotice {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #f4f0e8;
  text-align: center;
  background: #171713;
}

.canvasNotice.is-hidden {
  display: none;
}

.tetraPanel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) 190px 170px 92px;
  gap: 1px;
  border-left: 1px solid var(--line);
  background: var(--line);
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.tetraPanel section {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
  padding: 14px;
  background: var(--panel);
}

.sectionHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.smallButton {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
}

.tetraPanel .diagnosticsSection {
  grid-template-rows: auto minmax(0, 1fr);
}

.tetraPanel .chatSection {
  grid-template-rows: auto minmax(0, 1fr) minmax(76px, auto) auto;
  gap: 12px;
}

.selectedSection,
.algorithmSection,
.diagnosticsSection {
  font-size: 12px;
}

pre {
  margin: 0;
  min-height: 0;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font: 12px/1.45 "SFMono-Regular", Consolas, monospace;
  color: #403b33;
}

.algoButtons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.chatLog {
  min-height: 0;
  max-height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
}

.chatHint,
.chatMessage {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f1e3;
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.chatMessage.user {
  background: #efe4cc;
  align-self: flex-end;
  max-width: 88%;
}

.chatMessage.tool {
  font-family: "SFMono-Regular", Consolas, monospace;
  color: #51483a;
  background: #f5eddd;
  font-size: 12px;
  white-space: normal;
}

.chatMessage.agent {
  background: #fffaf0;
  max-width: 96%;
}

.toolTrace {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f5eddd;
  color: #51483a;
  font: 12px/1.45 "SFMono-Regular", Consolas, monospace;
}

.toolTrace summary {
  cursor: pointer;
  padding: 8px 10px;
  color: var(--muted);
}

.toolTrace pre {
  max-height: 220px;
  border-top: 1px solid var(--line);
  padding: 10px;
}

.citationTray {
  min-height: 76px;
  max-height: 150px;
  overflow: auto;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 7px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f1e3;
}

.citationEmpty {
  color: var(--muted);
  font-size: 12px;
}

.citationChip {
  max-width: 100%;
  border: 1px solid #c8b995;
  border-radius: 6px;
  background: #fffaf0;
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.35;
}

.citationChip strong {
  display: block;
  color: var(--ink);
  font-weight: 650;
}

.citationChip span {
  color: var(--muted);
}

.chatForm {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  min-height: 0;
}

textarea {
  width: 100%;
  min-height: 42px;
  resize: none;
  max-height: 92px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  padding: 8px 10px;
  font: inherit;
}

@media (max-width: 900px) {
  .tetraTopbar,
  .tetraControls {
    align-items: stretch;
    flex-direction: column;
  }

  .tetraControls,
  select,
  input {
    width: 100%;
    max-width: none;
  }

  .tetraWorkspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) minmax(420px, 46vh);
  }

  .tetraPanel {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: minmax(0, 1fr) 130px 92px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .tetraPanel .chatSection,
  .tetraPanel .diagnosticsSection {
    grid-column: 1 / -1;
  }

  .tetraPanel .chatSection {
    grid-row: 1;
  }
}
