@font-face {
    font-family: 'Ample Display';
    src: url('../fonts/webfontkit-20201011-123230/ample_script-webfont.woff2') format('woff2'),
         url('../fonts/webfontkit-20201011-123230/ample_script-webfont.woff') format('woff');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Ample Display';
    src: url('../fonts/webfontkit-20201011-123230/ample_script-webfont.woff2') format('woff2'),
         url('../fonts/webfontkit-20201011-123230/ample_script-webfont.woff') format('woff');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Ample Display';
    src: url('../fonts/webfontkit-20201011-123230/ample_script-webfont.woff2') format('woff2'),
         url('../fonts/webfontkit-20201011-123230/ample_script-webfont.woff') format('woff');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

:root {
    --primary-color: #00A7B5;
    --background-color: #FFFFFF;
    --grid-bg-color: #E6E6E6;
    --cell-inactive: #FFFFFF;
    --cell-active: #8c52ff;
    --cell-playing: #90EE90;
    --text-color: #333333;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 12px; /* reduced */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.sequencer-container {
    width: 100%;
    max-width: 1200px;
    background-color: var(--background-color);
}

header {
    display: grid;
    grid-template-columns: 1fr auto;
    margin-bottom: 16px;
    gap: 12px;
    align-items: flex-start;
    padding: 0 4px;
}

.header-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

h1 {
    display: block;
    margin: 0;
}

.title-image-wrap {
    display: block;
    margin: 0;
}

.title-image {
    max-width: none;
    height: 64px; /* increased slightly as requested */
    width: auto;
    display: block;
    /* small upward tweak so it lines up with controls */
    margin-top: -6px;
}

.subtitle {
    color: var(--primary-color);
    font-family: 'Ample Display', sans-serif;
    font-size: 20px;
    font-weight: 700;
    opacity: 0.85;
    letter-spacing: -0.01em;
    margin-left: 1px;
}

.logo {
    height: 46px;
    width: auto;
}

.control-panel-wrapper {
    display: flex;
    justify-content: center;
    margin-bottom: 12px;
}

.control-panel {
    background-color: white;
    padding: 6px;
    border-radius: 8px;
    display: inline-grid;
    grid-template-columns: auto 1fr;
    gap: 6px;
    align-items: stretch;
    width: auto;
}

.playback-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--primary-color);
    padding: 4px 8px;
    border-radius: 4px;
    color: white;
}

.transport-info {
    display: grid;
    grid-template-columns: repeat(3, auto);
    gap: 2px;
    align-items: center;
    background: var(--primary-color);
    padding: 4px 8px;
    border-radius: 4px;
    color: white;
}

/* legacy duplicate removed/compacted - original single .control-panel above is authoritative */

.playback-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.control-btn {
    background: none;
    border: none;
    color: white;
    font-size: 16px; /* slightly smaller */
    cursor: pointer;
    padding: 2px; /* reduced */
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.volume-control {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: 86px; /* reduced */
    margin: 0 6px; /* reduced */
}

.volume-slider {
    width: 86px; /* reduced */
    height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
    position: relative;
    cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 20px;
    background: white;
    border-radius: 2px;
    cursor: pointer;
}

.volume-slider::-moz-range-thumb {
    width: 12px;
    height: 20px;
    background: white;
    border-radius: 2px;
    cursor: pointer;
    border: none;
}

.transport-controls {
    display: flex;
    gap: 20px;
    align-items: center;
}

.transport-info > div {
    display: flex;
    align-items: center;
    background: rgba(0,0,0,0.08);
    padding: 3px 6px;
    border-radius: 3px;
    margin: 0 2px;
}

.transport-info label {
    font-size: 12px;
    opacity: 0.9;
    margin-right: 4px;
}

.transport-info input,
.transport-info select {
    background: white;
    border: none;
    border-radius: 3px;
    padding: 2px 4px;
    font-size: 12px;
    width: 45px;
    color: var(--primary-color);
    font-weight: 500;
}

/* Make the Load Loop dropdown wider to support longer loop names */
#loadLoop {
    width: 180px; /* ~3x the previous 45px; adjust as needed */
    min-width: 140px;
}

.volume-slider {
    width: 80px;
    height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
    position: relative;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    margin: 0 4px;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 18px;
    background: white;
    border-radius: 2px;
    cursor: pointer;
    border: none;
}

.volume-slider::-moz-range-thumb {
    width: 12px;
    height: 18px;
    background: white;
    border-radius: 2px;
    cursor: pointer;
    border: none;
}

.control-btn {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sequencer-grid {
    background-color: var(--primary-color);
    padding: 0;
    border-radius: 10px;
    border: 3px solid #00656a;
    box-shadow: 0 2px 0 rgba(0,0,0,0.15) inset;
}

.drums-section,
.percussion-section {
    display: flex;
}

/* White separator line between sections */
.drums-section {
    border-bottom: 2.5px solid rgba(255, 255, 255, 0.75);
    padding-bottom: 0;
    margin-bottom: 2px;
}

.instrument-labels {
    width: 140px; /* increased to fit longer names */
    color: white;
    display: flex;
    flex-direction: column;
    gap: 3px; /* reduced */
}

.instrument-labels div {
    height: 20px; /* match grid cell height */
    display: flex;
    align-items: center;
    padding: 0 4px; /* reduced padding to align with grid */
    cursor: grab;
    font-size: 0.86em;
    position: relative;
    letter-spacing: 0.02em;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Smaller font for long instrument names */
.instrument-labels div:nth-child(2),
.instrument-labels div:nth-child(3) {
    font-size: 0.78em;
    letter-spacing: 0;
}

/* Volume knob base (matches reference) */
.instrument-labels div::before {
    content: '';
    width: 14px;
    height: 14px;
    border-radius: 50%;
    /* Use user's volume knob image (keeps exact same visual footprint) */
    background-image: url("../images/Volume Knob (1).png");
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    display: inline-block;
    margin-right: 6px;
    /* keep a subtle outline and depth so the knob stands out against the panel */
    box-shadow: 0 0 0 2px var(--primary-color), inset 0 -1px 0 rgba(255,255,255,0.06), 0 1px 2px rgba(0,0,0,0.25);
    position: relative;
    filter: brightness(1.05) contrast(1.02);
    /* Rotate the pseudo-element according to the --rotation property (set by JS) */
    transform: rotate(var(--rotation, 0deg));
    transform-origin: 50% 50%;
    transition: transform 0.06s linear, filter 0.12s ease;
    will-change: transform;
}

/* Volume knob indicator line */
.instrument-labels div::after {
    /* Removed the previous white indicator line for the image-based knob.
       Rotation is still stored in --rotation for compatibility with JS, but
       no visual line overlay will be displayed. */
    content: none;
}

.grid {
    /* layout variables - change these to resize the grid/cells responsively */
    --cell: 24px;           /* cell content width (includes border because box-sizing:border-box) */
    --gap: 2px;             /* reduced gap between columns to match reference */
    --grid-padding: 4px;    /* reduced padding to align with labels */
    --sep-thickness: 2.5px; /* vertical separator thickness */
    --sep-color: rgba(255,255,255,0.75); /* increased contrast for white separators */

    flex-grow: 1;
    display: grid;
    grid-template-columns: repeat(32, var(--cell));
    grid-auto-rows: 20px;
    gap: var(--gap);
    justify-content: start;
    background-color: var(--primary-color);
    padding: var(--grid-padding);
    border-radius: 6px;
    position: relative;
    overflow: visible;
}

.grid .separator-1,
.grid .separator-2,
.grid .separator-3,
.grid .separator-4,
.grid .separator-5,
.grid .separator-6,
.grid .separator-7 {
    position: absolute;
    top: 0;
    bottom: 0;
    width: var(--sep-thickness);
    background-color: var(--sep-color);
    pointer-events: none;
    z-index: 10;
}

/* Position separators after every 4th column */
.grid .separator-1 { left: calc((4 * (var(--cell) + var(--gap))) - (var(--gap) / 2)); }
.grid .separator-2 { left: calc((8 * (var(--cell) + var(--gap))) - (var(--gap) / 2)); }
.grid .separator-3 { left: calc((12 * (var(--cell) + var(--gap))) - (var(--gap) / 2)); }
.grid .separator-4 { left: calc((16 * (var(--cell) + var(--gap))) - (var(--gap) / 2)); }
.grid .separator-5 { left: calc((20 * (var(--cell) + var(--gap))) - (var(--gap) / 2)); }
.grid .separator-6 { left: calc((24 * (var(--cell) + var(--gap))) - (var(--gap) / 2)); }
.grid .separator-7 { left: calc((28 * (var(--cell) + var(--gap))) - (var(--gap) / 2)); }

/* Ensure cells render below separators */
.grid-cell { z-index: 1; position: relative; }

.grid-cell {
    /* keep explicit size to match the grid tracks */
    width: 24px;
    height: 20px;
    background-color: white;
    border: 1px solid #00656a;
    border-radius: 3px;
    cursor: pointer;
    box-shadow: 0 1px 0 rgba(0,0,0,0.08) inset;
}

.grid-cell.active {
    background-color: var(--cell-active);
    box-shadow: 0 2px 0 rgba(0,0,0,0.12) inset, 0 0 0 2px rgba(0,0,0,0.04);
}

.grid-cell.playing {
    background-color: var(--cell-playing);
    outline: 3px solid rgba(144,238,144,0.6);
}

/* Measure lines */
/* Removed measure-specific rules so every cell is identical */

/* make the instrument labels area visually separated */
.drums-section .instrument-labels,
.percussion-section .instrument-labels {
    background: transparent;
}

/* Add hover and active states for volume knobs */
.instrument-labels div:hover::before {
    /* slightly brighten the image on hover to increase visibility */
    filter: brightness(1.2) contrast(1.05);
}

.instrument-labels div:active {
    cursor: grabbing;
}

/* Position the additional separators */
/* separators are positioned responsively above */

/* Dynamic barlines created by JavaScript: separate beats visually. */
.barline-overlay { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
.barline { 
    position: absolute; /* left is set inline in JS */ 
    top: var(--grid-padding); 
    bottom: var(--grid-padding); 
    width: 2.5px; 
    background: rgba(0,0,0,0.75); 
    pointer-events: none;
}

/* Visually hide controls while keeping them in the DOM and accessible to scripts.
   This keeps event listeners and values intact but removes the buttons from
   the layout and tab order. */
.invisible-control {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    border: 0 !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    white-space: nowrap !important;
    background: transparent !important;
    color: transparent !important;
    pointer-events: none !important; /* prevent accidental clicks */
}

/* Info Modal Styles */
.info-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.info-modal.hidden {
    display: none;
}

.info-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    cursor: pointer;
}

.info-modal-content {
    position: relative;
    background: linear-gradient(135deg, #0088a8, #00a5b8);
    border: 3px solid #005a6f;
    border-radius: 12px;
    padding: 16px;
    max-width: 900px;
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    color: white;
    font-family: Inter, system-ui, -apple-system, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.info-screen-img {
    width: 100%;
    max-width: 850px;
    height: auto;
    display: block;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.info-close-btn {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    transition: transform 0.2s ease;
}

.info-close-btn:hover {
    transform: scale(1.1);
}

.info-modal-content h2 {
    text-align: center;
    font-size: 32px;
    margin: 0 0 20px 0;
    font-weight: 700;
}

.info-body {
    font-size: 14px;
    line-height: 1.6;
}

.info-body h3 {
    font-size: 16px;
    font-weight: 700;
    margin: 16px 0 8px 0;
    text-decoration: underline;
}

.info-body ol, .info-body ul {
    margin: 8px 0;
    padding-left: 20px;
}

.info-body li {
    margin: 6px 0;
}

.info-body strong {
    font-weight: 700;
}

.info-footer {
    margin-top: 20px;
    text-align: center;
    font-size: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.3);
    padding-top: 12px;
}

.info-footer p {
    margin: 4px 0;
}

.info-icon-btn {
    position: absolute;
    bottom: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    transition: transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.info-icon-btn:hover {
    transform: scale(1.1);
}

/* Info open button next to Load Loop */
.info-open-btn {
    background: none;
    border: none;
    color: white;
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
    margin-left: 6px;
    transition: transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.info-open-btn:hover {
    transform: scale(1.15);
}

.info-icon-img {
    width: 20px;
    height: 20px;
    display: block;
    filter: brightness(0) invert(1);
}

/* Responsive adjustments for different viewport sizes */
@media (max-width: 1200px) {
    .grid { --cell: 20px; --grid-padding: 3px; }
    .info-screen-img { max-width: 700px; }
}

@media (max-width: 900px) {
    /* Stack control panel items for narrow widths */
    .control-panel { flex-direction: column; align-items: stretch; gap: 10px; }
    .transport-info { display: flex; flex-wrap: wrap; gap: 8px; }
    .tempo-control, .beats-control, .loop-control { min-width: 120px; }

    /* Make the grid scrollable horizontally on small screens */
    .grid { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .grid-cell { width: var(--cell); height: calc(var(--cell) * 0.85); }

    /* Slightly larger touch targets */
    .control-btn { width: 44px; height: 44px; font-size: 18px; }
    .volume-slider { width: 140px; }

    /* Make knob graphic slightly larger and preserve rotation behaviour */
    .instrument-labels div::before { width: 18px; height: 18px; margin-right: 8px; }
    .instrument-labels div { height: 22px; }

    /* Modal scales down to fit narrow screens */
    .info-modal-content { max-width: 95%; padding: 12px; }
    .info-screen-img { max-width: 100%; height: auto; }
}

@media (max-width: 600px) {
    :root { font-size: 14px; }
    .grid { --cell: 14px; --grid-padding: 2px; }
    .grid-cell { width: var(--cell); height: calc(var(--cell) * 0.9); }

    /* Reduce label area and wrap long names */
    .instrument-labels { min-width: 100px; max-width: 130px; }
    .instrument-labels div { font-size: 0.78em; padding: 2px 4px; }

    /* Bigger knobs for touch - increase pseudo-element but keep layout flow */
    .instrument-labels div::before { width: 20px; height: 20px; margin-right: 8px; }

    /* Improve hit targets for mobile */
    .info-open-btn, .info-icon-btn { width: 40px; height: 40px; }
    .info-icon-img { width: 22px; height: 22px; }

    /* Make modal full-screen on very small devices for readability */
    .info-modal-content { width: 100%; height: 100%; border-radius: 0; max-width: none; max-height: none; }
    .info-modal-overlay { background: rgba(0,0,0,0.75); }
}

/* Ensure the sequencer container remains padded on very small devices */
@media (max-width: 420px) {
    .sequencer-container { padding: 8px; }
}

/* Debug overlay (small, monospace) */
#debug-overlay {
    box-shadow: 0 2px 8px rgba(0,0,0,0.6);
    border-radius: 6px;
    line-height: 1.2;
}
