:root {
  --bg: #10141c;
  --panel: #171d28;
  --ink: #e7edf6;
  --muted: #8b97a8;
  --line: #2a3344;
  --gold: #e2b340;
  --beam: #6ec4ff;
  --ok: #7ddeb0;
  --font: "Avenir Next", "Segoe UI", sans-serif;
  --mono: "SFMono-Regular", "Menlo", "Consolas", monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

.app {
  height: 100%;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto minmax(0, 0.42fr) auto;
}

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

.app > footer {
  min-height: auto;
}

.topbar,
footer,
.hud,
.progress-wrap,
.logs,
.params {
  padding-left: 16px;
  padding-right: 16px;
}

.topbar,
footer {
  padding-top: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

footer {
  border-bottom: 0;
  border-top: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
  position: relative;
  z-index: 5;
  min-height: auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  position: relative;
  z-index: 20;
}

.kicker {
  margin: 0 0 2px;
  color: var(--gold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 11px;
}

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
}

.controls {
  display: flex;
  gap: 8px;
  align-items: end;
}

.speed {
  display: grid;
  gap: 3px;
  font-size: 11px;
  color: var(--muted);
}

select,
button,
input {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 11px;
  font: inherit;
}

.params {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px 10px;
  padding-top: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  align-items: end;
}

.params label {
  display: grid;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}

.params input,
.params select {
  width: 100%;
  min-width: 0;
  font-family: var(--mono);
  font-size: 12px;
}

.nuclide-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 4.6rem;
  gap: 6px;
}

.params-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  justify-content: end;
}

.params-error {
  margin: 0;
  color: #ff8b6b;
  font-size: 12px;
}

button:hover,
select:hover,
input:hover { border-color: var(--beam); }

.view-menu {
  position: relative;
}

.view-menu-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 11.5rem;
  max-width: 16rem;
  text-align: left;
}

.view-menu-btn span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.view-menu-btn::after {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--muted);
  flex: none;
}

.view-menu-btn[aria-expanded="true"]::after {
  transform: rotate(180deg);
}

.view-menu-panel {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 30;
  min-width: max(100%, 15rem);
  display: grid;
  gap: 2px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.4);
}

.view-menu-panel label {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 7px;
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
}

.view-menu-panel label:hover,
.view-menu-panel label:focus-within {
  background: #1c2432;
}

.view-menu-panel input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 0;
  padding: 0;
  background: none;
  border: 1px solid var(--line);
  accent-color: var(--beam);
}

.chamber-panel {
  position: relative;
  min-height: 0;
  margin: 0 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  overflow: hidden;
}

.chamber-panel.is-single,
.chamber-panel.is-empty {
  grid-template-columns: minmax(0, 1fr);
}

.views-empty {
  margin: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}

.chamber-pane {
  position: relative;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

canvas {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: block;
  background: radial-gradient(circle at 50% 50%, #1c2432 0%, #10141c 72%);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.current-op {
  position: absolute;
  left: 16px;
  bottom: 16px;
  width: min(420px, calc(100% - 32px));
  background: rgba(16, 20, 28, 0.92);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  backdrop-filter: blur(8px);
  z-index: 15;
  touch-action: none;
}

.current-op.is-dragging {
  user-select: none;
}

.op-chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: -4px -4px 8px;
  padding: 4px;
  cursor: grab;
}

.current-op.is-dragging .op-chrome {
  cursor: grabbing;
}

.op-chrome .panel-label {
  margin: 0;
  min-width: 0;
  flex: 1;
}

.op-toggle {
  width: 26px;
  height: 26px;
  padding: 0;
  flex: none;
  line-height: 1;
  font-size: 16px;
}

.current-op.is-min {
  width: auto;
  max-width: min(260px, calc(100% - 32px));
  padding: 8px 10px;
}

.current-op.is-min .op-chrome {
  margin: 0;
}

.current-op.is-min .op-body {
  display: none;
}

.panel-label {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.op-phase {
  margin: 0 0 4px;
  color: var(--beam);
  font-size: 12px;
}

.current-op.is-done .panel-label,
.current-op.is-done .op-phase {
  color: var(--gold);
}

.current-op h2 {
  margin: 0 0 8px;
  font-size: 16px;
}

.current-op pre,
.current-op p {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
}

#op-result {
  margin-top: 8px;
  color: var(--ok);
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding-top: 10px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.stat strong {
  font-size: 15px;
  font-family: var(--mono);
}

.progress-wrap {
  height: 8px;
  margin: 8px 16px 0;
  padding: 0;
  background: #222a38;
  border-radius: 99px;
  overflow: hidden;
}

.progress {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--beam), var(--gold));
}

.logs {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 16px;
  min-height: 0;
  overflow: clip;
  contain: layout paint;
  padding-top: 10px;
  padding-bottom: 8px;
}

.logs > div {
  position: relative;
  min-height: 0;
  height: 100%;
  overflow: clip;
}

.logs .panel-label {
  margin: 0;
}

.log,
.golds {
  position: absolute;
  top: 22px;
  right: 0;
  bottom: 0;
  left: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: auto;
  overscroll-behavior: contain;
  font-family: var(--mono);
  font-size: 12px;
}

.log li,
.golds li {
  padding: 5px 0;
  border-bottom: 1px solid #232b39;
  background: var(--bg);
}

.log li.gold,
.golds li { color: var(--gold); }
.log li.miss { color: var(--muted); }
.empty { color: var(--muted); }

@media (max-width: 1100px) {
  .params { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .hud,
  .topbar,
  .params { display: block; }

  .logs {
    display: flex;
    flex-direction: column;
  }

  .logs > div {
    flex: 1;
    min-height: 0;
  }

  .stat,
  .controls,
  .params label { margin-top: 8px; }

  .current-op:not(.is-min) { width: min(420px, calc(100% - 24px)); }

  .chamber-panel {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }

  .chamber-panel.is-single,
  .chamber-panel.is-empty {
    grid-template-rows: minmax(0, 1fr);
  }
}
