:root {
  --ink: #152028;
  --ink-soft: #3d4f5c;
  --paper: #f3f6f4;
  --panel: rgba(255, 255, 255, 0.78);
  --line: rgba(21, 32, 40, 0.1);
  --brand: #0f3d38;
  --accent: #c45c26;
  --received: #1d6fd8;
  --received-bg: rgba(29, 111, 216, 0.1);
  --received-border: rgba(29, 111, 216, 0.45);
  --prepared: #b45309;
  --prepared-bg: rgba(180, 83, 9, 0.1);
  --prepared-border: rgba(180, 83, 9, 0.45);
  --failed: #b42318;
  --failed-bg: rgba(180, 35, 24, 0.1);
  --failed-border: rgba(180, 35, 24, 0.45);
  --sent: #1f8a4c;
  --sent-bg: rgba(31, 138, 76, 0.1);
  --sent-border: rgba(31, 138, 76, 0.45);
  --shadow: 0 18px 50px rgba(15, 40, 36, 0.12);
  --radius: 18px;
  --font-display: "Instrument Serif", Georgia, serif;
  --font-body: "DM Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font-body);
  background: var(--paper);
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 480px at 8% -10%, rgba(29, 111, 216, 0.18), transparent 60%),
    radial-gradient(700px 420px at 92% 0%, rgba(31, 138, 76, 0.16), transparent 55%),
    linear-gradient(160deg, #e8efeb 0%, #f7f4ef 48%, #e7eef6 100%);
  animation: drift 18s ease-in-out infinite alternate;
}

@keyframes drift {
  from { filter: saturate(1); transform: scale(1); }
  to { filter: saturate(1.08); transform: scale(1.03); }
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1.5rem clamp(1.25rem, 4vw, 3rem) 0.75rem;
  animation: rise 0.7s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 5vw, 3.4rem);
  line-height: 0.95;
  letter-spacing: -0.02em;
  color: var(--brand);
}

.brand-sub {
  margin: 0.35rem 0 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.nav-link {
  color: var(--brand);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 6px 2px;
}
.nav-link:hover { text-decoration: underline; }

.nav-cluster {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.ai-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.7rem;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1;
  border: 1px solid transparent;
  white-space: nowrap;
}
.ai-badge.is-loading {
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink-soft);
  border-color: var(--line);
}
.ai-badge.is-on {
  background: #1f8a4c;
  color: #f3fff8;
  border-color: rgba(15, 70, 40, 0.35);
  box-shadow: 0 0 0 3px rgba(31, 138, 76, 0.18);
}
.ai-badge.is-off {
  background: #7a1f28;
  color: #fff5f5;
  border-color: rgba(60, 10, 16, 0.4);
  box-shadow: 0 0 0 3px rgba(122, 31, 40, 0.16);
}
.ai-badge.is-idle {
  background: #8b9099;
  color: #f4f5f7;
  border-color: rgba(40, 45, 55, 0.28);
  box-shadow: none;
}
.ai-badge.is-error {
  background: #b42318;
  color: #fff5f5;
  border-color: rgba(70, 12, 8, 0.4);
  box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.18);
}

.tabs {
  display: flex;
  gap: 0.4rem;
  padding: 0.3rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.tab {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-weight: 600;
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.tab:hover { color: var(--ink); }
.tab.is-active {
  background: var(--brand);
  color: #f5faf8;
  transform: translateY(-1px);
}

main {
  padding: 0.75rem clamp(1.25rem, 4vw, 3rem) 2.5rem;
}

.screen { display: none; animation: rise 0.55s ease both; }
.screen.is-active { display: block; }

.screen-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.screen-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 3vw, 2.4rem);
  font-weight: 400;
  color: var(--brand);
}

.screen-lede {
  margin: 0.35rem 0 0;
  max-width: 42rem;
  color: var(--ink-soft);
  line-height: 1.45;
}

.screen-actions {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.legend {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.swatch {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  display: inline-block;
}
.swatch.received { background: var(--received); box-shadow: 0 0 0 3px var(--received-bg); }
.swatch.prepared { background: var(--prepared); box-shadow: 0 0 0 3px var(--prepared-bg); }
.swatch.sent { background: var(--sent); box-shadow: 0 0 0 3px var(--sent-bg); }

.btn {
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  padding: 0.7rem 1.25rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary {
  background: var(--accent);
  color: #fff8f3;
  box-shadow: 0 10px 24px rgba(196, 92, 38, 0.28);
}
.btn.ghost {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
  color: var(--ink);
}
.btn:disabled,
.btn:disabled:hover {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
  box-shadow: none;
}

.comms-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: min(70vh, 720px);
  max-height: min(75vh, 820px);
  overflow: hidden;
  position: relative;
  backdrop-filter: blur(12px);
}

.comms-stream {
  height: min(70vh, 720px);
  overflow: auto;
  padding: 1rem 1.1rem 1.4rem;
  scroll-behavior: smooth;
}

.empty-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 2rem;
  color: var(--ink-soft);
  text-align: center;
  pointer-events: none;
}
.empty-hint.is-hidden { display: none; }

.comm-card {
  border-radius: 14px;
  padding: 0.85rem 1rem;
  margin: 0 0 0.75rem;
  border: 1px solid;
  animation: card-in 0.35s ease both;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.comm-card.received {
  background: var(--received-bg);
  border-color: var(--received-border);
}
.comm-card.prepared {
  background: var(--prepared-bg);
  border-color: var(--prepared-border);
}
.comm-card.failed {
  background: var(--failed-bg);
  border-color: var(--failed-border);
}
.comm-card.sent {
  background: var(--sent-bg);
  border-color: var(--sent-border);
}

.comm-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.85rem;
  align-items: baseline;
  margin-bottom: 0.35rem;
  font-size: 0.82rem;
}

.comm-dir {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.comm-card.received .comm-dir { color: var(--received); }
.comm-card.prepared .comm-dir { color: var(--prepared); }
.comm-card.failed .comm-dir { color: var(--failed); }
.comm-card.sent .comm-dir { color: var(--sent); }

.comm-peer { font-weight: 600; color: var(--ink); }
.comm-proto, .comm-time { color: var(--ink-soft); }
.comm-summary {
  margin: 0;
  font-weight: 600;
  line-height: 1.35;
}
.comm-detail {
  margin: 0.55rem 0 0;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(21, 32, 40, 0.06);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 420px;
  overflow: auto;
  color: var(--ink-soft);
}

.interpret-layout {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem clamp(1rem, 2vw, 1.5rem) 1.5rem;
  backdrop-filter: blur(12px);
  display: grid;
  gap: 0.55rem;
}

.field-label {
  font-weight: 600;
  font-size: 0.92rem;
  margin-top: 0.35rem;
}
.optional {
  font-weight: 400;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.field {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  font: inherit;
  padding: 0.75rem 0.9rem;
}
.field:focus {
  outline: 2px solid rgba(15, 61, 56, 0.35);
  outline-offset: 1px;
}

.input-area { min-height: 7rem; resize: vertical; }
.output-area {
  min-height: 22rem;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9rem;
  line-height: 1.45;
  background: rgba(15, 61, 56, 0.04);
}

.interpret-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0.25rem 0 0.5rem;
}

.status-line { color: var(--ink-soft); font-size: 0.9rem; }

@media (max-width: 720px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .nav-cluster { width: 100%; }
  .tabs { flex: 1; width: auto; }
  .tab { flex: 1; text-align: center; }
  .comms-panel, .comms-stream { min-height: 60vh; height: 60vh; max-height: none; }
}
