:root {
  --void: #080b12;
  --ink: #10151f;
  --panel: rgba(16, 21, 32, 0.78);
  --ember: #ff8a65;
  --ember-deep: #e85d3a;
  --ice: #b7d4de;
  --iris: #9aa8ff;
  --paper: #f3efe6;
  --mute: #9aa3b5;
  --line: rgba(183, 212, 222, 0.22);
  --text: #f3efe6;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --ui: Cinzel, "Palatino Linotype", serif;
  --display: "Cinzel Decorative", Cinzel, serif;
  --serif: "IM Fell English", "Times New Roman", serif;
  --xavian: "Noto Sans Glagolitic", "Noto Sans Runic", serif;
  --nav-h: 3.5rem;
  --dock-h: 4.4rem;
  --pad: clamp(1rem, 4.2vw, 5.5rem);
}

*,
*::before,
*::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--void);
  color: var(--text);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.6;
}

body {
  overflow-x: hidden;
  padding-bottom: calc(var(--dock-h) + env(safe-area-inset-bottom, 0px));
}

.orb {
  position: fixed;
  width: 480px;
  height: 480px;
  top: 0;
  left: 0;
  margin: -240px 0 0 -240px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(circle, rgba(255, 138, 101, 0.16) 0%, rgba(154, 168, 255, 0.1) 38%, transparent 68%);
  opacity: 0;
  transition: opacity 0.4s ease;
}

body.has-pointer .orb { opacity: 1; }

#field {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.mesh {
  position: fixed;
  inset: -20%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(154, 168, 255, 0.22), transparent 42%),
    radial-gradient(ellipse at 90% 20%, rgba(255, 138, 101, 0.14), transparent 38%),
    radial-gradient(ellipse at 50% 100%, rgba(8, 11, 18, 0.95), transparent 48%);
  animation: mesh 22s ease-in-out infinite alternate;
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 40%, transparent 20%, rgba(8, 11, 18, 0.55) 100%);
}

.nav, main, .site-foot, .dock { position: relative; z-index: 2; }

.nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-height: var(--nav-h);
  padding: 0.55rem var(--pad);
  padding-top: calc(0.55rem + env(safe-area-inset-top, 0px));
  position: sticky;
  top: 0;
  backdrop-filter: blur(18px);
  background: linear-gradient(to bottom, rgba(8, 11, 18, 0.92), rgba(8, 11, 18, 0.2) 85%, transparent);
  z-index: 6;
}

.brand {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  text-decoration: none;
  color: inherit;
}

.seal {
  font-family: "Noto Sans Runic", var(--xavian);
  color: var(--ember);
  font-size: 1.4rem;
  text-shadow: 0 0 18px rgba(255, 138, 101, 0.55);
  animation: pulse 5.5s ease-in-out infinite;
}

.brand-type {
  font-family: var(--display);
  font-size: 0.95rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-weight: 700;
}

.top-nav { display: none; gap: 1.5rem; }

.top-nav a,
.dock a {
  color: var(--mute);
  text-decoration: none;
  font-family: var(--ui);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-weight: 500;
}

.top-nav a:hover,
.dock a:hover { color: var(--paper); }

.hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  align-items: center;
  padding: 0.8rem var(--pad) 2.4rem;
}

.hero-copy { order: 2; text-align: center; }
.rings { order: 1; }

.rings {
  position: relative;
  width: min(250px, 70vw);
  aspect-ratio: 1;
  margin: 0 auto;
}

.ring { width: 100%; height: 100%; }

.spin-stroke {
  stroke: rgba(183, 212, 222, 0.35);
  stroke-width: 1;
  stroke-dasharray: 18 14;
  animation: dash 28s linear infinite;
}

.spin-stroke-b {
  stroke: rgba(255, 138, 101, 0.4);
  stroke-dasharray: 4 10;
  animation-duration: 16s;
  animation-direction: reverse;
}

.ring-text {
  fill: var(--ice);
  font-family: var(--xavian);
  font-size: 12px;
  letter-spacing: 5px;
}

.ring-a {
  animation: spin 70s linear infinite;
  transform-origin: 200px 200px;
  transform-box: view-box;
}
.ring-b {
  animation: spin 46s linear infinite reverse;
  fill: var(--ember);
  transform-origin: 200px 200px;
  transform-box: view-box;
}

.core {
  position: absolute;
  inset: 31%;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 35%, rgba(255, 138, 101, 0.22), transparent 60%),
    rgba(10, 14, 22, 0.92);
  border: 1px solid var(--line);
  box-shadow: 0 0 50px rgba(255, 138, 101, 0.18), inset 0 0 24px rgba(154, 168, 255, 0.12);
}

.core span {
  font-family: "Noto Sans Runic", var(--xavian);
  font-size: 2.4rem;
  color: var(--paper);
  text-shadow: 0 0 20px rgba(255, 138, 101, 0.7);
  animation: pulse 5.5s ease-in-out infinite;
}

.kicker {
  font-family: var(--ui);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-size: 0.68rem;
  color: var(--ember);
  margin: 0 0 0.7rem;
  font-weight: 500;
}

h1 {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(3.2rem, 16vw, 7rem);
  line-height: 0.86;
  margin: 0 0 0.9rem;
  letter-spacing: -0.04em;
  color: var(--paper);
}

.lede {
  max-width: 34rem;
  font-size: 1.18rem;
  color: var(--mute);
  margin: 0 auto 1.4rem;
}

.hero-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--paper);
  font-family: var(--ui);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.95rem 1.1rem;
  min-height: 48px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover { transform: translateY(-1px); }

.btn.primary {
  background: var(--ember);
  border-color: var(--ember);
  color: #1a0c08;
  box-shadow: 0 10px 30px rgba(255, 138, 101, 0.28);
}

.btn.ghost:hover {
  border-color: var(--ice);
  box-shadow: 0 0 0 1px var(--ice);
}

.btn.small { padding: 0.7rem 0.95rem; font-size: 0.65rem; min-height: 44px; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem 1rem;
  margin: 1.7rem 0 0;
  padding: 0;
}

.stats div {
  border-top: 1px solid var(--line);
  padding-top: 0.55rem;
  text-align: center;
}

.stats dt {
  font-family: var(--ui);
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--mute);
}

.stats dd {
  margin: 0.1rem 0 0;
  font-family: var(--display);
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--paper);
}

.translator, .codex, .ledger {
  padding: 2.2rem var(--pad);
  scroll-margin-top: calc(var(--nav-h) + env(safe-area-inset-top, 0px) + 0.4rem);
  scroll-margin-bottom: calc(var(--dock-h) + env(safe-area-inset-bottom, 0px) + 0.5rem);
}

.translator {
  background: linear-gradient(180deg, transparent, rgba(16, 21, 32, 0.65) 12%, rgba(16, 21, 32, 0.65) 88%, transparent);
}

.section-head { max-width: 38rem; margin-bottom: 1.3rem; }

.section-head.row {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-width: none;
}

h2 {
  font-family: var(--display);
  font-size: clamp(1.9rem, 7vw, 2.9rem);
  margin: 0 0 0.45rem;
  letter-spacing: -0.03em;
  font-weight: 700;
}

.mode-bar {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-bottom: 1rem;
}

.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  background: rgba(8, 11, 18, 0.65);
  border-radius: 999px;
  padding: 0.2rem;
  position: relative;
}

.mode {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--mute);
  font-family: var(--ui);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.64rem;
  padding: 0.85rem 0.4rem;
  min-height: 46px;
  cursor: pointer;
  border-radius: 999px;
  -webkit-tap-highlight-color: transparent;
}

.mode.is-active {
  background: rgba(255, 138, 101, 0.16);
  color: var(--paper);
}

#swap { width: 100%; }

.panes {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.pane {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  border-radius: 1.25rem;
}

.pane.flash {
  animation: bind 0.9s ease;
}

.pane header, .pane footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.55rem;
}

.pane h3 {
  margin: 0;
  font-family: var(--ui);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.68rem;
  color: var(--ember);
  font-weight: 500;
}

.count {
  font-family: var(--ui);
  font-size: 0.75rem;
  color: var(--mute);
}

textarea {
  flex: 1;
  width: 100%;
  min-height: 168px;
  margin: 0.7rem 0;
  resize: vertical;
  background: rgba(8, 11, 18, 0.7);
  border: 1px solid rgba(183, 212, 222, 0.14);
  color: var(--text);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.55;
  padding: 0.95rem;
  outline: none;
  border-radius: 0.85rem;
}

#result {
  font-family: var(--xavian);
  font-size: 1.15rem;
  letter-spacing: 0.08em;
  line-height: 1.75;
  color: var(--ice);
}

body.is-decode #source {
  font-family: var(--xavian);
  letter-spacing: 0.08em;
  color: var(--ice);
}

body.is-decode #result {
  font-family: var(--serif);
  letter-spacing: 0;
  color: var(--text);
}

textarea:focus {
  border-color: var(--ember);
  box-shadow: 0 0 0 3px rgba(255, 138, 101, 0.18);
}

.pane footer {
  min-height: 48px;
  flex-wrap: wrap;
  flex-direction: column;
  align-items: stretch;
}

.pane footer .btn.primary { width: 100%; }

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  width: 100%;
}

.status {
  margin: 0;
  font-family: var(--ui);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  color: var(--ice);
  text-align: center;
}

.status.is-error { color: var(--ember); }

.cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

.cards article {
  padding: 1.2rem 1.15rem;
  border: 1px solid var(--line);
  background: rgba(16, 21, 32, 0.7);
  border-radius: 1.1rem;
}

.num {
  font-family: var(--display);
  color: var(--ember);
  letter-spacing: 0.12em;
  font-weight: 700;
}

.cards h3 {
  font-family: var(--display);
  font-size: 1.15rem;
  margin: 0.3rem 0;
}

.cards p, .hint, .section-head p { color: var(--mute); }

.alphabet-panel {
  margin-top: 1.6rem;
  padding: 1.15rem;
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  background: rgba(16, 21, 32, 0.7);
}

.alphabet-panel h3 {
  font-family: var(--ui);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--ember);
  margin: 0 0 0.3rem;
}

.glyphs {
  list-style: none;
  padding: 0;
  margin: 0.9rem 0 0;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 0.32rem;
}

.glyphs li {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-family: var(--xavian);
  font-size: clamp(1rem, 4.6vw, 1.3rem);
  color: var(--ice);
  border: 1px solid var(--line);
  background: rgba(8, 11, 18, 0.55);
  border-radius: 0.45rem;
}

.ledger-list { display: grid; gap: 0.7rem; }

.entry {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.45rem;
  padding: 0.95rem 1rem;
  border: 1px solid var(--line);
  background: rgba(16, 21, 32, 0.65);
  border-radius: 1rem;
  cursor: pointer;
}

.entry:hover { border-color: var(--ember); }

.entry .dir {
  font-family: var(--ui);
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ice);
}

.entry .when {
  display: inline;
  color: var(--mute);
  font-size: 0.82rem;
  margin-left: 0.55rem;
}

.entry .src, .entry .out {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry .out { font-family: var(--xavian); color: var(--ice); }

.empty { color: var(--mute); font-style: italic; }

.site-foot {
  padding: 1.8rem var(--pad) 1.4rem;
  text-align: center;
  color: var(--mute);
  border-top: 1px solid var(--line);
  font-family: var(--ui);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.site-foot .seal { display: block; margin-bottom: 0.35rem; }

.dock {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 7;
  background: rgba(8, 11, 18, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(18px);
  padding: 0.35rem 0.4rem calc(0.35rem + env(safe-area-inset-bottom, 0px));
}

.dock a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.12rem;
  min-height: 52px;
}

.dock a.is-on { color: var(--paper); }
.dock a.is-on .dock-mark { color: var(--ember); }

.dock-mark {
  font-family: var(--xavian);
  color: var(--ice);
  font-size: 1.05rem;
  line-height: 1;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--dock-h) + env(safe-area-inset-bottom, 0px) + 0.8rem);
  transform: translateX(-50%);
  z-index: 9;
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ember);
  padding: 0.8rem 1.1rem;
  font-family: var(--ui);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.68rem;
  border-radius: 999px;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 2rem);
  text-align: center;
}

.rise {
  animation: rise 0.9s ease both;
}

.delay-1 { animation-delay: 0.1s; }
.delay-2 { animation-delay: 0.2s; }
.delay-3 { animation-delay: 0.32s; }
.delay-4 { animation-delay: 0.44s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes dash { to { stroke-dashoffset: -400; } }

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.06); opacity: 0.8; }
}

@keyframes mesh {
  from { transform: translate3d(-2%, -1%, 0) scale(1); }
  to { transform: translate3d(3%, 2%, 0) scale(1.08); }
}

@keyframes bind {
  0% { box-shadow: 0 0 0 0 rgba(255, 138, 101, 0.45); }
  100% { box-shadow: var(--shadow); }
}

@media (min-width: 640px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .hero-actions { display: flex; justify-content: center; }
  .hero-actions .btn { width: auto; }
  .rings { width: min(320px, 52vw); }
}

@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .top-nav { display: flex; }
  .nav { justify-content: space-between; }
  .dock { display: none; }
  .hero {
    grid-template-columns: minmax(280px, 420px) 1fr;
    gap: 3rem;
    min-height: calc(100vh - 84px);
    padding: 2rem var(--pad) 4rem;
  }
  .hero-copy { order: 2; text-align: left; }
  .lede { margin: 0 0 1.4rem; }
  .hero-actions { justify-content: flex-start; }
  .stats div { text-align: left; }
  .rings { order: 1; width: min(420px, 100%); }
  .core span { font-size: 3.1rem; }
  .lede { font-size: 1.28rem; }
  .mode-bar {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
  .modes { display: inline-flex; }
  .mode { padding: 0.75rem 1.15rem; }
  #swap { width: auto; }
  .panes { grid-template-columns: 1fr 1fr; }
  .cards { grid-template-columns: repeat(3, 1fr); }
  .section-head.row {
    flex-direction: row;
    justify-content: space-between;
    align-items: end;
  }
  .glyphs { grid-template-columns: repeat(16, minmax(0, 1fr)); }
  .entry {
    grid-template-columns: 8rem 1fr 1fr;
    gap: 1rem;
    align-items: center;
  }
  .entry .when { display: block; margin: 0.2rem 0 0; margin-left: 0; }
  .pane footer { flex-direction: row; align-items: center; }
  .pane footer .btn.primary { width: auto; }
  .btn-row { width: auto; }
  textarea { min-height: 230px; font-size: 1.1rem; }
  .toast {
    left: auto;
    right: 1.4rem;
    bottom: 1.4rem;
    transform: none;
  }
  .translator, .codex, .ledger { padding: 4rem var(--pad); }
}

@media (prefers-reduced-motion: reduce) {
  .ring-a, .ring-b, .spin-stroke, .core span, .seal, .mesh, .rise, .pane.flash, .orb {
    animation: none;
  }
  .rise { opacity: 1; transform: none; }
}
