:root {
  --bg: #0f1116;
  --bg2: #161922;
  --card: #1a1e29;
  --line: #2a3040;
  --text: #eef1f7;
  --muted: #8d95a8;
  --accent: #ff7a45;
  --accent2: #ffb347;
  --mid: #4fc3f7;
  --ok: #46d39a;
  --warn: #ff6a6a;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --radius: 18px;
  --state: var(--muted);
}
[data-theme="light"] {
  --bg: #f3f4f8;
  --bg2: #e9ebf2;
  --card: #ffffff;
  --line: #dde1ea;
  --text: #171a22;
  --muted: #646c80;
  --ok: #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; position: relative; overflow: hidden; transition: box-shadow .25s; }

/* ---------- panels ---------- */
.panels { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-top: 16px; }
.panel { padding: 16px 18px 18px; }
.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; }

.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; }

.sig { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg2); }
.stepper button { width: 40px; height: 42px; border: 0; background: transparent; font-size: 1.3rem; user-select: none; }
.stepper span { min-width: 46px; text-align: center; font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
select {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; height: 44px; padding: 0 12px; font-size: 1rem;
}
select.wide { width: 100%; }
select:focus, 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; }
.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; }

.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); margin-left: auto; }

.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; }

#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;
}


/* =================== Nova Makam =================== */
:root { --koma: #b388ff; --scale: #4fc3f7; --wkey: #f7f8fb; --bkey: #1b1f29; }
[data-theme="light"] { --koma: #8e5cf0; --scale: #1e9fd8; }

.pick { display: grid; gap: 10px; }
.pick-row { display: flex; align-items: flex-start; gap: 12px; }
.pick-lbl { flex: none; width: 58px; padding-top: 8px; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
#makamChips .chip { font-weight: 600; font-size: .95rem; padding: 8px 14px; }
.karar-chips .chip { min-width: 46px; text-align: center; position: relative; }
.karar-chips .chip.home::after {
  content: "★"; position: absolute; top: -8px; right: -5px; font-size: .72rem; color: var(--accent2);
}
.karar-chips .chip.active.home::after { color: #ffe08a; }

.title-row { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; margin: 16px 0 6px; }
.title-row h1 { margin: 0; font-size: 2rem; letter-spacing: -.5px; }
.title-row h1 small { font-size: .55em; color: var(--muted); font-weight: 600; margin-left: 6px; letter-spacing: 0; }
.facts { display: flex; gap: 8px; flex-wrap: wrap; }
.fact { padding: 3px 11px; border-radius: 99px; background: var(--bg2); border: 1px solid var(--line); color: var(--muted); font-size: .82rem; }
.fact b { color: var(--text); font-weight: 600; }

/* degree strip */
.degrees { display: flex; align-items: stretch; margin: 10px 0 2px; overflow-x: auto; padding: 8px 6px 24px; }
.deg {
  flex: 1 1 0; min-width: 76px; border: 1px solid var(--line); background: var(--bg2); border-radius: 14px;
  padding: 7px 6px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative;
  transition: transform .08s, border-color .12s, background .12s; color: inherit;
}
.deg:active { transform: scale(.97); }
.deg .perde { font-size: .74rem; color: var(--muted); white-space: nowrap; }
.deg .nm { font-size: 1.25rem; font-weight: 800; line-height: 1.15; white-space: nowrap; }
.deg .kv { font-size: .74rem; font-weight: 700; min-height: 1.1em; white-space: nowrap; color: var(--muted); }
.deg.koma { border-color: color-mix(in srgb, var(--koma) 70%, var(--line)); background: color-mix(in srgb, var(--koma) 14%, var(--bg2)); }
.deg.koma .kv { color: var(--koma); }
.deg.karar { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--bg2)); }
.deg.guclu::before {
  content: "G"; position: absolute; top: -8px; right: -6px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--ok); color: #fff; font-size: .66rem; font-weight: 800; display: grid; place-items: center;
}
.deg.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.deg .ix { position: absolute; bottom: -21px; font-size: .72rem; color: var(--muted); }
.gap { flex: 0 0 24px; position: relative; }
.gap::before { content: ""; position: absolute; top: 50%; left: 3px; right: 3px; height: 2px; background: var(--line); }
.gap span { position: absolute; bottom: -21px; left: 0; right: 0; text-align: center; font-size: .74rem; font-weight: 700; color: var(--muted); }
.cins-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 4px; font-size: .8rem; }
.cins { padding: 2px 10px; border-radius: 8px; border: 1px dashed var(--line); color: var(--muted); }
.cins b { color: var(--text); font-weight: 600; }

/* keyboard bar */
.kb-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin: 12px 0 8px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .78rem; color: var(--muted); align-items: center; }
.legend > span { display: inline-flex; align-items: center; gap: 5px; }
.sw { width: 14px; height: 14px; border-radius: 4px; display: inline-grid; place-items: center; font-style: normal; font-size: .58rem; font-weight: 800; color: #fff; }
.sw-karar { background: var(--accent); }
.sw-scale { background: var(--scale); }
.sw-koma { background: var(--koma); }
.sw-guclu { background: var(--ok); border-radius: 50%; }
.kb-nav { display: flex; gap: 6px; align-items: center; }
.kb-nav .icon-btn { font-size: 1.4rem; line-height: 1; }

/* keyboard */
.kb-wrap { border-radius: 14px; padding: 12px 8px 8px; background: linear-gradient(#262b38, #14171e); box-shadow: inset 0 2px 8px rgba(0,0,0,.5); }
[data-theme="light"] .kb-wrap { background: linear-gradient(#3a4050, #252935); }
.kb { position: relative; height: 230px; display: flex; user-select: none; -webkit-user-select: none; touch-action: none; }
.key { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; cursor: pointer; }
.key.white {
  flex: 1 1 0; min-width: 0; height: 100%; margin-right: 2px; border-radius: 0 0 8px 8px; background: var(--wkey);
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.08), 0 2px 0 rgba(0,0,0,.35); color: #4a5163; padding-bottom: 12px;
}
.key.white:last-child { margin-right: 0; }
.key.black {
  position: absolute; top: 0; height: 60%; z-index: 2; border-radius: 0 0 6px 6px; background: var(--bkey);
  box-shadow: inset 0 -5px 0 rgba(255,255,255,.07), 0 3px 4px rgba(0,0,0,.5); color: #a6aec0; padding-bottom: 8px;
}
.key .kn { font-size: .78rem; font-weight: 700; line-height: 1.1; white-space: nowrap; pointer-events: none; }
.key.black .kn { font-size: .64rem; }
.key .kl { font-size: .62rem; opacity: .55; margin-top: 2px; text-transform: uppercase; pointer-events: none; }
.key .badge {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 34px; min-width: 24px; padding: 2px 5px; border-radius: 7px;
  background: var(--koma); color: #fff; font-size: .74rem; font-weight: 800; text-align: center; line-height: 1.25; white-space: nowrap;
  pointer-events: none; box-shadow: 0 1px 3px rgba(0,0,0,.35);
}
.key.white .badge { bottom: auto; top: calc(60% + 6px); }
.key.white .gdot { top: calc(60% + 6px); }
.key.white .gdot + .badge { top: calc(60% + 28px); }
.key.black.has-kl .badge { bottom: 48px; }
.key .gdot {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%); width: 18px; height: 18px; border-radius: 50%;
  background: var(--ok); color: #fff; font-size: .62rem; font-weight: 800; display: grid; place-items: center; pointer-events: none;
}
.key.black .gdot { top: 6px; }

/* scale colouring */
.key.white.in { background: color-mix(in srgb, var(--scale) 40%, var(--wkey)); color: #0b3446; }
.key.black.in { background: color-mix(in srgb, var(--scale) 58%, var(--bkey)); color: #fff; }
.key.white.km { background: color-mix(in srgb, var(--koma) 45%, var(--wkey)); color: #34186a; }
.key.black.km { background: color-mix(in srgb, var(--koma) 66%, var(--bkey)); color: #fff; }
.key.white.kr { background: color-mix(in srgb, var(--accent) 58%, var(--wkey)); color: #4d1d04; }
.key.black.kr { background: color-mix(in srgb, var(--accent) 72%, var(--bkey)); color: #fff; }
.key.km .badge { background: #6a3fd0; }
.key.desc::after {
  content: ""; position: absolute; inset: 4px; border: 2px dashed color-mix(in srgb, var(--scale) 85%, transparent);
  border-radius: 0 0 6px 6px; pointer-events: none;
}
.key.out.white { color: #a2a8b6; }
.key.out.black { color: #4b5160; }
.key.dim { opacity: .55; }
.key.white.down { background: var(--accent2) !important; box-shadow: inset 0 -2px 0 rgba(0,0,0,.15); transform: translateY(2px); color: #4d1d04; }
.key.black.down { background: var(--accent) !important; color: #fff; }
.key.kr .kn::before { content: "●"; display: block; font-size: .6rem; text-align: center; margin-bottom: 1px; }

.play-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.btn.big { padding: 11px 16px; font-size: .98rem; display: inline-flex; align-items: center; gap: 6px; }
.btn.ghost2 { background: var(--bg2); color: var(--text); border: 1px solid var(--line); }
.btn.on { background: #e0445a !important; color: #fff !important; border-color: #e0445a !important; }
#timbreChips { margin-left: auto; }

/* cents table */
.cents { width: 100%; border-collapse: separate; border-spacing: 3px; margin: 10px 0 8px; table-layout: fixed; }
.cents th, .cents td { text-align: center; padding: 6px 0; border-radius: 8px; font-variant-numeric: tabular-nums; }
.cents th { font-size: .8rem; color: var(--muted); font-weight: 600; background: var(--bg2); }
.cents td { font-weight: 700; background: var(--bg2); font-size: .9rem; }
.cents td.nz { background: color-mix(in srgb, var(--koma) 28%, var(--bg2)); color: var(--text); }
.cents td.z { color: var(--muted); font-weight: 500; }
.cents tr.inrow td { font-size: .7rem; font-weight: 600; color: var(--muted); padding: 2px 0; background: transparent; }
.row-btns { display: flex; gap: 8px; }
#about p { margin: 6px 0; line-height: 1.45; }
#about ul { margin: 6px 0; padding-left: 18px; line-height: 1.5; }

@media (max-width: 760px) {
  .kb { height: 200px; }
  #timbreChips { margin-left: 0; }
}
@media (max-width: 480px) {
  .pick-row { flex-direction: column; gap: 4px; }
  .pick-lbl { padding-top: 0; }
  .karar-chips .chip { min-width: 40px; padding: 7px 8px; }
  .title-row h1 { font-size: 1.6rem; }
  .deg { min-width: 62px; }
  .deg .nm { font-size: 1.05rem; }
  .kb { height: 190px; }
  .key .kn { font-size: .66rem; }
  .key.black .kn { font-size: .54rem; }
  .key .badge { font-size: .66rem; padding: 1px 3px; min-width: 18px; }
  .legend { gap: 8px; }
  .btn.big { padding: 10px 12px; font-size: .9rem; }
}
/* ---------- 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; }
}

/* ---------- Scale (QT) ---------- */
.qt-btn { font-weight: 800; letter-spacing: .04em; }
.qt-btn.active { background: var(--koma); border-color: var(--koma); color: #fff; box-shadow: 0 0 14px color-mix(in srgb, var(--koma) 60%, transparent); }
body.qt-edit .kb-wrap { box-shadow: inset 0 2px 8px rgba(0,0,0,.5), 0 0 0 2px var(--koma); }
.key.cust.white { background: color-mix(in srgb, var(--koma) 30%, var(--wkey)); color: #34186a; }
.key.cust.black { background: color-mix(in srgb, var(--koma) 50%, var(--bkey)); color: #fff; }
.qt-oct { position: relative; height: 118px; display: flex; margin: 12px 0 10px; user-select: none; touch-action: manipulation; }
.qk { border: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 1px; padding-bottom: 6px; font-weight: 700; }
.qk.w { flex: 1; height: 100%; background: #f7f8fb; color: #4a5163; border-radius: 0 0 8px 8px; margin-right: -1px; }
.qk.b { position: absolute; top: 0; width: 10%; height: 60%; margin-left: -5%; background: #1b1f29; color: #a6aec0; border-color: #000; border-radius: 0 0 6px 6px; z-index: 2; font-size: .7rem; }
.qk .qn { font-size: .78rem; }
.qk .qv { font-size: .72rem; font-variant-numeric: tabular-nums; opacity: .7; }
.qk.on.w { background: color-mix(in srgb, var(--koma) 50%, #f7f8fb); color: #2a1059; }
.qk.on.b { background: color-mix(in srgb, var(--koma) 75%, #1b1f29); color: #fff; }
.qk.on .qv { opacity: 1; }
.qk.sel { outline: 3px solid var(--accent); outline-offset: -3px; }
.qt-fine { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.qt-fine b { min-width: 34px; font-size: 1.1rem; }
.qt-step button { width: auto; min-width: 38px; padding: 0 8px; font-size: 1rem; }
.qt-step span { min-width: 52px; }
#qtAmtChips small { opacity: .75; font-size: .72rem; }
.qt-acts { margin-top: 12px; flex-wrap: wrap; }
.qt-slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.slot {
  border: 1px solid var(--line); background: var(--bg2); border-radius: 10px; padding: 7px 6px; min-height: 52px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; overflow: hidden;
}
.slot b { font-size: .95rem; }
.slot span { font-size: .7rem; color: var(--muted); max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot.full { border-color: color-mix(in srgb, var(--koma) 60%, var(--line)); }
.slot.active { background: var(--koma); border-color: var(--koma); color: #fff; }
.slot.active span { color: #fff; opacity: .9; }
body.qt-saving .slot { border-style: dashed; border-color: var(--accent); animation: blink 1s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .55; } }
#qtSave.on { background: #e0445a; }
