body {
    background: #fff;
    font-family: 'Space Mono', monospace;
    text-align: center;
    color: #1a1a1a;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 16px 60px;
    gap: 20px;
}

h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.controls {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
    justify-content: center;
    background: #fff;
    border: 1px solid #e2e0d8;
    border-radius: 12px;
    padding: 10px 20px;
}

.ctrl-group {
    display: flex;
    align-items: center;
    gap: 7px;
}

.ctrl-label {
    font-size: 11px;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

select {
    font-family: inherit;
    font-size: 12px;
    background: #f5f4f0;
    border: 1px solid #ddd;
    border-radius: 6px;
    color: #1a1a1a;
    padding: 4px 8px;
    cursor: pointer;
    outline: none;
}

input[type=range] {
    width: 80px;
    accent-color: #1a1a1a;
    cursor: pointer;
}

.bpm-val {
    font-size: 12px;
    min-width: 28px;
    color: #555;
}

#play-btn {
    width: 38px;
    height: 38px;
    border-radius: 25%;
    border: 2px solid #1a1a1a;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: #1a1a1a;
    flex-shrink: 0;
    transition: background 0.1s, color 0.1s;
}

#play-btn:hover { background: #f0efe9; }
#play-btn.playing { background: #1a1a1a; color: #fff; }

#clear-btn {
    font-family: inherit;
    font-size: 11px;
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid #ddd;
    background: transparent;
    cursor: pointer;
    color: #777;
}

#clear-btn:hover { background: #f5f4f0; }

#piano-toggle-btn {
    font-family: inherit;
    font-size: 11px;
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid #ddd;
    background: transparent;
    cursor: pointer;
    color: #777;
}

#piano-toggle-btn:hover {
    background: #f5f4f0;
}

#piano-toggle-btn.active {
    background: #1a1a1a;
    color: #fff;
    border-color: #1a1a1a;
}

#share-btn {
    font-family: inherit;
    font-size: 11px;
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid #ddd;
    background: transparent;
    cursor: pointer;
    color: #777;
}

#share-btn:hover {
    background: #f5f4f0;
}

.divider {
    width: 1px;
    height: 24px;
    background: #e2e0d8;
}

.grid-outer {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.layer-row {
    display: flex;
    align-items: stretch;
    gap: 0;
}

.layer-label {
    width: 72px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-end;
    padding-right: 10px;
    gap: 2px;
}

.layer-name {
    font-size: 10px;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.layer-sub {
    font-size: 9px;
    color: #bbb;
}

.staff {
    flex: 1;
    position: relative;
    background: #fff;
    border: 1px solid #e2e0d8;
    border-radius: 8px;
    overflow: visible;
    display: flex;
    flex-direction: column;
}

.staff.melody { min-height: 180px; }
.staff.bass { min-height: 120px; }
.staff.drums { min-height: 60px; }

.cell-grid {
    position: absolute;
    inset: 0;
    display: grid;
    border-radius: 8px;
    overflow: hidden;
}

.barline {
    position: absolute;
    top: 8px;
    bottom: 8px;
    width: 1px;
    background: #ccc;
    pointer-events: none;
    z-index: 2;
}

.cell {
    position: relative;
    user-select: none;
    cursor: pointer;
    border-right: 1px solid #f0efe9;
    border-bottom: 1px solid #f0efe9;
    transition: background 0.04s;
}

.cell:last-child {
    border-right: none;
}

.cell:hover {
    background: rgba(0, 0, 0, 0.03);
}

.cell.col-playing {
    position: relative;
}

.cell.col-playing::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(220, 80, 30, 0.10);
    pointer-events: none;
}

.cell.col-playing.melody .note-head,
.cell.col-playing.bass .note-head {
    animation: play-hit-scale 0.18s ease-out;
}

.cell.col-playing.drums .note-head {
    animation: play-hit-drums 0.18s ease-out;
}

.note-head {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.05s, transform 0.05s;
    pointer-events: none;
    z-index: 3;
}

@keyframes play-hit-scale {
    0% { transform: translateX(-50%) scale(1); }
    40% { transform: translateX(-50%) scale(1.08); }
    100% { transform: translateX(-50%) scale(1); }
}

@keyframes play-hit-drums {
    0% { transform: translate(-50%, -50%) scale(1); }
    40% { transform: translate(-50%, -50%) scale(1.08); }
    100% { transform: translate(-50%, -50%) scale(1); }
}

.cell.active {

}

.drums .note-head {
    width: 14px;
    height: 14px;
    background: #1a1a1a;
    border-radius: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

.drums .cell.active .note-head {
    opacity: 1;
}

.melody .note-head {
    width: 18px;
    height: 12px;
    background: #1a1a1a;
}

.bass .note-head {
    width: 16px;
    height: 10px;
    background: #b85c0a;
}


.melody .cell[data-row="0"] .note-head { top: 6px; }
.melody .cell[data-row="1"] .note-head { top: 40px; }
.melody .cell[data-row="2"] .note-head { top: 56px; }
.melody .cell[data-row="3"] .note-head { top: 70px; }
.melody .cell[data-row="4"] .note-head { top: 86px; }
.melody .cell[data-row="5"] .note-head { top: 100px; }

.bass .cell[data-row="0"] .note-head { top: 8px; }
.bass .cell[data-row="1"] .note-head { top: 20px; }
.bass .cell[data-row="2"] .note-head { top: 32px; }
.bass .cell[data-row="3"] .note-head { top: 44px; }

.drums .cell[data-row="0"] .note-head { top: 10px; }
.drums .cell[data-row="1"] .note-head { top: 26px; }

.drum-label-col {
    position: absolute;
    left: 4px;
    top: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    pointer-events: none;
    z-index: 4;
}

.drum-label {
    font-size: 8px;
    color: #bbb;
    line-height: 1;
}

#piano-popup {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    background: #fff;
    border: 1px solid #e2e0d8;
    border-bottom: none;
    border-radius: 12px 12px 0 0;
    padding: 16px 20px 12px;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.10);
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

#piano-popup.open {
    transform: translateX(-50%) translateY(0%);
}
 
.piano-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 4px;
}
 
.piano-popup-label {
    font-size: 10px;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.piano-close {
    font-size: 14px;
    cursor: pointer;
    color: #aaa;
    background: none;
    border: none;
    line-height: 1;
    padding: 0 2px;
}
.piano-close:hover { color: #333; }

.piano {
    display: inline-flex;
}

.key-group {
    position: relative;
}

.white {
    width: 50px;
    height: 160px;
    background: white;
    border: 2px solid #333;
    border-radius: 0 0 8px 8px;
    margin-right: -2px;
    z-index: 1;
    position: relative;
    cursor: pointer;
    transition: background 0.07s, transform 0.07s;
}

.white.active {
    transform: translateY(3px);
    background: #aaaaaa;
}

.key-group:first-child .white {
    border-top-left-radius: 12px;
    border-bottom-left-radius: 12px;
}

.key-group:last-child .white {
    border-top-right-radius: 12px;
    border-bottom-right-radius: 12px;
}

.black {
    position: absolute;
    width: 32px;
    height: 100px;
    border-radius: 0 0 5px 5px;
    background: #111;
    z-index: 2;
    top: 0;
    transition: background 0.07s;
    right: -18px;
    cursor: pointer;
}

.black.active {
    background: #555;
}

.key:hover {
    filter: brightness(1.08);
}

#viz-wrap {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
}

.viz-label-col {
    width: 72px;
    flex-shrink: 0;
    text-align: right;
    padding-right: 10px;
}

.viz-label {
    font-size: 9px;
    color: #bbb;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

canvas#viz {
    flex: 1;
    height: 40px;
    border-radius: 6px;
    background: #fff;
    border: 1px solid #e2e0d8;
}

.step-indicator-wrap {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0;
}

.step-indicator-spacer {
    width: 72px;
    flex-shrink: 0;
}

.step-dots {
    flex: 1;
    display: flex;
    gap: 0;
}

.step-dot {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: #e2e0d8;
    margin: 0 1px;
    transition: background 0.05s;
}

.step-dot.active {
    background: #dc501e;
}