:root {
  --ink: #0e0d0b;
  --ink-2: #17150f;
  --paper: #ece4d1;
  --paper-dim: #b8ae97;
  --bone: #f5ecd6;
  --copper: #c48a5a;
  --copper-deep: #8a5a36;
  --ember: #e9b27a;
  --line: rgba(236, 228, 209, 0.16);
  --line-strong: rgba(236, 228, 209, 0.42);
  --serif: 'Fraunces', 'Times New Roman', serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100vh;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--mono);
  font-size: 14px;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background:
    radial-gradient(ellipse at 50% 0%, #1a1612 0%, #0e0d0b 60%),
    var(--ink);
  background-attachment: fixed;
  position: relative;
  padding: 28px 40px 24px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 28px;
  min-height: 100vh;
}

/* --- Texture overlays --- */
.grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  opacity: 0.08;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' 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.8 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}
.vignette {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 99;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(0,0,0,0.55) 100%);
}

/* --- Chrome / Header --- */
.chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 2;
}
.chrome::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -4px;
  height: 1px;
  background: var(--line);
  opacity: 0.5;
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
  font-family: var(--serif);
}
.brand__mark {
  font-size: 22px;
  color: var(--copper);
  transform: translateY(2px);
}
.brand__word {
  font-size: 22px;
  font-weight: 500;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}
.chrome__meta {
  display: flex;
  gap: 28px;
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--paper-dim);
}
.meta-cell em { font-style: normal; color: var(--paper-dim); margin-right: 6px; }
.meta-cell b { font-weight: 500; color: var(--paper); font-family: var(--mono); }
.meta-cell--dot::before {
  content: "·";
  margin-right: 10px;
  color: var(--copper);
}
.meta-cell--live { display: inline-flex; align-items: center; gap: 8px; }
.pulse {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--copper);
  box-shadow: 0 0 0 0 rgba(196, 138, 90, 0.6);
  animation: pulse 2.2s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(196,138,90,0.6); }
  70% { box-shadow: 0 0 0 8px rgba(196,138,90,0); }
  100% { box-shadow: 0 0 0 0 rgba(196,138,90,0); }
}

/* --- Main stage --- */
.stage {
  display: grid;
  grid-template-columns: 180px 1fr 220px;
  align-items: center;
  gap: 40px;
  position: relative;
  z-index: 2;
}

.rail {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding-top: 18px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--paper-dim);
  position: relative;
}
.rail__label {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 300;
  font-size: 15px;
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--paper);
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.rail__label span {
  font-family: var(--mono);
  font-style: normal;
  color: var(--copper);
  margin-right: 8px;
  font-size: 11px;
  letter-spacing: 0.1em;
}
.rail__list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.rail__list li {
  position: relative;
  padding-left: 16px;
}
.rail__list li::before {
  content: "";
  position: absolute;
  left: 0; top: 6px;
  width: 8px; height: 1px;
  background: var(--copper);
}

/* --- Dial --- */
.dial {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  position: relative;
}

.dial__caption {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 10.5px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--paper-dim);
}
.caption__num { color: var(--copper); }
.caption__rule {
  width: 44px; height: 1px;
  background: var(--line-strong);
}
.caption__title { color: var(--paper); font-weight: 500; }

.ring-wrap {
  position: relative;
  width: min(560px, 62vmin);
  aspect-ratio: 1;
}
.ring {
  width: 100%;
  height: 100%;
  overflow: visible;
  transform: rotate(-90deg);
}
.ring__glow { opacity: 0.8; }
.ring__hairline {
  fill: none;
  stroke: var(--line);
  stroke-width: 1;
}
.ring__inner {
  fill: none;
  stroke: var(--line);
  stroke-width: 1;
  stroke-dasharray: 2 4;
}
.ring__track {
  fill: none;
  stroke: rgba(236, 228, 209, 0.08);
  stroke-width: 2;
}
.ring__progress {
  fill: none;
  stroke: var(--bone);
  stroke-width: 2.5;
  stroke-linecap: round;
  transition: stroke 0.6s ease;
}
.ring__progress.is-final {
  stroke: var(--copper);
  filter: drop-shadow(0 0 6px rgba(196, 138, 90, 0.5));
}
.ring__cap {
  fill: var(--bone);
  transition: fill 0.6s ease, r 0.3s ease;
}
.ring__cap.is-final {
  fill: var(--ember);
}
.ring__ticks line {
  stroke: var(--line-strong);
  stroke-width: 1;
}
.ring__ticks line.major {
  stroke: var(--paper-dim);
  stroke-width: 1.25;
}

/* Center readout */
.readout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 8%;
  pointer-events: none;
}
.readout__time {
  font-family: var(--serif);
  font-weight: 300;
  font-size: clamp(72px, 13vmin, 148px);
  letter-spacing: -0.04em;
  line-height: 0.95;
  color: var(--paper);
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  justify-content: center;
  font-feature-settings: "lnum", "tnum";
}
.readout__colon {
  margin: 0 0.04em;
  opacity: 0.6;
  animation: blink 1.1s steps(2, end) infinite;
}
.readout__colon.is-static { animation: none; opacity: 0.8; }
@keyframes blink {
  50% { opacity: 0.15; }
}

.readout__sub {
  margin-top: 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 10.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--paper-dim);
}
.sub__cell em { font-style: normal; margin-right: 6px; opacity: 0.65; }
.sub__cell b { font-weight: 500; color: var(--paper); }
.sub__sep { color: var(--copper); font-size: 8px; }

.readout__status {
  margin-top: 14px;
  font-size: 10px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--copper);
  font-weight: 500;
  min-height: 1em;
}

/* --- Controls --- */
.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 22px;
  background: transparent;
  color: var(--paper);
  border: 1px solid var(--line-strong);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.25s var(--ease), color 0.25s var(--ease), border-color 0.25s var(--ease), transform 0.2s var(--ease);
  position: relative;
  overflow: hidden;
}
.btn:hover {
  border-color: var(--paper);
  background: rgba(236, 228, 209, 0.04);
}
.btn:active { transform: translateY(1px); }
.btn--ghost { color: var(--paper-dim); }
.btn--ghost:hover { color: var(--paper); }

.btn--primary {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--paper);
  padding: 16px 30px;
  font-weight: 500;
}
.btn--primary:hover {
  background: var(--bone);
  color: var(--ink);
  transform: translateY(-1px);
  box-shadow: 0 10px 30px -12px rgba(245, 236, 214, 0.4);
}
.btn--primary.is-running {
  background: transparent;
  color: var(--paper);
  border-color: var(--copper);
}
.btn--primary.is-running:hover {
  background: rgba(196, 138, 90, 0.08);
}
.btn__glyph {
  font-size: 9px;
  color: var(--copper);
  margin-right: 2px;
}
.btn--primary .btn__glyph { color: var(--copper-deep); }
.btn--primary.is-running .btn__glyph { color: var(--copper); }
.btn__kbd {
  margin-left: 6px;
  padding: 2px 6px;
  background: rgba(14, 13, 11, 0.1);
  border: 1px solid currentColor;
  border-radius: 2px;
  font-size: 9px;
  opacity: 0.55;
  letter-spacing: 0.08em;
}
.btn--primary.is-running .btn__kbd {
  background: rgba(236, 228, 209, 0.04);
}

/* --- Presets / Right rail --- */
.presets {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.preset {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: baseline;
  gap: 8px;
  padding: 14px 14px 14px 16px;
  background: transparent;
  color: var(--paper-dim);
  border: 1px solid var(--line);
  border-left: 2px solid var(--line);
  font-family: var(--mono);
  text-align: left;
  cursor: pointer;
  transition: all 0.25s var(--ease);
  border-radius: 2px;
  position: relative;
}
.preset:hover {
  color: var(--paper);
  border-color: var(--line-strong);
  border-left-color: var(--copper);
}
.preset.is-active {
  color: var(--paper);
  border-color: var(--line-strong);
  border-left-color: var(--copper);
  background: rgba(236, 228, 209, 0.025);
}
.preset.is-active::after {
  content: "";
  position: absolute;
  right: 12px; top: 50%;
  width: 5px; height: 5px;
  margin-top: -2.5px;
  background: var(--copper);
  border-radius: 50%;
}
.preset__num {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 300;
  line-height: 1;
  color: var(--paper);
  font-variant-numeric: tabular-nums;
}
.preset__unit {
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--paper-dim);
}
.preset__name {
  justify-self: end;
  font-size: 10px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--paper-dim);
}
.preset--custom .preset__num { font-size: 20px; }

.custom-row {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.custom-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: rgba(236, 228, 209, 0.025);
  border: 1px solid var(--line);
  border-radius: 2px;
}
.custom-label span {
  font-size: 9px;
  letter-spacing: 0.2em;
  color: var(--copper);
  text-transform: uppercase;
}
.custom-label input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--paper);
  font-family: var(--serif);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
/* Hide number input spinners */
.custom-label input::-webkit-outer-spin-button,
.custom-label input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.custom-label input[type=number] { -moz-appearance: textfield; }

.custom-apply {
  padding: 0 14px;
  background: var(--copper);
  color: var(--ink);
  border: none;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-weight: 500;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.2s ease;
}
.custom-apply:hover { background: var(--ember); }

/* --- Footer --- */
.footer {
  display: grid;
  grid-template-columns: 1fr 3fr 1fr;
  gap: 40px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--paper-dim);
  position: relative;
  z-index: 2;
}
.footer__cell { display: flex; flex-direction: column; gap: 4px; }
.footer__cell em { font-style: normal; opacity: 0.55; font-size: 9px; }
.footer__cell b { font-family: var(--serif); font-size: 14px; font-weight: 400; color: var(--paper); letter-spacing: 0.02em; text-transform: none; }
.footer__cell--wide b { font-style: italic; opacity: 0.8; }

/* --- Completion flourish --- */
body.is-complete .ring__progress {
  stroke: var(--ember);
  animation: completePulse 1.4s ease-out 2;
}
@keyframes completePulse {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(233, 178, 122, 0)); }
  50% { filter: drop-shadow(0 0 16px rgba(233, 178, 122, 0.7)); }
}
body.is-complete .readout__time {
  animation: completeFade 1.4s ease-out;
}
@keyframes completeFade {
  0% { color: var(--ember); }
  100% { color: var(--paper); }
}

/* --- Entry animation --- */
.chrome, .rail, .dial, .footer { animation: rise 1s var(--ease) both; }
.rail--left { animation-delay: 0.15s; }
.dial { animation-delay: 0.25s; }
.rail--right { animation-delay: 0.35s; }
.footer { animation-delay: 0.5s; }
@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Responsive --- */
@media (max-width: 1100px) {
  .stage { grid-template-columns: 1fr; gap: 28px; }
  .rail { padding-top: 0; max-width: 520px; margin: 0 auto; width: 100%; }
  .rail--left { order: 3; }
  .rail--right { order: 2; }
  .dial { order: 1; }
  .presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .preset { grid-template-columns: 1fr; justify-items: start; }
  .preset__name { justify-self: start; }
  .rail__list { flex-direction: row; flex-wrap: wrap; gap: 20px; }
}

@media (max-width: 720px) {
  body { padding: 20px 18px; gap: 20px; }
  .chrome { flex-direction: column; align-items: flex-start; gap: 12px; }
  .chrome__meta { gap: 18px; font-size: 9.5px; }
  .brand__word { font-size: 18px; }
  .brand__mark { font-size: 18px; }
  .ring-wrap { width: min(92vw, 440px); }
  .readout__sub { gap: 10px; font-size: 9px; }
  .controls { flex-wrap: wrap; justify-content: center; gap: 8px; }
  .btn { padding: 12px 16px; font-size: 10px; }
  .btn--primary { padding: 14px 22px; }
  .btn__kbd { display: none; }
  .presets { grid-template-columns: repeat(2, 1fr); }
  .footer { grid-template-columns: 1fr; gap: 14px; }
}

@media (max-width: 380px) {
  .chrome__meta { flex-wrap: wrap; gap: 12px; }
  .readout__sub { flex-direction: column; gap: 4px; }
  .sub__sep { display: none; }
  .custom-row { grid-template-columns: 1fr 1fr; }
  .custom-apply { grid-column: 1 / -1; padding: 10px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .pulse { animation: none; }
  .readout__colon { animation: none; opacity: 0.7; }
}
