:root {
  --bg: #e8e2d6;
  --panel: #f3efe6;
  --ink: #1f1e1b;
  --muted: #5c574e;
  --line: #c9c1b2;
  --accent: #1f5f8b;
  --accent-2: #b33a3a;
  --warm: #c47a3a;
  --shadow: 0 1px 0 rgba(31, 30, 27, 0.06), 0 12px 28px rgba(31, 30, 27, 0.08);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 500px at 10% -10%, #f7f1e4 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #d9e3ea 0%, transparent 50%),
    var(--bg);
}

body {
  min-height: 100vh;
}

.app {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  grid-template-rows: auto 1fr;
  gap: 1rem;
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem 1.25rem 1.5rem;
  min-height: 100vh;
}

.header {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
  padding: 0.25rem 0.15rem 0.5rem;
  border-bottom: 1px solid var(--line);
}

.brand h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3rem);
  letter-spacing: 0.04em;
  font-weight: 600;
  line-height: 1;
}

.brand p {
  margin: 0.4rem 0 0;
  max-width: 52ch;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.4;
}

.status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.9rem;
  color: var(--accent);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 0.9rem 1rem 1.1rem;
  box-shadow: var(--shadow);
  align-self: start;
  position: sticky;
  top: 0.75rem;
  max-height: calc(100vh - 1.5rem);
  overflow: auto;
}

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

.panel section + section {
  border-top: 1px dashed var(--line);
  padding-top: 0.85rem;
}

.table-wrap {
  overflow-x: auto;
  margin-bottom: 0.5rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  padding: 0.2rem;
}

td {
  padding: 0.2rem;
}

td input,
label select,
label input[type="number"] {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
  border-radius: 2px;
  padding: 0.28rem 0.35rem;
  font: inherit;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.8rem;
}

.z-cell {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.78rem;
  color: var(--muted);
  padding-left: 0.35rem;
}

.btn-x {
  border: none;
  background: transparent;
  color: var(--accent-2);
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.1rem 0.35rem;
}

label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.55rem;
}

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

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.45rem;
}

.btn {
  border: 1px solid var(--ink);
  background: #fffdf8;
  color: var(--ink);
  border-radius: 2px;
  padding: 0.55rem 0.4rem;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

.btn:hover {
  background: #efe8da;
}

.btn.ghost {
  border-color: var(--line);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #f7f4ef;
}

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

.footnote {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--muted);
}

.viz {
  display: grid;
  grid-template-rows: 1.1fr 1fr 1fr;
  gap: 0.85rem;
  min-height: 70vh;
}

.card {
  margin: 0;
  background: #f7f4ef;
  border: 1px solid var(--line);
  border-radius: 2px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 180px;
  overflow: hidden;
}

.card figcaption {
  padding: 0.45rem 0.7rem;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: #f3efe6;
}

.card canvas {
  width: 100%;
  flex: 1;
  display: block;
  min-height: 140px;
}

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

  .panel {
    position: static;
    max-height: none;
  }

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

  .status {
    align-items: flex-start;
  }

  .viz {
    min-height: auto;
    grid-template-rows: 240px 220px 240px;
  }
}
