body {
    background-color: rgb(24, 18, 34);
    margin: 0;
    padding: 10px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Improve layout stability */
*, *::before, *::after {
    box-sizing: border-box;
}

/* Mobile-first responsive container */
.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 0;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    body {
        padding: 6px;
        font-size: 16px;
    }
    
    .title {
        font-size: 1.2em;
        flex-wrap: wrap;
        justify-content: center;
        text-align: center;
    }
    
    .logo {
        width: 40px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 6px;
        font-size: 16px;
    }
    
    .title {
        font-size: 1.2em;
        margin: 6px 0;
        text-align: center;
        justify-content: center;
    }
    
    .logo {
        width: 35px;
    }
    
    .space {
        margin: 0 5px;
    }
}
/* prevent select text but can grab */
.prevent-select {
    -webkit-user-select: none; /* Safari */
    -moz-user-select: none; /* Firefox */
    -ms-user-select: none; /* IE10+/Edge */
    user-select: none; /* Standard */
  }
.space {
    margin: 0px 10px;
}

.title {
    color: rgb(255, 255, 255);
    font-size: 1.5em;
    margin: 0px;
    padding: 0px;
    align-items: center;
    display: flex;

}
.logo{
    width: 50px;
}
.header {
    display: flex;
    background-color: rgb(14, 89, 164);
    padding: 10px;
    margin-top: 10px;
    margin-bottom: 10px;
    border-radius: 0.5em;
    flex-wrap: wrap;
    gap: 10px;
}

/* Mobile-first responsive design */
@media (max-width: 768px) {
    .header {
        padding: 8px;
        gap: 8px;
    }
}
.style-part {
    display: flex;
    padding: 5px;
    align-items: center;
    background-color: rgb(65, 65, 65);
    border-radius: 0.25em;
    justify-content: space-around;
    flex-wrap: wrap;
    margin: 5px 5px;
}
.style-part::-webkit-scrollbar {
    height: 0;
}
.btn-style-part{
    border-radius: 0.25em;

}
.btn-style-part:hover:enabled{
    cursor: pointer;
    background: rgb(108, 236, 4);
    border-radius: 0.5em;
}
.chord-creator{
        display: flex;
    padding: 5px;
    align-items: center;
    background-color: rgb(65, 65, 65);
    border-radius: 0.25em;
    gap: 1em;
    flex-wrap: wrap;
    margin: 5px 5px;

}
.chords {
    background-color: rgb(65, 65, 65);
    height: 56px;
    text-align: center;
    color: aliceblue;
    border-radius: 0 0 5% 5%;
    font-size: 0.8em;
    position: relative; /* for overlay */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 2px;
}

.chords.highlight {
    outline: 2px solid #00BCD4;
    box-shadow: 0 0 0 2px rgba(0,188,212,0.2) inset, 0 0 12px rgba(0,188,212,0.6);
}
.chords.highlight .line { color: #00BCD4; }
.chords.selected { outline: 2px dashed #FFA726; }
/* Orange tempo tick overlay on top of blue highlight (no fade-in, only fade-out) */
.chords.highlight::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    border-radius: 4px;
    background: radial-gradient(circle at 50% 50%, rgba(255, 165, 0, 0.45), rgba(255, 165, 0, 0) 60%);
    opacity: 0; /* hidden until tick */
    transition: none; /* avoid any fade-in */
}
.chords.highlight.tick::after {
    opacity: 1; /* instantly show */
    animation: tickPulseOut 140ms ease-out; /* then fade out */
}
@keyframes tickPulseOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}
.chords:hover{
    cursor: grab;
    background: rgb(14, 89, 164);
    border-radius: 0.5em;
}
/* on mouse click */
.chords:active{
    cursor: grabbing;
}

/* Enhanced chord editing controls */
.chord-controls {
    display: none;
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    border-radius: 4px;
    padding: 2px;
    z-index: 1000;
}

.chords.selected .chord-controls {
    display: flex;
    gap: 2px;
}

.chords:hover .chord-controls {
    display: flex;
    gap: 2px;
}

/* Make chord controls accessible without hover */
.chords:focus-within .chord-controls,
.chords:active .chord-controls {
    display: flex;
}

.chord-btn {
    background: #4CAF50;
    border: none;
    color: white;
    padding: 2px 4px;
    font-size: 10px;
    border-radius: 2px;
    cursor: pointer;
    min-width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation; /* Improve touch response */
}
.chord-btn.play { background: #2196F3; }

/* Mobile optimizations for chord control buttons */
@media (max-width: 768px) {
    .chord-btn {
        min-width: 20px;
        height: 20px;
        padding: 3px 5px;
        font-size: 11px;
        border-radius: 3px;
    }
    
    .chord-controls {
        top: -28px;
        padding: 3px;
        gap: 3px;
    }
}

@media (max-width: 480px) {
    .chord-btn {
        min-width: 24px;
        height: 24px;
        padding: 4px 6px;
        font-size: 12px;
        border-radius: 4px;
    }
    
    .chord-controls {
        top: -32px;
        padding: 4px;
        gap: 4px;
        transform: translateX(-50%);
    }
    
    .chords {
        margin: 3px;
        padding: 3px;
    }
}

/* Touch devices: show controls on focus/active to avoid layout jumps */
@media (hover: none) and (pointer: coarse) {
    .chord-controls {
        display: none;
        top: auto;
        bottom: -26px;
    }
    /* When selected on mobile/touch, force the controls above the beat to avoid clipping */
    .chords.selected .chord-controls {
        display: flex;
        top: -28px;
        bottom: auto;
    }
    .chords:focus-within .chord-controls,
    .chords:active .chord-controls {
        display: flex;
    }
}

.chord-btn:hover {
    background: #45a049;
}

.chord-btn.delete {
    background: #f44336;
}

.chord-btn.delete:hover {
    background: #da190b;
}

.chord-btn.split {
    background: #2196F3;
}

.chord-btn.split:hover {
    background: #0b7dda;
}

.chord-name {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.chord-name:hover {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

/* Add chord button */
.add-chord-btn {
    background: rgba(76, 175, 80, 0.3);
    border: 2px dashed #4CAF50;
    color: #4CAF50;
    height: 50px;
    width: 2em;
    border-radius: 0.25em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    margin: 2px;
    touch-action: manipulation; /* Improve touch response */
}

.add-chord-btn:hover {
    background: rgba(76, 175, 80, 0.5);
    border-color: #45a049;
    color: #45a049;
}

/* Mobile optimizations for chord buttons */
@media (max-width: 768px) {
    .add-chord-btn {
        width: 3em;
        height: 45px;
        font-size: 20px;
        margin: 1px;
    }
}

@media (max-width: 480px) {
    .add-chord-btn {
        width: 100%;
        height: 40px;
        font-size: 18px;
        margin: 2px 0;
        border-radius: 4px;
    }
}

/* Quarter note support */
.quarter-bars {
    width: 1em;
}

/* Chord selector styles */
.chord-selector {
    background: rgba(0, 0, 0, 0.8);
    color: white;
    border: 1px solid #4CAF50;
    border-radius: 4px;
    padding: 2px;
    font-size: 0.8em;
    width: 100%;
    outline: none;
    max-height: 200px;
}

.chord-selector:focus {
    border-color: #45a049;
    box-shadow: 0 0 5px rgba(69, 160, 73, 0.5);
}

.chord-selector option[disabled] {
    color: #888;
    font-style: italic;
    text-align: center;
}

/* Mobile optimizations for popups and modals */
@media (max-width: 768px) {
    .chord-selector {
        font-size: 14px;
        padding: 8px;
        max-height: 150px;
    }
    
    /* Popup positioning for mobile */
    .add-chord-popup {
        position: fixed !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        width: 90vw !important;
        max-width: 300px !important;
        z-index: 3000 !important;
    }
}

@media (max-width: 480px) {
    .chord-selector {
        font-size: 16px; /* Larger for mobile accessibility */
        padding: 10px;
    }
    
    .add-chord-popup {
        width: 95vw !important;
        max-width: none !important;
        margin: 10px !important;
    }
    
    /* Make buttons touch-friendly */
    button {
        min-height: 44px;
        min-width: 44px;
        touch-action: manipulation;
    }
    
    input, select {
        min-height: 44px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

/* Enhanced chord family display */
.chord-family {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 5px 0;
}

.chord-family button {
    background: #2196F3;
    border: none;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.chord-family button:hover {
    background: #1976D2;
    transform: translateY(-1px);
}

.chord-family button:active {
    transform: translateY(0);
}

/* Smart chord suggestions */
.chord-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid #333;
    border-radius: 4px;
    z-index: 1001;
    max-height: 150px;
    overflow-y: auto;
}

.chord-suggestion-item {
    padding: 8px;
    cursor: pointer;
    color: white;
    border-bottom: 1px solid #333;
}

.chord-suggestion-item:hover {
    background: rgba(76, 175, 80, 0.3);
}

.chord-suggestion-item:last-child {
    border-bottom: none;
}

/* Integrated Scale Selector Styles - Mobile Responsive */
.scale-group {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
}

.scale-label {
    color: white;
    font-size: 14px;
    font-weight: bold;
    margin-right: 5px;
    white-space: nowrap;
}

.scale-select {
    min-width: 70px;
    font-size: 14px;
}

/* General input sizing */
.controler {
    box-sizing: border-box;
}

input.controler[type="number"] {
    width: 70px;
    min-width: 50px;
    max-width: 80px;
}

select.controler {
    min-width: 80px;
    max-width: 150px;
}

/* Specific styling for tempo input */
#tempo {
    width: 60px !important;
    text-align: center;
}

label[for="tempo"] {
    font-size: 12px;
    color: white;
    margin-left: 5px;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .scale-group {
        gap: 3px;
        order: 1; /* Move to second line on mobile */
        width: 100%;
        justify-content: flex-start;
        margin-top: 5px;
    }
    
    .scale-label {
        font-size: 12px;
        margin-right: 3px;
    }
    
    .scale-select {
        min-width: 55px;
        max-width: 70px;
        font-size: 12px;
        padding: 6px 8px;
    }
}

@media (max-width: 480px) {
    .scale-group {
        gap: 2px;
    }
    
    .scale-label {
        font-size: 11px;
    }
    
    .scale-select {
        min-width: 50px;
        max-width: 60px;
        font-size: 11px;
        padding: 5px 6px;
    }
}


.whole-bars {
    width: 4em;
}

.half-bars {
    width: 2em;
}

.sequencer {
    display: flex;
    border: #ffffff 1px solid;
    border-radius: 0.25em;
    flex-wrap: wrap;
    background: repeating-linear-gradient(45deg, #000000, #000000 10px, #101010 10px, #101010 20px);
    gap: 1px;
    padding: 0.25em;

}
.sequencer {
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
}
.part-container{
    display: flex;
    flex-direction: column;
    margin: 2px 0px;
    gap: 1px;
}
.chords-container{
    display: flex;
    gap: 1px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;

}
.part-name {
    height: 1.2em;
    line-height: 1.2em;
    color: white;
    padding-left: 5px;
}


.lines {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr; /* each bar gets equal width */
    align-items: center;
    justify-items: center; /* center the pipe within each cell */
    color: rgb(160, 159, 159);
    font-size: 0.8em;
    width: 100%;
}
.line {
    display: block;
    width: 100%;
    text-align: center;
    pointer-events: none;
}

.raw-data {
    display: flex;
    flex-direction: column;
    margin-top: 10px;
}
.raw-input-wrapper {
    position: relative;
}
.raw-highlights {
    position: absolute;
    inset: 0;
    margin: 0;
    padding: 8px;
    color: transparent;
    white-space: pre-wrap;
    word-wrap: break-word;
    font: inherit;
    background: transparent;
    pointer-events: none;
}
.raw-data textarea {
    width: 100%;
    max-width: 100%;
    background: #1b1b1b;
    color: #fff;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 8px;
    position: relative;
    background-clip: padding-box;
}
.raw-highlights .hl-part { color: #4CAF50; font-weight: bold; }
.raw-highlights .hl-bar  { color: #00BCD4; font-weight: bold; }
.raw-highlights .hl-chord{ color: #E0E0E0; }
.button-group{
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
}
#submit{
    background-color: rgb(14, 89, 164);
    color: white;
    border: none;
    border-radius: 0.5em;
    padding: 0.5em;
    font-size: 1em;
}
.controlers{
    display: flex;
    justify-content: space-around;
    align-items: center;
    gap: 0.5em;
    flex-wrap: wrap;
}

/* Modern toolbar styling */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 8px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px;
    backdrop-filter: blur(6px);
    align-items: center;
}
.group { display: inline-flex; align-items: center; gap: 8px; }
.transport-group .btn { padding: 6px 10px; border-radius: 6px; }
.transport-group .btn { background: #4CAF50; color: #fff; border: none; }
.transport-group .btn.secondary { background: #9E9E9E; }
.seek { width: 180px; }
.time { font-family: monospace; opacity: 0.85; }
.toggle { display: inline-flex; align-items: center; gap: 6px; }
.bpm { margin-left: 4px; opacity: 0.85; }

@media (max-width: 768px) {
  .toolbar { gap: 8px; padding: 6px; }
  .seek { width: 140px; }
}

/* Mobile responsive controls */
@media (max-width: 768px) {
    .controlers {
        gap: 8px;
        justify-content: center;
    }
    
    .controler {
        font-size: 12px;
        padding: 8px 12px;
        min-width: auto;
    }
    
    input.controler {
        width: 60px;
    }
    
    label[for="tempo"] {
        font-size: 11px;
        margin-left: 3px;
    }
}

@media (max-width: 480px) {
    .controlers {
        gap: 8px;
        flex-direction: row; /* keep compact like PC */
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
    }
    
    .controler {
        font-size: 14px;
        padding: 8px 10px;
        width: auto; /* don't stretch full width on mobile */
        box-sizing: border-box;
        flex: 0 0 auto;
    }
    
    input.controler[type="number"] {
        width: 56px;
        max-width: 64px;
    }
    
    select.controler {
        min-width: 70px;
        max-width: 120px;
    }
    
    input.controler {
        width: 60px;
        max-width: 80px;
    }
    
    #tempo {
        width: 60px !important;
    }
    
    .scale-group {
        width: 100%;
        justify-content: center;
        margin: 5px 0;
        padding: 5px;
        background: rgba(255, 255, 255, 0.1);
        border-radius: 4px;
    }

    /* Style-part: switch to horizontal scroll to fit many buttons */
    .style-part {
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 6px;
        padding-bottom: 8px;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
    }
    .btn-style-part {
        flex: 0 0 auto;
        padding: 8px 10px;
    }

    /* Button group stacks for narrow screens */
    .button-group {
        flex-direction: column;
        gap: 8px;
    }

    /* Beat sizing variables to ensure 4 quarters = 1 whole */
    :root {
        --beat-unit: 18px;  /* width of a quarter beat */
        --beat-gap: 2px;    /* must match container gap */
    }

    /* Tighter but readable sequencer spacing on mobile */
    .chords-container {
        gap: var(--beat-gap); /* slight separation between beats */
    }
    .chords {
        margin: 0; /* rely on container gap for spacing */
        padding: 0; /* ensure beat width math is exact */
        flex: 0 0 auto; /* prevent flex shrinking/growing */
    }
    .chord-name { padding: 2px; }
    .add-chord-btn {
        margin: 0; /* consistent with chords */
    }
    .lines {
        column-gap: 3px; /* thin bar spacing inside beat */
    }
    /* Maintain proportional widths including internal gaps:
       4 * quarter + 3 * gap = whole
       2 * half + 1 * gap = whole */
    .quarter-bars { width: var(--beat-unit); }
    .half-bars { width: calc(2 * var(--beat-unit) + var(--beat-gap)); }
    .whole-bars { width: calc(4 * var(--beat-unit) + 3 * var(--beat-gap)); }
}


.part-name.IA {
    background-color: #4287f5;
    /* Color for part name IA */
}

.part-name.IB {
    background-color: #4287f5;
    /* Color for part name IB */
}

.part-name.IC {
    background-color: #4287f5;
    /* Color for part name IC */
}

.part-name.A {
    background-color: #664455;
    /* Color for part name A */
}

.part-name.B {
    background-color: #664490;
    /* Color for part name B */
}

.part-name.C {
    background-color: #661090;
    /* Color for part name C */
}

.part-name.D {
    background-color: #660080;
    /* Color for part name D */
}

.part-name.AA {
    background-color: #d1f542;
    color: black;
    /* Color for part name AA */
}

.part-name.BB {
    background-color: #42f5f2;
    /* Color for part name BB */
    color: black;
}

.part-name.CC {
    background-color: #c842f5;
    /* Color for part name CC */
    color: black;
}

.part-name.DD {
    background-color: #aa42f5;
    /* Color for part name DD */
    color: black;
}

.part-name.EA {
    background-color: #f54242;
    /* Color for part name EA */
}

.part-name.EB {
    background-color: #f54242;
    /* Color for part name EB */
}

.part-name.EC {
    background-color: #f54242;
    /* Color for part name EC */
}

.part-name.BA {
    background-color: #8cf542;
    /* Color for part name BA */
}

#status-bar {
    height: 20px;
    color: red;
    visibility: hidden;
}

/* Show the status bar when the 'visible' class is added */
#status-bar.visible {
    visibility: visible;
}


/* Custom player style */
#player midi-player {
    display: block;
    width: inherit;
    margin: 4px;
    margin-bottom: 0;
  }
  /* Hide built-in player controls since we have Play/Stop above */
  #player midi-player::part(control-panel) { display: none; }
  #player midi-player::part(play-button) {
    color: #353;
    border: 2px solid currentColor;
    background-color: rgb(255, 255, 255);
    border-radius: 20px;
    transition: all 0.2s;
    content: 'hello';
  }
  #player midi-player::part(play-button):hover {
    color: #0a0;
    background-color: #5f5;
    border-radius: 10px;
  }
  #player midi-player::part(time) {
    font-family: monospace;
  }
  
  /* Custom visualizer style */
  #player midi-visualizer .piano-roll-visualizer {
    background: rgb(255, 255, 255);
    border: 2px solid black;
    border-top: none;
    border-radius: 0 0 10px 10px;
    margin: 4px;
    margin-top: 0;
    overflow: auto;
    max-width: 100%;
  }
  #player midi-visualizer svg rect.note {
    opacity: 0.6;
    stroke-width: 2;
  }
  #player midi-visualizer svg rect.note[data-instrument="0"]{
    fill: #e22;
    stroke: #500;
  }
  #player midi-visualizer svg rect.note[data-instrument="2"]{
    fill: #2ee;
    stroke: #055;
  }
  #player midi-visualizer svg rect.note[data-is-drum="true"]{
    fill: #888;
    stroke: #888;
  }
  #player midi-visualizer svg rect.note.active {
    opacity: 0.9;
    stroke: #000;
  }
/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
  }
  
  /* Modal Content */
  .modal-content {
    display: flex;
    flex-direction: column;
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    width: min(90vw, 480px);
    border-radius: 0.5em;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap ;
  }

@media (max-width: 480px) {
  .modal-content {
    padding: 14px;
  }
}
  
  /* The Close Button */
  .close {
    color: #aaaaaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
  }
  
  .close:hover,
  .close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
  }


  .slider-container {
    width: 100%;
    height: 300px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sliders {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 4em;
}

.volume {
    font-size: 0.8em;

}

/* Simple VU bar under each slider */
.vu-bar {
    position: relative;
    width: 100%;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 6px;
}
.vu-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0%;
    background: linear-gradient(90deg, #4CAF50, #FFC107, #F44336);
    transition: width 80ms linear;
}
.vu-peak {
    position: absolute;
    top: -2px;
    width: 2px;
    bottom: -2px;
    background: #ff5722;
    opacity: 0.9;
    transform: translateX(0%);
    transition: transform 120ms linear, opacity 400ms ease-out;
}

.slider {
    -webkit-appearance: none;  /* Override default CSS styles */
    appearance: none;
    height: 200px;
    width: 5px; /* Specifying a width is required for Firefox. */

    background: #d3d3d3;
    outline: none; /* Remove outline */
    opacity: 0.7; /* Set transparency (it will be visible while sliding) */
    -webkit-transition: .2s; /* 0.2 seconds transition on hover */
    transition: opacity .2s;
    writing-mode: bt-lr; /* IE */
    -webkit-appearance: slider-vertical; /* WebKit browsers like Chrome, Safari, etc. */
}

.slider:hover {
    opacity: 1; /* Fully visible on hover */
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none; /* Override default look */
    appearance: none;
    width: 20px;
    height: 20px;
    background: #4CAF50; /* Green background */
    cursor: pointer; /* Cursor on hover */
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #4CAF50;
    cursor: pointer;
}

