:root {
  color-scheme: dark;
  --bg: #080b0f;
  --panel: #141a21;
  --panel-2: #1d2630;
  --panel-3: #0d1218;
  --line: #2f3a47;
  --line-soft: rgba(255, 255, 255, 0.08);
  --text: #f3f6f8;
  --muted: #9ba9b8;
  --muted-2: #6f7e8e;
  --accent: #42d69b;
  --accent-2: #7ec8ff;
  --gold: #f2b84b;
  --danger: #e05c57;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.36);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #05070a;
  color: var(--text);
  text-rendering: geometricPrecision;
}

* {
  scrollbar-width: thin;
  scrollbar-color: #405060 #0c1117;
}

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

button,
select,
input,
textarea {
  border: 1px solid var(--line);
  background: #0c1218;
  color: var(--text);
  border-radius: var(--radius);
}

button {
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
  transition: border-color 120ms ease, background-color 120ms ease, color 120ms ease, transform 120ms ease;
}

button:hover {
  border-color: #617284;
  background: #151d26;
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

button.primary {
  background: linear-gradient(180deg, #57e5ae 0%, #36c98f 48%, #25ad76 100%);
  color: #06110c;
  border-color: #5fe7b4;
  font-weight: 750;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 8px 22px rgba(66, 214, 155, 0.18);
}

.has-tooltip {
  position: relative;
}

.has-tooltip[data-tooltip]:hover::after,
.has-tooltip[data-tooltip]:focus-visible::after,
.has-tooltip[data-tooltip]:focus-within::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 9px);
  z-index: 20;
  width: max-content;
  max-width: min(300px, calc(100vw - 32px));
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: #10161d;
  color: var(--text);
  border-radius: 6px;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.36);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
  text-align: left;
  text-transform: none;
  transform: translateX(-50%);
  pointer-events: none;
  white-space: normal;
}

.panel .has-tooltip[data-tooltip]:hover::after,
.panel .has-tooltip[data-tooltip]:focus-visible::after,
.panel .has-tooltip[data-tooltip]:focus-within::after {
  left: auto;
  right: 0;
  max-width: min(300px, calc(100vw - 32px), calc(100% + 140px));
  transform: none;
}

.has-tooltip[data-tooltip]:hover::before,
.has-tooltip[data-tooltip]:focus-visible::before,
.has-tooltip[data-tooltip]:focus-within::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc(100% + 4px);
  z-index: 21;
  width: 9px;
  height: 9px;
  background: #10161d;
  border-right: 1px solid rgba(255, 255, 255, 0.15);
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  transform: translateX(-50%) rotate(45deg);
  pointer-events: none;
}

.panel .has-tooltip[data-tooltip]:hover::before,
.panel .has-tooltip[data-tooltip]:focus-visible::before,
.panel .has-tooltip[data-tooltip]:focus-within::before {
  left: auto;
  right: 18px;
  transform: rotate(45deg);
}

.icon-button,
.seed-actions button,
.full {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 430px;
  height: 100vh;
  overflow: hidden;
}

.viewport {
  position: relative;
  min-width: 0;
  background:
    radial-gradient(circle at 22% 30%, rgba(126, 200, 255, 0.12), transparent 28%),
    radial-gradient(circle at 68% 62%, rgba(66, 214, 155, 0.1), transparent 30%),
    radial-gradient(circle at 48% 46%, rgba(242, 184, 75, 0.055), transparent 24%),
    radial-gradient(circle at 18% 84%, rgba(196, 155, 255, 0.055), transparent 22%),
    #05070a;
  overflow: hidden;
}

.viewport::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(circle at 13% 23%, rgba(255, 255, 255, 0.34) 0 1px, transparent 1.6px),
    radial-gradient(circle at 33% 67%, rgba(126, 200, 255, 0.18) 0 1px, transparent 1.8px),
    radial-gradient(circle at 72% 18%, rgba(255, 255, 255, 0.22) 0 1px, transparent 1.6px),
    radial-gradient(circle at 58% 76%, rgba(255, 255, 255, 0.18) 0 1px, transparent 1.8px),
    linear-gradient(rgba(126, 200, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(126, 200, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(5, 7, 10, 0.46), transparent 24%, transparent 76%, rgba(5, 7, 10, 0.2)),
    linear-gradient(180deg, rgba(5, 7, 10, 0.2), transparent 25%, rgba(5, 7, 10, 0.3));
  background-size: auto, auto, auto, auto, 96px 96px, 96px 96px, auto, auto;
}

.viewport::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background-image:
    radial-gradient(rgba(255, 255, 255, 0.28) 0.8px, transparent 0.9px),
    radial-gradient(rgba(126, 200, 255, 0.18) 0.8px, transparent 0.9px);
  background-position: 0 0, 47px 31px;
  background-size: 94px 94px, 128px 128px;
  opacity: 0.5;
}

.universe-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  z-index: 2;
  align-items: flex-start;
  padding: 22px 24px;
  pointer-events: none;
}

h1 {
  margin: 0;
  font-size: clamp(27px, 3.1vw, 46px);
  font-weight: 820;
  letter-spacing: 0;
  text-shadow: 0 18px 42px rgba(0, 0, 0, 0.58);
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.readouts {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  gap: 8px;
  align-self: start;
  width: min(360px, 42vw);
  pointer-events: auto;
}

.readout {
  background: linear-gradient(180deg, rgba(17, 23, 31, 0.9), rgba(10, 14, 19, 0.82));
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  padding: 9px 10px;
  min-width: 0;
  box-shadow: inset 2px 0 0 rgba(126, 200, 255, 0.28), 0 12px 32px rgba(0, 0, 0, 0.22);
}

.readout.has-tooltip[data-tooltip]:hover::after,
.readout.has-tooltip[data-tooltip]:focus-within::after,
.legend-item.has-tooltip[data-tooltip]:hover::after {
  left: 0;
  transform: none;
}

.readout.has-tooltip[data-tooltip]:hover::before,
.readout.has-tooltip[data-tooltip]:focus-within::before,
.legend-item.has-tooltip[data-tooltip]:hover::before {
  left: 18px;
  transform: rotate(45deg);
}

.readout span,
.field span,
.param-label small,
.diagnostic span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.readout strong {
  display: block;
  margin-top: 3px;
  font-size: 17px;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.legend {
  position: absolute;
  left: 18px;
  bottom: 17px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: calc(100% - 36px);
  z-index: 2;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 9px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(10, 13, 17, 0.84);
  backdrop-filter: blur(8px);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 12px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  position: relative;
  flex: 0 0 auto;
  box-shadow: 0 0 12px color-mix(in srgb, currentColor 25%, transparent);
}

.legend-item .dot {
  width: 12px;
  height: 12px;
}

.glyph-speck {
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.16), 0 0 10px rgba(255, 255, 255, 0.12);
}

.glyph-disc {
  border-radius: 50%;
  opacity: 0.82;
}

.glyph-ring {
  border-radius: 50%;
  background: transparent !important;
  border: 2px solid currentColor;
}

.glyph-ring::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: currentColor;
}

.glyph-diamond {
  border-radius: 2px;
  transform: rotate(45deg);
}

.glyph-cross {
  border-radius: 0;
  background: transparent !important;
}

.glyph-cross::before,
.glyph-cross::after {
  content: "";
  position: absolute;
  background: currentColor;
  border-radius: 2px;
}

.glyph-cross::before {
  left: 5px;
  top: 0;
  width: 2px;
  height: 12px;
}

.glyph-cross::after {
  left: 0;
  top: 5px;
  width: 12px;
  height: 2px;
}

.panel {
  min-width: 0;
  height: 100vh;
  overflow: auto;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 180px),
    linear-gradient(180deg, #161d25, #10161d);
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 46px rgba(0, 0, 0, 0.22);
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 0 10px;
  gap: 4px;
  background: rgba(17, 23, 30, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.tab {
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  text-transform: capitalize;
  min-height: 44px;
  font-size: 15px;
}

.tab.active {
  color: var(--text);
  background: linear-gradient(180deg, rgba(126, 200, 255, 0.11), rgba(66, 214, 155, 0.07));
  box-shadow: inset 0 -2px 0 var(--accent), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.tab.has-tooltip[data-tooltip]:hover::after,
.tab.has-tooltip[data-tooltip]:focus-visible::after {
  top: calc(100% + 9px);
  bottom: auto;
  left: 50%;
  right: auto;
  transform: translateX(-50%);
}

.tab.has-tooltip[data-tooltip]:hover::before,
.tab.has-tooltip[data-tooltip]:focus-visible::before {
  top: calc(100% + 4px);
  bottom: auto;
  left: 50%;
  right: auto;
  transform: translateX(-50%) rotate(225deg);
}

.tab:first-child.has-tooltip[data-tooltip]:hover::after,
.tab:first-child.has-tooltip[data-tooltip]:focus-visible::after {
  left: 8px;
  right: auto;
  transform: none;
}

.tab:first-child.has-tooltip[data-tooltip]:hover::before,
.tab:first-child.has-tooltip[data-tooltip]:focus-visible::before {
  left: 28px;
  right: auto;
  transform: rotate(225deg);
}

.tab:last-child.has-tooltip[data-tooltip]:hover::after,
.tab:last-child.has-tooltip[data-tooltip]:focus-visible::after {
  left: auto;
  right: 8px;
  transform: none;
}

.tab:last-child.has-tooltip[data-tooltip]:hover::before,
.tab:last-child.has-tooltip[data-tooltip]:focus-visible::before {
  left: auto;
  right: 28px;
  transform: rotate(225deg);
}

.tabpane {
  padding: 18px 16px 24px;
}

.control-row,
.library-actions,
.seed-row {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.control-row {
  grid-template-columns: repeat(3, 1fr);
}

.seed-row {
  grid-template-columns: 1fr 82px;
}

.library-actions {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  padding: 9px 11px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

input[type="range"] {
  height: 20px;
  padding: 0;
  accent-color: #8bc5ff;
  background: transparent;
  border: 0;
  box-shadow: none;
}

output {
  color: var(--gold);
  font-weight: 750;
  letter-spacing: 0;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.metric-grid .readout:nth-child(-n+5) {
  box-shadow: inset 2px 0 0 rgba(66, 214, 155, 0.38), 0 10px 26px rgba(0, 0, 0, 0.18);
}

.metric-grid .readout:nth-child(6),
.metric-grid .readout:nth-child(9),
.metric-grid .readout:nth-child(11) {
  box-shadow: inset 2px 0 0 rgba(242, 184, 75, 0.42), 0 10px 26px rgba(0, 0, 0, 0.18);
}

.readout:hover,
.diagnostic:hover,
.species-panel:hover,
.seed-card:hover,
.event:hover {
  border-color: rgba(126, 200, 255, 0.28);
}

.diagnostic {
  margin: 14px 0;
  padding: 14px;
  border: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(126, 200, 255, 0.08), transparent 38%),
    linear-gradient(180deg, #101820, #0c1117);
  border-radius: var(--radius);
  box-shadow: inset 2px 0 0 rgba(66, 214, 155, 0.42);
}

.diagnostic strong {
  display: block;
  margin-top: 3px;
  font-size: 18px;
  line-height: 1.15;
}

.diagnostic p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.species-panel {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #101820, #0c1117);
  border-radius: var(--radius);
}

.species-panel > span {
  color: var(--muted);
  font-size: 12px;
}

.species-row {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 22px;
  padding: 3px 0;
}

.species-row strong {
  font-size: 13px;
  font-weight: 650;
}

.species-row em {
  color: var(--gold);
  font-size: 12px;
  font-style: normal;
}

.species-row strong,
.legend-item,
.topbar p,
.readout span {
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.2);
}

.param-list {
  display: grid;
  gap: 0;
}

.param {
  padding: 13px 0 14px;
  border-bottom: 1px solid var(--line-soft);
}

.param-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.param-label strong {
  font-size: 14px;
}

.param-label em {
  color: var(--gold);
  font-style: normal;
  font-size: 12px;
}

.full {
  width: 100%;
  margin-top: 14px;
}

.seed-list,
.timeline {
  display: grid;
  gap: 10px;
}

.seed-card,
.event {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #121a22, #0e141a);
  border-radius: var(--radius);
  padding: 11px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.seed-card.active {
  border-color: var(--accent);
}

.seed-card header,
.event header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
}

.title-input {
  border: 0;
  background: transparent;
  min-height: 28px;
  padding: 0;
  font-weight: 750;
}

.seed-card p,
.event p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.seed-card textarea {
  margin-top: 8px;
  min-height: 72px;
  resize: vertical;
}

.seed-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.event h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.event time {
  color: var(--gold);
  font-size: 12px;
  white-space: nowrap;
}

.status-toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 5;
  max-width: min(360px, calc(100vw - 32px));
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #111820;
  color: var(--text);
  border-radius: var(--radius);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.32);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
}

.status-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.noscript {
  margin: 0;
  padding: 12px 16px;
  background: var(--danger);
  color: #fff;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(420px, 58vh) minmax(360px, 42vh);
  }

  .panel {
    height: auto;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .topbar {
    flex-direction: column;
  }

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

@media (max-width: 560px) {
  .topbar {
    padding: 14px;
    gap: 12px;
  }

  .has-tooltip[data-tooltip]:hover::after,
  .has-tooltip[data-tooltip]:focus-visible::after,
  .has-tooltip[data-tooltip]:focus-within::after,
  .panel .has-tooltip[data-tooltip]:hover::after,
  .panel .has-tooltip[data-tooltip]:focus-visible::after,
  .panel .has-tooltip[data-tooltip]:focus-within::after {
    left: 0;
    right: auto;
    max-width: calc(100vw - 32px);
    transform: none;
  }

  .has-tooltip[data-tooltip]:hover::before,
  .has-tooltip[data-tooltip]:focus-visible::before,
  .has-tooltip[data-tooltip]:focus-within::before,
  .panel .has-tooltip[data-tooltip]:hover::before,
  .panel .has-tooltip[data-tooltip]:focus-visible::before,
  .panel .has-tooltip[data-tooltip]:focus-within::before {
    left: 18px;
    right: auto;
    transform: rotate(45deg);
  }

  .tab.has-tooltip[data-tooltip]:hover::after,
  .tab.has-tooltip[data-tooltip]:focus-visible::after {
    max-width: calc(100vw - 24px);
  }

  .readouts {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .readout {
    padding: 8px;
  }

  .readout strong {
    font-size: 15px;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .control-row,
  .seed-actions {
    grid-template-columns: 1fr;
  }
}
