:root {
  --ink: #253342;
  --muted: #6e7b84;
  --cream: #fffaf0;
  --paper: rgba(255, 255, 255, 0.88);
  --peach: #ff9c83;
  --peach-dark: #ec735d;
  --yellow: #ffd96b;
  --mint: #80d5bd;
  --blue: #79bce7;
  --line: #dbe5e5;
  --shadow: 0 14px 30px rgba(63, 91, 99, 0.13), 0 3px 0 rgba(37, 51, 66, 0.07);
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: #fff3d9;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background:
    radial-gradient(circle at 15% 15%, rgba(255, 255, 255, 0.92) 0 5%, transparent 5.2%),
    linear-gradient(155deg, #fff7e5 0%, #eff9ef 58%, #e7f6fa 100%);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; }
button { touch-action: manipulation; }

.sky-blob {
  position: fixed;
  z-index: 0;
  border-radius: 999px;
  filter: blur(1px);
  pointer-events: none;
}

.blob-one { width: 280px; height: 280px; left: -160px; top: 24%; background: rgba(255, 205, 115, .33); }
.blob-two { width: 360px; height: 360px; right: -220px; top: 9%; background: rgba(121, 188, 231, .22); }

.app-shell {
  position: relative;
  z-index: 1;
  width: min(100%, 720px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) 20px max(28px, env(safe-area-inset-bottom));
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.eyebrow, .card-kicker { margin: 0 0 3px; color: var(--peach-dark); font-size: 11px; font-weight: 900; letter-spacing: .13em; }
h1 { margin: 0; font-size: clamp(25px, 6vw, 34px); line-height: 1.1; letter-spacing: -.04em; }

.wake-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 13px;
  border: 1px solid rgba(37, 51, 66, .09);
  border-radius: 999px;
  color: #3a685d;
  background: rgba(255,255,255,.72);
  box-shadow: 0 5px 18px rgba(57, 86, 92, .08);
  font-size: 12px;
  font-weight: 800;
}

.wake-button[aria-pressed="false"] { color: var(--muted); }
.wake-dot { width: 9px; height: 9px; border-radius: 50%; background: #4fc29f; box-shadow: 0 0 0 5px rgba(79,194,159,.14); }
.wake-button[aria-pressed="false"] .wake-dot { background: #a7b0b2; box-shadow: none; }

.stage {
  position: relative;
  display: grid;
  justify-items: center;
  min-height: 360px;
  padding: 12px 0 18px;
}

.cloud { position: absolute; width: 74px; height: 25px; border-radius: 999px; background: rgba(255,255,255,.72); }
.cloud::before, .cloud::after { content: ""; position: absolute; bottom: 0; border-radius: 50%; background: inherit; }
.cloud::before { width: 35px; height: 35px; left: 10px; }
.cloud::after { width: 28px; height: 28px; right: 8px; }
.cloud-left { left: 3%; top: 78px; transform: scale(.8); }
.cloud-right { right: 1%; top: 40px; transform: scale(.55); }

.character { position: relative; width: 174px; height: 218px; margin-top: 4px; filter: drop-shadow(0 13px 13px rgba(69,93,96,.18)); }
.head { position: absolute; z-index: 5; top: 10px; left: 53px; width: 68px; height: 60px; border: 4px solid var(--ink); border-radius: 48% 48% 45% 45%; background: #fff7dc; }
.ear { position: absolute; z-index: 3; top: 3px; width: 28px; height: 32px; border: 4px solid var(--ink); background: #fff7dc; transform: rotate(45deg); }
.ear::after { content: ""; position: absolute; inset: 6px; border-radius: 3px; background: #ffb49c; }
.ear-left { left: 49px; }
.ear-right { right: 49px; transform: rotate(-45deg); }
.face-dot { position: absolute; top: 24px; width: 6px; height: 9px; border-radius: 50%; background: var(--ink); }
.eye-left { left: 17px; } .eye-right { right: 17px; }
.mouth { position: absolute; left: 27px; top: 38px; width: 10px; height: 6px; border-bottom: 3px solid var(--ink); border-radius: 50%; }

.body {
  position: absolute;
  z-index: 4;
  left: 27px;
  bottom: 18px;
  width: 120px;
  height: 150px;
  overflow: hidden;
  border: 5px solid var(--ink);
  border-radius: 50% 50% 20px 20px / 15% 15% 18px 18px;
  background: linear-gradient(145deg, #ffae91 0 67%, #ff9278 68%);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.body::after { content: ""; position: absolute; left: 50%; bottom: 23px; width: 56px; height: 28px; border: 4px solid var(--ink); border-radius: 50%; background: #ffe580; transform: translateX(-50%); }
.heart { position: absolute; z-index: 2; left: 50%; bottom: 30px; transform: translateX(-50%); font-size: 19px; font-weight: 900; }
.pendulum { position: absolute; z-index: 2; left: calc(50% - 3px); top: 26px; width: 6px; height: 87px; border-radius: 99px; background: var(--ink); transform-origin: 50% 3px; transform: rotate(-23deg); transition: transform 95ms cubic-bezier(.2,.8,.3,1); }
.pendulum-weight { position: absolute; left: 50%; top: 47px; width: 24px; height: 18px; border: 3px solid var(--ink); border-radius: 45%; background: var(--yellow); transform: translateX(-50%); }
.character.beat-right .pendulum { transform: rotate(23deg); }
.character.beat-left .pendulum { transform: rotate(-23deg); }
.character.accent .head { animation: nod .18s ease-out; }

.arm { position: absolute; z-index: 3; top: 116px; width: 48px; height: 13px; border: 4px solid var(--ink); border-radius: 99px; background: #fff7dc; }
.arm-left { left: 5px; transform: rotate(27deg); } .arm-right { right: 5px; transform: rotate(-27deg); }
.foot { position: absolute; z-index: 3; bottom: 6px; width: 37px; height: 18px; border: 4px solid var(--ink); border-radius: 99px; background: #fff7dc; }
.foot-left { left: 34px; transform: rotate(-8deg); } .foot-right { right: 34px; transform: rotate(8deg); }

@keyframes nod { 50% { transform: translateY(5px) scale(1.03); } }

.tempo-readout { display: flex; align-items: baseline; gap: 7px; margin-top: -4px; }
.tempo-readout strong { font-size: clamp(49px, 14vw, 72px); line-height: .9; letter-spacing: -.07em; font-variant-numeric: tabular-nums; }
.tempo-readout span { color: var(--muted); font-size: 14px; font-weight: 900; letter-spacing: .08em; }
.tempo-name { margin: 7px 0 12px; color: var(--muted); font-size: 13px; font-weight: 700; }
.beat-dots { display: flex; justify-content: center; gap: 9px; min-height: 16px; }
.beat-dot { width: 11px; height: 11px; border: 2px solid rgba(37,51,66,.22); border-radius: 50%; background: rgba(255,255,255,.75); transition: transform .12s ease, background .12s ease; }
.beat-dot.first { border-color: rgba(236,115,93,.55); }
.beat-dot.active { transform: scale(1.48); background: var(--mint); border-color: var(--ink); }
.beat-dot.active.first { background: var(--yellow); }

.control-card, .sound-card, .subdivision-card {
  padding: 18px;
  border: 1px solid rgba(37,51,66,.08);
  border-radius: 24px;
  background: var(--paper);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.card-heading, .setting-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
h2 { margin: 0; font-size: 17px; letter-spacing: -.02em; }
.tap-button { min-height: 39px; padding: 8px 13px; border: 0; border-radius: 13px; color: #4b6570; background: #e8f5f4; font-size: 12px; font-weight: 900; }
.tap-button:active { transform: translateY(2px); }

.tempo-controls { display: grid; grid-template-columns: 42px 1fr 42px; align-items: center; gap: 12px; margin-top: 19px; }
.round-button, .stepper button { display: grid; place-items: center; border: 0; color: var(--ink); background: #f2f7f5; font-size: 24px; font-weight: 600; }
.round-button { width: 42px; height: 42px; border-radius: 50%; }
.round-button:active, .stepper button:active { background: #e0eeeb; transform: translateY(1px); }

input[type="range"] { width: 100%; height: 32px; margin: 0; background: transparent; accent-color: var(--peach); cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 8px; border-radius: 99px; background: linear-gradient(90deg, var(--mint), var(--yellow), var(--peach)); }
input[type="range"]::-webkit-slider-thumb { width: 26px; height: 26px; margin-top: -9px; border: 4px solid #fff; border-radius: 50%; background: var(--peach-dark); box-shadow: 0 3px 8px rgba(37,51,66,.24); -webkit-appearance: none; }
input[type="range"]::-moz-range-track { height: 8px; border-radius: 99px; background: linear-gradient(90deg, var(--mint), var(--yellow), var(--peach)); }
input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border: 4px solid #fff; border-radius: 50%; background: var(--peach-dark); box-shadow: 0 3px 8px rgba(37,51,66,.24); }
.range-labels { display: flex; justify-content: space-between; margin: -1px 54px 0; color: #93a0a5; font-size: 10px; font-weight: 800; }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.compact-card { min-height: 134px; }
.setting-note { margin: 16px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.stepper { display: flex; gap: 6px; }
.stepper button { width: 37px; height: 37px; border-radius: 12px; }
.speaker { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 13px; color: #51756c; background: #e8f5ef; font-weight: 900; }
.small-slider { margin-top: 14px !important; }

.subdivision-card { margin-top: 14px; padding: 15px 18px 17px; }
.subdivision-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.subdivision-hint { flex: 0 0 auto; padding: 7px 10px; border-radius: 999px; color: #4b7167; background: #e8f5ef; font-size: 11px; font-weight: 850; }
.subdivision-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.subdivision-option { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; min-height: 67px; padding: 8px 5px; border: 2px solid transparent; border-radius: 16px; color: var(--muted); background: #f1f6f4; font-size: 12px; font-weight: 850; }
.subdivision-option.active { border-color: var(--peach); color: var(--ink); background: #fff2ec; }
.subdivision-option:active { transform: translateY(2px); }
.subdivision-glyph { display: flex; align-items: center; justify-content: center; gap: 5px; height: 13px; }
.subdivision-glyph i { display: block; width: 7px; height: 7px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 2px rgba(128,213,189,.16); }
.subdivision-glyph .main-dot { width: 11px; height: 11px; background: var(--peach); box-shadow: 0 0 0 3px rgba(255,156,131,.14); }
.subdivision-option.active .subdivision-glyph i { background: #5fc5aa; }
.subdivision-option.active .subdivision-glyph .main-dot { background: var(--peach-dark); }
.subdivision-note { margin: 10px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }

.sound-card { margin-top: 14px; padding: 15px 18px 17px; }
.sound-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.sound-option { min-height: 43px; border: 2px solid transparent; border-radius: 14px; color: var(--muted); background: #f1f6f4; font-size: 12px; font-weight: 850; }
.sound-option span { margin-right: 3px; color: #99aaa6; }
.sound-option.active { border-color: var(--peach); color: var(--ink); background: #fff2ec; }
.sound-option.active span { color: var(--peach-dark); }

.primary-action { margin: 0 0 17px; }

.play-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  width: 100%;
  min-height: 60px;
  margin-top: 0;
  border: 3px solid var(--ink);
  border-radius: 20px;
  color: #fff;
  background: var(--peach);
  box-shadow: 0 7px 0 var(--peach-dark), 0 16px 24px rgba(236,115,93,.22);
  font-size: 17px;
  font-weight: 950;
  letter-spacing: .02em;
}
.play-button:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--peach-dark), 0 8px 16px rgba(236,115,93,.18); }
.play-button.running { background: #5dc3a7; box-shadow: 0 7px 0 #379a80, 0 16px 24px rgba(55,154,128,.22); }
.play-icon { width: 0; height: 0; margin-left: 3px; border-top: 8px solid transparent; border-bottom: 8px solid transparent; border-left: 13px solid #fff; }
.running .play-icon { width: 13px; height: 15px; margin: 0; border: 0; border-left: 5px solid #fff; border-right: 5px solid #fff; }
.status-text { margin: 14px 0 0; color: var(--muted); text-align: center; font-size: 11px; font-weight: 700; }
.no-sleep-video { position: fixed; width: 1px; height: 1px; left: -2px; bottom: -2px; opacity: .01; pointer-events: none; }
.audio-bridge { display: none; }

@media (min-width: 680px) {
  .app-shell { padding-inline: 34px; }
  .stage { min-height: 370px; }
  .character { transform: scale(1.05); transform-origin: center bottom; }
}

@media (max-width: 430px) {
  .app-shell { padding-left: 15px; padding-right: 15px; }
  .wake-button { padding-inline: 11px; }
  .stage { min-height: 348px; padding-top: 5px; }
  .character { transform: scale(.93); transform-origin: center top; margin-bottom: -13px; }
  .settings-grid { grid-template-columns: 1fr; }
  .compact-card { min-height: 0; }
  .setting-note { margin-top: 10px; }
}

@media (max-height: 720px) and (orientation: landscape) {
  .app-shell { width: min(100%, 960px); }
  .stage { min-height: 300px; }
  .character { transform: scale(.78); transform-origin: center top; margin-bottom: -50px; }
}

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