/* --- THEME DEFINITIONS --- */

:root {
    --trans-speed: 0.3s;
}

[data-theme="standard"] {
    --primary: #ff6b4a;
    --primary-dim: rgba(255, 107, 74, 0.1);
    --bg: #f5f6fa;
    --surface: #ffffff;
    --card-bg: #e4e7eb;
    --text: #2d3436;
    --text-light: #636e72;
    --border: #dfe6e9;
    --shadow: rgba(0,0,0,0.05);
    --danger: #d63031;
    --btn-text: #4a4a4a;
    --menu-bg: rgba(255, 255, 255, 0.98);
    --ring-track: #dfe6e9;
    --ring-color: #ff6b4a;
}

[data-theme="ocean"] {
    --primary: #0984e3;
    --primary-dim: rgba(9, 132, 227, 0.1);
    --bg: #f0f9ff;
    --surface: #ffffff;
    --card-bg: #dfe6e9;
    --text: #2c3e50;
    --text-light: #576574;
    --border: #c7ecee;
    --shadow: rgba(9, 132, 227, 0.1);
    --danger: #ff7675;
    --btn-text: #2c3e50;
    --menu-bg: rgba(255, 255, 255, 0.98);
    --ring-track: #c7ecee;
    --ring-color: #0984e3;
}

[data-theme="forest"] {
    --primary: #00b894;
    --primary-dim: rgba(0, 184, 148, 0.1);
    --bg: #f1f2f6;
    --surface: #ffffff;
    --card-bg: #ced6e0;
    --text: #2f3542;
    --text-light: #747d8c;
    --border: #a4b0be;
    --shadow: rgba(0, 184, 148, 0.1);
    --danger: #ff6b6b;
    --btn-text: #2f3542;
    --menu-bg: rgba(255, 255, 255, 0.98);
    --ring-track: #a4b0be;
    --ring-color: #00b894;
}

[data-theme="night"] {
    --primary: #ff7675;
    --primary-dim: rgba(255, 118, 117, 0.15);
    --bg: #1e272e;
    --surface: #2f3640;
    --card-bg: #353b48;
    --text: #f5f6fa;
    --text-light: #dcdde1;
    --border: #4b6584;
    --shadow: rgba(0,0,0,0.3);
    --danger: #e17055;
    --btn-text: #f5f6fa;
    --menu-bg: rgba(47, 54, 64, 0.98);
    --ring-track: #4b6584;
    --ring-color: #ff7675;
}


/* --- GLOBAL STYLES --- */

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 20px 15px;
    box-sizing: border-box;
    transition: background-color var(--trans-speed), color var(--trans-speed);
}

.container {
    width: 100%;
    max-width: 500px;
    position: relative;
    padding-bottom: 80px;
}


/* --- HEADER & MENU --- */

header {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    margin-bottom: 20px;
    padding: 0 10px;
}

h1 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.menu-btn {
    position: absolute;
    right: 0;
    color: var(--text-light);
    cursor: pointer;
    padding: 5px;
    z-index: 101;
    display: flex;
    align-items: center;
    justify-content: center;
}

.menu-btn svg {
    width: 24px;
    height: 24px;
}

.theme-menu {
    position: absolute;
    top: 50px;
    right: 10px;
    width: 180px;
    background: var(--menu-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    z-index: 100;
    border: 1px solid var(--border);
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-origin: top right;
}

.theme-menu.open {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

.menu-title {
    font-size: 0.7rem;
    color: var(--text-light);
    font-weight: 700;
    padding: 5px 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 5px;
    text-transform: uppercase;
}

.theme-item {
    padding: 10px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.2s;
}

.theme-item:hover {
    background: var(--primary-dim);
    color: var(--primary);
}

.color-preview {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.reset-item {
    color: var(--danger);
}

.reset-item:hover {
    background: rgba(214, 48, 49, 0.1);
    color: var(--danger);
}


/* --- SETTINGS CARD --- */

.settings-card {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 15px;
    margin-bottom: 20px;
    transition: background-color var(--trans-speed);
}

.btn-connect {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 25px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.95rem;
    background: var(--primary);
    color: white;
    margin-bottom: 15px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    transition: background var(--trans-speed), transform 0.1s;
}

.btn-connect.connected {
    background: #00b894;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
    transition: opacity 0.3s;
}

.controls-row {
    display: flex;
    gap: 10px;
    margin-bottom: 5px;
}

.control-pill {
    background: var(--surface);
    border-radius: 15px;
    padding: 10px;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px var(--shadow);
}

.control-pill label {
    font-size: 0.65rem;
    color: var(--text-light);
    margin-bottom: 4px;
    font-weight: 700;
    text-transform: uppercase;
}

input[type="number"] {
    border: none;
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--primary);
    text-align: center;
    width: 100%;
    background: transparent;
}

input[type="number"]:focus {
    outline: none;
}

input[type="number"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    color: var(--text-light);
}

.mode-switch {
    display: flex;
    background: rgba(0,0,0,0.05);
    border-radius: 20px;
    padding: 3px;
    width: 100%;
    margin-bottom: 10px;
}

[data-theme="night"] .mode-switch {
    background: rgba(255,255,255,0.1);
}

.mode-option {
    flex: 1;
    text-align: center;
    padding: 8px;
    font-size: 0.75rem;
    border-radius: 18px;
    cursor: pointer;
    color: var(--text-light);
    font-weight: 600;
    transition: all var(--trans-speed);
}

.mode-option.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.level-select {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 10px;
}

.lvl-dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--text-light);
    cursor: pointer;
    border: 2px solid transparent;
    box-shadow: 0 2px 5px var(--shadow);
    transition: all var(--trans-speed);
}

.lvl-dot.active {
    border-color: var(--primary);
    color: var(--primary);
    transform: scale(1.1);
}

.section-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 8px;
    padding-left: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}


/* --- TABS & DRILL GRID --- */

.tabs-container {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 10px;
    margin-bottom: 20px;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
}

.tab-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 12px 5px;
    border-radius: 16px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-light);
    font-weight: 600;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all var(--trans-speed);
    text-align: center;
}

.tab-btn.active {
    background: var(--surface);
    border: 1px solid var(--primary);
    color: var(--primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.icon-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px;
    width: 10px;
    height: 10px;
    margin-bottom: 2px;
}

.icon-dot {
    background-color: var(--text-light);
    border-radius: 50%;
    opacity: 0.5;
}

.tab-btn.active .icon-dot {
    background-color: var(--primary);
    opacity: 1;
}


/* === REDESIGNED DRILL LIST (Single Column) === */

.drill-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}

.hidden {
    display: none !important;
}


/* === WIDE BUTTON STYLE === */

.btn-drill {
    width: 100%;
    min-height: 60px;
    padding: 0 15px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 15px;

    background: var(--surface);
    border: 1px solid transparent;
    border-radius: 12px;
    color: var(--btn-text);
    box-shadow: 0 1px 3px var(--shadow);
    position: relative;
    transition: transform 0.1s, background-color 0.2s;
    user-select: none;
    -webkit-user-select: none;
    cursor: pointer;
}

.btn-drill:active {
    transform: scale(0.98);
}

.btn-drill.running {
    border-color: var(--primary);
    background: var(--primary-dim);
    color: var(--primary);
}

.btn-drill:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
    background: rgba(0,0,0,0.05);
}


/* Left-side visual icon */

.btn-drill .drill-icon {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px;
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    opacity: 0.7;
}

.btn-drill .drill-icon .d-dot {
    background-color: #b2bec3;
    border-radius: 50%;
    transition: background-color var(--trans-speed);
}

.btn-drill.running .drill-icon .d-dot {
    background-color: var(--primary);
}


/* Text Label */

.btn-drill span {
    flex: 1;
    text-align: left;
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* Random Badge (Right side now) */

.mark-random {
    position: static;
    width: 22px;
    height: 22px;
    border: 1.5px solid var(--danger);
    color: var(--danger);
    border-radius: 50%;
    font-size: 0.65rem;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    line-height: 1;
    flex-shrink: 0;
}


/* Sorting Grip Handle */

.drill-grab-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 100%;
    cursor: grab;
    color: var(--text-light);
    opacity: 0.3;
    font-size: 1.4rem;
    margin-left: 5px;
    border-left: 1px solid var(--border);
    padding-left: 10px;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

.drill-grab-handle:hover {
    opacity: 1;
    color: var(--primary);
}

.btn-drill.dragging {
    opacity: 0.5;
    background: var(--card-bg);
    border: 1px dashed var(--text-light);
}


/* --- FOOTER & LOGS --- */

#status-text {
    text-align: center;
    font-size: 0.8rem;
    color: var(--primary);
    font-weight: 700;
    height: 20px;
    margin-bottom: 5px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.log-box {
    margin-top: 10px;
    background: #2d3436;
    color: #00cec9;
    padding: 12px;
    border-radius: 10px;
    font-family: monospace;
    font-size: 0.65rem;
    height: 120px;
    overflow-y: auto;
    display: none;
    border: 1px solid #636e72;
    line-height: 1.4;
}

.log-box div {
    margin-bottom: 2px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 2px;
}

.footer-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    font-size: 0.8rem;
    color: var(--text-light);
    font-weight: 600;
    padding: 0 5px;
}


/* --- SWAP BUTTON (Between Balls) --- */

.swap-zone {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2px 0;
    margin: -8px 0 8px 0;
    position: relative;
    z-index: 5;
}


/* Optional: A line behind the button to connect the balls visually */

.swap-zone::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
    transform: translateX(-50%);
    z-index: -1;
}

.btn-swap {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-light);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    transition: all 0.2s ease;
}

.btn-swap:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: scale(1.1);
}

.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
}

#stats-display {
    font-variant-numeric: tabular-nums;
}


/* TOAST - Z-Index updated to 300 to show over modal */

#toast {
    visibility: hidden;
    min-width: 250px;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 50px;
    padding: 16px;
    position: fixed;
    z-index: 300;
    left: 50%;
    bottom: 30px;
    transform: translateX(-50%);
    font-size: 0.9rem;
    opacity: 0;
    transition: opacity 0.5s, bottom 0.5s;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

#toast.show {
    visibility: visible;
    opacity: 1;
    bottom: 50px;
}


/* --- MODALS --- */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(8px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--surface);
    width: 95%;
    max-width: 400px;
    max-height: 90vh;
    border-radius: 25px;
    padding: 20px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}


/* MODAL HEADER - GENERAL */

.modal-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    width: 100%;
}

.modal-title {
    font-weight: normal;
    color: var(--text);
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    text-align: left;
    margin-right: 10px;
}


/* EDITOR MODAL HEADER SPECIFIC */
/* Switches to column layout for Editor only */

#editor-modal .modal-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
}


/* Row 1: Title and Close */

#editor-modal .header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    min-width: 0;
}


/* New Title Container allowing full width and edit icon */

#editor-modal .title-container {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    cursor: pointer;
    margin-right: 10px;
}

#editor-drill-name {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#editor-drill-edit-icon {
    font-size: 1rem;
    opacity: 0.5;
    flex-shrink: 0;
    color: var(--primary);
}


/* Row 2: Actions */

#editor-modal .header-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}


/* Adjustments for buttons inside new layout */

.btn-header-share {
    margin-right: 0;
}

.random-toggle-container {
    margin-right: 0;
}

.modal-close {
    font-size: 1.5rem;
    color: var(--text-light);
    cursor: pointer;
    line-height: 1;
}

.modal-body {
    overflow-y: auto;
    flex: 1;
    padding-right: 5px;
}


/* --- EDITOR SPECIFIC (Smart Grid Layout) --- */

.ball-group {
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 15px;
    overflow: hidden;
    background: var(--bg);
    transition: opacity 0.3s;
}

.ball-group.inactive {
    opacity: 0.5;
    border-style: dashed;
}

.group-title {
    background: var(--card-bg);
    padding: 8px 12px;
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--text-light);
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}


/* Toggle Switch for Active/Inactive Ball */

.ball-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.toggle-switch {
    position: relative;
    width: 30px;
    height: 16px;
    background: #b2bec3;
    border-radius: 15px;
    transition: background 0.2s;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.ball-toggle.active .toggle-switch {
    background: var(--primary);
}

.ball-toggle.active .toggle-switch::after {
    transform: translateX(14px);
}


/* Random Toggle (Header) */

.random-toggle-container {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.random-toggle-container input {
    display: none;
}

.random-toggle-container input:checked + .toggle-switch {
    background: var(--primary);
}

.random-toggle-container input:checked + .toggle-switch::after {
    transform: translateX(14px);
}


/* Round Plus Button */

.btn-add-opt {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    font-weight: 400;
    line-height: 1;
    padding: 0 0 2px 0;
    transition: all 0.2s;
}

.btn-add-opt:hover {
    background: var(--primary);
    color: white;
    transform: scale(1.1);
}

.option-card {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.option-card:last-child {
    border-bottom: none;
}

.option-label {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 5px;
    text-transform: uppercase;
    display: block;
}


/* --- GRID & INPUT STYLES (Replaced Sliders) --- */

.editor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    margin-bottom: 10px;
}

.editor-field {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
}

.field-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
    padding: 0 4px;
}

.field-header label {
    font-size: 0.6rem;
    color: var(--text-light);
    font-weight: 700;
    text-transform: uppercase;
}

.field-header .range-hint {
    font-size: 0.5rem;
    color: #b2bec3;
}


/* Fast Input Styling */

.editor-field input {
    border: none;
    background: transparent;
    font-size: 0.95rem;
    color: var(--text);
    font-weight: 700;
    text-align: center;
    width: 100%;
    padding: 4px 0;
    -moz-appearance: textfield;
}

.editor-field input:focus {
    outline: none;
    color: var(--primary);
}


/* Spin Toggle Row */

.spin-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    padding: 0 4px;
}

.spin-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-light);
    text-transform: uppercase;
}

.spin-capsule {
    display: flex;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2px;
}

.sc-opt {
    padding: 4px 12px;
    font-size: 0.65rem;
    font-weight: 700;
    border-radius: 10px;
    cursor: pointer;
    color: var(--text-light);
    transition: all 0.2s;
}

.sc-opt.active {
    background: var(--text);
    color: var(--bg);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}


/* Color Coding for Toggle */

.sc-opt:first-child.active {
    background: #e17055;
    color: white;
}

.sc-opt:last-child.active {
    background: #0984e3;
    color: white;
}


/* --- EDITOR ACTION BUTTONS --- */

.card-actions {
    display: flex;
    gap: 8px;
    margin-top: 5px;
}

.btn-action {
    flex: 1;
    padding: 8px;
    border-radius: 8px;
    border: none;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    text-transform: uppercase;
    color: white;
}

.btn-act-test {
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-act-test:hover {
    background: var(--text-light);
    color: white;
}

.btn-act-test:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-act-clone {
    background: #0984e3;
}

.btn-act-clone:hover {
    background: #00cec9;
}

.btn-act-del {
    background: var(--danger);
}

.btn-act-del:hover {
    opacity: 0.8;
}

.btn-act-del:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}


/* Share Button */

.btn-header-share {
    background: transparent;
    border: none;
    color: var(--primary);
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    flex-shrink: 0;
}

.btn-header-share:hover {
    transform: scale(1.1);
    color: var(--text);
}

.btn-header-share svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}


/* --- MODAL FOOTER --- */

.modal-footer {
    margin-top: 15px;
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.btn-modal {
    padding: 12px 8px;
    border-radius: 10px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.8rem;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    transition: transform 0.1s, opacity 0.2s;
}

.btn-modal:active {
    transform: scale(0.96);
}

.btn-delete-drill {
    background: var(--danger);
    color: white;
    width: 44px;
    flex: 0 0 44px;
    padding: 0;
}

.btn-delete-drill svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.btn-delete-drill:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.btn-test-combo {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
    flex: 1.2;
}

[data-theme="night"] .btn-test-combo {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-test-combo:hover {
    background: var(--primary-dim);
}

.btn-save-as {
    background: transparent;
    border: 2px solid var(--text);
    color: var(--text);
    flex: 1.2;
}

.btn-save-as:hover {
    background: rgba(0,0,0,0.05);
}

[data-theme="night"] .btn-save-as:hover {
    background: rgba(255,255,255,0.1);
}

.btn-save {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
    flex: 1.5;
}

.btn-save:hover {
    background: var(--primary-dim);
}


/* --- RUN OVERLAY --- */

#run-ui {
    display: none;
    flex-direction: column;
    align-items: center;
    width: 100%;
    justify-content: center;
    text-align: center;
}

.modal-overlay.open #run-ui {
    display: flex;
}

.countdown-circle {
    position: relative;
    width: 200px;
    height: 200px;
    margin-bottom: 30px;
}

.countdown-circle svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.track {
    fill: none;
    stroke: var(--ring-track);
    stroke-width: 8;
}

.progress {
    fill: none;
    stroke: var(--primary);
    stroke-width: 8;
    stroke-dasharray: 565;
    stroke-dashoffset: 0;
    stroke-linecap: round;
}

.center-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.count-val {
    font-size: 4.5rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1;
    font-feature-settings: "tnum";
    font-variant-numeric: tabular-nums;
}

.status-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 5px;
}

.run-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    margin-top: 10px;
}

.btn-run-ctrl {
    width: 100%;
    padding: 15px;
    border-radius: 15px;
    border: none;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.1s;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.btn-run-ctrl:active {
    transform: scale(0.95);
}

.btn-pause {
    background: var(--card-bg);
    color: var(--text);
}

.btn-stop-run {
    background: var(--danger);
    color: white;
    padding: 30px;
    font-size: 1.5rem;
    margin-top: 10px;
}

.pulse-anim {
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }

    100% {
        opacity: 1;
    }
}


/* --- LAST PLAYED HIGHLIGHT --- */

.btn-drill.last-played {
    border-color: var(--primary);
    background: var(--surface);
}


/* Optional: Add a small indicator icon */

.btn-drill.last-played::after {
    content: '●';
    color: var(--primary);
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8rem;
}


/* -----------------------------
   Music Playlist Controls
   ----------------------------- */

.music-control {
    min-width: 180px;
}

.music-file-input {
    display: none;
}


/*
 * flattened for the music card.
 * dili na kinahanglan murag giant launch button.
 */
.music-file-btn {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 100%;
    min-height: 34px;
    box-sizing: border-box;

    padding: 6px 10px;

    border: 1px solid var(--border);
    border-radius: 10px;

    background: var(--surface);
    color: var(--text);

    cursor: pointer;

    font-size: 0.78rem;
    font-weight: 700;

    user-select: none;
}

.music-file-btn:active {
    transform: scale(0.98);
}

.music-playlist-info {
    margin-top: 6px;

    max-width: 220px;

    font-size: 0.78rem;
    line-height: 1.25;

    opacity: 0.85;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.music-playlist-select {
    width: 100%;
    box-sizing: border-box;

    margin-top: 4px;
    padding: 6px 8px;

    border: 1px solid var(--border);
    border-radius: 9px;

    background: var(--surface);
    color: var(--text);

    font-size: 0.78rem;
    font-weight: 600;
}

.music-saved-playlist-btn {
    width: 100%;
    min-height: 34px;

    margin-top: 5px;

    cursor: pointer;
}

.music-source-divider {
    margin: 6px 0;

    text-align: center;

    font-size: 0.62rem;
    font-weight: 700;

    color: var(--text-light);
}


@media (max-width: 600px) {

    .music-control {
        min-width: 150px;
        width: 100%;
    }

    .music-file-btn {
        width: 100%;
        min-height: 34px;
    }

    .music-playlist-info {
        max-width: 100%;
        text-align: center;
    }
}


/* =========================================================
   Playlist Manager
   ========================================================= */

.music-manage-btn {
    margin-top: 8px;
    min-height: 36px;
    padding: 8px 14px;

    border: 1px solid var(--border);
    border-radius: 10px;

    background: transparent;
    color: var(--text);

    font-size: 0.86rem;
    font-weight: 600;

    cursor: pointer;
}

.music-manage-btn:active {
    transform: scale(0.98);
}


/*
 * hidden by default.
 * open class gets added by playlist-ui.js
 */

.playlist-manager-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;

    display: none;
    align-items: center;
    justify-content: center;

    padding: 18px;

    background: rgba(0, 0, 0, 0.55);
}

.playlist-manager-modal.open {
    display: flex;
}

.playlist-manager-card {
    width: min(520px, 100%);
    max-height: 80vh;

    display: flex;
    flex-direction: column;

    border: 1px solid var(--border);
    border-radius: 18px;

    background: var(--surface);
    color: var(--text);

    overflow: hidden;

    box-shadow:
        0 18px 50px rgba(0, 0, 0, 0.28);
}

.playlist-manager-header {
    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 16px;
    padding: 18px;

    border-bottom: 1px solid var(--border);
}

.playlist-manager-title {
    font-size: 1.15rem;
    font-weight: 700;
}

.playlist-manager-subtitle {
    margin-top: 2px;

    font-size: 0.8rem;
    color: var(--text-light);
}

.playlist-manager-close {
    width: 38px;
    height: 38px;

    display: flex;
    align-items: center;
    justify-content: center;

    border: 0;
    border-radius: 10px;

    background: transparent;
    color: var(--text);

    font-size: 1.7rem;
    line-height: 1;

    cursor: pointer;
}

.playlist-manager-close:active {
    transform: scale(0.96);
}

.playlist-manager-list {
    padding: 10px;
    overflow-y: auto;
}

.playlist-manager-row {
    display: flex;
    align-items: center;
    justify-content: space-between;

    min-height: 64px;

    padding: 12px 14px;
    margin-bottom: 8px;

    border: 1px solid var(--border);
    border-radius: 12px;

    background: var(--surface);
}

.playlist-manager-row-info {
    min-width: 0;
    flex: 1;
}

.playlist-manager-row-name {
    font-weight: 700;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.playlist-manager-row-meta {
    margin-top: 4px;

    font-size: 0.78rem;
    color: var(--text-light);
}

.playlist-manager-empty {
    padding: 28px 16px;

    text-align: center;

    font-size: 0.9rem;
    color: var(--text-light);
}

.playlist-manager-row-actions {
    display: flex;
    align-items: center;
    gap: 6px;

    margin-left: 12px;

    flex-wrap: wrap;
    justify-content: flex-end;
}

.playlist-manager-action-btn {
    min-height: 34px;
    padding: 6px 10px;

    border: 1px solid var(--border);
    border-radius: 9px;

    background: transparent;
    color: var(--text);

    font-size: 0.78rem;
    font-weight: 600;

    cursor: pointer;
}

.playlist-manager-action-btn:active {
    transform: scale(0.97);
}

.playlist-manager-delete-btn {
    color: #c0392b;
}

.playlist-manager-delete-btn:active {
    opacity: 0.75;
}

.playlist-manager-row-clickable {
    cursor: pointer;
}

.playlist-manager-row-clickable:active {
    opacity: 0.75;
}

.playlist-tracks-header {
    display: flex;
    align-items: center;

    gap: 12px;
    padding: 12px 14px;

    border-bottom: 1px solid var(--border);
}

.playlist-tracks-title {
    min-width: 0;

    font-size: 1rem;
    font-weight: 700;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.playlist-tracks-list {
    padding: 10px;
    overflow-y: auto;
}

.playlist-track-row {
    display: flex;
    align-items: center;

    gap: 12px;

    min-height: 58px;

    padding: 10px 12px;
    margin-bottom: 8px;

    border: 1px solid var(--border);
    border-radius: 12px;

    background: var(--surface);
}

.playlist-track-number {
    width: 28px;
    flex: 0 0 28px;

    text-align: center;

    font-size: 0.82rem;
    font-weight: 700;

    color: var(--text-light);
}

.playlist-track-info {
    min-width: 0;
    flex: 1;
}

.playlist-track-name {
    font-size: 0.9rem;
    font-weight: 700;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.playlist-track-meta {
    margin-top: 3px;

    font-size: 0.75rem;
    color: var(--text-light);
}

.playlist-track-remove-btn {
    flex: 0 0 auto;

    margin-left: 8px;

    color: #c0392b;
}

.playlist-track-remove-btn:active {
    opacity: 0.75;
}

.playlist-track-move-actions {
    display: flex;
    gap: 4px;

    flex: 0 0 auto;
}

.playlist-track-move-btn {
    width: 34px;
    min-width: 34px;
    padding: 6px 0;

    font-size: 1rem;
    font-weight: 800;
}

.playlist-track-move-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.playlist-track-move-btn:disabled:active {
    transform: none;
}


@media (max-width: 600px) {

    .playlist-manager-modal {
        padding: 10px;
    }

    .playlist-manager-card {
        max-height: 88vh;
        border-radius: 16px;
    }

    .playlist-manager-header {
        padding: 16px;
    }
}
