/* ============================================================
   DESIGN SYSTEM — JafaStageCenter
   Premium design tokens, components, and utilities.
   Inspired by Linear / Raycast / Ableton aesthetic.
   ============================================================ */

/* ── Fonts ── */
@font-face {
    font-family: 'Sen';
    src: url('../fonts/Sen-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Sen';
    src: url('../fonts/Sen-Bold.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

/* ── Reset ── */
*, *::before, *::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

*:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ── Design Tokens — Dark (default) ── */
:root {
    /* Surfaces — Graphite dark (neutral charcoal, not navy) */
    --bg-app: #141416;
    --bg-panel: #1B1B1E;
    --bg-surface: #222226;
    --bg-surface-hover: #2A2A2F;
    --bg-elevated: #313137;
    --bg-input: #0F0F11;
    --bg-preview: #0A0A0C;
    --bg-inset: #0C0C0E;

    /* Borders & dividers — ultra-subtle glass edges */
    --border-subtle: rgba(255, 255, 255, 0.03);
    --border-default: rgba(255, 255, 255, 0.09);
    --border-strong: rgba(255, 255, 255, 0.16);
    --border-focus: rgba(99, 155, 255, 0.5);

    /* Text — never pure white */
    --text-primary: #ECECEF;
    --text-secondary: #A6A6B0;
    --text-tertiary: #7C7C87;
    --text-inverse: #141416;
    --text-accent: #7EB0FF;

    /* Accent palette — refined for premium feel */
    --accent: #4F7FFF;
    --accent-hover: #6690FF;
    --accent-subtle: rgba(79, 127, 255, 0.08);
    --accent-glow: rgba(79, 127, 255, 0.18);

    --teal: #2DD4BF;
    --teal-subtle: rgba(45, 212, 191, 0.08);
    --green: #34D399;
    --green-subtle: rgba(52, 211, 153, 0.08);
    --red: #F87171;
    --red-subtle: rgba(248, 113, 113, 0.08);
    --amber: #FBBF24;
    --amber-subtle: rgba(251, 191, 36, 0.08);

    /* Chord / Worship accent — high contrast neon */
    --chord-color: #00E5FF;
    --chord-glow: rgba(0, 229, 255, 0.15);

    /* Elevation — deep shadows for layered feel */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.45);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.55);
    --shadow-glow: 0 0 24px var(--accent-glow);
    --shadow-inset: inset 0 1px 3px rgba(0,0,0,0.4);

    /* Glass surfaces */
    --glass-bg: rgba(17, 22, 32, 0.92);
    --glass-border: rgba(255, 255, 255, 0.04);

    /* Spacing — 4px base */
    --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px;
    --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px;
    --s12: 48px; --s16: 64px;

    /* Typography scale */
    --font-xs: 0.6875rem;   /* 11px */
    --font-sm: 0.8125rem;   /* 13px */
    --font-base: 0.9375rem; /* 15px */
    --font-lg: 1.125rem;    /* 18px */
    --font-xl: 1.5rem;      /* 24px */
    --font-2xl: 2rem;       /* 32px */
    --font-3xl: 2.5rem;     /* 40px */

    /* Radius */
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 14px;
    --r-xl: 20px;
    --r-full: 9999px;

    /* Motion */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
    --duration-fast: 0.15s;
    --duration-normal: 0.25s;
    --duration-slow: 0.4s;

    /* Legacy compat — other templates still reference these */
    --bg-element: var(--bg-surface);
    --bg-element-hover: var(--bg-surface-hover);
    --input-bg: var(--bg-input);
    --pad-container: var(--bg-input);
    --border-color: var(--border-default);
    --text-main: var(--text-primary);
    --text-muted: var(--text-secondary);
    --accent-primary: var(--accent);
    --accent-secondary: var(--teal);
    --accent-success: var(--green);
    --accent-danger: var(--red);
    --accent-warning: var(--amber);
    --accent-active-bg: var(--accent-subtle);
    --shadow-color: rgba(0, 0, 0, 0.5);
    --glow-primary: var(--accent-glow);
    --glow-success: var(--green-subtle);
    --radius-sm: var(--r-sm);
    --radius-md: var(--r-md);
    --radius-lg: var(--r-lg);
    --radius-xl: var(--r-xl);
    --radius-full: var(--r-full);
    --transition-fast: var(--duration-fast) var(--ease-in-out);
    --transition-smooth: var(--duration-normal) var(--ease-out);
}

/* ── Light Theme ── */
[data-theme="light"] {
    --bg-app: #F5F6F8;
    --bg-panel: #FFFFFF;
    --bg-surface: #F0F1F4;
    --bg-surface-hover: #E6E8EC;
    --bg-elevated: #FFFFFF;
    --bg-input: #F0F1F4;
    --bg-preview: #FAFBFC;
    --bg-inset: #ECEDF0;

    --border-subtle: rgba(0, 0, 0, 0.04);
    --border-default: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.14);
    --border-focus: rgba(37, 99, 235, 0.4);

    --text-primary: #1A1D24;
    --text-secondary: #5C6370;
    --text-tertiary: #8C929E;
    --text-inverse: #F0F2F5;
    --text-accent: #2563EB;

    --accent: #2563EB;
    --accent-hover: #1D4ED8;
    --accent-subtle: rgba(37, 99, 235, 0.06);
    --accent-glow: rgba(37, 99, 235, 0.10);
    --teal: #0D9488;
    --teal-subtle: rgba(13, 148, 136, 0.06);
    --green: #059669;
    --green-subtle: rgba(5, 150, 105, 0.06);
    --red: #DC2626;
    --red-subtle: rgba(220, 38, 38, 0.06);
    --amber: #D97706;
    --amber-subtle: rgba(217, 119, 6, 0.06);

    --chord-color: #0891B2;
    --chord-glow: rgba(8, 145, 178, 0.1);

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.08);
    --shadow-glow: 0 0 24px var(--accent-glow);
    --shadow-inset: inset 0 1px 2px rgba(0,0,0,0.06);

    --glass-bg: rgba(255, 255, 255, 0.95);
    --glass-border: rgba(0, 0, 0, 0.05);
}

/* ── Base ── */
body {
    font-family: 'Sen', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    background: var(--bg-app);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background var(--duration-normal) var(--ease-out),
                color var(--duration-normal) var(--ease-out);
}

/* ── Scrollbar — thin, minimal ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.08);
    border-radius: var(--r-full);
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.14);
}
[data-theme="light"] ::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.1);
}
[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.18);
}

/* ── Form Controls — Raycast-style glowing inputs ── */
input, textarea, select {
    width: 100%;
    padding: var(--s3) var(--s4);
    border: 1px solid var(--border-default);
    border-radius: var(--r-md);
    font-family: inherit;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: var(--font-sm);
    box-shadow: var(--shadow-inset);
    transition: border-color var(--duration-fast) var(--ease-in-out),
                box-shadow var(--duration-fast) var(--ease-in-out);
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

input::placeholder, textarea::placeholder {
    color: var(--text-tertiary);
}

/* ── Toggle Switch ── */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-surface-hover);
    border-radius: var(--r-full);
    transition: background var(--duration-normal) var(--ease-out);
}
.slider::before {
    content: "";
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: var(--text-primary);
    border-radius: 50%;
    transition: transform var(--duration-normal) var(--ease-out);
}
input:checked + .slider {
    background: var(--accent);
}
input:checked + .slider::before {
    transform: translateX(20px);
    background: white;
}

/* ── Global tactile press feedback ──
   Every button scales down slightly on press so nothing feels flat/dead.
   Per-component :active rules (higher specificity) can still override. */
button {
    transition: transform var(--duration-fast) var(--ease-in-out),
                background-color var(--duration-fast) var(--ease-in-out),
                border-color var(--duration-fast) var(--ease-in-out),
                color var(--duration-fast) var(--ease-in-out);
}
button:active { transform: scale(0.955); }

/* ── Button System ── */
.btn, [class*="btn-"] {
    font-family: inherit;
    font-weight: 700;
    border-radius: var(--r-md);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s2);
    padding: var(--s3) var(--s5);
    font-size: var(--font-sm);
    line-height: 1;
    transition: all var(--duration-fast) var(--ease-in-out);
    white-space: nowrap;
    text-decoration: none;
}

.btn:active, [class*="btn-"]:active {
    transform: scale(0.955);
}

.btn-primary {
    background: var(--accent);
    color: white;
    border: none;
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
}
.btn-secondary:hover {
    background: var(--bg-surface);
    border-color: var(--accent);
    color: var(--accent);
}

.btn-ghost {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
}
.btn-ghost:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

.btn-danger {
    background: transparent;
    border: 1px solid var(--red);
    color: var(--red);
}
.btn-danger:hover {
    background: var(--red);
    color: white;
}

.btn-sm { padding: var(--s1) var(--s3); font-size: var(--font-xs); }
.btn-lg { padding: var(--s4) var(--s8); font-size: var(--font-base); }

/* ── Segmented Control (pill switch) ── */
.segmented-control {
    display: inline-flex;
    background: var(--bg-surface);
    border-radius: var(--r-full);
    padding: 3px;
    gap: 2px;
    border: 1px solid var(--border-default);
}
.segmented-control button {
    background: transparent;
    border: none;
    padding: var(--s2) var(--s5);
    font-family: inherit;
    font-size: var(--font-sm);
    font-weight: 600;
    color: var(--text-secondary);
    border-radius: var(--r-full);
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-out);
    letter-spacing: 0.02em;
}
.segmented-control button:hover {
    color: var(--text-primary);
}
.segmented-control button.active {
    background: var(--text-primary);
    color: var(--bg-panel);
    box-shadow: var(--shadow-sm);
}

/* ── Modal ── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(16px);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn var(--duration-fast) var(--ease-out);
}
.modal-content {
    background: var(--bg-panel);
    padding: var(--s8);
    border-radius: var(--r-xl);
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid var(--border-default);
    box-shadow: var(--shadow-lg);
    animation: modalIn var(--duration-normal) var(--ease-out);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--s6);
}
.modal-header h3, .modal-header span:first-child {
    font-size: var(--font-lg);
    font-weight: 700;
}
.modal-close {
    background: var(--bg-surface);
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: var(--r-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all var(--duration-fast) var(--ease-in-out);
}
.modal-close:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

/* ── Card ── */
.card {
    background: var(--bg-panel);
    border: 1px solid var(--border-default);
    border-radius: var(--r-lg);
    padding: var(--s6);
}
.card-header {
    display: flex;
    gap: var(--s2);
    color: var(--text-tertiary);
    font-size: var(--font-xs);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding-bottom: var(--s4);
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: var(--s5);
}

/* ── Section Header (settings, groups) ── */
.settings-section {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--r-lg);
    padding: var(--s6);
    margin-bottom: var(--s5);
}
.settings-section h4 {
    margin: 0 0 var(--s5);
    color: var(--text-tertiary);
    font-size: var(--font-xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: var(--s3);
}
.settings-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--s4);
    font-size: var(--font-sm);
}
.settings-row:last-child { margin-bottom: 0; }
.settings-row label {
    color: var(--text-secondary);
}

/* ── Toast ── */
#toast-container {
    /* prawy dolny róg — top-center zasłaniał tytuł piosenki w panelu LIVE */
    position: fixed;
    bottom: var(--s5);
    right: var(--s5);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: var(--s3);
    pointer-events: none;
}
.toast {
    background: var(--bg-elevated);
    color: var(--text-primary);
    padding: var(--s3) var(--s6);
    border-radius: var(--r-full);
    font-weight: 600;
    font-size: var(--font-sm);
    border: 1px solid var(--border-default);
    box-shadow: var(--shadow-lg);
    animation: toastIn var(--duration-slow) var(--ease-out),
               toastOut var(--duration-normal) var(--ease-in-out) 2.6s forwards;
}

/* ── File Upload ── */
.file-upload-row {
    display: flex;
    align-items: center;
    gap: var(--s3);
    margin-top: var(--s3);
}
.custom-file-label {
    flex-grow: 1;
    border: 1px dashed var(--border-strong);
    border-radius: var(--r-md);
    padding: var(--s3) var(--s4);
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: var(--font-sm);
    transition: all var(--duration-fast) var(--ease-in-out);
}
.custom-file-label:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ── Instruction Box ── */
.instruction-box {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--r-lg);
    padding: var(--s5);
    margin-bottom: var(--s6);
    font-size: var(--font-sm);
    color: var(--text-secondary);
    line-height: 1.6;
}
.instruction-box pre {
    background: var(--bg-app);
    padding: var(--s3);
    border-radius: var(--r-sm);
    color: var(--green);
    border: 1px solid var(--border-default);
    font-family: 'Courier New', monospace;
    overflow-x: auto;
    font-size: var(--font-xs);
}

/* ── Reset Button ── */
.reset-btn {
    width: 100%;
    background: var(--red-subtle);
    color: var(--red);
    border: 1px solid rgba(248, 113, 113, 0.2);
    padding: var(--s3);
    border-radius: var(--r-md);
    cursor: pointer;
    font-weight: 700;
    font-family: inherit;
    font-size: var(--font-sm);
    transition: all var(--duration-fast) var(--ease-in-out);
}
.reset-btn:hover {
    background: var(--red);
    color: white;
}

/* ── QR Styles ── */
.qr-container {
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    gap: var(--s6);
    flex-wrap: wrap;
}
.qr-box {
    text-align: center;
}
.qr-box img {
    width: 140px;
    height: 140px;
    border: 2px solid var(--border-strong);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-md);
}
.qr-box h3 {
    color: var(--text-tertiary);
    font-size: var(--font-xs);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin: 0 0 var(--s3);
}

/* ── Badge / Chip ── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px var(--s2);
    border-radius: var(--r-full);
    font-size: var(--font-xs);
    font-weight: 700;
    letter-spacing: 0.02em;
}
.badge-accent {
    background: var(--accent-subtle);
    color: var(--accent);
}
.badge-green {
    background: var(--green-subtle);
    color: var(--green);
}
.badge-red {
    background: var(--red-subtle);
    color: var(--red);
}
.badge-amber {
    background: var(--amber-subtle);
    color: var(--amber);
}

/* ── Keyframes ── */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastIn {
    0% { opacity: 0; transform: translateY(-20px) scale(0.96); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-12px); }
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 8px var(--accent-glow); }
    50% { box-shadow: 0 0 24px var(--accent-glow); }
}

@keyframes rotateBorder {
    to { --preview-angle: 360deg; }
}

@property --preview-angle {
    syntax: '<angle>';
    initial-value: 0deg;
    inherits: false;
}

@keyframes led-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ── Reduced Motion ── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
