:root {
  --bg: #0f1116;
  --bg2: #161922;
  --card: #1a1e29;
  --line: #2a3040;
  --text: #eef1f7;
  --muted: #8d95a8;
  --accent: #ff7a45;
  --accent2: #ffb347;
  --mid: #4fc3f7;
  --ok: #46d39a;
  --warn: #ff6a6a;
  --c-D: #ff7a45;
  --c-T: #4fc3f7;
  --c-K: #9b8cff;
  --c-S: #46d39a;
  --c-R: #ff5fa2;
  --c-Z: #ffd166;
  --c-C: #2ec4b6;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --radius: 18px;
}
[data-theme="light"] {
  --bg: #f3f4f8;
  --bg2: #e9ebf2;
  --card: #ffffff;
  --line: #dde1ea;
  --text: #171a22;
  --muted: #646c80;
  --ok: #1fae74;
  --c-T: #1e9fd8;
  --c-K: #7a68f0;
  --c-S: #1fae74;
  --shadow: 0 8px 24px rgba(30,40,70,.10);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(1200px 600px at 50% -200px, rgba(255,122,69,.13), transparent 70%), var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- header ---------- */
.top {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  max-width: 1100px; margin: 0 auto; padding: 14px 18px;
  padding-top: max(14px, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.25rem; letter-spacing: .2px; }
.brand b { color: var(--accent); }
.top-actions { display: flex; gap: 8px; justify-self: end; }
.maker-logo {
  justify-self: center; display: block; background: #fff; border-radius: 12px; padding: 5px 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,.18); transition: transform .12s, box-shadow .12s; line-height: 0;
}
[data-theme="light"] .maker-logo { box-shadow: 0 0 0 1px var(--line); }
.maker-logo:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(79,195,247,.35); }
.maker-logo img { height: 36px; width: auto; display: block; }
.foot .dev { color: var(--text); }
.foot .dev a { color: var(--accent); font-weight: 600; text-decoration: none; }
.foot .dev a:hover { text-decoration: underline; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); display: grid; place-items: center; font-weight: 700;
}
.icon-btn:hover, .chip:hover { border-color: var(--accent); }

main { max-width: 1100px; margin: 0 auto; padding: 0 18px 20px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}

/* ---------- stage ---------- */
.stage { padding: 16px 20px 18px; text-align: center; position: relative; overflow: hidden; }
.stage-top { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.pill { padding: 3px 11px; border-radius: 99px; background: var(--bg2); border: 1px solid var(--line); color: var(--muted); font-size: .82rem; }

.meter-head { display: flex; align-items: baseline; justify-content: center; gap: 16px; margin-top: 8px; }
.sig-big { font-size: 3.6rem; font-weight: 800; letter-spacing: -1px; line-height: 1; }
.grouping { font-size: 1.15rem; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }

/* nabız noktaları: gruplar halinde */
.beats { display: flex; justify-content: center; align-items: center; gap: 18px; flex-wrap: wrap; margin: 16px auto 14px; min-height: 40px; }
.bgroup { display: flex; gap: 7px; align-items: center; padding: 6px 9px; border-radius: 99px; background: var(--bg2); border: 1px solid var(--line); transition: border-color .1s, background .1s; }
.bgroup.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--bg2)); }
.dot { width: 16px; height: 16px; border-radius: 50%; background: var(--line); transition: background .06s, transform .06s, box-shadow .06s; }
.dot.first { width: 22px; height: 22px; }
.dot.on { background: var(--accent2); transform: scale(1.18); box-shadow: 0 0 14px color-mix(in srgb, var(--accent2) 70%, transparent); }
.dot.first.on { background: var(--accent); box-shadow: 0 0 18px color-mix(in srgb, var(--accent) 80%, transparent); }

/* bölüm düğmeleri */
.sections { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin: 2px 0 8px; }
.sec {
  min-width: 96px; padding: 8px 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg2);
  display: flex; align-items: center; gap: 8px; font-weight: 600; position: relative; transition: border-color .12s, background .12s, transform .08s;
}
.sec b { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--line); font-size: .9rem; }
.sec:hover { border-color: var(--accent); }
.sec:active { transform: scale(.97); }
.sec.active { border-color: var(--accent); }
.sec.active b { background: var(--accent); color: #fff; }
.sec.now { background: color-mix(in srgb, var(--accent) 18%, var(--bg2)); box-shadow: 0 0 0 2px var(--accent); }
.sec.fill.now { background: color-mix(in srgb, var(--c-R) 22%, var(--bg2)); box-shadow: 0 0 0 2px var(--c-R); }
.sec.fill b { background: color-mix(in srgb, var(--c-R) 70%, var(--line)); color: #fff; }
.sec.end b { background: color-mix(in srgb, var(--warn) 70%, var(--line)); color: #fff; font-size: .7rem; }
.sec.queued { animation: blink .5s ease-in-out infinite alternate; }
.sec.queued::after { content: "▸"; position: absolute; top: -8px; right: -4px; background: var(--accent2); color: #000; border-radius: 99px; width: 18px; height: 18px; font-size: .7rem; display: grid; place-items: center; }
@keyframes blink { from { border-color: var(--line); } to { border-color: var(--accent2); background: color-mix(in srgb, var(--accent2) 16%, var(--bg2)); } }
.af-row { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.af-row .chip { padding: 5px 10px; font-size: .8rem; }

/* çok satırlı adım ızgarası */
.edit-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 18px 0 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.edit-head .chip { padding: 5px 10px; font-size: .82rem; }
.grid-wrap { overflow-x: auto; padding: 6px 2px 8px; -webkit-overflow-scrolling: touch; }
.grid { display: grid; gap: 6px; width: max-content; margin: 0 auto; }
.trow { display: flex; align-items: center; gap: 8px; }
.trow .tname {
  position: sticky; left: 0; z-index: 3; width: 104px; flex: none; text-align: left; padding: 0 8px; height: 38px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: .8rem; font-weight: 600;
  display: flex; align-items: center; gap: 7px; white-space: nowrap; overflow: hidden;
}
.tname .mdot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.trow.muted .tname .mdot { background: var(--warn); }
.trow.muted .tname { color: var(--muted); text-decoration: line-through; }
.trow.muted .cells { opacity: .35; }
.trow.empty .cells { opacity: .55; }
.cells { display: flex; gap: 10px; }
.ggroup { display: flex; gap: 3px; }
.step {
  width: 30px; height: 38px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg2);
  display: grid; place-items: center; font-weight: 800; font-size: .8rem; padding: 0; position: relative;
  user-select: none; touch-action: manipulation; transition: transform .06s, box-shadow .06s; color: #fff;
}
.step.beat { background: color-mix(in srgb, var(--line) 55%, var(--bg2)); }
.step[data-s] { border-color: transparent; }
.step[data-s="D"] { background: var(--c-D); }
.step[data-s="T"] { background: var(--c-T); }
.step[data-s="K"] { background: var(--c-K); }
.step[data-s="S"] { background: var(--c-S); }
.step[data-s="R"] { background: var(--c-R); }
.step[data-s="Z"] { background: var(--c-Z); color: #3a2a00; }
.step[data-s="C"] { background: var(--c-C); }
.step[data-s="H"] { background: #8d95a8; }
.trow .tname { cursor: pointer; }
.step.soft { opacity: .55; }
.step.soft::after { content: ""; position: absolute; inset: 3px; border-radius: 6px; border: 1.5px dashed rgba(255,255,255,.75); }
.step.cur { transform: translateY(-3px); box-shadow: 0 0 0 2px var(--text), 0 6px 14px rgba(0,0,0,.3); }
.step:not([data-s]).cur { background: color-mix(in srgb, var(--text) 22%, var(--bg2)); }
.step:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.grid.dense .step { width: 26px; }
.grid.dense .cells { gap: 8px; }

.sw { width: 20px; height: 20px; border-radius: 6px; display: inline-grid; place-items: center; color: #fff; font-style: normal; font-weight: 800; font-size: .72rem; flex: none; }
.sw[data-s="D"] { background: var(--c-D); } .sw[data-s="T"] { background: var(--c-T); } .sw[data-s="K"] { background: var(--c-K); }
.sw[data-s="S"] { background: var(--c-S); } .sw[data-s="R"] { background: var(--c-R); } .sw[data-s="Z"] { background: var(--c-Z); color: #3a2a00; }
.sw[data-s="C"] { background: var(--c-C); }
.hint { margin: 6px 0 0; font-size: .76rem; color: var(--muted); }

/* mikser */
.mixer { display: grid; gap: 8px; margin-top: 10px; }
.mrow { display: grid; grid-template-columns: 36px 104px 1fr 30px; align-items: center; gap: 8px; }
.mrow b { text-align: right; font-variant-numeric: tabular-nums; font-size: .85rem; }
.mbtn { width: 36px; height: 32px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg2); display: grid; place-items: center; }
.mrow.muted .mbtn { color: var(--warn); border-color: var(--warn); }
.mrow.muted .mname, .mrow.muted b { color: var(--muted); }
.mname { font-size: .88rem; }

.tempo { margin-top: 14px; }
.tempo-num { font-size: 1.5rem; color: var(--muted); font-weight: 600; }
.tempo-num b { font-size: 3.8rem; color: var(--text); font-weight: 800; letter-spacing: -1px; font-variant-numeric: tabular-nums; vertical-align: -6px; }
.tempo-num .unit { font-size: 2rem; color: var(--accent); }
.tempo-word { color: var(--muted); font-size: .9rem; min-height: 1.2em; }
.tempo-row { display: flex; align-items: center; gap: 12px; max-width: 520px; margin: 8px auto 0; }
.round { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg2); font-size: 1.4rem; flex: none; user-select: none; touch-action: manipulation; }
.round:active { border-color: var(--accent); }

.controls { display: flex; align-items: center; justify-content: center; gap: 22px; margin: 14px 0 4px; }
.play {
  width: 96px; height: 96px; border-radius: 50%; border: 0; position: relative;
  background: linear-gradient(145deg, var(--accent2), var(--accent)); color: #fff;
  box-shadow: 0 10px 30px rgba(255,122,69,.45); display: grid; place-items: center;
  transition: transform .08s;
}
.play:active { transform: scale(.95); }
.play svg { width: 46px; height: 46px; }
.play .i-stop { display: none; }
body.playing .play .i-stop { display: block; }
body.playing .play .i-play { display: none; }
body.playing .play { background: linear-gradient(145deg, #ff6a6a, #e0445a); box-shadow: 0 10px 30px rgba(224,68,90,.45); }
body.playing .play.pulse::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid #ff6a6a; animation: pulse .5s ease-out; pointer-events: none;
}
@keyframes pulse { from { transform: scale(1); opacity: .8; } to { transform: scale(1.4); opacity: 0; } }
.tap {
  width: 76px; height: 76px; border-radius: 22px; border: 1px solid var(--line);
  background: var(--bg2); font-weight: 800; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px; user-select: none; touch-action: manipulation;
}
.tap small { font-weight: 500; font-size: .7rem; color: var(--muted); }
button.tap:active, button.tap.hit { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--bg2)); }
.counter b { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.advice { margin: 8px 0 2px; min-height: 1.4em; font-weight: 600; color: var(--accent); }
body.idle .advice { color: var(--muted); font-weight: 500; }

/* ---------- panels ---------- */
.panels { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-top: 16px; }
.panel { padding: 16px 18px 18px; }
.panel-wide { grid-column: 1 / -1; }
.panel h2 { margin: 0 0 6px; font-size: 1.05rem; }
.lbl { display: flex; justify-content: space-between; margin: 14px 0 6px; font-size: .85rem; color: var(--muted); }
.lbl b { color: var(--text); font-weight: 600; }

.rhythm-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin-top: 10px; }
.rcard {
  text-align: left; border: 1px solid var(--line); background: var(--bg2); border-radius: 14px; padding: 11px 13px;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: baseline; transition: border-color .12s, transform .08s;
}
.rcard:hover { border-color: var(--accent); }
.rcard:active { transform: scale(.98); }
.rcard b { font-size: 1rem; }
.rcard .rsig { font-weight: 800; color: var(--accent); font-size: 1.05rem; }
.rcard small { color: var(--muted); font-size: .76rem; grid-column: 1 / -1; }
.rcard .key { color: var(--muted); font-size: .7rem; border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; margin-right: 6px; font-weight: 600; }
.rcard.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.rcard.active .rsig, .rcard.active small, .rcard.active .key { color: #fff; border-color: rgba(255,255,255,.5); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--bg2); border-radius: 10px; padding: 7px 11px;
  font-size: .9rem; line-height: 1.1;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg2); width: max-content; }
.stepper button { width: 38px; height: 38px; border: 0; background: transparent; font-size: 1.2rem; user-select: none; }
.stepper span { min-width: 48px; text-align: center; font-size: 1.1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 1px; }
.slider { width: 100%; accent-color: var(--accent); height: 28px; }

.toggles { display: grid; gap: 10px; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; margin: 8px 0; }
.toggles .switch { margin: 0; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch span {
  width: 42px; height: 24px; border-radius: 99px; background: var(--line); position: relative; flex: none;
  transition: background .15s;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform .15s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch em { font-style: normal; }

.trainer-grid { display: grid; grid-template-columns: auto auto 1fr; align-items: center; gap: 10px 12px; margin-top: 8px; }
.trainer-grid .lbl { margin: 0; }
.trainer-grid.off { opacity: .5; }

.stroke-info { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 10px; }
.stroke-info li { display: grid; grid-template-columns: 120px 1fr; gap: 10px; align-items: start; }
.stroke-info li span { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.stroke-info em { font-style: normal; display: inline-flex; gap: 6px; align-items: center; font-size: .88rem; }

.btn {
  border: 0; border-radius: 12px; padding: 9px 16px; background: var(--accent); color: #fff; font-weight: 600;
}
.btn.ghost { background: var(--bg2); color: var(--text); border: 1px solid var(--line); }
.small-btn { padding: 6px 12px; font-size: .82rem; }

.steps { margin: 8px 0 10px; padding-left: 20px; display: grid; gap: 7px; line-height: 1.4; }

.foot { text-align: center; padding: 10px 18px 30px; color: var(--muted); font-size: .9rem; }
.foot p { margin: 4px 0; }
.foot .credits a { color: inherit; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .92rem;
  transition: .2s; pointer-events: none; z-index: 60; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text);
  max-width: 460px; width: calc(100% - 32px); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog h3 { margin-top: 0; }
.keys { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.keys td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
kbd {
  display: inline-block; padding: 2px 7px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg2); font-size: .82rem; font-family: inherit;
}

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .panels { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .top { grid-template-columns: 1fr auto; row-gap: 10px; }
  .maker-logo { grid-column: 1 / -1; grid-row: 1; }
  .maker-logo img { height: 30px; }
  .brand { font-size: 1.1rem; white-space: nowrap; gap: 8px; }
  .brand img { width: 30px; height: 30px; }
}
@media (max-width: 480px) {
  main { padding: 0 10px 16px; }
  .stage { padding: 12px 10px 14px; }
  .sig-big { font-size: 2.8rem; }
  .beats { gap: 10px; }
  .bgroup { gap: 5px; padding: 5px 7px; }
  .dot { width: 13px; height: 13px; } .dot.first { width: 18px; height: 18px; }
  .trow .tname { width: 84px; font-size: .74rem; padding: 0 6px; }
  .stroke-info li { grid-template-columns: 1fr; gap: 4px; }
  .sections { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .sec { min-width: 0; padding: 7px 2px; gap: 3px; font-size: .72rem; flex-direction: column; }
  .sec b { width: 24px; height: 24px; }
  .mrow { grid-template-columns: 34px 84px 1fr 28px; }
  .tempo-num b { font-size: 3.2rem; }
  .controls { gap: 16px; }
  .play { width: 86px; height: 86px; }
  .tap { width: 68px; height: 68px; }
  .rhythm-list { grid-template-columns: 1fr 1fr; gap: 8px; }
  .rcard { padding: 9px 10px; }
}
@media (prefers-reduced-motion: reduce) {
  body.playing .play.pulse::before { animation: none; }
}
