/* ═══════════════════════════════════════════════════════════════════════
   repunify — design tokens
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  --bg:            #06070a;
  --bg-raise:      #0c0e14;
  --ink:           #eef1f6;
  --ink-dim:       #9aa3b8;
  --ink-faint:     #5a6277;
  --line:          rgba(255, 255, 255, 0.08);
  --line-soft:     rgba(255, 255, 255, 0.045);

  --accent:        #5eead4;
  --accent-deep:   #1f9e8c;
  --accent-glow:   rgba(94, 234, 212, 0.35);
  --violet:        #a78bfa;
  --violet-glow:   rgba(167, 139, 250, 0.3);
  --amber:         #fbbf5c;

  --font-sans: 'Inter Tight', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --pad: clamp(1.15rem, 4vw, 2.75rem);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

.mono { font-family: var(--font-mono); font-feature-settings: 'zero' 1; }

button { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

/* ═════════════════════════════ atmosphere ═════════════════════════════ */

.aurora {
  position: fixed;
  inset: -20vmax;
  z-index: 0;
  pointer-events: none;
  filter: blur(80px);
  opacity: 0.55;
}

.blob {
  position: absolute;
  display: block;
  border-radius: 50%;
  will-change: transform;
}

.blob-a {
  width: 46vmax; height: 46vmax;
  top: 6%; left: 8%;
  background: radial-gradient(circle at 50% 50%, rgba(45, 212, 191, 0.5), transparent 68%);
  animation: drift-a 26s var(--ease) infinite alternate;
}
.blob-b {
  width: 40vmax; height: 40vmax;
  top: 32%; right: 4%;
  background: radial-gradient(circle at 50% 50%, rgba(139, 92, 246, 0.45), transparent 68%);
  animation: drift-b 32s var(--ease) infinite alternate;
}
.blob-c {
  width: 34vmax; height: 34vmax;
  bottom: 2%; left: 38%;
  background: radial-gradient(circle at 50% 50%, rgba(56, 189, 248, 0.3), transparent 70%);
  animation: drift-c 38s var(--ease) infinite alternate;
}

@keyframes drift-a { to { transform: translate3d(12vmax, 8vmax, 0) scale(1.15); } }
@keyframes drift-b { to { transform: translate3d(-14vmax, -6vmax, 0) scale(0.88); } }
@keyframes drift-c { to { transform: translate3d(6vmax, -12vmax, 0) scale(1.2); } }

/* Fine film grain keeps the large gradients from banding. */
.grain {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.4;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
}

/* A soft vignette pulls focus to the middle of the stage. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(ellipse 120% 80% at 50% 42%, transparent 35%, rgba(6, 7, 10, 0.72) 100%);
}

/* ═══════════════════════════════ topbar ═══════════════════════════════ */

.topbar {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: clamp(1rem, 2.5vw, 1.6rem) var(--pad);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: var(--ink);
}

.mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  width: 30px; height: 30px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, rgba(94, 234, 212, 0.14), rgba(167, 139, 250, 0.08));
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-style: normal;
}
.mark b { color: var(--accent); font-weight: 700; }
.mark i { color: var(--ink-faint); font-style: normal; font-weight: 400; }

.wordmark-text {
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--ink-dim);
}

/* Segmented mode switch. Both segments are equal width so the thumb only ever
   needs to translate — no width animation, no layout thrash. */
.modes {
  position: relative;
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.mode {
  position: relative;
  z-index: 1;
  flex: 1 0 auto;
  min-width: 7.4rem;
  border: 0;
  background: none;
  cursor: pointer;
  padding: 0.44rem 0.95rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  color: var(--ink-faint);
  transition: color 0.25s var(--ease);
}
.mode .mono { font-size: 0.78em; }
.mode:hover { color: var(--ink-dim); }
.mode.is-active { color: var(--bg); }

.mode-thumb {
  position: absolute;
  z-index: 0;
  top: 3px; left: 3px;
  width: calc(50% - 3px);
  height: calc(100% - 6px);
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), #74d8f5);
  box-shadow: 0 2px 18px var(--accent-glow);
  transition: transform 0.4s var(--ease);
}
.modes[data-active="repunit"] .mode-thumb { transform: translateX(100%); }

/* ════════════════════════════════ stage ════════════════════════════════ */

.stage {
  position: relative;
  z-index: 2;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(1.75rem, 4vh, 3.25rem);
  width: 100%;
  max-width: 62rem;
  margin: 0 auto;
  padding: clamp(1rem, 3vh, 2rem) var(--pad) clamp(2rem, 5vh, 3.5rem);
}

/* ───────────────────────────────  hero  ─────────────────────────────── */

.hero {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.eyebrow {
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 0.7rem;
}

.field { width: 100%; max-width: 40rem; }

.numinput {
  width: 100%;
  border: 0;
  background: none;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: clamp(2.6rem, 11vw, 5.4rem);
  font-weight: 300;
  line-height: 1.08;
  letter-spacing: 0.01em;
  text-align: center;
  caret-color: var(--accent);
  font-variant-numeric: tabular-nums;
  padding: 0.1em 0 0.12em;
  outline: none;
}
.numinput::placeholder { color: rgba(255, 255, 255, 0.09); }
.numinput::selection { background: var(--accent-glow); color: #fff; }

.rail {
  position: relative;
  height: 2px;
  border-radius: 2px;
  overflow: hidden;
  background: linear-gradient(90deg, transparent, var(--line), transparent);
}
.rail::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0;
  transition: opacity 0.4s var(--ease);
}
body.has-value .rail::after { opacity: 0.45; }

.rail-scan {
  position: absolute;
  top: 0; left: 0;
  width: 34%; height: 100%;
  background: linear-gradient(90deg, transparent, #fff, transparent);
  opacity: 0;
  filter: blur(0.5px);
}
body.is-busy .rail-scan {
  opacity: 0.9;
  animation: scan 0.75s linear infinite;
}
@keyframes scan {
  from { transform: translateX(-120%); }
  to   { transform: translateX(400%); }
}

.hint {
  margin: 1.15rem 0 0;
  font-size: 0.86rem;
  color: var(--ink-faint);
  max-width: 34rem;
}
.hint .mono { color: var(--ink-dim); }

.samples {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  margin-top: 1.25rem;
}

.chip {
  border: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.02);
  color: var(--ink-faint);
  border-radius: 999px;
  padding: 0.3rem 0.72rem;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  cursor: pointer;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease),
              background-color 0.2s var(--ease), transform 0.2s var(--ease);
}
.chip:hover {
  color: var(--accent);
  border-color: rgba(94, 234, 212, 0.35);
  background: rgba(94, 234, 212, 0.06);
  transform: translateY(-1px);
}
.chip:active { transform: translateY(0); }

/* ──────────────────────────────  result  ────────────────────────────── */

.result {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: clamp(1.4rem, 3vh, 2.25rem);
}
.result[hidden] { display: none; }

.result > * {
  animation: rise 0.55s var(--ease) both;
}
.result > *:nth-child(2) { animation-delay: 0.07s; }
.result > *:nth-child(3) { animation-delay: 0.12s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

.equation {
  border: 1px solid var(--line-soft);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.012));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: clamp(1.15rem, 3.5vw, 1.9rem);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 24px 60px -30px rgba(0, 0, 0, 0.9);
}

.step-label {
  margin: 0 0 0.6rem;
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* Each step is centred on the same axis as the hero; the copy control is
   pulled out of flow so it cannot bias that centre line. */
.line {
  position: relative;
  text-align: center;
  padding-inline: 2.9rem;
}
.line + .line { margin-top: clamp(1.6rem, 4vw, 2.4rem); }

/* Long answers are scaled down so a 1,000,000-digit result does not shout
   louder than a three-digit one. */
.multiplier {
  display: block;
  font-size: clamp(1.15rem, 4.4vw, 2.1rem);
  font-weight: 500;
  line-height: 1.32;
  color: var(--accent);
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 28px var(--accent-glow);
}
.multiplier[data-size="lg"] { font-size: clamp(0.95rem, 3vw, 1.45rem); line-height: 1.45; }
.multiplier[data-size="md"] { font-size: clamp(0.8rem, 2.2vw, 1.05rem); line-height: 1.55; }
.multiplier .sep { opacity: 0.32; padding: 0 0.06em; }
.multiplier .trunc {
  display: block;
  margin: 0.35em 0;
  font-size: 0.72em;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  text-shadow: none;
}

/* The 0/1 payload, rendered as a strip of illuminated cells. Cell size is a
   tier set by the digit count, capped against the viewport so short answers
   still fit on one line on a phone. */
.target {
  --cell: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
  align-content: flex-start;
  font-family: var(--font-mono);
}
.target[data-size="xl"] { --cell: min(1.75rem, 6vw); }
.target[data-size="lg"] { --cell: min(1.25rem, 4.6vw); }
.target[data-size="md"] { --cell: min(0.85rem, 3vw); }
.target[data-size="sm"] { --cell: min(0.55rem, 2vw); }
.target[data-size="xs"] { --cell: min(0.4rem, 1.5vw); }

.target .d {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--cell);
  height: var(--cell);
  border-radius: calc(var(--cell) * 0.2);
  font-size: calc(var(--cell) * 0.58);
  line-height: 1;
  transition: transform 0.2s var(--ease);
}
.target .d-1 {
  color: #04140f;
  font-weight: 700;
  background: linear-gradient(150deg, #7ff3dd, var(--accent-deep));
  box-shadow: 0 0 calc(var(--cell) * 0.55) var(--accent-glow);
}
.target .d-0 {
  color: var(--ink-faint);
  background: rgba(255, 255, 255, 0.035);
  box-shadow: inset 0 0 0 1px var(--line-soft);
}
.target.is-dense .d { border-radius: 1px; font-size: 0; }
.target.is-dense .d-1 { box-shadow: none; }

/* Separates the head and tail samples of a truncated strip onto their own row. */
.target .gap {
  flex-basis: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0.55rem 0;
}
.target .gap b {
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
  padding: 0.24rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--line-soft);
  background: rgba(10, 12, 17, 0.9);
  white-space: nowrap;
}

/* Purely-textual variant used when the answer is astronomically long. */
.target.is-abstract {
  display: block;
  font-size: clamp(1.05rem, 3.6vw, 1.7rem);
  color: var(--accent);
  line-height: 1.45;
  text-shadow: 0 0 28px var(--accent-glow);
}
.target.is-abstract .qty { color: var(--ink); font-weight: 600; }
.target.is-abstract .note { display: block; font-family: var(--font-sans); font-size: 0.8rem; color: var(--ink-faint); text-shadow: none; margin-top: 0.4rem; }

.copy {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.025);
  color: var(--ink-faint);
  cursor: pointer;
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease),
              background-color 0.2s var(--ease), opacity 0.2s var(--ease);
}
.copy:hover:not(:disabled) { color: var(--accent); border-color: rgba(94, 234, 212, 0.35); background: rgba(94, 234, 212, 0.07); }
.copy:disabled { opacity: 0.25; cursor: not-allowed; }
.copy svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* Fade-in only applies where the control is out of flow (wide viewports).
   Narrow layouts place it in the flow, where a hidden button would reserve
   dead space, so it stays visible there. */
@media (hover: hover) and (min-width: 34.0625rem) {
  .copy { opacity: 0; }
  .equation:hover .copy,
  .copy:focus-visible { opacity: 1; }
  .copy:disabled { opacity: 0; }
  .equation:hover .copy:disabled { opacity: 0.25; }
}

.notice {
  margin: clamp(1.6rem, 4vw, 2.4rem) 0 0;
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  border: 1px solid rgba(251, 191, 92, 0.22);
  background: rgba(251, 191, 92, 0.07);
  color: var(--amber);
  font-size: 0.78rem;
  line-height: 1.6;
  text-align: center;
}
.notice[hidden] { display: none; }

/* ─────────────────────────────  metrics  ───────────────────────────── */

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
  gap: 1px;
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  overflow: hidden;
  background: var(--line-soft);
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.85rem 1rem;
  background: rgba(10, 12, 17, 0.72);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.metric-label {
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.metric-value {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 500;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.metric-time .metric-value {
  color: var(--violet);
  font-size: 1.35rem;
  font-weight: 700;
  text-shadow: 0 0 26px var(--violet-glow);
}
.metric-time.flash .metric-value { animation: flash 0.5s var(--ease); }
@keyframes flash {
  0%   { transform: scale(1.06); filter: brightness(1.7); }
  100% { transform: none; filter: none; }
}

.metric-note {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.02em;
  color: var(--ink-faint);
  min-height: 1em;
}

.metric-spark { justify-content: space-between; }

.spark {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 22px;
}
.spark i {
  flex: 1;
  min-width: 2px;
  max-width: 7px;
  height: 100%;
  border-radius: 1px;
  transform: scaleY(var(--h, 0.04));
  transform-origin: bottom;
  background: linear-gradient(180deg, var(--violet), rgba(167, 139, 250, 0.18));
  transition: transform 0.3s var(--ease), opacity 0.3s var(--ease);
}
.spark i.is-empty { opacity: 0.22; background: var(--ink-faint); }

/* ─────────────────────────────  explainer  ─────────────────────────── */

.explain {
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.018);
  overflow: hidden;
}

.explain summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.1rem;
  cursor: pointer;
  list-style: none;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink-dim);
  transition: color 0.2s var(--ease);
}
.explain summary::-webkit-details-marker { display: none; }
.explain summary:hover { color: var(--ink); }

.chev {
  width: 8px; height: 8px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform 0.3s var(--ease);
}
.explain[open] .chev { transform: rotate(225deg) translate(-2px, -2px); }

.explain-body {
  padding: 0 1.1rem 1.1rem;
  font-size: 0.82rem;
  line-height: 1.75;
  color: var(--ink-dim);
}
.explain-body ol { margin: 0; padding-left: 1.15rem; }
.explain-body li { margin-bottom: 0.5rem; }
.explain-body li::marker { color: var(--ink-faint); font-family: var(--font-mono); font-size: 0.8em; }
.explain-body .k { font-family: var(--font-mono); color: var(--accent); overflow-wrap: anywhere; }
.explain-body .v { font-family: var(--font-mono); color: var(--ink); }

/* ───────────────────────────  empty state  ─────────────────────────── */

.empty { text-align: center; }
.empty[hidden] { display: none; }
.empty-text {
  margin: 0;
  font-size: 0.85rem;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}
.empty-text.is-error { color: var(--amber); }

/* ─────────────────────────────  footer  ────────────────────────────── */

.footer {
  position: relative;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35rem 1rem;
  padding: 1.1rem var(--pad) 1.5rem;
  font-size: 0.68rem;
  color: var(--ink-faint);
  border-top: 1px solid var(--line-soft);
  text-align: center;
}
.footer .mono { font-size: 0.95em; }
.footer a { color: var(--ink-dim); text-decoration: none; border-bottom: 1px solid var(--line); }
.footer a:hover { color: var(--accent); border-color: var(--accent); }

/* ──────────────────────────────  toast  ────────────────────────────── */

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 2rem;
  transform: translate(-50%, 1.4rem);
  padding: 0.55rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(12, 14, 20, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  font-size: 0.78rem;
  color: var(--ink);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s var(--ease), transform 0.28s var(--ease);
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ══════════════════════════════ responsive ══════════════════════════ */

@media (max-width: 34rem) {
  .wordmark-text { display: none; }
  .mode { min-width: 0; padding-inline: 0.7rem; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metric-spark { grid-column: 1 / -1; }

  /* Reclaim the gutters: the copy control drops below the value instead. */
  .line { padding-inline: 0; }
  .copy { position: static; transform: none; margin-top: 0.9rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .rail-scan { opacity: 0 !important; }
}
