/* Reset & Base */
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', sans-serif; background: #f4f7f6; color: #333; padding: 20px; }

.container { 
    max-width: 900px; margin: 0 auto; background: #fff; 
    padding: 40px; border-radius: 16px; 
    box-shadow: 0 10px 30px rgba(0,0,0,0.05); 
}

/* Header */
.editor-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; }
.editor-controls { display: flex; gap: 10px; }

.editor-button { 
    padding: 10px 20px; border: none; border-radius: 6px; 
    font-weight: normal; /* Requested Change */
    cursor: pointer; transition: 0.2s; background: #e0e0e0;
}
#reset-defaults { background: #6c757d; color: white; }

/* Connection Screen */
#connection-screen { text-align: center; padding: 60px 0; }

/* Mode Tabs */
.mode-tabs { display: flex; justify-content: center; gap: 15px; margin-bottom: 30px; }
.mode-tab { 
    padding: 8px 25px; border-radius: 20px; border: 2px solid #eee; 
    cursor: pointer; font-weight: bold; color: #999; background: #fff;
}
.mode-tab.active { border-color: #007bff; color: #007bff; background: #f0f7ff; }

/* Knob Interface */
.knob-interface { 
    background: #fff; border: 1px solid #eee; border-radius: 12px; 
    padding: 40px; display: flex; flex-direction: column; align-items: center; 
    box-shadow: inset 0 0 20px rgba(0,0,0,0.01);
}

.rotation-row { display: flex; align-items: center; gap: 40px; margin-bottom: 40px; }

/* Knob Visual */
.knob-visual {
    width: 140px; height: 140px; border-radius: 50%;
    background: linear-gradient(145deg, #ffffff, #e6e6e6);
    box-shadow: 10px 10px 20px #d1d1d1, -10px -10px 20px #ffffff;
    position: relative; border: 1px solid #f0f0f0;
}
.knob-visual::after {
    content: ''; width: 12px; height: 12px; background: #333;
    border-radius: 50%; position: absolute; top: 20px; left: 50%;
    transform: translateX(-50%);
}

/* Drop Zones */
.function-group { display: flex; flex-direction: column; align-items: center; }
.slot-label { font-size: 0.7rem; text-transform: uppercase; color: #999; margin-bottom: 8px; font-weight: 700; letter-spacing: 1px; }

.function-slot {
    width: 140px; height: 85px; border: 2px dashed #ccc; border-radius: 10px;
    background: #fafafa; display: flex; align-items: center; justify-content: center;
    text-align: center; padding: 10px; transition: 0.2s;
}
.slot-value { font-weight: 600; font-size: 0.9rem; pointer-events: none; }
.function-slot.highlight { border-color: #007bff; background: #e6f7ff; }
.function-slot.has-keycode { border-style: solid; border-color: #ddd; background: #fff; box-shadow: 0 4px 10px rgba(0,0,0,0.03); }

/* Toggle Switch (Pill Style) */
.layer-toggle-container { margin-top: 30px; border-top: 1px solid #eee; width: 100%; padding-top: 25px; display: flex; flex-direction: column; align-items: center; }
.toggle-wrapper { display: flex; align-items: center; gap: 15px; cursor: pointer; }

.toggle-switch {
    position: relative; width: 50px; height: 26px;
    background-color: #ccc; border-radius: 13px; transition: 0.3s;
}
.toggle-switch::after {
    content: ''; position: absolute; top: 3px; left: 3px;
    width: 20px; height: 20px; background: white;
    border-radius: 50%; transition: 0.3s; box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
input:checked + .toggle-switch { background-color: #007bff; }
input:checked + .toggle-switch::after { transform: translateX(24px); }

.toggle-label { font-weight: 600; color: #555; user-select: none; }

/* Hidden Layer 2 */
#layer-2-slots { margin-top: 20px; padding: 20px; background: #f8f9fa; border-radius: 12px; border: 1px dashed #ddd; display: none; }

/* MIDI Inputs */
.midi-controls { display: flex; gap: 15px; background: #f8f9fa; padding: 15px; border-radius: 8px; border: 1px solid #eee; }
.midi-controls input { width: 60px; padding: 5px; text-align: center; border: 1px solid #ccc; border-radius: 4px; }

/* Logs */
.status-messages { 
    margin: 30px 0; max-height: 150px; overflow-y: auto; 
    border: 1px solid #eee; padding: 10px; border-radius: 6px; font-family: monospace; font-size: 0.85rem;
}
.status-message { margin-bottom: 5px; padding: 5px; border-radius: 3px; }
.status-message.success { background: #d4edda; color: #155724; }
.status-message.error { background: #f8d7da; color: #721c24; }
.status-message.info { background: #e2e3e5; color: #383d41; }

/* Palette */
.palette-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: flex-end;   /* <--- This is the change (was center) */
    border-bottom: 2px solid #eee; 
    padding-bottom: 10px; 
    margin-bottom: 15px; 
}
.keycode-section h3 { margin: 0; padding: 0; }

.palette-tabs { display: flex; gap: 10px; }
.palette-tab {
    padding: 6px 16px; border: 1px solid #ddd; background: #f8f9fa; border-radius: 6px;
    cursor: pointer; font-size: 0.85rem; font-weight: 600; color: #666; transition: 0.2s;
}
.palette-tab:hover { background: #eee; }
.palette-tab.active { background: #007bff; color: white; border-color: #007bff; }

.palette-subtitle {
    font-size: 0.85rem;
    color: #888;
    margin-top: 4px;
    font-weight: normal;
}

.keycode-grid { 
    display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); 
    gap: 10px; min-height: 250px; align-content: start;
}
.key-square {
    /* 1. Make them all the same shape */
    height: 60px;            /* Fixed height forces equality */
    width: 100%;             /* Fills the grid column perfectly */
    
    /* 2. Center text perfectly (even for 2 lines) */
    display: flex;
    align-items: center;     /* Vertical Center */
    justify-content: center; /* Horizontal Center */
    
    /* 3. Text Styling */
    text-align: center;
    font-size: 0.8rem;
    line-height: 1.2;        /* Tighter line height for wrapped text */
    padding: 4px;            /* Smaller padding allows more text space */
    
    /* 4. Visuals */
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    cursor: grab;
    transition: all 0.2s ease;
    user-select: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.key-square:hover { 
    border-color: #007bff; 
    color: #007bff; 
    transform: translateY(-2px); 
    box-shadow: 0 4px 8px rgba(0,0,0,0.08); 
}

/* Pagination */
.pagination-controls {
    display: flex; justify-content: center; align-items: center; gap: 15px;
    margin-top: 20px; padding-top: 15px; border-top: 1px solid #eee;
}
.pagination-controls button {
    padding: 6px 14px; border: 1px solid #ddd; background: white; border-radius: 4px; cursor: pointer;
}
.pagination-controls button:disabled { opacity: 0.5; cursor: default; }
#page-indicator { font-size: 0.9rem; font-weight: 600; color: #666; }

/* --- TOOLTIP STYLES --- */

/* 1. Ensure the square is the reference point for the tooltip position */
.key-square {
    position: relative; 
}

/* 2. The Tooltip Body (hidden by default) */
.key-square[data-tooltip]::after {
    content: attr(data-tooltip); /* Pull text from the JS attribute */
    position: absolute;
    bottom: 110%; /* Place it just above the square */
    left: 50%;
    transform: translateX(-50%) translateY(10px); /* Center horizontal, slight offset vertical */
    
    background: #333;
    color: #fff;
    padding: 6px 10px;
    border-radius: 5px;
    font-size: 0.75rem;
    line-height: 1.2;
    white-space: nowrap; /* Don't wrap text unless very long */
    pointer-events: none; /* Let mouse pass through */
    z-index: 1000;
    
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, transform 0.2s;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
}

/* 3. The Little Arrow (Triangle) below the tooltip */
.key-square[data-tooltip]::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    border: 6px solid transparent;
    border-top-color: #333;
    z-index: 1000;
    
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, transform 0.2s;
}

/* 4. Hover State: Show them and slide up slightly */
.key-square[data-tooltip]:hover::after,
.key-square[data-tooltip]:hover::before {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}