:root {
  --bg: #f2ecdf;
  --panel: rgba(255, 251, 245, 0.95);
  --line: rgba(69, 57, 42, 0.16);
  --ink: #211d16;
  --muted: #6d6558;
  --accent: #87512d;
  --accent-soft: rgba(135, 81, 45, 0.1);
  --ok: #365f47;
  --warn: #8d4035;
  --shadow: 0 18px 48px rgba(41, 27, 11, 0.1);
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(135, 81, 45, 0.16), transparent 24%),
    radial-gradient(circle at bottom right, rgba(54, 95, 71, 0.14), transparent 22%),
    linear-gradient(180deg, #fbf6ed 0%, #eee1cf 100%);
}

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

button {
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: #fffaf4;
  padding: 12px 18px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.secondary {
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
  border: 1px solid var(--line);
}

textarea {
  width: 100%;
  min-height: 96px;
  resize: vertical;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  padding: 14px 16px;
}

input,
select {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  padding: 10px 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.hero,
.panel,
.source-drawer {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
  padding: 22px;
  border-radius: 24px;
}

.hero h1,
.panel h2,
.source-drawer h3 {
  margin: 0;
}

.hero-copy {
  max-width: 62ch;
  color: var(--muted);
  line-height: 1.5;
  margin: 10px 0 0;
}

.status-card {
  min-width: 220px;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  line-height: 1.45;
}

.top-nav {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 10px;
}

.top-nav a {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
  padding: 7px 11px;
  text-decoration: none;
  font-size: 0.84rem;
}

.climate-shell {
  background: #eef3f1;
}

.climate-topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 12px 4px 18px;
}

.climate-topbar h1 {
  margin: 0;
  font-size: 1.55rem;
}

.climate-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 16px;
  height: calc(100vh - 108px);
}

.map-panel {
  min-height: 560px;
  border: 1px solid var(--line);
  background: #dce7e3;
  overflow: hidden;
}

#climate-map {
  width: 100%;
  height: 100%;
}

.climate-controls {
  display: grid;
  gap: 14px;
  align-content: start;
  overflow: auto;
}

.compact-panel .tool-form {
  padding: 18px;
}

.climate-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.json-output {
  margin: 18px;
  max-height: 290px;
  overflow: auto;
  white-space: pre-wrap;
  font: 12px/1.45 Consolas, "Liberation Mono", monospace;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  padding: 12px;
}

.series-table {
  padding: 0 18px 18px;
  overflow: auto;
}

.series-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.series-table th,
.series-table td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 6px 4px;
}

.status-card.ready {
  border-color: rgba(54, 95, 71, 0.24);
  color: var(--ok);
}

.status-card.error {
  border-color: rgba(141, 64, 53, 0.24);
  color: var(--warn);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.95fr);
  gap: 18px;
  margin-top: 18px;
}

.tool-layout {
  display: grid;
  grid-template-columns: minmax(320px, 0.85fr) minmax(0, 1.15fr);
  gap: 18px;
  margin-top: 18px;
  align-items: start;
}

.stack {
  display: grid;
  gap: 18px;
}

.panel {
  border-radius: 22px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  padding: 18px 18px 0;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.phase-line,
.plan-summary {
  color: var(--muted);
  padding: 12px 18px 0;
  line-height: 1.45;
}

.transcript {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 58vh;
  max-height: 58vh;
  overflow: auto;
  padding: 18px;
}

.message {
  padding: 14px 16px;
  border-radius: 18px;
  line-height: 1.55;
}

.message.user {
  align-self: flex-end;
  max-width: 82%;
  background: #2e4f43;
  color: #f9f6f0;
}

.message.assistant {
  align-self: flex-start;
  max-width: 88%;
  background: var(--accent-soft);
}

.pending-answer {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

.pending-answer strong,
.pending-answer small {
  display: block;
}

.pending-answer small {
  margin-top: 2px;
}

.loading-dot {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(0.82);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

.message.error {
  background: rgba(141, 64, 53, 0.12);
  color: var(--warn);
}

.composer {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--line);
}

.tool-form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: auto;
}

.layer-summary,
.evidence-list,
.trace-list {
  display: grid;
  gap: 12px;
  padding: 16px 18px 18px;
}

.layer-card,
.evidence-card,
.trace-card,
.neighbor-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  padding: 14px;
}

.layer-card p,
.trace-card p,
.evidence-card p,
.neighbor-card p {
  margin: 8px 0 0;
}

.run-details {
  margin-top: 12px;
}

.run-details summary,
.run-section summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
}

.run-section {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  padding: 12px 14px;
}

.run-section > summary {
  display: grid;
  gap: 4px;
  list-style-position: inside;
}

.run-section > summary span {
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.run-section > summary strong {
  color: var(--ink);
  line-height: 1.35;
}

.run-profile {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(54, 95, 71, 0.08);
  color: var(--ok);
  padding: 10px 12px;
  font-weight: 700;
}

.phase-details {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.phase-nested {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}

.guidance-group {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.58);
}

.guidance-title,
.guidance-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.guidance-items {
  display: grid;
  gap: 6px;
}

.guidance-item small {
  width: 100%;
  color: var(--muted);
  font-size: 0.76rem;
  overflow-wrap: anywhere;
}

.empty-note {
  color: var(--muted);
  margin: 0;
}

.raw-payload pre {
  max-height: 240px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 12px/1.45 Consolas, "Liberation Mono", monospace;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.debug-trace {
  padding-top: 0;
}

.meta-list,
.trace-meta {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.meta-row,
.trace-row {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 10px;
}

.meta-label,
.trace-label {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.76rem;
  background: rgba(54, 95, 71, 0.1);
  color: var(--ok);
}

.citation {
  background: rgba(135, 81, 45, 0.12);
  color: var(--accent);
}

.source-drawer {
  width: min(860px, 92vw);
  border-radius: 22px;
  padding: 20px;
}

.source-drawer::backdrop {
  background: rgba(26, 24, 20, 0.4);
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.drawer-meta,
.drawer-body,
.neighbor-list {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.74);
  padding: 14px;
}

.drawer-body {
  white-space: pre-wrap;
  line-height: 1.7;
}

.neighbor-list {
  display: grid;
  gap: 10px;
}

.markdown h1,
.markdown h2,
.markdown h3,
.markdown h4 {
  margin: 0 0 10px;
  line-height: 1.25;
  color: var(--ink);
}

.markdown h1 {
  font-size: 1.5rem;
}

.markdown h2 {
  font-size: 1.28rem;
}

.markdown h3 {
  font-size: 1.12rem;
}

.markdown h4 {
  font-size: 1rem;
}

.markdown p,
.markdown ul,
.markdown ol,
.markdown pre,
.markdown .table-wrap {
  margin: 0 0 12px;
}

.markdown ul,
.markdown ol {
  padding-left: 20px;
}

.markdown li + li {
  margin-top: 4px;
}

.markdown code {
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(33, 29, 22, 0.08);
}

.markdown pre {
  overflow: auto;
  max-width: 100%;
  padding: 12px;
  border-radius: 12px;
  background: rgba(33, 29, 22, 0.08);
}

.markdown pre code {
  padding: 0;
  border-radius: 0;
  background: transparent;
}

.markdown .table-wrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.62);
}

.markdown table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  font-size: 0.92rem;
  line-height: 1.42;
}

.markdown th,
.markdown td {
  padding: 10px 12px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.markdown th:last-child,
.markdown td:last-child {
  border-right: 0;
}

.markdown tbody tr:last-child td {
  border-bottom: 0;
}

.markdown th {
  background: rgba(54, 95, 71, 0.1);
  color: var(--ink);
  font-weight: 700;
  text-align: left;
}

.markdown :last-child {
  margin-bottom: 0;
}

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

  .hero,
  .layout,
  .tool-layout {
    grid-template-columns: 1fr;
    display: grid;
  }

  .transcript {
    min-height: 46vh;
    max-height: none;
  }

  .meta-row,
  .trace-row,
  .form-grid {
    grid-template-columns: 1fr;
  }
}
