:root {
  color-scheme: light;
  --bg: #f9fafb;
  --ink: #000;
  --line: #d1d5db;
  --panel: #fff;
  --teal: #14b8a6;
  --indigo: #6366f1;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  line-height: 1.4;
}

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible {
  outline: 3px solid var(--indigo);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 1rem;
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.home {
  color: #000;
  font-weight: 700;
  text-decoration: none;
}

.home:hover { text-decoration: underline; }

.top h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.gene {
  margin: 0;
  flex-basis: 100%;
  font-size: 0.95rem;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-left: auto;
}

.tabs button {
  min-height: 44px;
  padding: 0.35rem 0.8rem;
  border: 2px solid #000;
  border-radius: 999px;
  background: #fff;
  font-weight: 700;
}

.tabs button[aria-selected="true"] {
  background: #000;
  color: #fff;
}

.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
}

.viewport {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#frame-title {
  margin: 0;
  padding: 0.55rem 0.9rem 0.15rem;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.view {
  position: relative;
  flex: 1;
  min-height: 420px;
}

.webgl-error {
  margin: 2rem 1rem;
  font-size: 1.15rem;
  max-width: 36rem;
}

#view-3d canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#diagram {
  display: block;
  width: 100%;
  height: 100%;
}

.hot { cursor: pointer; }

.tag {
  pointer-events: auto;
  border: 1.5px solid #000;
  background: #fff;
  color: #000;
  border-radius: 7px;
  padding: 0.15rem 0.4rem;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

#define {
  margin: 0;
  padding: 0.9rem 1rem 1rem;
  border-left: 1px solid var(--line);
  background: var(--panel);
  overflow: auto;
}

#define h2 {
  margin: 0 0 0.4rem;
  font-size: 1.15rem;
  text-transform: capitalize;
}

#define p {
  margin: 0;
  font-size: 1.05rem;
}

#notice {
  margin: 0;
  padding: 0.7rem 0.9rem;
  border-top: 1px solid var(--line);
  background: #fff;
  font-size: 1.08rem;
  min-height: 3.4rem;
}

.transport {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.9rem 0.75rem;
  border-top: 1px solid var(--line);
  background: #fff;
}

.transport button {
  min-height: 44px;
  min-width: 44px;
  padding: 0.35rem 0.75rem;
  border: 2px solid #000;
  border-radius: 10px;
  background: #fff;
  font-weight: 700;
}

.transport button[aria-pressed="true"] {
  background: #000;
  color: #fff;
}

#play { min-width: 5.5rem; }

.slider-label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex: 1 1 180px;
  min-width: 180px;
  font-weight: 700;
  font-size: 0.95rem;
}

.slider-label input {
  flex: 1;
  min-height: 44px;
  accent-color: #000;
}

#frame-count {
  font-variant-numeric: tabular-nums;
  min-width: 3.2rem;
}

.speeds { display: flex; gap: 0.3rem; }

#selftest-out {
  margin: 0;
  padding: 0 0.9rem;
  white-space: pre-wrap;
}

@media (max-width: 860px) {
  .tabs { margin-left: 0; }
  .stage { grid-template-columns: 1fr; grid-template-rows: minmax(420px, 1fr) auto; }
  #define {
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: 28vh;
  }
  .view { min-height: 380px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto; }
}
