:root {
  --bg-deep: #0c0b0a;
  --bg-soft: #151310;
  --ink: #ece5d5;
  --ink-dim: rgba(236, 229, 213, 0.52);
  --ink-faint: rgba(236, 229, 213, 0.26);
  --gold: #c9a86a;
  --gold-hi: #e6ca8e;
  --gold-dim: rgba(201, 168, 106, 0.42);
  --gold-line: rgba(201, 168, 106, 0.22);
  --amber: #c09463;
  --font-display: "Fraunces", "Didot", Georgia, "Times New Roman", serif;
  --font-ui: "Manrope", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
}

body {
  background:
    radial-gradient(120% 90% at 50% 38%, #171412 0%, var(--bg-deep) 58%, #090807 100%);
  color: var(--ink);
  font-family: var(--font-ui);
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-font-smoothing: antialiased;
}

/* ---------- ambient layers ---------- */

#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

#grain {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0.045;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.8'/%3E%3C/svg%3E");
}

.halo {
  position: fixed;
  left: 50%;
  top: 42%;
  width: min(78vw, 430px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(
    circle,
    rgba(201, 168, 106, 0.09) 0%,
    rgba(201, 168, 106, 0.035) 42%,
    transparent 70%
  );
  animation: haloBreathe 7s ease-in-out infinite;
}

@keyframes haloBreathe {
  0%,
  100% {
    opacity: 0.75;
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.045);
  }
}

/* ---------- layout ---------- */

.app {
  position: relative;
  z-index: 3;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding:
    calc(env(safe-area-inset-top) + 18px)
    calc(env(safe-area-inset-right) + 20px)
    calc(env(safe-area-inset-bottom) + 18px)
    calc(env(safe-area-inset-left) + 20px);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 10px;
  letter-spacing: 0.52em;
  color: var(--gold-dim);
  font-weight: 600;
}

.brand-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 10px rgba(201, 168, 106, 0.75);
}

.head-actions {
  display: flex;
  gap: 10px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--gold-line);
  background: rgba(255, 255, 255, 0.022);
  color: var(--ink-dim);
  cursor: pointer;
  transition: color 0.35s, border-color 0.35s, box-shadow 0.35s, transform 0.12s;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.icon-btn:active {
  transform: scale(0.92);
}

@media (hover: hover) {
  .icon-btn:hover {
    color: var(--gold-hi);
    border-color: rgba(201, 168, 106, 0.5);
    box-shadow: 0 0 18px rgba(201, 168, 106, 0.14);
  }
}

/* ---------- dial ---------- */

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

#dial {
  position: relative;
  width: min(80vw, 380px);
  aspect-ratio: 1;
  cursor: pointer;
  outline: none;
}

#dialSvg {
  width: 100%;
  height: 100%;
  display: block;
}

#track {
  fill: none;
  stroke: rgba(236, 229, 213, 0.055);
  stroke-width: 1.5;
}

#segPre,
#segExtract {
  fill: none;
  stroke-width: 5;
  stroke-linecap: butt;
}

#segPre {
  stroke: rgba(192, 148, 99, 0.34);
}

#segExtract {
  stroke: rgba(201, 168, 106, 0.5);
}

#progress {
  fill: none;
  stroke: url(#goldGrad);
  stroke-width: 5;
  stroke-linecap: round;
  filter: drop-shadow(0 0 6px rgba(201, 168, 106, 0.55));
  transition: opacity 0.3s;
}

#ticks line {
  stroke: rgba(236, 229, 213, 0.14);
  stroke-width: 1.2;
}

#ticks line.tick5 {
  stroke: rgba(236, 229, 213, 0.3);
  stroke-width: 1.6;
}

#boundaryTick {
  stroke: var(--gold);
  stroke-width: 2.2;
  stroke-linecap: round;
  opacity: 0.65;
  filter: drop-shadow(0 0 4px rgba(201, 168, 106, 0.6));
}

#dialCenter {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
}

#phaseLabel {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  color: var(--ink-faint);
  transition: color 0.5s;
}

#timeReadout {
  display: flex;
  align-items: baseline;
  justify-content: center;
  line-height: 1;
  font-family: var(--font-display);
  font-variation-settings: "SOFT" 0, "WONK" 0;
  font-weight: 320;
  font-size: clamp(88px, 25vmin, 148px);
  color: var(--ink);
  text-shadow: 0 0 34px rgba(230, 202, 142, 0.12);
  transition: opacity 0.4s;
  font-variant-numeric: tabular-nums;
}

#time {
  min-width: 1.7em;
  text-align: center;
}

#timeUnit {
  font-size: 0.19em;
  font-weight: 500;
  color: var(--gold-dim);
  margin-left: 0.45em;
  font-family: var(--font-ui);
}

#hint {
  height: 16px;
  font-size: 10.5px;
  letter-spacing: 0.34em;
  text-indent: 0.34em;
  color: var(--ink-faint);
  transition: opacity 0.4s;
}

/* phase moods */

body.phase-pre #phaseLabel {
  color: rgba(192, 148, 99, 0.75);
}

body.phase-extract #phaseLabel {
  color: var(--gold-dim);
}

body.running #timeReadout {
  text-shadow: 0 0 44px rgba(230, 202, 142, 0.2);
}

body.paused #timeReadout {
  opacity: 0.42;
}

body.paused #phaseLabel {
  animation: blink 1.8s ease-in-out infinite;
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

body.done #dialCenter {
  animation: donePulse 1.9s ease-in-out infinite;
}

@keyframes donePulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.018);
  }
}

body.done #timeReadout {
  color: var(--gold-hi);
  text-shadow: 0 0 46px rgba(230, 202, 142, 0.35);
}

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

.foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding-bottom: 4px;
}

.footline {
  width: 42px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-dim), transparent);
}

#stateNote {
  font-size: 10.5px;
  letter-spacing: 0.4em;
  text-indent: 0.4em;
  color: var(--ink-faint);
  min-height: 14px;
  transition: color 0.5s;
}

body.done #stateNote {
  color: var(--gold-dim);
}

/* ---------- settings sheet ---------- */

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 8;
  background: rgba(6, 5, 4, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9;
  max-width: 480px;
  margin: 0 auto;
  background: rgba(23, 21, 17, 0.94);
  -webkit-backdrop-filter: blur(26px) saturate(1.2);
  backdrop-filter: blur(26px) saturate(1.2);
  border-top: 1px solid rgba(201, 168, 106, 0.16);
  border-radius: 28px 28px 0 0;
  padding: 12px 26px calc(env(safe-area-inset-bottom) + 26px);
  transform: translateY(104%);
  transition: transform 0.48s cubic-bezier(0.22, 0.9, 0.25, 1);
  box-shadow: 0 -18px 60px rgba(0, 0, 0, 0.5);
}

.sheet.open {
  transform: translateY(0);
}

.sheet-grip {
  width: 38px;
  height: 4px;
  border-radius: 4px;
  background: rgba(236, 229, 213, 0.14);
  margin: 2px auto 18px;
}

.sheet-title {
  text-align: center;
  font-size: 12px;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  color: var(--gold-dim);
  font-weight: 600;
  margin-bottom: 26px;
}

.row {
  margin-bottom: 24px;
}

.row-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}

.row-label {
  font-size: 13px;
  letter-spacing: 0.16em;
  color: var(--ink-dim);
}

.row-value {
  font-family: var(--font-display);
  font-weight: 340;
  font-size: 24px;
  color: var(--gold-hi);
}

.row-value span {
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--gold-dim);
  margin-left: 3px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(
    to right,
    var(--gold) 0%,
    var(--gold) var(--fill, 0%),
    rgba(201, 168, 106, 0.16) var(--fill, 0%),
    rgba(201, 168, 106, 0.16) 100%
  );
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -10px;
  border-radius: 50%;
  background: #171410;
  border: 1.5px solid var(--gold);
  box-shadow: 0 0 14px rgba(201, 168, 106, 0.35);
  transition: transform 0.15s;
}

input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.16);
}

input[type="range"]::-moz-range-track {
  height: 2px;
  border-radius: 2px;
  background: rgba(201, 168, 106, 0.16);
}

input[type="range"]::-moz-range-progress {
  height: 2px;
  border-radius: 2px;
  background: var(--gold);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #171410;
  border: 1.5px solid var(--gold);
  box-shadow: 0 0 14px rgba(201, 168, 106, 0.35);
}

.row-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 9.5px;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.toggle-row .row-label {
  margin-bottom: 0;
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .knob {
  position: absolute;
  inset: 0;
  border-radius: 26px;
  background: rgba(236, 229, 213, 0.09);
  border: 1px solid rgba(236, 229, 213, 0.14);
  transition: background 0.35s, border-color 0.35s;
  cursor: pointer;
}

.switch .knob::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink-dim);
  transition: transform 0.35s cubic-bezier(0.3, 0.9, 0.3, 1), background 0.35s;
}

.switch input:checked + .knob {
  background: rgba(201, 168, 106, 0.24);
  border-color: var(--gold-line);
}

.switch input:checked + .knob::after {
  transform: translateX(20px);
  background: var(--gold-hi);
  box-shadow: 0 0 10px rgba(201, 168, 106, 0.55);
}

.sheet-close {
  width: 100%;
  height: 48px;
  border-radius: 24px;
  border: 1px solid var(--gold-line);
  background: rgba(201, 168, 106, 0.06);
  color: var(--gold-hi);
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  cursor: pointer;
  transition: background 0.35s, box-shadow 0.35s, transform 0.12s;
  margin-top: 6px;
}

.sheet-close:active {
  transform: scale(0.98);
}

@media (hover: hover) {
  .sheet-close:hover {
    background: rgba(201, 168, 106, 0.12);
    box-shadow: 0 0 22px rgba(201, 168, 106, 0.14);
  }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .halo,
  body.done #dialCenter,
  body.paused #phaseLabel {
    animation: none;
  }
  * {
    transition-duration: 0.01ms !important;
  }
}
