@font-face { font-family: 'EB Garamond'; src: url(fonts/ebgaramond-regular.woff2) format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'EB Garamond'; src: url(fonts/ebgaramond-bold.woff2) format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'EB Garamond'; src: url(fonts/ebgaramond-italic.woff2) format('woff2'); font-weight: 400; font-style: italic; font-display: swap; }

:root {
  --bg: #17130f; --panel: #211b16; --panel2: #2b241d; --line: #3a3027;
  --text: #f3e9d8; --muted: #c9bba6; --accent: #e0a24a; --rec: #e2604c;
  --c0: #e0a24a; --c1: #4fb3a5; --c2: #e0705a; --c3: #8f7ae6;
  --r: 18px; --gap: 8px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overscroll-behavior: none; }
body { font-family: 'EB Garamond', 'Garamond', 'Times New Roman', serif; font-size: 18px; line-height: 1.3;
  font-variant-numeric: lining-nums tabular-nums; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overflow: hidden; }
button, select, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
.i { width: 22px; height: 22px; display: block; }
.num { font-variant-numeric: lining-nums tabular-nums; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { height: 100%; height: 100dvh; display: grid; max-width: 1280px; margin: 0 auto;
  grid-template-columns: minmax(0, 1fr); grid-template-rows: 52px 58px 14px 44px minmax(0, 1fr) auto; grid-template-areas: 'top' 'trans' 'beats' 'views' 'stage' 'strip';
  padding: 0 12px calc(8px + var(--safe-b)); }
.top { grid-area: top; display: flex; align-items: center; gap: 10px; }
.brand { font-size: 26px; font-weight: 700; margin: 0; flex: 1; letter-spacing: .01em; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px; border-radius: 20px; background: var(--panel2); font-size: 19px; }
.chip .i { width: 12px; height: 12px; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; color: var(--muted); }
.icon-btn:active { background: var(--panel2); }

.transport { grid-area: trans; display: flex; align-items: center; gap: 6px; min-width: 0; }
.t-btn { width: 48px; flex: none; height: 46px; border-radius: 14px; background: var(--panel); display: grid; place-items: center; color: var(--text); }
.t-btn.small { width: 42px; color: var(--muted); }
.t-btn .stop { display: none; }
.t-btn[aria-pressed=true] .play { display: none; }
.t-btn[aria-pressed=true] .stop { display: block; }
#playBtn[aria-pressed=true] { background: #3a3122; color: var(--accent); }
.t-btn.rec { color: var(--rec); }
.t-btn.rec[aria-pressed=true] { background: var(--rec); color: #fff; animation: pulse 1s ease-in-out infinite; }
.t-btn.rec.armed { background: #5a2a22; color: #ffd9cf; }
#metBtn[aria-pressed=true] { color: var(--accent); background: #3a3122; }
.t-btn:active { transform: scale(.95); }
.tempo { flex: 1; min-width: 0; height: 46px; border-radius: 14px; background: var(--panel); display: flex; align-items: baseline; justify-content: center; gap: 5px; touch-action: none; }
.tempo .num { font-size: 26px; line-height: 46px; }
.tempo .unit { color: var(--muted); font-size: 15px; font-style: italic; }
@keyframes pulse { 50% { opacity: .75; } }

.beats { grid-area: beats; display: flex; gap: 3px; align-items: center; padding: 0 2px; }
.beats i { flex: 1; height: 3px; border-radius: 2px; background: var(--line); transition: background .08s; }
.beats i.bar { margin-left: 4px; }
.beats i.on { background: var(--accent); }
.beats i.count { background: var(--rec); }

.views { grid-area: views; display: flex; align-items: center; justify-content: space-between; gap: 6px; min-width: 0; }
.seg { display: inline-flex; background: var(--panel); border-radius: 12px; padding: 3px; }
.seg button { height: 36px; padding: 0 10px; border-radius: 9px; color: var(--muted); font-size: 17px; min-width: 44px; }
.seg button[aria-selected=true], .seg button[aria-checked=true] { background: var(--panel2); color: var(--text); box-shadow: 0 1px 0 #0006; }

.stage { grid-area: stage; position: relative; min-height: 0; display: flex; flex-direction: column; justify-content: center; gap: 8px; }
.melbar { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 16px; color: var(--muted); flex-wrap: nowrap; }
.melbar[hidden] { display: none; }
.melbar select { background: var(--panel); border: 0; border-radius: 9px; height: 34px; padding: 0 6px; color: var(--text); }
.oct { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.oct button { width: 36px; height: 34px; border-radius: 9px; background: var(--panel); font-size: 20px; }
.oct span { width: 22px; text-align: center; }

.pads { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap); width: 100%; max-width: min(100%, calc(100dvh - 300px));
  margin: 0 auto; aspect-ratio: 1; touch-action: none; }
.pad { position: relative; border-radius: var(--r); --c: var(--c0); touch-action: none;
  background: radial-gradient(120% 120% at 30% 20%, color-mix(in srgb, var(--c) 34%, #2b241d) 0%, color-mix(in srgb, var(--c) 16%, #1d1813) 70%);
  box-shadow: inset 0 1px 0 #ffffff14, inset 0 -2px 0 #0000004d, 0 2px 0 #0000004d;
  display: flex; flex-direction: column; justify-content: flex-end; padding: 8px 6px 8px 8px; overflow: hidden; transition: transform .09s ease-out, filter .14s; }
.pad[data-row="1"] { --c: var(--c1); } .pad[data-row="2"] { --c: var(--c2); } .pad[data-row="3"] { --c: var(--c3); }
.pad .lbl { font-size: 15px; font-feature-settings: 'lnum' 1; white-space: nowrap; letter-spacing: -.01em; line-height: 1.1; color: color-mix(in srgb, var(--c) 35%, var(--text)); pointer-events: none; }
.pad .key { position: absolute; top: 7px; right: 9px; font-size: 13px; color: var(--muted); opacity: .8; display: none; pointer-events: none; }
.pad .glow { position: absolute; inset: 0; border-radius: inherit; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at var(--x, 50%) var(--y, 50%), color-mix(in srgb, var(--c) 85%, #fff) 0%, transparent 70%); }
.pad.hit { transform: scale(.955); filter: brightness(1.35); }
.pad.hit .glow { opacity: .8; transition: none; }
.pad .glow { transition: opacity .28s ease-out; }
.pad.tonic { box-shadow: inset 0 1px 0 #ffffff14, 0 2px 0 #0000004d; }
.pad.tonic::before { content: ''; position: absolute; top: 10px; left: 10px; width: 11px; height: 11px; border-radius: 50%; background: #fff6e6; box-shadow: 0 0 0 3px #0000004d; pointer-events: none; z-index: 1; }
.pad.tonic .lbl { color: #fff6e6; }
.pad.mic .lbl::after { content: ' •'; color: var(--rec); }
.pad.flash { animation: seqflash .18s ease-out; }
@keyframes seqflash { 0% { filter: brightness(1.5); } 100% { filter: none; } }
@media (hover: hover) and (pointer: fine) { .pad .key { display: block; } }
@media (prefers-reduced-motion: reduce) { .pad.hit { transform: none; } .pad .glow { display: none; } .t-btn.rec[aria-pressed=true] { animation: none; } }

.grid { display: none; overflow-y: auto; overflow-x: hidden; touch-action: pan-y; padding-bottom: 6px; height: 100%; }
.app[data-view=grid] .pads { display: none; }
.app[data-view=grid] .grid { display: block; }
.grow { display: grid; grid-template-columns: 84px 1fr; align-items: center; gap: 6px; margin: 3px 0; }
.gname { font-size: 13.5px; letter-spacing: -.01em; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 5px; }
.gname::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--c); flex: none; }
.gcells { display: grid; grid-template-columns: repeat(var(--steps), 1fr); gap: 2px; }
.gc { height: 26px; border-radius: 4px; background: #2c241d; touch-action: manipulation; }
.gc.beat { background: #3b3127; }
.gc.barline { margin-left: 3px; }
.gc.on { background: var(--c); }
.gc.ph { box-shadow: inset 0 0 0 2px #f3e9d880; }
.grow[data-row="0"] { --c: var(--c0); } .grow[data-row="1"] { --c: var(--c1); } .grow[data-row="2"] { --c: var(--c2); } .grow[data-row="3"] { --c: var(--c3); }
.gnote { font-size: 13px; color: var(--muted); margin: 8px 0 2px; font-style: italic; }

.status { position: absolute; left: 0; right: 0; bottom: -2px; text-align: center; font-size: 15px; color: var(--muted); font-style: italic; pointer-events: none; min-height: 18px; }

.strip { grid-area: strip; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; padding-top: 10px; font-size: 16px; color: var(--muted); }
.ctl { display: flex; align-items: center; gap: 6px; }
.ctl select { background: var(--panel); border: 0; border-radius: 9px; height: 38px; padding: 0 6px; color: var(--text); }
.ctl.swing { flex: 1; min-width: 0; }
.ctl.swing input { flex: 1; min-width: 40px; width: 100%; accent-color: var(--accent); height: 38px; }
.ctl.swing .num { width: 34px; text-align: right; color: var(--text); }

.sheet { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.scrim { position: absolute; inset: 0; background: #0009; }
.panel { position: relative; width: 100%; max-width: 560px; max-height: 86dvh; overflow: auto; background: var(--panel); border-radius: 22px 22px 0 0;
  padding: 6px 18px calc(18px + var(--safe-b)); -webkit-user-select: text; user-select: text; touch-action: pan-y; }
@media (min-width: 700px) { .sheet { align-items: center; } .panel { border-radius: 22px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--panel); padding: 6px 0; }
.sheet-head h2 { margin: 0; font-size: 24px; }
.sheet-body p { color: var(--muted); margin: 6px 0 12px; }
.sheet-body a { color: var(--accent); }
.sheet-body h3 { font-size: 19px; margin: 18px 0 6px; }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card { text-align: left; background: var(--panel2); border-radius: 14px; padding: 12px; min-height: 76px; }
.card b { display: block; font-size: 20px; }
.card span { color: var(--muted); font-size: 15px; }
.card[aria-pressed=true] { box-shadow: inset 0 0 0 2px var(--accent); }
.menu-list { display: grid; gap: 6px; }
.menu-list button, .btn { text-align: left; background: var(--panel2); border-radius: 12px; min-height: 48px; padding: 10px 14px; font-size: 19px; }
.menu-list button small { display: block; color: var(--muted); font-size: 15px; }
.btn { text-align: center; }
.btn.primary { background: var(--accent); color: #1d160c; font-weight: 700; }
.btn.danger { color: var(--rec); }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.row > .btn { flex: 1; }
.field { display: grid; grid-template-columns: 82px 1fr 64px; align-items: center; gap: 8px; margin: 10px 0; }
.field input[type=range] { width: 100%; accent-color: var(--accent); height: 36px; }
.field output { text-align: right; color: var(--muted); }
.text-in { width: 100%; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); padding: 0 10px; }
.saved { display: grid; gap: 6px; margin-top: 8px; }
.saved .it { display: flex; align-items: center; gap: 6px; background: var(--panel2); border-radius: 12px; padding: 4px 6px 4px 12px; }
.saved .it span { flex: 1; }
.saved .it small { color: var(--muted); }
.saved .it button { min-width: 44px; height: 40px; border-radius: 9px; }
.wave { width: 100%; height: 110px; background: var(--bg); border-radius: 10px; display: block; touch-action: none; }
.meter { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; margin: 8px 0; }
.meter i { display: block; height: 100%; width: 0; background: var(--c1); }
.keymap { font-size: 16px; color: var(--muted); }
.keymap kbd { font: inherit; background: var(--panel2); border-radius: 5px; padding: 0 6px; color: var(--text); }
.credits li { margin: 4px 0; color: var(--muted); }
.tempo-big { font-size: 56px; text-align: center; margin: 6px 0; }

.splash { position: fixed; inset: 0; z-index: 20; background: radial-gradient(90% 60% at 50% 35%, #2b241d, var(--bg)); display: grid; place-items: center; text-align: center; }
.splash[hidden] { display: none; }
.splash-title { font-size: 54px; font-weight: 700; }
.splash p { color: var(--muted); font-style: italic; margin: 4px 0 26px; font-size: 20px; }
.big { background: var(--accent); color: #1d160c; font-weight: 700; font-size: 22px; height: 58px; padding: 0 34px; border-radius: 29px; }
.loadbar { width: 180px; height: 3px; margin: 22px auto 0; background: var(--line); border-radius: 2px; overflow: hidden; opacity: 0; }
.loadbar.on { opacity: 1; }
.loadbar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }

/* phone portrait: taller pads fill the space under the thumbs */
@media (max-width: 700px) and (orientation: portrait) {
  .stage { justify-content: flex-end; padding-bottom: 22px; }
  .pads { aspect-ratio: 4 / 6; max-width: 100%; max-height: 100%; height: auto; width: min(100%, calc((100dvh - 262px) * 0.6667)); }
  .app[data-mode=bass] .pads, .app[data-mode=keys] .pads { width: min(100%, calc((100dvh - 312px) * 0.6667)); }
  .stage { justify-content: center; }
}
@media (max-width: 370px) { .seg button { padding: 0 8px; font-size: 16px; } .t-btn.small { width: 38px; } }

/* desktop: pads left, grid right */
@media (min-width: 980px) {
  .app { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 28px; padding-top: 10px;
    grid-template-rows: 56px 58px 6px 44px 1fr auto; grid-template-areas: 'top top' 'trans trans' 'beats beats' 'views views' 'stage stage' 'strip strip'; }
  .stage { flex-direction: row; align-items: center; gap: 28px; }
  .stage .pads { width: min(600px, calc(100dvh - 250px)); max-width: none; flex: none; margin: 0; }
  .pad .lbl { font-size: 18px; } .pad .key { font-size: 15px; opacity: 1; }
  .tempo { flex: 0 1 220px; }
  .transport { justify-content: flex-start; }
  .ctl.swing { flex: 0 1 360px; }
  .grow { grid-template-columns: 110px 1fr; }
  .gname { font-size: 16px; color: var(--text); }
  .gc { height: 30px; }
  .strip { max-width: 760px; }
  .seg button { height: 38px; padding: 0 16px; font-size: 18px; }
  .app .grid, .app[data-view=grid] .grid { display: block; flex: 1; height: auto; max-height: 100%; }
  .app[data-view=grid] .pads { display: grid; }
  .views .seg:first-child { display: none; }
  .melbar { position: absolute; top: -4px; left: 0; }
  .app[data-mode=bass] .stage, .app[data-mode=keys] .stage { padding-top: 40px; }
}
/* landscape phone */
@media (max-height: 500px) and (orientation: landscape) {
  .app { max-width: none; grid-template-columns: auto 1fr; column-gap: 14px; grid-template-rows: 44px 50px 6px 40px 1fr auto;
    grid-template-areas: 'stage top' 'stage trans' 'stage beats' 'stage views' 'stage melx' 'stage strip'; padding-top: max(8px, env(safe-area-inset-top, 0px)); }
  .stage { height: 100%; }
  .stage .pads { width: calc(100dvh - 20px); max-width: none; }
  .app[data-view=grid] .stage { width: 60vw; }
  .brand { font-size: 22px; }
}
