:root {
  --bg: #050608;
  --bg-2: #0b0d11;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-2: rgba(255, 255, 255, 0.08);
  --line: rgba(255, 255, 255, 0.08);
  --text: #f3f5f8;
  --muted: #7d838e;
  --dim: #3a3f48;
  --accent: #3ee6c1;
  --energy: 0;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --display: "Saira", "SF Pro Display", system-ui, sans-serif;
  --ui: "Inter Tight", -apple-system, "SF Pro Text", system-ui, sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Ambient light ---------- */
.ambient {
  position: fixed;
  inset: -20%;
  pointer-events: none;
  background:
    radial-gradient(42% 32% at 50% 36%, color-mix(in oklab, var(--accent) calc(8% + var(--energy) * 22%), transparent), transparent 72%),
    radial-gradient(60% 50% at 50% 110%, rgba(255, 255, 255, 0.03), transparent 70%);
  transition: background 0.6s linear;
}

/* ---------- Layout ---------- */
.app {
  position: relative;
  height: 100svh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  padding: calc(var(--sat) + 10px) calc(var(--sar) + 16px) calc(var(--sab) + 14px) calc(var(--sal) + 16px);
  opacity: 0;
  transform: scale(.97);
  transition: opacity .7s var(--ease-out), transform .9s var(--ease-out);
}
.app.on { opacity: 1; transform: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  transition: color .3s;
}
.bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; }
.bars i {
  width: 3px; border-radius: 2px;
  background: var(--dim);
  transition: background .4s, box-shadow .4s;
}
.bars i:nth-child(1) { height: 4px; }
.bars i:nth-child(2) { height: 7px; }
.bars i:nth-child(3) { height: 10px; }
.bars i:nth-child(4) { height: 12px; }
.gps[data-level="1"] .bars i:nth-child(-n+1),
.gps[data-level="2"] .bars i:nth-child(-n+2),
.gps[data-level="3"] .bars i:nth-child(-n+3),
.gps[data-level="4"] .bars i:nth-child(-n+4) { background: var(--accent); }
.gps[data-level="1"] .bars i:nth-child(-n+1) { background: #ff6b5a; }
.gps[data-level="2"] .bars i:nth-child(-n+2) { background: #ffb547; }
.gps:not([data-level="0"]) { color: var(--text); }
.gps.searching .bars i { animation: search 1.2s ease-in-out infinite; }
.gps.searching .bars i:nth-child(2) { animation-delay: .15s; }
.gps.searching .bars i:nth-child(3) { animation-delay: .3s; }
.gps.searching .bars i:nth-child(4) { animation-delay: .45s; }
@keyframes search { 0%, 100% { background: var(--dim); } 50% { background: var(--muted); } }

.clock {
  font-family: var(--display);
  font-weight: 500;
  font-size: 17px;
  letter-spacing: .04em;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  transition: transform .25s var(--ease-spring), color .2s;
}
.icon-btn:active { transform: scale(.9); color: var(--text); }

/* ---------- Gauge ---------- */
.gauge-wrap {
  display: grid;
  place-items: center;
  min-height: 0;
}

.gauge {
  position: relative;
  width: min(100%, 58svh, 460px);
  aspect-ratio: 1;
  container-type: inline-size;
}

.gauge-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }

.track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.06);
  stroke-width: 14;
  stroke-linecap: round;
}
.arc, .arc-glow {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-dasharray: 801.1 801.1;
  stroke-dashoffset: 801.1;
}
.arc { stroke-width: 14; }
.arc-glow { stroke-width: 22; opacity: calc(.25 + var(--energy) * .35); }

.tick { stroke: rgba(255, 255, 255, 0.16); stroke-linecap: round; transition: stroke .35s; }
.tick.major { stroke: rgba(255, 255, 255, 0.34); }
.tick.lit { stroke: var(--accent); }
.tick-label {
  fill: var(--muted);
  font-family: var(--display);
  font-size: 15px;
  font-weight: 500;
  text-anchor: middle;
  dominant-baseline: central;
  transition: fill .35s;
}
.tick-label.lit { fill: var(--text); }

.tip-core { fill: #fff; }
.tip { transition: opacity .3s; }

.readout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 4cqw;
}

.digits {
  display: flex;
  font-family: var(--display);
  font-weight: 600;
  font-size: 34cqw;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  transition: opacity .4s, filter .4s;
}
.digits.stale { opacity: .35; filter: blur(1px); }

.digit {
  position: relative;
  height: 1em;
  width: .58em;
  overflow: hidden;
  transition: width .5s var(--ease-out), opacity .35s;
  -webkit-mask-image: linear-gradient(transparent, #000 14%, #000 86%, transparent);
  mask-image: linear-gradient(transparent, #000 14%, #000 86%, transparent);
}
.digit.hidden { width: 0; opacity: 0; }
.strip {
  display: flex;
  flex-direction: column;
  transition: transform .38s var(--ease-out);
  will-change: transform;
}
.strip span { display: block; height: 1em; text-align: center; }

.unit {
  margin-top: 1.5cqw;
  padding: 1.2cqw 3.6cqw;
  border-radius: 999px;
  font-family: var(--display);
  font-size: 4.4cqw;
  font-weight: 600;
  letter-spacing: .22em;
  text-indent: .22em;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--surface);
  transition: transform .25s var(--ease-spring), color .2s;
}
.unit:active { transform: scale(.92); color: var(--text); }

/* ---------- Stats ---------- */
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 14px 4px;
  border-radius: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  position: relative;
}
.stat + .stat::before {
  content: "";
  position: absolute;
  left: 0; top: 15%; bottom: 15%;
  width: 1px;
  background: var(--line);
}
.label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}
.val {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.val small { font-size: 12px; color: var(--muted); margin-left: 2px; font-weight: 500; }

/* ---------- Media ---------- */
.media {
  position: relative;
  overflow: hidden;
  border-radius: 28px;
  padding: 16px 16px 12px;
  background: rgba(20, 22, 27, 0.72);
  border: 1px solid var(--line);
  isolation: isolate;
}
.media-bg {
  position: absolute;
  inset: -40px;
  z-index: -1;
  background-size: cover;
  background-position: center;
  filter: blur(40px) saturate(1.5);
  opacity: 0;
  transform: scale(1.1);
  transition: opacity 1s ease, background-image .6s;
}
.media-bg.on { opacity: .42; }
.media::after {
  content: "";
  position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(180deg, rgba(5, 6, 8, .15), rgba(5, 6, 8, .55));
}

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

.art {
  position: relative;
  flex: none;
  width: 58px; height: 58px;
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface-2);
  display: grid; place-items: center;
  color: var(--muted);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}
.art img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  opacity: 0;
  transform: scale(1.08);
  transition: opacity .5s ease, transform .7s var(--ease-out);
}
.art img.loaded { opacity: 1; transform: none; }

.meta { flex: 1; min-width: 0; }
.title-wrap { overflow: hidden; -webkit-mask-image: linear-gradient(90deg, #000 88%, transparent); mask-image: linear-gradient(90deg, #000 88%, transparent); }
.title {
  display: inline-block;
  white-space: nowrap;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -.01em;
}
.title.marquee { animation: marquee var(--mq-dur, 10s) linear infinite; padding-right: 40px; }
@keyframes marquee {
  0%, 18% { transform: translateX(0); }
  82%, 100% { transform: translateX(var(--mq-dist, 0)); }
}
.artist {
  margin-top: 3px;
  font-size: 14px;
  color: rgba(243, 245, 248, .62);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.swap { animation: swap .55s var(--ease-out); }
@keyframes swap { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.connect-btn {
  display: none;
  flex: none;
  height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  background: #1ed760;
  color: #04120a;
  font-weight: 700;
  font-size: 14px;
  transition: transform .25s var(--ease-spring);
}
.connect-btn:active { transform: scale(.94); }
.media[data-state="off"] .connect-btn { display: block; }
.media[data-state="off"] .controls,
.media[data-state="off"] .progress { opacity: .3; pointer-events: none; }

.progress {
  margin: 14px 2px 4px;
  height: 3px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .12);
  overflow: hidden;
}
.progress i {
  display: block;
  height: 100%;
  background: rgba(255, 255, 255, .85);
  transform-origin: left;
  transform: scaleX(0);
  transition: transform .5s linear;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding-top: 6px;
  transition: opacity .3s;
}
.ctl {
  width: 72px; height: 64px;
  display: grid; place-items: center;
  border-radius: 20px;
  color: var(--text);
  transition: transform .3s var(--ease-spring), background .2s;
}
.ctl:active { transform: scale(.86); background: var(--surface-2); }
.ctl.play {
  width: 74px; height: 74px;
  border-radius: 50%;
  background: var(--text);
  color: #08090b;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
.ctl.play:active { background: #d9dce1; }
.ctl.play svg { position: absolute; transition: transform .35s var(--ease-spring), opacity .2s; }
.ctl.play { position: relative; }
.ctl.play .i-pause { opacity: 0; transform: scale(.4) rotate(-30deg); }
.media.playing .ctl.play .i-play { opacity: 0; transform: scale(.4) rotate(30deg); }
.media.playing .ctl.play .i-pause { opacity: 1; transform: none; }
.ctl.bump { animation: bump .45s var(--ease-out); }
@keyframes bump { 30% { transform: translateX(var(--bx, 6px)); } }

/* ---------- Landscape ---------- */
@media (orientation: landscape) {
  .app {
    grid-template-columns: minmax(0, 1.05fr) minmax(300px, .95fr);
    grid-template-rows: auto minmax(0, 1fr);
    column-gap: 22px;
    padding-top: calc(var(--sat) + 8px);
    padding-bottom: calc(var(--sab) + 10px);
  }
  .topbar { grid-column: 1 / -1; }
  .gauge { width: min(100%, calc(100dvh - var(--sat) - var(--sab) - 70px), 560px); }
  .side { justify-content: center; }
  .stats { grid-template-columns: repeat(2, 1fr); row-gap: 14px; }
  .stat:nth-child(3)::before { display: none; }
}
@media (orientation: landscape) and (max-height: 430px) {
  .topbar { height: 36px; }
  .side { gap: 8px; }
  .stats { grid-template-columns: repeat(4, 1fr); padding: 10px 2px; }
  .stat:nth-child(3)::before { display: block; }
  .val { font-size: 19px; }
  .media { padding: 12px 14px 8px; border-radius: 22px; }
  .art { width: 48px; height: 48px; }
  .progress { margin-top: 10px; }
  .ctl { height: 54px; }
  .ctl.play { width: 62px; height: 62px; }
}

/* ---------- Settings sheet ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, .55);
  opacity: 0; visibility: hidden;
  transition: opacity .35s, visibility .35s;
}
.scrim.on { opacity: 1; visibility: visible; }

.sheet {
  position: fixed;
  z-index: 41;
  left: 0; right: 0; bottom: 0;
  margin: 0 auto;
  max-width: 560px;
  max-height: 88dvh;
  display: flex; flex-direction: column;
  border-radius: 28px 28px 0 0;
  background: #121419;
  border: 1px solid var(--line);
  border-bottom: 0;
  transform: translateY(105%);
  transition: transform .5s var(--ease-out);
  -webkit-user-select: text;
  user-select: text;
}
.sheet.on { transform: none; }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--dim); margin: 10px auto 0; flex: none; }
.sheet-scroll {
  overflow-y: auto;
  padding: 12px 20px calc(var(--sab) + 20px);
  -webkit-overflow-scrolling: touch;
}
.sheet h2 { font-family: var(--display); font-size: 26px; font-weight: 650; margin: 4px 0 16px; }
.sheet h3 {
  font-size: 12px; font-weight: 650; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); margin: 22px 4px 8px;
}
.group {
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 4px 14px;
}
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 56px;
  font-size: 16px;
}
.row + .row { border-top: 1px solid var(--line); }
.row > span:first-child { white-space: nowrap; }
.row em, .field em { font-style: normal; color: var(--muted); font-size: 13px; }

.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 12px;
  background: rgba(0, 0, 0, .35);
}
.seg button {
  min-width: 52px;
  height: 34px;
  padding: 0 10px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  transition: background .25s, color .25s;
}
.seg button.on { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 0 rgba(255, 255, 255, .06) inset; }

.status-line { padding: 12px 0 4px; font-size: 14px; color: var(--muted); }
.status-line.ok { color: #1ed760; }
.field { display: block; padding: 10px 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .copy-row input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, .35);
  color: var(--text);
  font: 15px/1 ui-monospace, "SF Mono", Menlo, monospace;
  outline: none;
}
.field input:focus, .copy-row input:focus { border-color: var(--accent); }
.copy-row { display: flex; align-items: center; gap: 8px; }
.copy-row code {
  flex: 1; min-width: 0;
  padding: 11px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, .35);
  font: 13px/1.3 ui-monospace, "SF Mono", Menlo, monospace;
  overflow-wrap: anywhere;
  color: rgba(243, 245, 248, .85);
}
.mini {
  flex: none;
  height: 40px; padding: 0 14px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 14px; font-weight: 600;
}
.btn-row { display: flex; gap: 10px; padding: 8px 0 14px; }
.btn {
  height: 48px;
  padding: 0 18px;
  border-radius: 14px;
  font-weight: 650;
  font-size: 15px;
  transition: transform .25s var(--ease-spring), opacity .2s;
}
.btn:active { transform: scale(.96); }
.btn.primary { background: var(--text); color: #07080a; flex: 1; }
.btn.ghost { background: var(--surface-2); }
.btn.small { height: 38px; font-size: 14px; }
.btn.wide { width: 100%; margin-top: 20px; }
.btn[hidden], .handoff[hidden] { display: none; }
.handoff { padding: 12px 0 14px; border-top: 1px solid var(--line); }
.handoff p { font-size: 13px; line-height: 1.45; color: var(--muted); margin-bottom: 10px; }

.toggle {
  position: relative;
  width: 52px; height: 32px;
  border-radius: 999px;
  background: var(--dim);
  transition: background .3s;
}
.toggle i {
  position: absolute; top: 3px; left: 3px;
  width: 26px; height: 26px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  transition: transform .35s var(--ease-spring);
}
.toggle[aria-checked="true"] { background: #34c77b; }
.toggle[aria-checked="true"] i { transform: translateX(20px); }

.foot { margin: 20px 4px 0; font-size: 12.5px; line-height: 1.5; color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  top: calc(var(--sat) + 62px);
  max-width: min(92vw, 420px);
  padding: 12px 18px;
  border-radius: 16px;
  background: rgba(30, 33, 40, .92);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .5);
  transform: translate(-50%, -16px);
  opacity: 0;
  pointer-events: none;
  transition: transform .45s var(--ease-out), opacity .3s;
}
.toast.on { transform: translate(-50%, 0); opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
