:root {
  --page-bg: #ffffff;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-border: rgba(180, 160, 210, 0.35);
  --text: #1a1d22;
  --muted: #5c5f66;
  --accent: #6b5a8c;
  --accent-text: #ffffff;
  --warn: #8a5c4a;
  --cloud-lavender: rgba(188, 155, 230, 0.55);
  --cloud-soft: rgba(218, 200, 245, 0.45);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  min-height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: "Atkinson Hyperlegible", "Atkinson Hyperlegible Next", system-ui,
    sans-serif;
  background: var(--page-bg);
  color: var(--text);
  line-height: 1.4;
}

/* Lavender cloud field */
.cloud-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  background: var(--page-bg);
}

.cloud {
  position: absolute;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.92;
  will-change: transform, opacity;
}

.cloud-a {
  width: min(105vw, 920px);
  height: min(56vh, 480px);
  left: -16%;
  top: 4%;
  background: radial-gradient(
    ellipse 82% 72% at 48% 48%,
    var(--cloud-lavender) 0%,
    var(--cloud-soft) 38%,
    transparent 68%
  );
  animation: drift-a 26s ease-in-out infinite alternate;
}

.cloud-b {
  width: min(88vw, 720px);
  height: min(46vh, 420px);
  right: -12%;
  top: -10%;
  background: radial-gradient(
    ellipse 78% 68% at 42% 52%,
    rgba(172, 140, 225, 0.5) 0%,
    rgba(228, 215, 255, 0.38) 48%,
    transparent 66%
  );
  animation: drift-b 22s ease-in-out infinite alternate;
}

.cloud-c {
  width: min(110vw, 980px);
  height: min(44vh, 400px);
  left: 8%;
  bottom: -18%;
  background: radial-gradient(
    ellipse 74% 64% at 52% 48%,
    rgba(178, 150, 232, 0.48) 0%,
    rgba(212, 198, 250, 0.32) 42%,
    transparent 68%
  );
  animation: drift-c 30s ease-in-out infinite alternate;
}

.cloud-d {
  width: min(82vw, 620px);
  height: min(58vh, 440px);
  right: 4%;
  bottom: 14%;
  background: radial-gradient(
    ellipse 70% 76% at 38% 50%,
    rgba(195, 168, 238, 0.45) 0%,
    rgba(236, 225, 255, 0.22) 55%,
    transparent 74%
  );
  animation: drift-d 24s ease-in-out infinite alternate;
}

@keyframes drift-a {
  0% {
    transform: translate(0, 0) scale(1) rotate(0deg);
    opacity: 0.88;
  }
  100% {
    transform: translate(14vw, 10vh) scale(1.14) rotate(5deg);
    opacity: 1;
  }
}

@keyframes drift-b {
  0% {
    transform: translate(2vw, 0) scale(1.05) rotate(0deg);
    opacity: 0.82;
  }
  100% {
    transform: translate(-12vw, 12vh) scale(0.92) rotate(-4deg);
    opacity: 0.98;
  }
}

@keyframes drift-c {
  0% {
    transform: translate(0, 2vh) rotate(0deg) scale(1);
    opacity: 0.9;
  }
  100% {
    transform: translate(-18vw, -14vh) rotate(8deg) scale(1.1);
    opacity: 0.72;
  }
}

@keyframes drift-d {
  0% {
    transform: translate(0, 0) scale(1.02);
    opacity: 0.65;
  }
  50% {
    transform: translate(8vw, -6vh) scale(1.08);
    opacity: 0.95;
  }
  100% {
    transform: translate(18vw, -12vh) scale(0.97);
    opacity: 0.78;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cloud {
    animation: none;
  }
}

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  max-width: 1200px;
  margin: 0 auto;
  padding: clamp(0.65rem, 2vw, 1rem);
  min-height: 0;
}

header h1 {
  font-size: clamp(1.05rem, 2.2vw, 1.2rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0 0 0.15rem;
}

.sub {
  color: var(--muted);
  margin: 0 0 0.35rem;
  font-size: 0.82rem;
}

.header-credits {
  margin: 0 0 0.65rem;
  font-size: 0.74rem;
  line-height: 1.45;
  color: var(--muted);
}

.header-credits a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

.header-credits a:hover {
  filter: brightness(1.08);
}

.credit-sep {
  margin: 0 0.35rem;
  opacity: 0.55;
}

.credit-flip {
  display: inline;
}

.dashboard {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0.55rem;
  min-height: 0;
  overflow: hidden;
}

.dashboard > * {
  min-height: 0;
}

.decay-banner {
  grid-column: 1 / -1;
  grid-row: 1;
  padding: 0.65rem 0.72rem;
  border: 1px solid rgba(160, 120, 200, 0.45);
  background: rgba(252, 250, 255, 0.92);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    0 10px 32px rgba(120, 80, 160, 0.1);
  max-height: min(340px, 38vh);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-height: 0;
}

.decay-banner-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.5rem;
  flex-shrink: 0;
}

.panel.decay-banner h2 {
  text-transform: none;
  letter-spacing: 0.02em;
  font-size: 0.95rem;
  color: var(--accent);
  margin: 0 0 0.35rem;
}

.decay-banner-lede {
  margin: 0;
  font-size: 0.73rem;
  line-height: 1.42;
  color: var(--text);
  max-width: 58em;
}

.decay-banner-lede strong {
  font-weight: 700;
}

.decay-pick {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.74rem;
  color: var(--muted);
  font-weight: 700;
}

.decay-pick select {
  min-width: 12rem;
  padding: 0.38rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.95);
  font-family: inherit;
  font-size: 0.78rem;
  color: var(--text);
}

.decay-meters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  font-size: 0.7rem;
  flex-shrink: 0;
}

.decay-meter {
  flex: 1 1 auto;
  min-width: 7rem;
  max-width: 14rem;
}

.decay-meter-row {
  display: flex;
  justify-content: space-between;
  gap: 0.35rem;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 0.15rem;
}

.decay-meter-bar {
  height: 6px;
  border-radius: 6px;
  background: rgba(140, 120, 180, 0.15);
  overflow: hidden;
}

.decay-meter-bar > span {
  display: block;
  height: 100%;
  border-radius: 6px;
  margin: 0;
  background: linear-gradient(
    90deg,
    rgb(134, 110, 180),
    rgb(190, 150, 212)
  );
  transition: width 0.25s ease;
}

.decay-meter.decay-meter-wear .decay-meter-bar > span {
  background: linear-gradient(
    90deg,
    rgb(190, 120, 100),
    rgb(210, 160, 140)
  );
}

.decay-meter-state {
  font-weight: 700;
  padding: 0.2rem 0.42rem;
  border-radius: 6px;
  background: rgba(140, 120, 180, 0.18);
  color: var(--text);
}

.decay-split {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.55rem;
  min-height: 0;
}

.decay-pane {
  border: 1px solid rgba(160, 140, 190, 0.28);
  border-radius: 8px;
  padding: 0.45rem 0.5rem;
  background: rgba(255, 255, 255, 0.75);
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.decay-pane-title {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.35rem;
  flex-shrink: 0;
}

.decay-msg-body {
  margin: 0;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  font-size: 0.72rem;
  line-height: 1.42;
  white-space: pre-wrap;
  word-break: break-word;
}

.decay-pane-stored .decay-msg-body {
  color: var(--text);
}

.decay-surfaced-body {
  transition:
    filter 0.35s ease,
    opacity 0.35s ease,
    letter-spacing 0.35s ease,
    color 0.35s ease;
}

.decay-episode-meta {
  margin: 0.42rem 0 0;
  font-size: 0.67rem;
  line-height: 1.38;
  color: var(--muted);
  font-style: italic;
  flex-shrink: 0;
}

.decay-pane-surface.decor-mild .decay-surfaced-body {
  opacity: 0.94;
  filter: blur(0.08px);
  letter-spacing: 0.015em;
  color: #2f3238;
}

.decay-pane-surface.decor-strong .decay-surfaced-body {
  opacity: 0.87;
  filter: blur(0.45px);
  letter-spacing: 0.038em;
  color: #4e4854;
}

.decay-pane-surface.decor-heavy .decay-surfaced-body {
  opacity: 0.78;
  filter: blur(0.72px);
  letter-spacing: 0.06em;
  color: #605864;
}

.col {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-height: 0;
}

.panel-records {
  grid-column: 2;
  grid-row: 2;
}

.col-readout {
  grid-column: 3;
  grid-row: 2;
}

.col-controls {
  grid-column: 1;
  grid-row: 2;
}

.panel-grow {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.panel-output-shell pre {
  flex: 1 1 auto;
  min-height: 0;
}

.panel-records .records-scroll {
  flex: 1 1 auto;
}

.panel-records {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 0.6rem 0.65rem;
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(120, 100, 160, 0.06);
}

.panel h2 {
  margin: 0 0 0.55rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.db-reset-row {
  margin-top: 0.45rem;
}

.btn-danger {
  background: #a84848;
  color: #fff;
}

.btn-danger:hover {
  filter: brightness(1.08);
}

.panel-hint {
  margin: 0.5rem 0 0;
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.35;
}

.panel-hint strong {
  color: var(--text);
  font-weight: 700;
}

.panel-hint code {
  font-size: 0.95em;
  font-weight: 700;
  color: var(--text);
  background: rgba(140, 120, 180, 0.12);
  padding: 0.08em 0.28em;
  border-radius: 4px;
}

button {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  padding: 0.4rem 0.75rem;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  border-radius: 6px;
}

button:hover {
  filter: brightness(1.07);
}

textarea,
input[type="text"],
input[type="number"] {
  width: 100%;
  margin-bottom: 0.45rem;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 0.45rem;
  font-family: inherit;
  font-size: 0.8rem;
  border-radius: 6px;
}

textarea {
  resize: none;
  flex: 1 1 auto;
  min-height: 0;
  max-height: min(26vh, 11rem);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.74rem;
  margin-top: 0.4rem;
}

.panel-records table {
  table-layout: fixed;
}

.panel-records .cell-id {
  width: 28%;
  max-width: 0;
  overflow: hidden;
}

.panel-records .cell-id span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.panel-records .cell-badge {
  width: 18%;
}

.panel-records .cell-state {
  width: 16%;
}

.panel-records .cell-num {
  width: 9%;
}

.panel-records .cell-actions {
  width: 12%;
}

th,
td {
  text-align: left;
  padding: 0.3rem 0.45rem;
  border-bottom: 1px solid rgba(160, 140, 190, 0.25);
}

th {
  color: var(--muted);
  font-weight: 700;
}

.badge {
  color: var(--warn);
  font-size: 0.68rem;
}

.row-actions button {
  margin-right: 0.3rem;
  margin-top: 0.2rem;
  padding: 0.22rem 0.45rem;
  font-size: 0.68rem;
  background: rgba(140, 120, 180, 0.22);
  color: var(--text);
  font-weight: 700;
}

.records-scroll {
  margin-top: 0.35rem;
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 0;
}

.out-scroll {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.72rem;
  color: var(--muted);
  overflow: auto;
  min-height: 0;
}

.log-panel .log-header,
.log-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.35rem;
}

.log-toolbar .log-hint {
  flex: 1 1 auto;
  margin: 0;
  min-width: 0;
}

.log-toolbar .btn-secondary {
  flex-shrink: 0;
  align-self: flex-start;
}

.btn-secondary {
  background: rgba(140, 120, 180, 0.2) !important;
  color: var(--text) !important;
  font-size: 0.72rem;
  padding: 0.32rem 0.58rem;
}

.log-hint {
  margin: 0 0 0.45rem;
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.35;
}

.log-lines {
  flex: 0 1 auto;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  min-height: 3rem;
  max-height: min(22vh, 10rem);
  overflow: auto;
  font-size: 0.68rem;
  line-height: 1.42;
  overscroll-behavior: contain;
}

/* Collapsed by default — keeps the main dashboard on one screen */
.log-drawer {
  flex: 0 0 auto;
}

.log-drawer-summary {
  list-style: none;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.6rem;
  padding: 0.1rem 0;
}

.log-drawer-summary::-webkit-details-marker {
  display: none;
}

.log-drawer-summary::before {
  content: "▸ ";
  font-size: 0.65rem;
  color: var(--accent);
}

.log-drawer[open] .log-drawer-summary::before {
  content: "▾ ";
}

.log-drawer-hint {
  font-weight: 400;
  font-size: 0.65rem;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
  opacity: 0.85;
}

.log-drawer-body {
  margin-top: 0.45rem;
  padding-top: 0.35rem;
  border-top: 1px solid rgba(160, 140, 190, 0.2);
}

.log-drawer-body .log-lines {
  max-height: min(30vh, 12rem);
}

.log-line {
  padding: 0.24rem 0.42rem;
  border-bottom: 1px solid rgba(160, 140, 190, 0.18);
  white-space: pre-wrap;
  word-break: break-word;
}

.log-line:last-child {
  border-bottom: none;
}

.log-line.log-ok {
  color: #2d6a4f;
  border-left: 2px solid #52b788;
  padding-left: 0.38rem;
}

.log-line.log-err {
  color: #9b4d3a;
  border-left: 2px solid #cb6a53;
  padding-left: 0.38rem;
}

.log-line.log-info {
  color: var(--muted);
  border-left: 2px solid rgba(160, 140, 190, 0.5);
  padding-left: 0.38rem;
}

@media (max-width: 860px) {
  .dashboard {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto minmax(0, min(165px, 28vh)) minmax(0, 1fr);
    overflow: hidden;
  }

  .decay-banner {
    grid-column: 1 / -1;
    grid-row: 1;
    max-height: min(260px, 36vh);
  }

  .decay-split {
    grid-template-columns: 1fr;
    gap: 0.38rem;
  }

  .col-controls {
    grid-column: 1;
    grid-row: 2;
  }

  .panel-records {
    grid-column: 1 / -1;
    grid-row: 3;
    max-height: none;
    min-height: 0;
  }

  .col-readout {
    grid-column: 2;
    grid-row: 2;
  }
}
