:root {
  --bg: #07080a;
  --bg2: #101318;
  --surface: #111318;
  --accent: #ff6f00;
  --blue: #3b82f6;
  --text: #ffffff;
  --muted: #858b98;
  --line: #1c2028;
  --line-strong: #2a2f3a;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --sans: "Inter", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button {
  font: inherit;
}

/* ============ SHELL ============ */
.shell {
  display: grid;
  grid-template-columns: minmax(340px, 410px) 1fr;
  height: 100vh;
  height: 100dvh;
}

/* ============ LEFT PANEL ============ */
.panel {
  --mx: -400px;
  --my: -400px;
  position: relative;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  padding: 36px 40px 28px;
  overflow-y: auto;
  /* cursor spotlight — background-attachment: scroll keeps it pinned to the viewport of the panel */
  background:
    radial-gradient(260px circle at var(--mx) var(--my), rgba(255, 111, 0, 0.07), transparent 70%),
    var(--bg2);
}

.panel-head {
  margin-bottom: 40px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-mark {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  filter: drop-shadow(0 0 8px rgba(255, 111, 0, 0.45));
  animation: breathe 4s ease-in-out infinite;
}

@keyframes breathe {
  0%,
  100% {
    filter: drop-shadow(0 0 6px rgba(255, 111, 0, 0.35));
  }
  50% {
    filter: drop-shadow(0 0 14px rgba(255, 111, 0, 0.7));
  }
}

.logo-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.brand {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.3em;
}

.version {
  font-family: var(--mono);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.controls {
  flex: 1;
}

/* Entrance choreography */
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.panel-head,
.field,
.btn-calc,
.btn-reset,
.panel-foot {
  /* `backwards` so the finished animation does not pin transform/opacity */
  animation: rise 0.7s var(--ease) backwards;
}
.field:nth-of-type(1) { animation-delay: 0.08s; }
.field:nth-of-type(2) { animation-delay: 0.16s; }
.field:nth-of-type(3) { animation-delay: 0.24s; }
.field:nth-of-type(4) { animation-delay: 0.32s; }
.btn-calc { animation-delay: 0.42s; }
.btn-reset { animation-delay: 0.48s; }
.panel-foot { animation-delay: 0.54s; }

/* Fields */
.field {
  margin-bottom: 30px;
}

.field-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 14px;
}

.num {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--accent);
  transition: text-shadow 0.3s;
}

.field:focus-within .num {
  text-shadow: 0 0 10px rgba(255, 111, 0, 0.8);
}

.field-title {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color 0.3s;
}

.field:focus-within .field-title {
  color: var(--text);
}

.field-aside {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--muted);
  transition: color 0.4s;
}

/* Value-changed highlight (HUD + hints) */
@keyframes flash {
  0% {
    color: var(--accent);
  }
  100% {
    color: inherit;
  }
}

.is-flash {
  animation: flash 0.9s var(--ease);
}

/* Segmented controls — thin technical grid */
.segment {
  display: grid;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
}

.sw-grid {
  grid-template-columns: repeat(3, 1fr);
}

.unit-grid {
  grid-template-columns: repeat(3, 1fr);
}

.seg-btn {
  position: relative;
  padding: 11px 6px;
  background: var(--bg2);
  border: 0;
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}

.seg-btn::after {
  content: "";
  position: absolute;
  left: 50%;
  right: 50%;
  bottom: 0;
  height: 1px;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(255, 111, 0, 0.7);
  transition: left 0.3s var(--ease), right 0.3s var(--ease);
}

.unit-grid .seg-btn {
  font-family: var(--mono);
  font-size: 0.7rem;
  padding: 11px 10px;
}

.seg-btn:hover {
  color: var(--text);
  background: #151a21;
}

.seg-btn:active {
  background: #1a2029;
}

.seg-btn.is-active {
  color: var(--accent);
  background: rgba(255, 111, 0, 0.07);
}

.seg-btn.is-active::after {
  left: 0;
  right: 0;
}

.seg-btn:focus-visible {
  outline: 1px solid var(--blue);
  outline-offset: -1px;
}

/* Inputs */
.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}

.pair-time {
  grid-template-columns: 1fr auto;
  align-items: end;
}

.input {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 0 8px;
  border-bottom: 1px solid var(--line-strong);
}

/* Focus underline grows from the centre */
.input::after {
  content: "";
  position: absolute;
  left: 50%;
  right: 50%;
  bottom: -1px;
  height: 1px;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(255, 111, 0, 0.6);
  transition: left 0.35s var(--ease), right 0.35s var(--ease);
}

.input:focus-within::after {
  left: 0;
  right: 0;
}

.input span {
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color 0.25s;
}

.input:focus-within span {
  color: var(--text);
}

.input input {
  width: 100%;
  padding: 0;
  background: none;
  border: 0;
  outline: 0;
  color: var(--text);
  font-family: var(--mono);
  font-size: 1.2rem;
  transition: color 0.3s;
}

/* Keystroke tick */
@keyframes tick {
  0% {
    color: var(--accent);
  }
  100% {
    color: var(--text);
  }
}

.input.is-tick input {
  animation: tick 0.5s var(--ease);
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* Stepper */
.stepper {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  transition: border-color 0.3s;
}

.stepper:hover {
  border-color: var(--line-strong);
}

.step-btn {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  background: var(--bg2);
  border: 0;
  color: var(--text);
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
}

.step-btn svg {
  width: 12px;
  height: 12px;
  transition: transform 0.2s var(--ease);
}

.step-btn:first-child {
  border-right: 1px solid var(--line);
}

.step-btn:last-child {
  border-left: 1px solid var(--line);
}

.step-btn:hover:not(:disabled) {
  background: #151a21;
  color: var(--accent);
}

.step-btn:hover:not(:disabled) svg {
  transform: scale(1.25);
}

.step-btn:active:not(:disabled) svg {
  transform: scale(0.85);
}

.step-btn:disabled {
  color: var(--line-strong);
  cursor: not-allowed;
}

.step-value {
  flex: 1;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
  overflow: hidden;
}

.step-value span {
  display: inline-block;
  font-family: var(--mono);
  font-size: 1.4rem;
  font-weight: 500;
  min-width: 1.4ch;
  text-align: center;
}

@keyframes slide-up {
  0% {
    transform: translateY(60%);
    opacity: 0;
    color: var(--accent);
  }
  100% {
    transform: none;
    opacity: 1;
  }
}

@keyframes slide-down {
  0% {
    transform: translateY(-60%);
    opacity: 0;
    color: var(--accent);
  }
  100% {
    transform: none;
    opacity: 1;
  }
}

.step-value span.is-up {
  animation: slide-up 0.3s var(--ease);
}

.step-value span.is-down {
  animation: slide-down 0.3s var(--ease);
}

.step-value small {
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Buttons */
.btn-calc {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  margin-top: 6px;
  background: var(--accent);
  border: 0;
  color: #0a0a0a;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  overflow: hidden;
  isolation: isolate;
  box-shadow: 0 0 28px rgba(255, 111, 0, 0.22);
  transition: background 0.2s, box-shadow 0.3s, transform 0.18s var(--ease);
}

/* Sheen that sweeps across on hover */
.btn-calc::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 35%, rgba(255, 255, 255, 0.28) 50%, transparent 65%);
  transform: translateX(-100%);
  transition: transform 0.7s var(--ease);
  pointer-events: none;
}

.btn-calc:hover::before {
  transform: translateX(100%);
}

.btn-calc > * {
  position: relative;
  z-index: 1;
}

.btn-icon {
  position: relative;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn-icon svg {
  position: absolute;
  inset: 0;
  width: 16px;
  height: 16px;
  transition: transform 0.2s var(--ease), opacity 0.2s;
}

.spinner {
  position: absolute;
  inset: 1px;
  border: 1.5px solid rgba(10, 10, 10, 0.25);
  border-top-color: #0a0a0a;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.2s;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.btn-calc.is-busy .btn-icon svg {
  opacity: 0;
  transform: translateX(8px);
}

.btn-calc.is-busy .spinner {
  opacity: 1;
  animation: spin 0.7s linear infinite;
}

.btn-calc.is-busy {
  background: #ff8324;
  box-shadow: 0 0 44px rgba(255, 111, 0, 0.5);
}

.btn-calc:hover {
  background: #ff8324;
  box-shadow: 0 0 36px rgba(255, 111, 0, 0.38);
}

.btn-calc:hover .btn-icon svg {
  transform: translateX(4px);
}

.btn-calc:active {
  transform: translateY(1px) scale(0.995);
}

.ripple {
  position: absolute;
  z-index: 0;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
  pointer-events: none;
  animation: ripple 0.6s ease-out forwards;
}

@keyframes ripple {
  to {
    transform: scale(60);
    opacity: 0;
  }
}

.btn-reset {
  display: block;
  margin: 18px auto 0;
  padding: 0;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 0.18s, letter-spacing 0.3s var(--ease);
}

.btn-reset:hover {
  color: var(--text);
  letter-spacing: 0.16em;
}

.panel-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 36px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.dot {
  width: 3px;
  height: 3px;
  background: var(--accent);
}

/* ============ RIGHT STAGE ============ */
.stage {
  --px: 0;
  --py: 0;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Calculation scan sweep */
.sweep {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.sweep::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -160px;
  width: 160px;
  background: linear-gradient(90deg, transparent, rgba(255, 111, 0, 0.12) 85%, rgba(255, 140, 40, 0.8));
  opacity: 0;
}

@keyframes sweep {
  0% {
    transform: translateX(0);
    opacity: 1;
  }
  100% {
    transform: translateX(calc(100vw + 160px));
    opacity: 1;
  }
}

.sweep.is-run::before {
  animation: sweep 0.5s cubic-bezier(0.3, 0, 0.3, 1) both;
}

/* HUD corner labels */
.hud {
  position: absolute;
  display: grid;
  grid-template-columns: auto auto;
  gap: 4px 14px;
  padding: 14px 18px;
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  pointer-events: none;
  animation: rise 1s var(--ease) 0.6s backwards;
}

.hud::before {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 1px solid var(--line-strong);
}

.hud-key {
  color: var(--muted);
}

.hud-val {
  color: var(--text);
}

.hud-tl {
  top: 24px;
  left: 28px;
}
.hud-tl::before {
  top: 0;
  left: 0;
  border-right: 0;
  border-bottom: 0;
}

.hud-tr {
  top: 24px;
  right: 28px;
  text-align: right;
}
.hud-tr::before {
  top: 0;
  right: 0;
  border-left: 0;
  border-bottom: 0;
}

.hud-bl {
  bottom: 24px;
  left: 28px;
}
.hud-bl::before {
  bottom: 0;
  left: 0;
  border-right: 0;
  border-top: 0;
}

.hud-br {
  bottom: 24px;
  right: 28px;
  text-align: right;
}
.hud-br::before {
  bottom: 0;
  right: 0;
  border-left: 0;
  border-top: 0;
}

/* Main readout */
.readout {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 9%;
  padding: 0 24px;
  text-align: center;
  pointer-events: none;
  /* gentle counter-parallax against the geometry */
  transform: translate3d(calc(var(--px) * -8px), calc(var(--py) * -6px), 0);
  animation: rise 1.1s var(--ease) 0.3s backwards;
}

.readout p {
  margin: 0;
}

.readout-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--muted);
}

.readout-time {
  margin-top: 10px !important;
  font-family: var(--mono);
  font-size: clamp(3.6rem, 9vw, 8.5rem);
  font-weight: 200;
  line-height: 1;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  text-shadow: 0 0 40px rgba(255, 111, 0, 0.35), 0 0 90px rgba(255, 111, 0, 0.15);
  transition: opacity 0.4s, text-shadow 0.4s;
}

.readout-time .sep {
  display: inline-block;
  margin: 0 0.18em;
  color: var(--accent);
  animation: blink 2.4s ease-in-out infinite;
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.readout-time.is-pulse {
  animation: pulse 0.7s ease-out;
}

@keyframes pulse {
  0% {
    transform: scale(1.03);
    text-shadow: 0 0 60px rgba(255, 111, 0, 0.9), 0 0 140px rgba(255, 111, 0, 0.45);
  }
  100% {
    transform: none;
    text-shadow: 0 0 40px rgba(255, 111, 0, 0.35), 0 0 90px rgba(255, 111, 0, 0.15);
  }
}

.readout-units {
  margin-top: 12px !important;
  font-size: 0.62rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--accent);
  transition: color 0.4s;
}

/* Context-aware: multi-day renders shift the caption to the cool accent */
.readout[data-scale="days"] .readout-units {
  color: var(--blue);
}

.readout-meta {
  margin-top: 22px !important;
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.readout-perpc {
  margin-top: 8px !important;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--blue);
  animation: rise 0.5s var(--ease);
}

.readout-error {
  margin-top: 14px !important;
  font-size: 0.8rem;
  color: #ff5a5a;
  animation: rise 0.4s var(--ease);
}

.readout-perpc:empty,
.readout-error:empty,
.readout-meta:empty {
  display: none;
}

.readout.has-error .readout-time {
  opacity: 0.25;
  text-shadow: none;
}

.readout.has-error .readout-units {
  color: var(--muted);
}

/* ============ RESPONSIVE ============ */
@media (max-width: 1100px) {
  .shell {
    grid-template-columns: minmax(320px, 360px) 1fr;
  }

  .panel {
    padding: 28px 28px 24px;
  }

  .readout-time {
    font-size: clamp(3rem, 8vw, 6rem);
  }
}

@media (max-width: 880px) {
  body {
    overflow: auto;
  }

  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    height: auto;
    min-height: 100dvh;
  }

  .stage {
    order: -1;
    height: 64vh;
    min-height: 440px;
  }

  .panel {
    border-right: 0;
    border-top: 1px solid var(--line);
    overflow: visible;
  }

  .readout {
    bottom: 11%;
  }

  .readout-time {
    font-size: clamp(3.2rem, 16vw, 6rem);
  }

  .hud-bl,
  .hud-br {
    display: none;
  }
}

@media (max-width: 480px) {
  .panel {
    padding: 24px 20px;
  }

  .pair {
    gap: 14px;
  }

  .pair-time {
    grid-template-columns: 1fr;
  }

  .sw-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .hud {
    padding: 10px 12px;
    font-size: 0.58rem;
  }

  .hud-tl {
    top: 14px;
    left: 14px;
  }

  .hud-tr {
    top: 14px;
    right: 14px;
  }
}

/* Touch devices: no hover sheen / spotlight */
@media (hover: none) {
  .btn-calc::before {
    display: none;
  }

  .panel {
    background: var(--bg2);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }

  .readout {
    transform: none;
  }
}
