:root {
  --bg: #f1f6f7;
  --panel: #ffffff;
  --ink: #0f2b2d;
  --muted: #5a7476;
  --line: #d5e2e4;
  --accent: #0f9ea8;
  --accent-2: #11b28f;
  --good: #067a52;
  --warn: #b65f00;
  --bad: #9b1f1f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 10%, rgba(17, 178, 143, 0.18) 0%, rgba(17, 178, 143, 0) 28%),
    radial-gradient(circle at 84% 5%, rgba(15, 158, 168, 0.2) 0%, rgba(15, 158, 168, 0) 30%),
    linear-gradient(180deg, #f8fbfc 0%, var(--bg) 100%);
  color: var(--ink);
  font-family: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
}

.app-shell {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 16px;
  height: calc(100vh - 72px);
  padding: 16px;
}

.panel {
  background: color-mix(in srgb, var(--panel) 92%, #ffffff 8%);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 12px 38px rgba(15, 43, 45, 0.08);
}

.controls {
  padding: 20px 18px;
  overflow-y: auto;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  font-weight: 700;
}

.brand h1 {
  margin: 2px 0 10px;
  font-size: 1.34rem;
  line-height: 1.22;
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.block {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbfc 100%);
}

.block h2 {
  margin: 0 0 10px;
  font-size: 0.96rem;
}

.steps {
  margin: 0 0 10px;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.9rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.field span {
  font-size: 0.77rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.03em;
}

.field input,
.field select {
  border: 1px solid #bfd1d3;
  background: #fff;
  color: var(--ink);
  border-radius: 9px;
  padding: 8px 9px;
  font: 500 13px/1 "JetBrains Mono", ui-monospace, monospace;
}

.mode-panel.hidden {
  display: none;
}

#tzField.hidden,
#basisWField.hidden {
  display: none;
}

.formula {
  margin: 2px 0 10px;
  border: 1px solid #c8d8da;
  border-radius: 10px;
  background: #f9fcff;
  padding: 8px;
  white-space: pre-wrap;
  font: 500 12px/1.45 "JetBrains Mono", ui-monospace, monospace;
  color: #1a4d51;
}

.grid2,
.grid3 {
  display: grid;
  gap: 8px;
}

.grid2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.hint {
  margin: 3px 0 10px;
  font-size: 0.84rem;
  color: var(--muted);
}

.mini-title {
  margin: 10px 0 8px;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 700;
}

.matrix-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 8px;
}

.matrix-grid.planar {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.matrix-grid input {
  width: 100%;
  border: 1px solid #bfd1d3;
  border-radius: 8px;
  padding: 7px;
  font: 500 12px/1 "JetBrains Mono", ui-monospace, monospace;
}

.matrix-grid input.hidden-3d {
  display: none;
}

.basis-wrap {
  display: grid;
  gap: 6px;
}

.action-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
  font: 700 12px/1.1 "IBM Plex Sans", system-ui, sans-serif;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}

.btn.secondary {
  background: #ebf6f7;
  border-color: #bbd8da;
  color: #0e4e53;
}

.btn.tertiary {
  background: #fff;
  border-color: #c7d7d9;
  color: #32595b;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 0.88rem;
  color: var(--muted);
}

.status {
  border: 1px solid #c6dde0;
  border-radius: 10px;
  padding: 10px;
  background: #f5fcff;
  color: #285e63;
  font-size: 0.86rem;
}

.status.ok {
  border-color: #9dd5bf;
  background: #eefaf4;
  color: var(--good);
}

.status.warn {
  border-color: #f0c89a;
  background: #fff7ee;
  color: var(--warn);
}

.status.error {
  border-color: #e3b1b1;
  background: #fff3f3;
  color: var(--bad);
}

.stage {
  padding: 14px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  align-content: start;
  overflow: hidden;
}

.viewport-wrap {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, #fdfefe 0%, #f2f8f9 100%);
  padding: 10px;
}

.viewport-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.viewport-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.icon-btn {
  min-width: 42px;
  padding: 9px 10px;
  font-size: 0.95rem;
}

.speed-btn {
  min-width: 74px;
  padding-inline: 10px;
}

.matrix-display-toggle {
  margin: 0 0 8px;
}

.viewcube-3d {
  position: relative;
  width: 82px;
  height: 82px;
  transform-style: preserve-3d;
  transform: rotateX(-26deg) rotateY(34deg);
  cursor: grab;
}

.viewcube-3d:active {
  cursor: grabbing;
}

.cube-face {
  position: absolute;
  width: 46px;
  height: 46px;
  left: 18px;
  top: 18px;
  border: 1px solid #7fa4ab;
  background: linear-gradient(180deg, #f1f9fa 0%, #d8ecef 100%);
  color: #173f44;
  border-radius: 6px;
  cursor: pointer;
  font: 700 10px/1 "IBM Plex Sans", system-ui, sans-serif;
  box-shadow: 0 4px 9px rgba(15, 43, 45, 0.14);
}

.cube-face:hover {
  background: linear-gradient(180deg, #f3fdfe 0%, #e0f2f5 100%);
}

.face-front {
  transform: translateZ(23px);
}

.face-back {
  transform: rotateY(180deg) translateZ(23px);
}

.face-right {
  transform: rotateY(90deg) translateZ(23px);
}

.face-left {
  transform: rotateY(-90deg) translateZ(23px);
}

.face-top {
  transform: rotateX(90deg) translateZ(23px);
}

.face-bottom {
  transform: rotateX(-90deg) translateZ(23px);
}


.scene-shell {
  position: relative;
}

.viewcube-nav {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  border: 1px solid rgba(133, 170, 176, 0.55);
  border-radius: 10px;
  background: rgba(248, 253, 254, 0.92);
  padding: 8px;
  box-shadow: 0 6px 20px rgba(15, 43, 45, 0.15);
  display: grid;
  justify-items: center;
  gap: 0;
}

.viewcube-nav[hidden] {
  display: none;
}

.cube-corner {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1px solid #7ea6ac;
  background: #e5f2f4;
  cursor: pointer;
  padding: 0;
}

.cube-corner:hover {
  background: #f7fdff;
}

.c-tfl {
  top: 16px;
  left: 20px;
}

.c-tfr {
  top: 16px;
  right: 20px;
}

.c-tbl {
  top: 28px;
  left: 12px;
}

.c-tbr {
  top: 28px;
  right: 12px;
}

.c-bfl {
  bottom: 28px;
  left: 20px;
}

.c-bfr {
  bottom: 28px;
  right: 20px;
}

.c-bbl {
  bottom: 16px;
  left: 12px;
}

.c-bbr {
  bottom: 16px;
  right: 12px;
}

.cube-iso-btn {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  border: 1px solid #b1dfd0;
  border-radius: 7px;
  background: #e7f6f1;
  color: #0f6b53;
  font: 700 9px/1 "IBM Plex Sans", system-ui, sans-serif;
  padding: 3px 6px;
  cursor: pointer;
}

.viewport-head h2 {
  margin: 0;
  font-size: 1.02rem;
}

.viewport-head p {
  margin: 4px 0 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

#scene {
  width: 100%;
  height: min(44vh, 380px);
  border: 1px solid #d5e4e6;
  border-radius: 10px;
  background:
    linear-gradient(0deg, rgba(15, 158, 168, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 158, 168, 0.06) 1px, transparent 1px),
    linear-gradient(180deg, #ffffff 0%, #eff7f8 100%);
  background-size: 24px 24px, 24px 24px, auto;
  cursor: grab;
}

#scene:active {
  cursor: grabbing;
}

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.dot {
  width: 10px;
  height: 10px;
  display: inline-block;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.dot.world {
  background: #0f9ea8;
}

.dot.local {
  background: #f97316;
}

.dot.path {
  background: #7c3aed;
}

.math-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  overflow-y: auto;
  padding-right: 4px;
}

.math-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
}

.math-card.full {
  grid-column: 1 / -1;
}

.matrix-card {
  min-height: 150px;
}

.math-card h3 {
  margin: 0 0 8px;
  font-size: 0.92rem;
}

.math-card pre {
  margin: 0;
  overflow: auto;
  max-height: 140px;
  font: 500 12px/1.45 "JetBrains Mono", ui-monospace, monospace;
  color: #123f43;
}

.summary-card {
  background: linear-gradient(180deg, #ffffff 0%, #f5fcff 100%);
}

.summary-out {
  border: 1px solid #c9dce0;
  border-radius: 10px;
  padding: 10px;
  background: #ffffff;
  color: #275a5f;
  font-size: 0.88rem;
  line-height: 1.45;
  max-height: 140px;
  overflow-y: auto;
}

.notes {
  margin: 0;
  padding-left: 18px;
  color: #365b5d;
  font-size: 0.87rem;
}

.validation {
  margin-top: 10px;
  border: 1px solid #c7dbdd;
  border-radius: 10px;
  background: #f6fdff;
  padding: 8px;
  font-size: 0.85rem;
  color: #2f6367;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
  }

  .controls {
    max-height: none;
  }

  .stage {
    grid-template-rows: auto;
    overflow: visible;
  }

  .math-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
    padding-right: 0;
  }

  #scene {
    height: min(54vh, 460px);
  }
}

@media (max-width: 720px) {
  .viewcube-nav {
    transform: scale(0.88);
    transform-origin: top right;
    right: 6px;
    top: 6px;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 10px;
    gap: 10px;
  }

  .grid2,
  .grid3 {
    grid-template-columns: 1fr;
  }

  .math-grid {
    grid-template-columns: 1fr;
  }

  #scene {
    height: 360px;
  }
}
