:root {
  --bg: #0f1115;
  --card: #171a21;
  --card-2: #1f232c;
  --line: #2a2f3a;
  --text: #e5e7eb;
  --muted: #8b93a1;
  --right: #ff7a45;
  --left: #38bdf8;
  --accent: #22c55e;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body { touch-action: manipulation; }
button { font-family: inherit; color: inherit; }
button:active { filter: brightness(1.15); }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- Main screen ---------- */
.app {
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 16px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  user-select: none;
  -webkit-user-select: none;
}

.top { display: flex; align-items: center; justify-content: space-between; }
h1 { font-size: 22px; margin: 0; letter-spacing: 0.3px; }
.settings-btn {
  display: flex; align-items: center; gap: 6px;
  height: 40px; padding: 0 14px; border-radius: 12px; border: 0;
  background: var(--card); color: var(--text); font-size: 14px;
}

.wheel-wrap { position: relative; padding: 0 8px; flex: 0 1 auto; margin: auto 0; }
#wheel { display: block; width: 100%; aspect-ratio: 1; }
/* Invisible tap target over the wheel's center label. */
.rhythm-btn {
  position: absolute; left: 50%; top: 50%; width: 46%; height: 36%;
  transform: translate(-50%, -50%); border-radius: 50%; border: 0; background: transparent;
}
.rhythm-btn:active { background: rgba(255, 255, 255, 0.06); }

.controls { display: contents; }

/* Tempo */
.tempo { display: grid; grid-template-columns: 56px 1fr 56px; align-items: center; gap: 12px; margin-top: auto; }
.step {
  height: 56px; border-radius: 14px; border: 0;
  background: var(--card-2); font-size: 28px; line-height: 1;
}
.tempo-value { text-align: center; }
.tempo-value output { font-size: 36px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tempo-value .unit { font-size: 18px; font-weight: 500; color: var(--muted); }
.tempo-value .muted { display: block; margin-top: 2px; }

/* Hand toggles */
.hands { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hand-toggle {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  height: 52px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card); font-size: 15px;
}
.hand-toggle .dot { width: 14px; height: 14px; border-radius: 50%; }
.hand-toggle.right .dot { background: var(--right); }
.hand-toggle.left .dot { background: var(--left); }
.hand-toggle[aria-pressed="false"] { color: var(--muted); border-style: dashed; }
.hand-toggle[aria-pressed="false"] .dot { background: transparent; box-shadow: inset 0 0 0 2px currentColor; }

/* Play */
.play {
  display: block; width: 100%; height: 60px; border-radius: 16px; border: 0;
  background: var(--accent); color: #052e16; font-size: 20px; font-weight: 700;
}
.play.playing { background: #ef4444; color: #450a0a; }

/* ---------- Sheets ---------- */
.sheet {
  width: 100%; max-width: 480px; margin: auto auto 0; padding: 0; border: 0;
  background: var(--card); color: var(--text);
  border-radius: 20px 20px 0 0;
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.55); }
.sheet-body {
  display: flex; flex-direction: column; gap: 14px;
  padding: 18px 16px calc(env(safe-area-inset-bottom) + 16px);
}
/* The heading takes initial focus so opening a sheet doesn't spotlight its first control. */
.sheet h2 { margin: 0; font-size: 18px; outline: none; }
.sheet h3 { font-size: 13px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: 0.08em; }
.done {
  height: 50px; border-radius: 14px; border: 0;
  background: var(--card-2); font-size: 17px; font-weight: 600;
}

.presets { display: flex; gap: 8px; flex-wrap: wrap; }
.presets button {
  flex: 1 1 auto; height: 44px; border-radius: 10px; border: 1px solid var(--line);
  background: transparent; font-size: 16px; font-variant-numeric: tabular-nums;
}
.presets button.active { background: var(--card-2); border-color: #3b4250; }

.ratio { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 8px; }
.hand-count .label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }
.hand-count.right .label { color: var(--right); }
.hand-count.left .label { color: var(--left); text-align: right; }
.hand-count.left .stepper { justify-content: flex-end; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button {
  width: 44px; height: 44px; border-radius: 12px; border: 0;
  background: var(--card-2); font-size: 24px; line-height: 1;
}
.stepper button:disabled { opacity: 0.3; }
.stepper output { min-width: 36px; text-align: center; font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; }
.swap { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--card-2); color: var(--muted); font-size: 20px; }
#tempo-info { margin: 0; }

.hand-card { background: var(--card-2); border-radius: var(--radius); padding: 12px; border-top: 3px solid; }
.hand-card.right { border-color: var(--right); }
.hand-card.left { border-color: var(--left); }
.hand-card.right h3 { color: var(--right); }
.hand-card.left h3 { color: var(--left); }
.hand-card select {
  width: 100%; height: 44px; border-radius: 10px; border: 0; padding: 0 10px;
  background: var(--card); color: var(--text); font-size: 16px; margin-bottom: 8px;
}
.slider { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
input[type="range"] { flex: 1; width: 100%; accent-color: #9ca3af; height: 32px; margin: 0; }
.hand-card.right input[type="range"] { accent-color: var(--right); }
.hand-card.left input[type="range"] { accent-color: var(--left); }

.options { display: flex; flex-direction: column; gap: 10px; font-size: 15px; }
.options label { display: flex; align-items: center; gap: 10px; min-height: 32px; }
.options input { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; }

/* ---------- Phone in landscape: wheel left, controls right ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  .app {
    max-width: none;
    height: 100vh;
    height: 100dvh;
    padding: calc(env(safe-area-inset-top) + 10px) calc(env(safe-area-inset-right) + 12px)
             calc(env(safe-area-inset-bottom) + 10px) calc(env(safe-area-inset-left) + 12px);
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    column-gap: 20px;
  }
  .wheel-wrap { padding: 0; display: flex; align-items: center; }
  #wheel {
    width: auto;
    height: min(
      calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 20px),
      calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right) - 360px)
    );
    height: min(
      calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 20px),
      calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right) - 360px)
    );
  }
  .controls { display: flex; flex-direction: column; justify-content: center; gap: 12px; min-height: 0; position: relative; }
  .settings-btn { position: fixed; top: calc(env(safe-area-inset-top) + 10px); right: calc(env(safe-area-inset-right) + 12px); height: 36px; }
  .top { display: contents; }
  .top h1 { display: none; }
  .tempo { margin-top: 0; }
  .play { height: 52px; }
}
