/* MFA Tool — a small, dependency-free two-base calculator.
   Dark "deep space" theme: cyan for the human decimal side, violet for the
   alien septenary side. No external fonts, no inline styles (strict CSP). */

:root {
  --bg: #04060d;
  --ink: #e8f1ff;
  --ink-dim: #93a6bf;
  --ink-faint: #5c6c84;
  --line: rgba(148, 178, 214, 0.14);
  --line-strong: rgba(148, 178, 214, 0.28);
  --dec: #38bdf8;
  --dec-2: #22d3ee;
  --sep: #c084fc;
  --sep-2: #a78bfa;
  --danger: #f87171;
  --font: "Inter", "SF Pro Text", system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans SC", "PingFang SC", "Microsoft YaHei",
    sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  --radius: clamp(18px, 2.4vw, 26px);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(1100px 620px at 10% -12%, rgba(56, 189, 248, 0.13), transparent 62%),
    radial-gradient(940px 540px at 94% 2%, rgba(192, 132, 252, 0.13), transparent 62%),
    radial-gradient(860px 620px at 50% 118%, rgba(34, 211, 238, 0.07), transparent 62%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.5;
  overflow-x: hidden;
}

::selection {
  background: rgba(56, 189, 248, 0.35);
  color: #fff;
}

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

/* ---------------------------------------------------------------- stars */

.starfield {
  position: fixed;
  inset: -12%;
  z-index: 0;
  pointer-events: none;
  opacity: 0.6;
  background-image:
    radial-gradient(1px 1px at 20% 30%, rgba(255, 255, 255, 0.55), transparent 60%),
    radial-gradient(1px 1px at 76% 14%, rgba(255, 255, 255, 0.4), transparent 60%),
    radial-gradient(1.5px 1.5px at 44% 68%, rgba(192, 132, 252, 0.45), transparent 60%),
    radial-gradient(1px 1px at 88% 78%, rgba(56, 189, 248, 0.45), transparent 60%),
    radial-gradient(1px 1px at 8% 84%, rgba(255, 255, 255, 0.3), transparent 60%),
    radial-gradient(1px 1px at 62% 44%, rgba(255, 255, 255, 0.25), transparent 60%);
  background-size: 520px 520px, 420px 420px, 640px 640px, 380px 380px, 460px 460px,
    300px 300px;
  animation: drift 140s linear infinite;
}

@keyframes drift {
  0% { transform: translate3d(0, 0, 0); }
  50% { transform: translate3d(-1.4%, -1.8%, 0); }
  100% { transform: translate3d(0, 0, 0); }
}

/* ------------------------------------------------------------- structure */

.wrap {
  position: relative;
  z-index: 1;
  width: min(1120px, 100% - 40px);
  margin-inline: auto;
  padding: clamp(26px, 5vw, 60px) 0 clamp(34px, 6vw, 70px);
}

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px 24px;
  margin-bottom: clamp(18px, 3vw, 26px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.sigil {
  width: clamp(42px, 5vw, 54px);
  height: clamp(42px, 5vw, 54px);
  flex: none;
  filter: drop-shadow(0 0 18px rgba(56, 189, 248, 0.32));
}

.brand-text h1 {
  margin: 0;
  font-size: clamp(24px, 3.6vw, 34px);
  font-weight: 650;
  letter-spacing: 0.015em;
  line-height: 1;
}

.brand-text .thin {
  margin-left: 9px;
  font-size: 0.58em;
  font-weight: 300;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.tagline {
  margin: 7px 0 0;
  font-size: 13px;
  color: var(--ink-dim);
}

.tagline .arrow {
  color: var(--sep);
  margin-inline: 2px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink-dim);
  font-family: var(--mono);
  font-size: 11.5px;
  white-space: nowrap;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 10px rgba(52, 211, 153, 0.8);
  animation: pulse 2.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.82); }
}

.intro {
  max-width: 68ch;
  margin: 0 0 clamp(18px, 3vw, 26px);
  color: var(--ink-dim);
  font-size: 14px;
  line-height: 1.75;
}

/* ----------------------------------------------------------------- deck */

.deck {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px minmax(0, 1fr);
  align-items: stretch;
  gap: clamp(10px, 1.6vw, 18px);
}

.panel {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: clamp(14px, 2vw, 20px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.012));
  box-shadow: 0 40px 90px -60px rgba(0, 0, 0, 0.9);
  transition: border-color 0.22s ease, box-shadow 0.22s ease;
}

.panel-dec { --accent: var(--dec); --accent-2: var(--dec-2); }
.panel-sep { --accent: var(--sep); --accent-2: var(--sep-2); }

.panel::before {
  content: "";
  position: absolute;
  inset: 0 18% auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.55;
  pointer-events: none;
}

.panel.is-active {
  border-color: color-mix(in srgb, var(--accent) 52%, var(--line));
  box-shadow:
    0 40px 90px -60px rgba(0, 0, 0, 0.9),
    0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent),
    0 26px 70px -48px var(--accent);
}

.panel.is-active::before {
  opacity: 1;
}

/* --------------------------------------------------------------- screen */

.screen {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 13px 15px 11px;
  border: 1px solid rgba(148, 178, 214, 0.12);
  border-radius: calc(var(--radius) - 10px);
  background:
    linear-gradient(180deg, rgba(3, 6, 12, 0.9), rgba(6, 10, 18, 0.62));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    inset 0 0 46px -26px var(--accent);
}

.screen-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  min-height: 30px;
}

.base-tag {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  line-height: 1.6;
  text-transform: uppercase;
  color: var(--accent);
}

.base-tag em {
  display: block;
  margin-top: 1px;
  font-style: normal;
  font-weight: 500;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}

.head-right {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  max-width: 58%;
  min-width: 0;
}

.live-dot {
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.18;
  transition: opacity 0.2s ease, box-shadow 0.2s ease;
}

.panel.is-active .live-dot {
  opacity: 1;
  box-shadow: 0 0 10px var(--accent);
}

.expr {
  overflow: hidden;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.9;
  color: var(--ink-faint);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.value {
  display: block;
  min-height: 1.16em;
  overflow: hidden;
  font-family: var(--mono);
  font-size: clamp(28px, 4.8vw, 44px);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.015em;
  line-height: 1.16;
  color: #f4f9ff;
  text-align: right;
  text-overflow: ellipsis;
  text-shadow: 0 0 26px color-mix(in srgb, var(--accent) 34%, transparent);
  white-space: nowrap;
}

.value[data-size="s"] {
  font-size: clamp(22px, 3.8vw, 34px);
}

.value[data-size="xs"] {
  font-size: clamp(16px, 2.8vw, 26px);
}

.value.is-approx {
  color: color-mix(in srgb, var(--ink) 78%, var(--accent));
}

.screen-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.base-hint {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.ghost {
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-dim);
  font-family: var(--font);
  font-size: 11.5px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.ghost:hover {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
}

/* -------------------------------------------------------------- keypads */

.pad {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(6px, 1.1vw, 10px);
  margin-top: auto;
}

.key {
  display: grid;
  place-items: center;
  min-height: clamp(46px, 6vw, 58px);
  padding: 0;
  border: 1px solid rgba(148, 178, 214, 0.16);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  color: var(--ink);
  font-family: var(--mono);
  font-size: clamp(16px, 2vw, 20px);
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}

.key:hover {
  border-color: var(--line-strong);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.03));
}

.key:active {
  transform: translateY(1px) scale(0.988);
}

.key.fn {
  font-family: var(--font);
  font-size: clamp(11px, 1.35vw, 13px);
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--ink-dim);
  text-transform: uppercase;
}

.key.op {
  border-color: color-mix(in srgb, var(--accent) 30%, var(--line));
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--accent) 15%, transparent),
    color-mix(in srgb, var(--accent) 5%, transparent)
  );
  color: color-mix(in srgb, var(--accent) 88%, white);
  font-size: clamp(18px, 2.2vw, 22px);
}

.key.op:hover {
  border-color: color-mix(in srgb, var(--accent) 48%, transparent);
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--accent) 24%, transparent),
    color-mix(in srgb, var(--accent) 9%, transparent)
  );
}

.key.eq {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #04121b;
  font-weight: 700;
  box-shadow: 0 16px 42px -20px var(--accent);
}

.key.eq:hover {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  filter: brightness(1.08);
}

.key.wide {
  grid-column: span 4;
  font-size: clamp(18px, 2.4vw, 24px);
}

/* ------------------------------------------------------------ connector */

.connector {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--ink-faint);
}

.connector .line {
  width: 1px;
  flex: 1;
  background: linear-gradient(transparent, var(--line-strong), transparent);
}

.connector .swap {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink-dim);
  font-size: 15px;
}

.connector .sync-label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.2em;
  color: var(--ink-faint);
}

/* -------------------------------------------------------------- status */

.status-line {
  margin: 18px 0 0;
  padding: 10px 14px;
  border: 1px solid rgba(248, 113, 113, 0.35);
  border-radius: 12px;
  background: rgba(248, 113, 113, 0.08);
  color: #fca5a5;
  font-size: 13px;
}

.status-line[hidden] {
  display: none;
}

/* -------------------------------------------------------------- footer */

.noscript {
  margin: 20px 0 0;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink-dim);
  background: rgba(255, 255, 255, 0.03);
}

.footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  justify-content: space-between;
  margin-top: clamp(30px, 5vw, 52px);
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--ink-faint);
  font-size: 12px;
}

.footer p {
  margin: 0;
}

.footer-sub {
  color: color-mix(in srgb, var(--ink-faint) 82%, transparent);
}

/* --------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 20;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(8, 14, 24, 0.94);
  color: var(--ink);
  font-size: 12.5px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  backdrop-filter: blur(8px);
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 900px) {
  .deck {
    grid-template-columns: minmax(0, 1fr);
  }

  .connector {
    display: none;
  }
}

@media (max-width: 560px) {
  .wrap {
    width: calc(100% - 28px);
  }

  .masthead {
    align-items: flex-start;
  }

  .status {
    font-size: 10.5px;
  }

  .value {
    font-size: clamp(26px, 8vw, 36px);
  }

  .key {
    min-height: 48px;
    border-radius: 12px;
  }

  .screen {
    padding: 11px 12px 9px;
  }
}

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