:root {
  --paper: #f3f3f1;
  --panel: #e4e4e2;
  --metal: #b9bbbd;
  --metal-dark: #8e9194;
  --ink: #161616;
  --muted: #6b6b6b;
  --orange: #ec5a29;
  --teal: #4fb3a9;
  --screen: #0d0d0d;
  --stroke: 2px solid var(--ink);
  --font: "Helvetica Neue", "Inter", Arial, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 2rem clamp(1rem, 4vw, 4.5rem) 4rem;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

button, input, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.4; }

.top {
  display: flex;
  gap: 2rem;
  margin-bottom: 1.4rem;
  font-size: 0.95rem;
}
.top a { color: var(--ink); text-decoration: none; border-bottom: var(--stroke); }
.top a:hover { color: var(--orange); border-color: var(--orange); }

.stage {
  position: relative;
  background: var(--panel);
  border: 3px solid var(--ink);
  border-radius: 28px;
  padding: clamp(1.5rem, 4vw, 4rem) clamp(1rem, 3vw, 3rem) 2.5rem;
}

.sticker {
  position: absolute;
  top: -3.6rem;
  right: -3rem;
  width: 7.5rem;
  height: 7.5rem;
  display: grid;
  place-items: center;
  background: var(--orange);
  color: #fff;
  text-align: center;
  font-size: 1.15rem;
  line-height: 1.1;
  clip-path: polygon(50% 0%, 57% 10%, 69% 4%, 72% 16%, 85% 15%, 83% 27%, 96% 31%, 89% 42%, 100% 50%, 89% 58%, 96% 69%, 83% 73%, 85% 85%, 72% 84%, 69% 96%, 57% 90%, 50% 100%, 43% 90%, 31% 96%, 28% 84%, 15% 85%, 17% 73%, 4% 69%, 11% 58%, 0% 50%, 11% 42%, 4% 31%, 17% 27%, 15% 15%, 28% 16%, 31% 4%, 43% 10%);
  transform: rotate(-8deg);
  z-index: 2;
}
body.playing .sticker { animation: wobble calc(60s / var(--bpm, 120)) ease-in-out infinite; }
@keyframes wobble {
  0%, 100% { transform: rotate(-8deg) scale(1); }
  50% { transform: rotate(-4deg) scale(1.06); }
}

.rig {
  display: grid;
  grid-template-columns: minmax(20rem, 26rem) minmax(18rem, 1fr);
  gap: clamp(1.5rem, 4vw, 3.5rem);
  align-items: start;
  justify-content: center;
}

.device {
  position: relative;
  background: var(--metal);
  border: var(--stroke);
  border-radius: 4px;
  box-shadow: 8px 8px 0 -2px var(--panel), 8px 8px 0 0 var(--ink);
}

.device-top { position: absolute; top: -14px; left: 14px; display: flex; gap: 10px; }
.knob-slot { width: 34px; height: 12px; border: var(--stroke); border-bottom: none; background: #ddd; }
.knob-slot.orange { background: var(--orange); }
.knob-slot.dark { width: 60px; background: #3a3a3a; }
button.knob-slot { padding: 0; cursor: pointer; }
.knob-slot.mode:hover { background: #ff7a4d; }
.knob-slot.mode[aria-pressed="true"] { height: 8px; margin-top: 4px; background: var(--ink); }

.device-head {
  display: flex;
  justify-content: space-between;
  background: #ececea;
  border-bottom: var(--stroke);
  padding: 0.9rem 0.9rem 1.4rem;
}
.brand-name { font-size: 2.3rem; line-height: 1; letter-spacing: -0.02em; }
.brand-sub { color: var(--orange); font-size: 1.05rem; margin-top: 0.2rem; }
.speaker {
  width: 6.5rem;
  height: 4.6rem;
  border: var(--stroke);
  border-radius: 3px;
  background: radial-gradient(circle, var(--ink) 2.2px, transparent 2.6px) 0 0 / 9px 9px, #5a5a5a;
}

.screen-tab {
  position: absolute;
  margin: -0.75rem 0 0 1rem;
  background: var(--orange);
  color: #fff;
  font-size: 0.72rem;
  padding: 0.1rem 0.45rem;
  border: 1.5px solid var(--ink);
}

.screen {
  background: var(--screen);
  border-bottom: var(--stroke);
  padding: 1.1rem 0.9rem 0.6rem;
  color: #f0f0f0;
}
.screen canvas { display: block; width: 100%; height: 5.5rem; }
.screen canvas[hidden] { display: none; }
.screen-settings { height: 5.5rem; display: flex; flex-direction: column; justify-content: center; gap: 0.7rem; font-family: var(--mono); font-size: 0.72rem; }
.screen-settings[hidden] { display: none; }
.lcd-field { display: flex; align-items: center; gap: 0.8rem; }
.lcd-field span { width: 2.6rem; color: var(--orange); }
.lcd-field input, .lcd-field select {
  width: min(18rem, 100%);
  border: 1.5px solid var(--teal);
  border-radius: 2px;
  background: transparent;
  color: var(--teal);
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 0.2rem 0.4rem;
  text-transform: none;
}
.lcd-field select option { background: var(--screen); color: var(--teal); }
.screen-row { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.4rem; font-family: var(--mono); font-size: 0.72rem; }
.screen-box { border: 1.5px solid var(--orange); padding: 0 0.3rem; min-width: 1.5rem; text-align: center; }
.screen-status { flex: 1; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.screen-status.error { color: var(--orange); }
.screen-small { color: var(--teal); font-size: 0.6rem; white-space: nowrap; }

.deck { padding: 1.1rem 0.9rem 1.2rem; }

.transport { display: flex; gap: 0.7rem; align-items: center; margin-bottom: 1.1rem; }

.key {
  width: 3rem;
  height: 3rem;
  border: var(--stroke);
  border-radius: 50%;
  background: #f4f4f4;
  box-shadow: 0 3px 0 var(--ink);
  font-size: 1rem;
  transition: transform 60ms, box-shadow 60ms;
}
.key:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.key.play { background: var(--orange); color: #fff; }
body.playing .key.play { box-shadow: 0 0 0 var(--ink); transform: translateY(3px); }
.key.toggle[aria-pressed="true"] { background: var(--ink); color: #fff; }

.device-head .tempo { margin: 0 1.1rem 0 auto; align-self: center; }
.tempo { display: flex; flex-direction: column; align-items: center; gap: 0.25rem; cursor: ns-resize; user-select: none; touch-action: none; outline: none; }
.tempo[aria-disabled="true"] { opacity: 0.4; cursor: default; }
.dial {
  position: relative;
  width: 3rem;
  height: 3rem;
  border: var(--stroke);
  border-radius: 50%;
  background: #f4f4f4;
  box-shadow: 0 3px 0 var(--ink);
}
.tempo:focus-visible .dial { outline: 2px solid var(--orange); outline-offset: 2px; }
.dial-mark {
  position: absolute;
  left: calc(50% - 1.5px);
  top: 0.2rem;
  width: 3px;
  height: 1rem;
  border-radius: 2px;
  background: var(--ink);
  transform-origin: 50% 1.3rem;
  transform: rotate(var(--angle, 0deg));
}
.tempo.override .dial-mark { background: var(--orange); }
.tempo-value { font-family: var(--mono); font-size: 0.66rem; }
.tempo.override .tempo-value { color: var(--orange); }

.pads { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.55rem; }

.pad {
  position: relative;
  aspect-ratio: 1 / 1.15;
  border: var(--stroke);
  border-radius: 4px;
  background: #2a2a2a;
  color: #f4f4f4;
  box-shadow: 0 4px 0 var(--ink);
  padding: 0.35rem;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 60ms, box-shadow 60ms, background 120ms;
}
.pad:active { transform: translateY(4px); box-shadow: 0 0 0 var(--ink); }
.pad.muted { background: #f0f0ee; color: var(--muted); }
.pad.empty .pad-key { opacity: 0.4; }
.pad-key { font-size: 1.25rem; line-height: 1; }
.pad-label { font-size: 0.56rem; }
.pad-count { position: absolute; right: 0.35rem; top: 0.35rem; font-size: 0.56rem; font-family: var(--mono); opacity: 0.7; }
.led {
  position: absolute;
  top: -0.75rem;
  left: 50%;
  width: 7px;
  height: 7px;
  margin-left: -3.5px;
  border-radius: 50%;
  background: #8f4a33;
}
.pad.hit .led { animation: led 260ms ease-out; }
.pad.hit:not(.muted) { animation: thump 160ms ease-out; }
@keyframes led {
  from { background: var(--orange); box-shadow: 0 0 8px var(--orange); }
  to { background: #8f4a33; box-shadow: none; }
}
@keyframes thump {
  from { background: var(--orange); }
}

.sheet {
  display: flex;
  border: var(--stroke);
  background: #fafaf8;
  box-shadow: 5px 5px 0 -2px #fafaf8, 5px 5px 0 0 var(--ink), 10px 10px 0 -2px #fafaf8, 10px 10px 0 0 var(--ink);
  min-height: 100%;
}
.sheet-spine { width: 1.1rem; background: var(--orange); border-right: var(--stroke); }
.sheet-body { flex: 1; display: flex; flex-direction: column; }
.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: var(--orange);
  color: #fff;
  border-bottom: var(--stroke);
}
textarea {
  flex: 1;
  min-height: 15rem;
  border: none;
  resize: vertical;
  padding: 0.6rem 0.9rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.75rem;
  text-transform: none;
  letter-spacing: 0;
  background: repeating-linear-gradient(to bottom, transparent 0 calc(1.75rem - 1px), #d8d8d6 calc(1.75rem - 1px) 1.75rem) 0 0.6rem / 100% 1.75rem local, #fafaf8;
}
textarea:focus { outline: none; background-color: #fff; }

.sheet-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border-top: var(--stroke);
}
.status { font-size: 0.68rem; color: var(--muted); }
.status.error { color: var(--orange); }

.pill {
  border: var(--stroke);
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  padding: 0.35rem 0.95rem;
  font-size: 0.78rem;
  box-shadow: 0 3px 0 var(--orange);
}
.pill:hover { background: var(--orange); }
.pill:active { transform: translateY(3px); box-shadow: none; }
.song {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 1.6rem 1.4rem;
  margin-top: 3.2rem;
  padding: 0.4rem 0.8rem 1rem 0.2rem;
}
.arrow { position: absolute; top: 0; right: 0.2rem; color: var(--orange); font-size: 1.5rem; line-height: 1.9rem; }

.card {
  position: relative;
}
.card-tab {
  display: inline-block;
  background: var(--orange);
  color: #fff;
  border: var(--stroke);
  border-bottom: none;
  padding: 0.25rem 0.9rem;
  font-size: 0.82rem;
  margin-left: -2px;
  box-shadow: 4px -3px 0 -2px var(--orange), 4px -3px 0 0 var(--ink);
}
.card-body {
  background: #d9d9d7;
  border: var(--stroke);
  padding: 0.6rem 0.7rem 0.8rem;
  box-shadow: 4px 4px 0 -2px #d9d9d7, 4px 4px 0 0 var(--ink), 8px 8px 0 -2px #d9d9d7, 8px 8px 0 0 var(--ink);
  transition: background 120ms;
}
.card.now .card-body { background: #ececea; }
.card.now .card-tab { background: var(--ink); }
.card-verse {
  font-size: 0.72rem;
  line-height: 1.3;
  min-height: 2.6em;
  margin-bottom: 0.6rem;
  text-transform: none;
  letter-spacing: 0;
}

.lane { position: relative; display: flex; align-items: center; gap: 0.35rem; margin-bottom: 0.35rem; }
.lane.muted { opacity: 0.35; }
.lane-key {
  flex: none;
  width: 1.15rem;
  height: 1.15rem;
  display: grid;
  place-items: center;
  background: #8b8d90;
  color: #fff;
  border: 1.5px solid var(--ink);
  font-size: 0.66rem;
}
.lane-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  border: 1.5px solid var(--ink);
  border-radius: 3px;
  background: #fafaf8;
}
.cell {
  position: relative;
  height: 0.85rem;
  border-left: 1px solid #b5b5b3;
}
.cell:first-child { border-left: none; }
.cell.beat { border-left-color: var(--ink); }
.cell.beat:first-child { border-left: none; }
.cell.on::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: var(--ink);
}
.cell.hold::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  background: var(--ink);
}
.cell.now { background: var(--orange); }
.cell.on.now::after { background: #fff; transform: scale(1.5); }

.captions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2.5rem;
  margin: 1.4rem 0 3rem;
  font-size: 0.92rem;
  line-height: 1.3;
}
.captions p { margin: 0; }

.manual { position: relative; border: var(--stroke); background: #fafaf8; border-left: 1.1rem solid var(--orange); }
.manual-tab {
  position: absolute;
  top: -1.55rem;
  left: -1.1rem;
  background: var(--orange);
  color: #fff;
  border: var(--stroke);
  padding: 0.1rem 0.6rem;
  font-size: 0.8rem;
}
.rules { list-style: none; margin: 0; padding: 0; font-size: 0.74rem; }
.rules li {
  display: grid;
  grid-template-columns: 1rem 2.6rem 11rem 1fr 1fr;
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.3rem 0.7rem;
  border-bottom: 1px solid #d0d0ce;
}
.rules li:hover { background: #fff; }
.rules li:hover .rule-index, .rules li:hover .rule-track { color: var(--orange); }
.rule-dot { width: 7px; height: 7px; border-radius: 50%; background: #c4c4c2; align-self: center; }
.rules li:hover .rule-dot { background: var(--ink); }
.rule-index { font-family: var(--mono); color: var(--muted); }
.rule-source, .rule-result { text-transform: none; letter-spacing: 0; }
.rule-result { color: var(--muted); }

.code summary { padding: 0.5rem 0.7rem; cursor: pointer; font-size: 0.78rem; }
.code pre {
  margin: 0;
  padding: 0.7rem;
  background: var(--screen);
  color: var(--teal);
  font-family: var(--mono);
  font-size: 0.72rem;
  white-space: pre-wrap;
  word-break: break-all;
  text-transform: none;
}

@media (max-width: 900px) {
  .rig { grid-template-columns: 1fr; }
  .captions { grid-template-columns: 1fr; gap: 1rem; }
  .rules li { grid-template-columns: 1rem 2.6rem 1fr; }
  .rule-source, .rule-result { grid-column: 3; }
  .sticker { right: -0.5rem; width: 6.5rem; height: 6.5rem; font-size: 0.95rem; }
}

/* ---------- Embedded (?embed=1 in a frame) ----------
   The host page's language: pale paper, dark ink, one accent (violet), sentence
   case, hairlines instead of hard shadows. Same markup and behaviour. */
.embed {
  --paper: #f3f2ee;
  --panel: transparent;
  --ink: #1b1c1e;
  --muted: #5d5f63;
  --orange: #7b4bf0;
  --teal: #b9a6f7;
  --screen: #1b1c1e;
  --line: #cfccc4;
  --stroke: 1px solid var(--line);
  --font: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
}
.embed body { padding: 8px 24px 24px; text-transform: none; letter-spacing: 0; }
.embed .sticker, .embed .device-top, .embed .speaker, .embed .brand-sub, .embed .sheet-spine { display: none; }
.embed .stage { border: 0; border-radius: 0; padding: 0; background: none; }
.embed .rig { grid-template-columns: minmax(18rem, 24rem) minmax(16rem, 1fr); gap: 28px; }
.embed .device { background: none; border: var(--stroke); border-radius: 6px; box-shadow: none; overflow: hidden; }
.embed .device-head { background: none; border-bottom: var(--stroke); padding: 12px 14px; }
.embed .brand-name { font-size: 15px; font-weight: 500; letter-spacing: 0; }
.embed .brand-name::after { content: " · text into rhythm"; color: var(--muted); font-weight: 400; }
.embed .screen-tab { display: none; }
.embed .screen { border-bottom: var(--stroke); border-radius: 0; }
.embed .screen-box { border-width: 1px; }
.embed .key { width: 2.6rem; height: 2.6rem; border: var(--stroke); background: var(--paper); box-shadow: none; }
.embed .key:hover:not(:disabled) { border-color: var(--muted); }
.embed .key:active:not(:disabled), .embed body.playing .key.play { transform: none; }
.embed .key.play { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.embed .pad { border: var(--stroke); background: var(--paper); color: var(--ink); box-shadow: none; border-radius: 6px; }
.embed .pad:active { transform: none; }
.embed .pad.muted { background: none; color: var(--muted); }
.embed .pad-label { font-size: 0.62rem; }
.embed .sheet { border: var(--stroke); border-radius: 6px; background: none; box-shadow: none; overflow: hidden; }
.embed .sheet-head { background: none; color: var(--muted); border-bottom: var(--stroke); font-size: 12px; }
.embed textarea { background: transparent; font-size: 0.9rem; }
.embed textarea:focus { background: transparent; }
.embed .sheet-foot { border-top: var(--stroke); }
.embed .pill { border: 0; background: var(--ink); color: var(--paper); box-shadow: none; font-size: 13px; }
.embed .pill:hover { background: var(--orange); }
.embed .pill:active { transform: none; }
.embed .song { margin-top: 28px; padding: 0; }
.embed .card-tab { background: none; color: var(--muted); border: 0; box-shadow: none; padding: 0 0 4px; margin: 0; font-size: 12px; }
.embed .card-body { background: none; border: var(--stroke); border-radius: 6px; box-shadow: none; }
.embed .card.now .card-body { background: rgba(123, 75, 240, .06); border-color: var(--orange); }
.embed .card.now .card-tab { background: none; color: var(--orange); }
.embed .cell.beat { border-left-color: var(--muted); }
.embed .captions { font-size: 13px; color: var(--muted); gap: 24px; margin: 24px 0; }
.embed .manual { border: var(--stroke); border-left: var(--stroke); border-radius: 6px; background: none; margin-top: 32px; }
.embed .manual-tab { position: static; display: block; background: none; color: var(--muted); border: 0; border-bottom: var(--stroke); padding: 8px 12px; font-size: 12px; }
.embed .dial { background: var(--paper); box-shadow: none; }
/* The licence link stays visible when embedded, as a quiet line under the page. */
.embed body { display: flex; flex-direction: column; }
.embed .top { display: flex; order: 99; margin: 24px 0 0; font-size: 12px; color: var(--muted); gap: 12px; }
.embed .top a { color: var(--muted); border-bottom: 1px solid var(--line); }
.embed .led { background: var(--line); }
.embed .lane-key { background: none; color: var(--muted); border: var(--stroke); }
@media (max-width: 900px) { .embed .rig { grid-template-columns: 1fr; } }
@media (max-width: 520px) {
  .embed body { padding: 6px 12px 20px; }
  .embed .pads { gap: 0.35rem; grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .embed .rig, .embed .device, .embed .sheet { min-width: 0; }
  .embed .pad { min-width: 0; padding: 0.25rem; }
  .embed .pad-label { font-size: 0.55rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
