/* Orrery — stylesheet. Dark by design (it is a sky). */

:root {
  --bg: #070912;
  --bg-2: #0b0f22;
  --panel: rgba(12, 15, 30, 0.72);
  --card: rgba(255, 255, 255, 0.035);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #e8ecff;
  --muted: #9aa3c7;
  --faint: #5f6788;
  --accent: #ffb347;
  --accent-2: #ff7a3d;
  --danger: #ff6b6b;
  --ring-hue: 12;
  --slider-hue: 222;
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --topbar-h: 58px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

html { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 17.5px; line-height: 1.45; -webkit-font-smoothing: antialiased; }

body {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr;
  height: 100dvh;
  overflow: hidden;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -9999px; top: 8px; z-index: 50; background: var(--accent); color: #111; padding: 8px 12px; border-radius: 8px; }
.skip:focus { left: 8px; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(7, 9, 18, 0.82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 9px; color: var(--text); user-select: none; }
.logo { width: 28px; height: 28px; color: #c9d2ff; }
.brand-name { font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; font-size: 16.25px; color: #d7deff; }

.name-wrap { flex: 1 1 160px; min-width: 0; }
.name-input {
  width: 100%;
  min-width: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--text);
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: border-color .15s, background .15s;
}
.name-input::placeholder { color: var(--faint); font-weight: 500; }
.name-input:hover { border-color: var(--border); }
.name-input:focus { outline: none; border-color: var(--border-strong); background: rgba(255, 255, 255, 0.04); }

.transport { display: flex; align-items: center; gap: 12px; }

.play {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  background: radial-gradient(circle at 35% 30%, #fff1cc, var(--accent) 45%, var(--accent-2));
  color: #2a1608;
  display: grid;
  place-items: center;
  box-shadow: 0 0 0 1px rgba(255, 190, 120, 0.25), 0 6px 22px rgba(255, 140, 60, 0.35);
  transition: transform .12s, box-shadow .2s;
}
.play:hover { transform: scale(1.05); }
.play:active { transform: scale(0.97); }
.play svg { width: 22px; height: 22px; fill: currentColor; }
.play .ico-pause { display: none; }
.play.playing .ico-play { display: none; }
.play.playing .ico-pause { display: block; }
.play.playing { box-shadow: 0 0 0 1px rgba(255, 190, 120, 0.35), 0 6px 28px rgba(255, 140, 60, 0.6); }

.bpm-wrap { display: flex; align-items: baseline; gap: 6px; }
.bpm-label { font-size: 12.5px; letter-spacing: 0.14em; color: var(--muted); font-weight: 700; }
.bpm-input {
  width: 62px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 18.75px;
  text-align: center;
  -moz-appearance: textfield;
}
.bpm-input::-webkit-outer-spin-button, .bpm-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-weight: 600;
  font-size: 16.25px;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: rgba(255, 255, 255, 0.08); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; fill: currentColor; opacity: 0.85; }
.btn.icon { width: 34px; justify-content: center; padding: 7px 0; font-family: var(--mono); }
.btn.primary { background: linear-gradient(180deg, #ffc46b, #ff8a45); color: #2a1608; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn[disabled] { opacity: 0.5; cursor: default; }

/* ----------------------------------------------------------------- stage */

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 356px;
  min-height: 0;
}

.canvas-wrap { position: relative; min-height: 0; overflow: hidden; background: var(--bg); }
canvas { display: block; touch-action: none; user-select: none; -webkit-user-select: none; }

.hint {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(10, 12, 26, 0.72);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  color: var(--muted);
  font-size: 15px;
  white-space: nowrap;
  max-width: calc(100% - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  transition: opacity .4s;
}
.hint.hide { opacity: 0; }
.hint-key { display: inline-block; font-family: var(--mono); font-size: 13.75px; padding: 1px 6px; border-radius: 5px; background: rgba(255, 255, 255, 0.1); color: var(--text); margin-right: 2px; }

/* ----------------------------------------------------------------- panel */

.panel {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-left: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card.ring-card { --slider-hue: var(--ring-hue); border-color: hsl(var(--ring-hue) 70% 60% / 0.3); }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card-title { margin: 0; font-size: 13.75px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.card-title .dot { width: 9px; height: 9px; border-radius: 50%; background: hsl(var(--ring-hue) 85% 62%); box-shadow: 0 0 10px hsl(var(--ring-hue) 85% 62% / 0.8); }
.ring-card .card-title { color: hsl(var(--ring-hue) 70% 78%); }

.ring-tabs { display: flex; gap: 5px; flex-wrap: wrap; }
.ring-tab {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid hsl(var(--h) 75% 62% / 0.6);
  background: transparent;
  color: hsl(var(--h) 75% 75%);
  font-family: var(--mono);
  font-size: 13.75px;
  font-weight: 700;
  padding: 0;
  display: grid;
  place-items: center;
  transition: background .12s, transform .12s;
}
.ring-tab:hover { transform: scale(1.08); }
.ring-tab[aria-selected="true"] { background: hsl(var(--h) 80% 60%); color: #0a0c18; border-color: transparent; box-shadow: 0 0 10px hsl(var(--h) 80% 60% / 0.6); }
.ring-tab.muted { opacity: 0.35; }

.row { display: flex; gap: 8px; align-items: flex-end; }
.row.two > * { flex: 1 1 0; min-width: 0; }
.row.btns { flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 13.75px; color: var(--muted); font-weight: 600; letter-spacing: 0.04em; }
.field[hidden] { display: none; }

select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, 0.05) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%239aa3c7' stroke-width='1.5'/></svg>") no-repeat right 10px center;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 28px 7px 10px;
  color: var(--text);
  font-weight: 600;
  font-size: 16.25px;
  text-overflow: ellipsis;
}
select:hover { border-color: var(--border-strong); }
select option { background: #121630; color: var(--text); }

.stepper { display: grid; grid-template-columns: 30px 1fr 30px; align-items: stretch; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: rgba(255, 255, 255, 0.04); height: 34px; }
.stepper button { border: 0; background: transparent; color: var(--muted); font-size: 20px; font-weight: 600; padding: 0; }
.stepper button:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.stepper output { display: grid; place-items: center; font-family: var(--mono); font-weight: 700; font-size: 17.5px; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }

.ctl { display: flex; flex-direction: column; gap: 2px; }
.ctl-head { display: flex; justify-content: space-between; align-items: baseline; }
.ctl-head label { font-size: 13.75px; color: var(--muted); font-weight: 600; letter-spacing: 0.04em; }
.ctl-head output { font-family: var(--mono); font-size: 13.75px; color: var(--text); opacity: 0.85; font-variant-numeric: tabular-nums; }
.ctl-row { display: flex; align-items: center; gap: 8px; }
.ctl-row input[type="range"] { flex: 1 1 auto; min-width: 0; }
.rot { display: flex; gap: 4px; }
.rot button, .chip {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  transition: background .12s, border-color .12s;
}
.rot button { width: 30px; padding: 5px 0; font-size: 17.5px; }
.rot button:hover, .chip:hover { background: rgba(255, 255, 255, 0.09); border-color: var(--border-strong); }
.chip[aria-pressed="true"] { background: hsl(var(--ring-hue) 80% 60%); color: #0a0c18; border-color: transparent; }
.chip.ghost { background: transparent; color: var(--muted); }
.chip.ghost.danger:hover { color: var(--danger); border-color: rgba(255, 107, 107, 0.4); }
.chip[disabled] { opacity: 0.4; cursor: default; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 24px;
  margin: 0;
  background: transparent;
  --fill: 50%;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, hsl(var(--slider-hue) 80% 62%) var(--fill), rgba(255, 255, 255, 0.12) var(--fill));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(5, 7, 16, 0.6), 0 2px 6px rgba(0, 0, 0, 0.5);
  transition: transform .1s;
}
input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.12); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.12); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 2px; background: hsl(var(--slider-hue) 80% 62%); }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 0 0 3px rgba(5, 7, 16, 0.6); }
input[type="range"].center::-webkit-slider-runnable-track {
  background: linear-gradient(to right, rgba(255, 255, 255, 0.12) min(var(--fill), 50%), hsl(var(--slider-hue) 80% 62%) min(var(--fill), 50%), hsl(var(--slider-hue) 80% 62%) max(var(--fill), 50%), rgba(255, 255, 255, 0.12) max(var(--fill), 50%));
}

.strip {
  display: grid;
  grid-template-columns: repeat(var(--cols, 16), minmax(0, 1fr));
  gap: 3px;
}
.strip.few { grid-template-columns: repeat(var(--cols, 8), 34px); }
.step {
  aspect-ratio: 1;
  min-width: 0;
  padding: 0;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.035);
  color: var(--faint);
  font-family: var(--mono);
  font-size: 11.25px;
  font-weight: 700;
  position: relative;
  transition: background .08s, transform .08s;
}
.step:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.step.first::after { content: ""; position: absolute; left: 50%; bottom: -5px; width: 3px; height: 3px; border-radius: 50%; background: rgba(255, 255, 255, 0.35); transform: translateX(-50%); }
.step.on { background: hsl(var(--ring-hue) 78% 56% / 0.85); color: #0a0c18; border-color: transparent; }
.step.accent { background: hsl(var(--ring-hue) 95% 70%); box-shadow: 0 0 10px hsl(var(--ring-hue) 90% 62% / 0.65); }
.step.playing { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.9); }
.strip.pitched .step { font-size: 10.625px; }

.panel-foot { color: var(--muted); font-size: 15px; padding: 4px 4px 0; }
.panel-foot p { margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 15px; }

/* --------------------------------------------------------------- dialogs */

.dialog {
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 0;
  background: #0f1228;
  color: var(--text);
  width: min(540px, calc(100vw - 32px));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.dialog::backdrop { background: rgba(3, 4, 10, 0.65); backdrop-filter: blur(8px); }
.dialog-body { padding: 22px 24px; display: flex; flex-direction: column; gap: 12px; margin: 0; }
.dialog h2 { margin: 0; font-size: 22.5px; letter-spacing: 0.01em; }
.dialog h3 { margin: 6px 0 0; font-size: 15px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.dialog p { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.share-row { display: flex; gap: 8px; }
.share-row input {
  flex: 1 1 auto;
  min-width: 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-family: var(--mono);
  font-size: 15px;
}

.preset-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.preset {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  transition: background .12s, border-color .12s;
}
.preset:hover { background: rgba(255, 255, 255, 0.08); border-color: var(--border-strong); }
.preset b { font-size: 17.5px; }
.preset span { font-size: 15px; color: var(--muted); line-height: 1.35; }
.preset small { font-family: var(--mono); color: var(--faint); font-size: 12.5px; letter-spacing: 0.08em; }

.help p { color: #c9d0ee; }
.help-list { margin: 0; padding-left: 18px; color: #c9d0ee; display: flex; flex-direction: column; gap: 4px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; align-items: baseline; }
.keys dt { font-family: var(--mono); font-size: 15px; color: var(--text); white-space: nowrap; }
.keys dt kbd { display: inline-block; padding: 1px 6px; border-radius: 5px; background: rgba(255, 255, 255, 0.1); border: 1px solid var(--border); }
.keys dd { margin: 0; color: var(--muted); font-size: 16.25px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  padding: 10px 16px;
  border-radius: 999px;
  background: #1a1f3f;
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 16.25px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 60;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(255, 107, 107, 0.5); }

/* ------------------------------------------------------------ responsive */

@media (max-width: 1100px) {
  .btn span { display: none; }
  .btn { padding: 7px 9px; }
  .btn.icon { width: 32px; }
}

@media (max-width: 900px) {
  body { height: auto; min-height: 100dvh; overflow: auto; grid-template-rows: var(--topbar-h) auto; }
  .topbar { position: sticky; top: 0; }
  .stage { grid-template-columns: 1fr; grid-template-rows: min(100vw, 64dvh) auto; }
  .canvas-wrap { min-height: 320px; }
  .panel { border-left: 0; border-top: 1px solid var(--border); overflow: visible; }
  .hint { font-size: 13.75px; }
  .preset-list { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  body { grid-template-rows: auto auto; }
  .topbar { flex-wrap: wrap; gap: 8px 10px; padding: 8px 10px; height: auto; }
  .brand-name { display: none; }
  .bpm-label { display: none; }
  .bpm-input { width: 54px; }
  .name-wrap { order: 10; flex: 1 1 100%; }
  .name-input { border-color: var(--border); background: rgba(255, 255, 255, 0.04); }
  .transport { margin-left: auto; }
  .actions { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
