:root {
  --bg: #0a0a0a;
  --paper: #f3efe7;
  --ink: #f3efe7;
  --ink-dim: rgba(243, 239, 231, 0.55);
  --ink-faint: rgba(243, 239, 231, 0.28);
  --bvg-red: #d61f26;
  --rule: rgba(243, 239, 231, 0.14);
  --line-color: #f3efe7;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  position: fixed;
  inset: 0;
  height: 100svh;
  isolation: isolate;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.18 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  opacity: 0.45;
  mix-blend-mode: overlay;
  pointer-events: none;
  z-index: -1;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.45) 100%);
  pointer-events: none;
  z-index: -1;
}

.page {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  height: 100svh;
  padding: calc(20px + var(--safe-top)) clamp(20px, 4vw, 56px) calc(16px + var(--safe-bottom));
  max-width: 1200px;
  margin: 0 auto;
  gap: clamp(16px, 3vh, 28px);
}

/* ── Top bar ───────────────────────────────────────── */
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 14px;
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 8px;
  border: 1px solid var(--rule);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-dim);
  text-decoration: none;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}
.back:hover,
.back:focus-visible {
  color: var(--ink);
  border-color: var(--ink-dim);
  background: rgba(243, 239, 231, 0.04);
  outline: none;
}

.top-right {
  display: inline-flex;
  align-items: center;
  gap: 14px;
}

.meta {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ── Lang toggle ───────────────────────────────────── */
.lang {
  display: inline-flex;
  border: 1px solid var(--rule);
  font-family: 'JetBrains Mono', monospace;
}
.lang button {
  appearance: none;
  background: transparent;
  border: 0;
  padding: 6px 10px;
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--ink-faint);
  cursor: pointer;
  text-transform: uppercase;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.18s ease, background 0.18s ease;
}
.lang button + button { border-left: 1px solid var(--rule); }
.lang button:hover { color: var(--ink-dim); }
.lang button.is-active {
  background: var(--paper);
  color: #0a0a0a;
}

/* ── Stage / lines ─────────────────────────────────── */
.stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 8px 0;
}

.lineset {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: clamp(23px, 5.85vh, 52px);
}

.line-row {
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: center;
  gap: 16px;
  animation: line-in 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.line-row.removing { animation: line-out 0.26s ease-in forwards; }

@keyframes line-in {
  from { opacity: 0; transform: scaleX(0.5) translateY(4px); transform-origin: left; }
  to   { opacity: 1; transform: scaleX(1) translateY(0); transform-origin: left; }
}
@keyframes line-out {
  to { opacity: 0; transform: translateX(-12px); }
}

.line-no {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--ink-faint);
  text-transform: uppercase;
}

.line {
  display: block;
  width: 100%;
  height: 3px;
  background: var(--line-color);
  box-shadow: 0 0 12px rgba(243, 239, 231, 0.3);
  transform-origin: left;
}

@media (prefers-reduced-motion: reduce) {
  .line-row { animation: none; }
  .line-row.removing { animation: none; opacity: 0; }
}

/* ── Controls ──────────────────────────────────────── */
.controls {
  display: grid;
  grid-template-columns: 1fr auto 1.4fr;
  align-items: stretch;
  gap: 10px;
  border-top: 1px solid var(--rule);
  padding-top: clamp(12px, 2vh, 18px);
}

.ctrl {
  appearance: none;
  border: 0;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-size: clamp(13px, 3vw, 15px);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px 20px;
  min-height: 56px;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease, color 0.16s ease, opacity 0.16s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.ctrl:disabled { opacity: 0.32; cursor: not-allowed; }

.ctrl-remove {
  background: transparent;
  color: var(--ink-dim);
  border: 1px solid var(--rule);
}
.ctrl-remove:not(:disabled):hover,
.ctrl-remove:not(:disabled):focus-visible {
  color: var(--ink);
  border-color: var(--ink-dim);
  background: rgba(243, 239, 231, 0.04);
  outline: none;
}

.ctrl-add {
  background: var(--paper);
  color: #0a0a0a;
  box-shadow: 8px 8px 0 var(--bvg-red);
}
.ctrl-add:not(:disabled):hover,
.ctrl-add:not(:disabled):focus-visible {
  background: var(--bvg-red);
  color: var(--paper);
  transform: translate(4px, 4px);
  box-shadow: 4px 4px 0 #0a0a0a;
  outline: none;
}
.ctrl-add:not(:disabled):active {
  transform: translate(8px, 8px);
  box-shadow: 0 0 0 #0a0a0a;
}

.ctrl-label { white-space: nowrap; }

.counter {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
  font-size: clamp(20px, 4.6vw, 26px);
  min-width: 56px;
  text-align: center;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  padding: 0 10px;
  letter-spacing: 0.1em;
  align-self: center;
  border-left: 1px solid var(--rule);
  border-right: 1px solid var(--rule);
}

/* ── Footer ────────────────────────────────────────── */
.foot {
  border-top: 1px solid var(--rule);
  padding-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  flex-wrap: wrap;
  gap: 10px 18px;
}
.foot .dot { color: var(--bvg-red); }
.foot-rec { display: inline-flex; align-items: center; gap: 6px; }

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 720px) {
  .meta { display: none; }
}

@media (max-width: 480px) {
  .ctrl-remove .ctrl-label { display: none; }
  .line-row { grid-template-columns: 32px 1fr; gap: 12px; }
  .controls { grid-template-columns: auto auto 1fr; }
}

@media (max-height: 600px) {
  .lineset { gap: clamp(14px, 3.5vh, 28px); }
}
