/* Design tokens follow the exordos.com palette: monochrome slate with a blue highlight. */
:root {
  --color-bg: #ffffff;
  --color-bg-soft: #fafafa;
  --color-bg-muted: #e7e7e7;
  --color-bg-elevated: #ffffff;
  --color-text: #15181d;
  --color-text-muted: #425163;
  --color-text-subtle: #748396;
  --color-border: #e3e3e3;
  --color-highlight: #5b8bed;
  --color-glow: #7d9ddf33;
  --color-focus-ring: #222a342e;
  --btn-primary-bg: #222a34;
  --btn-primary-fg: #ffffff;
  --btn-primary-hover: #425163;
  --btn-secondary-bg: #e7e7e7;
  --btn-secondary-fg: #15181d;
  --btn-secondary-border: #e3e3e3;
  --btn-secondary-hover: #c9ced5;
  --shadow-xs: 0 1px 4px #15181d33;
  --shadow-segment: 0 1px 0 #15181d14;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, sans-serif;
  --font-mono: "Fira Code", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;
  color-scheme: light;
}

html.dark {
  --color-bg: #15181d;
  --color-bg-soft: #1a1e24;
  --color-bg-muted: #222a34;
  --color-bg-elevated: #1a1e24;
  --color-text: #f7fdff;
  --color-text-muted: #9aa8b8;
  --color-text-subtle: #748396;
  --color-border: #2a3340;
  --color-highlight: #7d9ddf;
  --color-glow: #20a7c91a;
  --color-focus-ring: #f7fdff52;
  --btn-primary-bg: #f7fdff;
  --btn-primary-fg: #15181d;
  --btn-primary-hover: #c9d8df;
  --btn-secondary-bg: #222a34;
  --btn-secondary-fg: #f7fdff;
  --btn-secondary-border: #2a3340;
  --btn-secondary-hover: #425163;
  --shadow-xs: 0 1px 4px #00000073;
  --shadow-segment: 0 1px 0 #0006;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s, color .2s;
}

button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--color-focus-ring);
}

/* --- header --- */

.header {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 56px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: color-mix(in srgb, var(--color-bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--color-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 18px;
}

.brand-mark { width: 24px; height: 24px; }

.header-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: transparent;
}
.icon-btn:hover { background: var(--color-bg-muted); }
.icon-btn svg { width: 18px; height: 18px; }

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: var(--radius-pill);
  background: var(--color-bg-muted);
}

.segmented button {
  border: 0;
  background: transparent;
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
}

.segmented button[aria-pressed="true"] {
  background: var(--color-bg);
  color: var(--color-text);
  box-shadow: var(--shadow-segment), var(--shadow-xs);
}

/* --- layout --- */

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 24px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 20px;
  background:
    radial-gradient(120% 70% at 50% 0%, var(--color-glow), transparent 70%),
    var(--color-bg-elevated);
}

.display-toggle { align-self: center; }

/* --- pendulum --- */

.pendulum {
  display: none;
  width: 180px;
  height: 207px;
  align-self: center;
}
.view-pendulum .pendulum { display: block; }

.pendulum-body { fill: var(--color-bg-muted); stroke: var(--color-border); stroke-width: 2; stroke-linejoin: round; }
.pendulum-scale { stroke: var(--color-text-subtle); stroke-width: 1.5; opacity: .5; }
.pendulum-rod { stroke: var(--color-text); stroke-width: 3; stroke-linecap: round; }
.pendulum-weight { fill: var(--color-highlight); }
.pendulum-pivot { fill: var(--color-text); }

/* --- tempo --- */

.tempo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.round {
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--btn-secondary-border);
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-fg);
  font-size: 26px;
  line-height: 1;
  transition: background-color .12s;
}
.round:hover { background: var(--btn-secondary-hover); }

.bpm-readout { display: flex; flex-direction: column; align-items: center; min-width: 0; }

#bpm {
  width: 4ch;
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  text-align: center;
  font-size: 88px;
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
#bpm::-webkit-inner-spin-button, #bpm::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.view-pendulum #bpm { font-size: 56px; }

.meta { font-size: 14px; color: var(--color-text-muted); }
#signature { font-family: var(--font-mono); }

input[type="range"] { width: 100%; accent-color: var(--btn-primary-bg); }

/* --- beats --- */

.beats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.beat {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background: var(--color-bg-muted);
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 600;
  transition: transform 60ms ease-out, background-color 60ms, color 60ms;
}

.beat.accent { border-color: var(--color-highlight); color: var(--color-highlight); }
.beat.mute { opacity: .4; border-style: dashed; border-color: var(--color-text-subtle); }

.beat.active { transform: scale(1.18); background: var(--color-text); color: var(--color-bg); }
.beat.accent.active { background: var(--color-highlight); color: #fff; }
.beat.mute.active { background: var(--color-bg-muted); color: var(--color-text-muted); }

.beats-hint { margin: -12px 0 0; text-align: center; font-size: 12px; color: var(--color-text-subtle); }

.check {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: -14px;
  font-size: 13px;
  color: var(--color-text-muted);
  cursor: pointer;
}
.check input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--color-highlight);
  cursor: pointer;
}

.remaining {
  margin: -12px 0 0;
  text-align: center;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--color-text-muted);
}

/* --- buttons (mirrors exordos .btn) --- */

.actions {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  font-weight: 600;
  white-space: nowrap;
  transition: background-color .12s, border-color .12s, color .12s;
}
.btn--lg { height: 48px; padding: 0 20px; font-size: 16px; }
.btn--primary { background: var(--btn-primary-bg); color: var(--btn-primary-fg); border-color: var(--btn-primary-bg); }
.btn--primary:hover { background: var(--btn-primary-hover); border-color: var(--btn-primary-hover); }
.btn--secondary { background: var(--btn-secondary-bg); color: var(--btn-secondary-fg); border-color: var(--btn-secondary-border); }
.btn--secondary:hover { background: var(--btn-secondary-hover); border-color: var(--btn-secondary-hover); }
.btn--ghost { background: transparent; color: var(--color-text); }
.btn--ghost:hover { background: var(--color-bg-muted); }
.btn--primary.playing { background: var(--color-highlight); border-color: var(--color-highlight); color: #fff; }

/* --- settings --- */

.settings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.settings .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field-label { font-size: 13px; font-weight: 500; color: var(--color-text-muted); }
.settings .wide { grid-column: 1 / -1; }

.signature-pick { display: flex; align-items: center; gap: 6px; color: var(--color-text); }
.signature-pick .select { flex: 1; }

/* --- dropdown (custom listbox, so the popup follows the site's tokens) --- */

.select { position: relative; }

.select-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  height: 40px;
  padding: 0 10px 0 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
  text-align: left;
  transition: border-color .12s, background-color .12s;
}
.select-button:hover { background: var(--color-bg-soft); border-color: var(--color-border-strong, var(--color-border)); }
.select-button[aria-expanded="true"] { border-color: var(--color-highlight); }

.select-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select-chevron { flex: none; width: 16px; height: 16px; color: var(--color-text-subtle); }
.select-button[aria-expanded="true"] .select-chevron { transform: rotate(180deg); }

.select-menu {
  position: absolute;
  z-index: 5;
  top: calc(100% + 4px);
  left: 0;
  width: 100%;
  min-width: max-content;
  max-height: 260px;
  overflow-y: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md, 0 16px 40px #15181d24);
}

.select-option {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--color-text);
  cursor: pointer;
  white-space: nowrap;
}
.select-option.active { background: var(--color-bg-muted); }
.select-option[aria-selected="true"] { color: var(--color-highlight); font-weight: 600; }

/* --- rhythm pictures --- */

.rhythm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
}

.rhythm {
  display: grid;
  place-items: center;
  height: 54px;
  padding: 4px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  color: var(--color-text);
  transition: border-color .12s, background-color .12s;
}
.rhythm:hover { background: var(--color-bg-soft); }
.rhythm[aria-checked="true"] {
  border-color: var(--color-highlight);
  color: var(--color-highlight);
  background: color-mix(in srgb, var(--color-highlight) 10%, transparent);
}
.rhythm svg { height: 34px; width: auto; max-width: 100%; }

.hint { margin: 0; text-align: center; font-size: 13px; color: var(--color-text-subtle); }

kbd {
  font: 12px var(--font-mono);
  padding: 1px 6px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg-soft);
  color: var(--color-text-muted);
}

@media (max-width: 420px) {
  .settings { grid-template-columns: 1fr; }
  #bpm { font-size: 72px; }
  .actions { grid-template-columns: 1fr 1fr; }
  .actions #play { grid-column: 1 / -1; }
}
