/* ===========================================
   Kinetic Typography - Swiss Minimalist Style
   Inspired by nomaszebras type foundry
   =========================================== */

/* Custom Font - Bizarre Love 86 for branding */
@font-face {
    font-family: 'BizarreLove86';
    src: url('../fonts/BizarreLove86.woff2') format('woff2'),
         url('../fonts/BizarreLove86.woff') format('woff');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* Variable Font - kineVF for animated Kinetype logo */
@font-face {
    font-family: 'kineVF';
    src: url('../fonts/kineVF.woff2') format('woff2-variations'),
         url('../fonts/kineVF.woff') format('woff-variations');
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}

/* Animation for variable font logo */
@keyframes kinetypeVF {
    0% {
        font-variation-settings: 'wght' 100;
    }
    50% {
        font-variation-settings: 'wght' 900;
    }
    100% {
        font-variation-settings: 'wght' 100;
    }
}

/* Theme variables - Light Mode (default) */
:root {
    --theme-bg: #ffffff;
    --theme-fg: #111111;
    --theme-border: #111111;
    --rail-width: 220px;
    --rule-h: 1px;
}

/* Theme variables - Dark Mode (same gray as dither background) */
[data-theme="dark"] {
    --theme-bg: #1a1a1a;
    --theme-fg: #ffffff;
    --theme-border: #444444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: var(--theme-bg);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    overflow: hidden;
    color: var(--theme-fg);
    transition: background 0.3s ease, color 0.3s ease;
}

/* ===========================================
   LOADING SCREEN - Swiss Minimalist Style
   =========================================== */

.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--theme-bg);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

.loading-logo {
    width: 144px;
    height: auto;
    margin-top: 8px;
}

/* Invert logo for dark mode */
[data-theme="dark"] .loading-logo {
    filter: invert(1);
}

.loading-name {
    font-family: 'kineVF', ui-monospace, monospace;
    font-size: 32px;
    font-weight: normal;
    letter-spacing: 0.05em;
    color: var(--theme-fg);
    margin-top: 8px;
}

/* Extra spacing for heavier letters (ype.) */
[data-kinetype] span:nth-child(n+6) {
    margin-left: 0.04em;
}

.loading-bar {
    width: 200px;
    height: 2px;
    background: #cccccc;
    position: relative;
    overflow: hidden;
}

/* Dark mode loading bar */
[data-theme="dark"] .loading-bar {
    background: #444444;
}

.loading-progress {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0%;
    background: var(--theme-fg);
    animation: loadingProgress 2s ease-in-out infinite;
}

@keyframes loadingProgress {
    0% {
        left: 0;
        width: 0%;
    }
    50% {
        left: 0;
        width: 100%;
    }
    100% {
        left: 100%;
        width: 0%;
    }
}

.loading-text {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 11px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--theme-fg);
    opacity: 0.6;
}

/* ===========================================
   LANGUAGE SELECTOR - Swiss/Vintage Style
   =========================================== */

.lang-selector {
    position: fixed;
    left: 0;
    top: 220px;
    z-index: 250;
    display: flex;
    flex-direction: column;
    gap: 0;
    border: 1px solid var(--theme-border);
    border-left: none;
    background: var(--theme-bg);
    width: 40.25px;
}

.lang-btn {
    width: 40.25px;
    height: 40.25px;
    padding: 0;
    font-family: inherit;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
    border: none;
    border-bottom: 1px solid var(--theme-border);
    background: var(--theme-bg);
    color: var(--theme-fg);
    cursor: pointer;
    transition: all 0.15s ease;
}

.lang-btn:last-child {
    border-bottom: none;
}

.lang-btn:hover {
    background: var(--theme-fg);
    color: var(--theme-bg);
}

.lang-btn.active {
    background: var(--theme-fg);
    color: var(--theme-bg);
}

/* ===========================================
   THEME TOGGLE - Swiss/Vintage Style
   =========================================== */

.theme-toggle {
    position: fixed;
    left: 0;
    top: 374px;
    z-index: 250;
    width: 40.25px;
    height: 40.25px;
    border: 1px solid var(--theme-border);
    border-left: none;
    border-right: none;
    background: var(--theme-bg);
    color: var(--theme-fg);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background: var(--theme-fg);
    color: var(--theme-bg);
}

.theme-toggle .icon-light,
.theme-toggle .icon-dark {
    position: absolute;
    transition: opacity 0.2s ease;
}

.theme-toggle .icon-dark {
    opacity: 1;
}

.theme-toggle .icon-light {
    opacity: 0;
}

[data-theme="dark"] .theme-toggle .icon-dark {
    opacity: 0;
}

[data-theme="dark"] .theme-toggle .icon-light {
    opacity: 1;
}

/* ===========================================
   HELP TOGGLE - Swiss/Vintage Style
   =========================================== */

.help-toggle {
    position: fixed;
    left: 0;
    top: 414px;
    z-index: 250;
    width: 40.25px;
    height: 40.25px;
    border: 1px solid var(--theme-border);
    border-left: none;
    border-right: none;
    background: var(--theme-bg);
    color: var(--theme-fg);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.help-toggle:hover {
    background: var(--theme-fg);
    color: var(--theme-bg);
}

/* ===========================================
   HELP MODAL
   =========================================== */

.help-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.help-modal.open {
    display: flex;
}

.help-modal-content {
    background: var(--theme-bg);
    border: 1px solid var(--theme-border);
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 30px;
    position: relative;
}

.help-sections {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px 30px;
}

.help-modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 30px;
    height: 30px;
    border: 1px solid var(--theme-border);
    background: var(--theme-bg);
    color: var(--theme-fg);
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.help-modal-close:hover {
    background: var(--theme-fg);
    color: var(--theme-bg);
}

.help-title {
    font-size: 16px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--theme-border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.help-brand {
    font-family: 'kineVF', ui-monospace, monospace;
    font-size: 18px;
    letter-spacing: 0.05em;
    color: var(--theme-fg);
    text-transform: none;
}

.help-title i {
    margin-right: 8px;
}

.help-section {
    margin-bottom: 20px;
}

.help-section h3 {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
    color: var(--theme-fg);
}

.help-section h3 i {
    margin-right: 6px;
    opacity: 0.7;
}

.help-section p {
    font-size: 12px;
    line-height: 1.6;
    opacity: 0.8;
}

.help-section a {
    color: var(--theme-fg);
    text-decoration: underline;
}

.help-section a:hover {
    opacity: 0.7;
}

.help-footer {
    margin-top: 25px;
    padding-top: 15px;
    border-top: 1px solid var(--theme-border);
    text-align: center;
}

.help-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
    font-size: 11px;
    opacity: 0.7;
    cursor: pointer;
}

.help-checkbox input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--theme-fg);
}

/* Main Layout - Canvas centered, panels floating */
.main-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    /* Light mode: fons clar amb trama grisa */
    background-color: #e0e0e0;
    background-image: url("data:image/svg+xml,%3Csvg width='2' height='2' viewBox='0 0 2 2' xmlns='http://www.w3.org/2000/svg'%3E%3Crect x='0' y='0' width='1' height='1' fill='%23ccc'/%3E%3Crect x='1' y='1' width='1' height='1' fill='%23ccc'/%3E%3C/svg%3E");
    background-size: 4px 4px;
    image-rendering: pixelated;
}

/* Dark mode: fons fosc amb trama */
:root[data-theme="dark"] .main-wrapper {
    background-color: #000;
    background-image: url("data:image/svg+xml,%3Csvg width='2' height='2' viewBox='0 0 2 2' xmlns='http://www.w3.org/2000/svg'%3E%3Crect x='0' y='0' width='1' height='1' fill='%23333'/%3E%3Crect x='1' y='1' width='1' height='1' fill='%23333'/%3E%3C/svg%3E");
}

#canvas-container {
    position: relative;
    box-shadow: none;
    border-radius: 0;
}

/* Watermark Overlay */
#watermark-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    display: none;
}

#watermark-overlay.visible {
    display: block;
}

#watermark-bg {
    position: absolute;
    left: 2px;
    top: 32px;
    height: 246px;
    width: auto;
    background: white;
}

#watermark-logo {
    position: absolute;
    left: 0;
    top: 30px;
    height: 250px;
    width: auto;
    opacity: 1;
}

/* Logo Toggle Row */
.logo-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
}

.logo-toggle-row label {
    font-size: 10px;
    color: var(--theme-fg);
    opacity: 0.7;
}

.toggle-group {
    display: flex;
    gap: 4px;
}

.toggle-btn {
    padding: 4px 10px;
    font-size: 10px;
    font-family: inherit;
    border: 1px solid var(--theme-border);
    background: var(--theme-bg);
    color: var(--theme-fg);
    cursor: pointer;
    transition: all 0.15s;
    font-weight: 500;
    letter-spacing: 0.02em;
}

.toggle-btn:hover {
    background: var(--theme-fg);
    color: var(--theme-bg);
}

.toggle-btn.active {
    background: var(--theme-fg);
    color: var(--theme-bg);
}

/* Align buttons */
.align-buttons {
    display: flex;
    gap: 4px;
}

.align-btn {
    flex: 1;
    padding: 5px 6px;
    font-size: 10px;
    font-family: inherit;
    border: 1px solid var(--theme-border);
    background: var(--theme-bg);
    color: var(--theme-fg);
    cursor: pointer;
    transition: all 0.15s;
    font-weight: 500;
}

.align-btn:hover {
    background: var(--theme-fg);
    color: var(--theme-bg);
}

.align-btn.active {
    background: var(--theme-fg);
    color: var(--theme-bg);
}

.format-info {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    color: #333;
    opacity: 0.6;
    font-size: 10px;
    pointer-events: none;
    letter-spacing: 0.05em;
}

/* Dark mode: text clar */
:root[data-theme="dark"] .format-info {
    color: #fff;
}

/* Floating Panels - Adobe Style */
.panel {
    position: fixed;
    top: 20px;
    width: var(--rail-width);
    max-height: calc(100vh - 40px);
    background: var(--theme-bg);
    border: 1px solid var(--theme-border);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    transition: box-shadow 0.2s, max-height 0.3s ease, background 0.3s ease, border-color 0.3s ease;
}

.panel.collapsed {
    max-height: 32px;
    overflow: hidden;
}

.panel.dragging {
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    opacity: 0.95;
}

.panel-left {
    left: 56px; /* Deixar espai pel logo lateral */
}

.panel-right {
    right: 20px;
}

/* Fixed Logo - Left Side Tab (Reckoner style) */
.fixed-logo {
    position: fixed;
    left: 0;
    top: 20px;
    z-index: 200;
    background: var(--theme-fg);
    padding: 73.6px 0;
    text-decoration: none;
    transition: background 0.3s ease;
    width: 40.25px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.fixed-logo:hover {
    background: var(--theme-fg);
}

.fixed-logo svg {
    width: 142.6px;
    height: 16.1px;
    transform: rotate(-90deg);
    flex-shrink: 0;
}

.fixed-logo svg path,
.fixed-logo svg polygon,
.fixed-logo svg circle {
    fill: #fff;
    transition: fill 0.3s ease;
}

/* Panel Header - Draggable */
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: var(--theme-fg);
    color: var(--theme-bg);
    cursor: move;
    user-select: none;
    border-radius: 3px 3px 0 0;
    flex-shrink: 0;
}

.panel.collapsed .panel-header {
    border-radius: 3px;
}

.panel-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.panel-title i {
    margin-right: 6px;
    opacity: 0.7;
}

.panel-controls {
    display: flex;
    gap: 4px;
}

.panel-btn {
    width: 18px;
    height: 18px;
    border: none;
    background: transparent;
    color: var(--theme-bg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    opacity: 0.6;
    transition: opacity 0.15s;
    padding: 0;
}

.panel-btn:hover {
    opacity: 1;
}

.panel.collapsed .panel-collapse i::before {
    content: "\f067";
}

/* Panel Content */
.panel-content {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    overflow-y: auto;
    overflow-x: visible;
    flex: 1;
}

/* Allow dropdown to overflow panel when open */
.panel-content:has(.dropdown.open) {
    overflow: visible;
}

.panel:has(.dropdown.open) {
    overflow: visible;
}

.panel-content::-webkit-scrollbar {
    width: 4px;
}

.panel-content::-webkit-scrollbar-track {
    background: transparent;
}

.panel-content::-webkit-scrollbar-thumb {
    background: var(--theme-border);
    border-radius: 2px;
}

/* Legacy rail styles removed - now using panels */

#controls { display: contents; }

/* Section titles - Swiss style */
.section-title {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--theme-fg);
    opacity: 0.4;
    padding: 0 0 8px 0;
    margin-top: 20px;
    font-weight: 500;
}

.section-title:first-child { 
    padding-top: 0; 
    margin-top: 0;
}

.section-title i { 
    margin-right: 6px; 
    font-size: 9px;
    opacity: 0.7;
}

/* Control groups */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 4px;
}

.control-group label {
    font-size: 10px;
    color: var(--theme-fg);
    opacity: 0.8;
    display: flex;
    justify-content: space-between;
    margin-bottom: 1px;
    letter-spacing: 0.02em;
}

.control-group label .value-display {
    color: var(--theme-fg);
    font-weight: 600;
    font-size: 10px;
    opacity: 1;
}

/* Sliders - Swiss minimal style */
.control-group input[type="range"] {
    width: 100%;
    height: 14px;
    -webkit-appearance: none;
    background: transparent;
    margin: 2px 0;
    position: relative;
}

.control-group input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: var(--rule-h);
    background: var(--theme-border);
    border: none;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--theme-bg);
    border-radius: 50%;
    cursor: pointer;
    margin-top: -7px;
    border: 2px solid var(--theme-fg);
    transition: all 0.15s ease;
}

.control-group input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--theme-fg);
}

.control-group input[type="range"]::-moz-range-track {
    width: 100%;
    height: var(--rule-h);
    background: var(--theme-border);
    border: none;
}

.control-group input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--theme-bg);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid var(--theme-fg);
}

.control-group input[type="range"]::-moz-range-thumb:hover {
    background: var(--theme-fg);
}

/* Color inputs */
.control-group input[type="color"] {
    width: 100%;
    height: 26px;
    border: 1px solid var(--theme-border);
    background: var(--theme-bg);
    cursor: pointer;
    padding: 2px;
    margin-top: 1px;
    -webkit-appearance: none;
}

.control-group input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.control-group input[type="color"]::-webkit-color-swatch {
    border: none;
}

/* Selects - Swiss style */
.control-group select {
    width: 100%;
    padding: 7px 10px;
    font-size: 10px;
    font-family: inherit;
    background: var(--theme-bg);
    color: var(--theme-fg);
    border: 1px solid var(--theme-border);
    border-radius: 0;
    cursor: pointer;
    letter-spacing: 0.02em;
    font-weight: 500;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%23111111' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 26px;
}

.control-group select:focus {
    outline: none;
    border-color: var(--theme-fg);
}

/* Select options - Swiss style dropdown */
.control-group select option {
    background: var(--theme-bg);
    color: var(--theme-fg);
    padding: 8px 10px;
    font-family: inherit;
    font-size: 11px;
    border: none;
}

.control-group select option:hover,
.control-group select option:focus,
.control-group select option:checked {
    background: var(--theme-fg);
    color: var(--theme-bg);
}

/* Textareas */
.control-group textarea {
    width: 100%;
    height: 40px;
    padding: 6px 8px;
    font-size: 11px;
    font-family: inherit;
    background: var(--theme-bg);
    color: var(--theme-fg);
    border: 1px solid var(--theme-border);
    resize: none;
    margin-top: 1px;
    letter-spacing: 0.01em;
}

.control-group textarea:focus {
    outline: none;
    border-color: var(--theme-fg);
}

/* Buttons - Swiss style */
.control-group button {
    width: 100%;
    padding: 7px 10px;
    font-size: 10px;
    font-family: inherit;
    border: 1px solid var(--theme-border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    background: var(--theme-bg);
    color: var(--theme-fg);
    font-weight: 500;
    transition: all 0.2s ease;
    margin-top: 1px;
    letter-spacing: 0.02em;
}

.control-group button:hover { 
    background: var(--theme-fg);
    color: var(--theme-bg);
}

.control-group button.secondary { 
    background: var(--theme-bg);
}

.control-group button.secondary:hover { 
    background: var(--theme-fg);
    color: var(--theme-bg);
}

.control-group button.accent { 
    background: var(--theme-fg); 
    color: var(--theme-bg); 
    border-color: var(--theme-fg);
}

.control-group button.accent:hover {
    background: var(--theme-bg);
    color: var(--theme-fg);
}

.button-row { 
    display: flex; 
    gap: 6px; 
    margin-top: 1px;
}

.button-row button { 
    flex: 1; 
    padding: 7px 6px;
    font-size: 10px;
    font-family: inherit;
    border: 1px solid var(--theme-border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--theme-bg);
    color: var(--theme-fg);
    font-weight: 500;
    transition: all 0.2s ease;
    letter-spacing: 0.02em;
}

.button-row button:hover {
    background: var(--theme-fg);
    color: var(--theme-bg);
}

.button-row button.secondary {
    background: var(--theme-bg);
}

.button-row button.secondary:hover {
    background: var(--theme-fg);
    color: var(--theme-bg);
}

.button-row button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.button-row button:disabled:hover {
    background: var(--theme-bg);
    color: var(--theme-fg);
}

/* Colors row */
.colors-row {
    display: flex;
    gap: 8px;
}

.colors-row .control-group {
    flex: 1;
    margin-bottom: 0;
}

/* Font name display */
.font-name { 
    font-size: 10px; 
    color: var(--theme-fg);
    opacity: 0.6;
    text-align: center; 
    margin-top: 4px;
    letter-spacing: 0.05em;
}

.hint { 
    font-size: 9px; 
    color: var(--theme-fg);
    opacity: 0.5;
    margin-top: 2px;
    letter-spacing: 0.02em;
}

input[type="file"] { display: none; }

/* Recording states */
.control-group button.recording {
    background: #ff3b30 !important;
    color: white !important;
    border-color: #ff3b30 !important;
    animation: pulse 1s infinite;
}

.control-group button.music-active {
    background: var(--theme-fg) !important;
    color: var(--theme-bg) !important;
    border-color: var(--theme-fg) !important;
}

.button-row button.demo-active {
    background: var(--theme-fg) !important;
    color: var(--theme-bg) !important;
    border-color: var(--theme-fg) !important;
    animation: demoPulse 1.2s infinite;
}

/* Recording indicator */
.recording-indicator {
    position: fixed;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    background: #ff3b30;
    color: white;
    padding: 8px 16px;
    font-weight: 500;
    font-size: 11px;
    display: none;
    align-items: center;
    gap: 8px;
    z-index: 200;
    letter-spacing: 0.05em;
}

.recording-indicator.active { display: flex; }

.recording-indicator .dot { 
    width: 8px; 
    height: 8px; 
    background: white; 
    border-radius: 50%; 
    animation: blink 1s infinite; 
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 59, 48, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(255, 59, 48, 0); }
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

@keyframes demoPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.75; }
}

/* Scrollbar styling for rails */
.rail::-webkit-scrollbar {
    width: 4px;
}

.rail::-webkit-scrollbar-track {
    background: transparent;
}

.rail::-webkit-scrollbar-thumb {
    background: var(--theme-border);
    opacity: 0.3;
}

.rail::-webkit-scrollbar-thumb:hover {
    opacity: 0.6;
}

/* Custom Dropdown - Swiss style (nomaszebras) */
.dropdown {
    position: relative;
    width: 100%;
}

.dropdown-toggle {
    width: 100%;
    padding: 7px 10px;
    font-size: 10px;
    font-family: inherit;
    background: var(--theme-bg);
    color: var(--theme-fg);
    border: 1px solid var(--theme-border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 500;
    letter-spacing: 0.02em;
    transition: all 0.15s ease;
}

.dropdown-toggle:hover {
    background: var(--theme-fg);
    color: var(--theme-bg);
}

.dropdown-toggle i {
    font-size: 8px;
    transition: transform 0.2s ease;
}

.dropdown.open .dropdown-toggle i {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--theme-bg);
    border: 1px solid var(--theme-border);
    padding: 8px 10px;
    display: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.dropdown-menu.two-columns {
    right: auto;
    min-width: 240px;
    columns: 2;
    column-gap: 12px;
}

.dropdown-menu.two-columns label {
    break-inside: avoid;
    text-align: left;
    justify-content: flex-start;
    white-space: nowrap;
}

.dropdown-menu.three-columns {
    right: auto;
    min-width: 280px;
    columns: 3;
    column-gap: 10px;
}

.dropdown-menu.three-columns label {
    break-inside: avoid;
    text-align: left;
    justify-content: flex-start;
}

.dropdown.open .dropdown-menu {
    display: block;
}

.dropdown-menu label {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    text-align: left;
    gap: 8px;
    padding: 5px 0;
    cursor: pointer;
    font-size: 11px;
    color: var(--theme-fg);
    opacity: 1;
    transition: opacity 0.15s ease;
}

.dropdown-menu label:hover {
    opacity: 0.7;
}

.dropdown-item {
    display: block;
    padding: 6px 8px;
    cursor: pointer;
    font-size: 11px;
    color: var(--theme-fg);
    transition: background 0.15s ease;
}

.dropdown-item:hover {
    background: var(--theme-fg);
    color: var(--theme-bg);
}

.dropdown-item.active {
    font-weight: 600;
}

.dropdown-menu input[type="radio"] {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border: 1px solid var(--theme-fg);
    border-radius: 0;
    background: var(--theme-bg);
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
}

.dropdown-menu input[type="radio"]:checked {
    background: var(--theme-fg);
}

/* Color Button - opens modal */
.color-btn {
    width: 100%;
    height: 28px;
    border: 1px solid var(--theme-border);
    cursor: pointer;
    transition: transform 0.1s ease;
}

.color-btn:hover {
    transform: scale(1.02);
}

/* Color Modal */
.color-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.color-modal.open {
    display: flex;
}

.color-modal-content {
    background: var(--theme-bg);
    border: 1px solid var(--theme-border);
    padding: 16px;
    width: 260px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.color-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--theme-border);
}

.color-modal-header span {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    opacity: 0.7;
}

.color-modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--theme-fg);
    line-height: 1;
    padding: 0;
    opacity: 0.6;
}

.color-modal-close:hover {
    opacity: 1;
}

.color-modal .color-wheel {
    width: 100%;
    height: auto;
    cursor: crosshair;
    border: none;
    display: block;
}

.lightness-slider-container {
    margin: 12px 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.lightness-slider-container label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.7;
    min-width: 60px;
}

.lightness-slider {
    flex: 1;
    height: 14px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
}

.lightness-slider::-webkit-slider-runnable-track {
    width: 100%;
    height: var(--rule-h);
    background: linear-gradient(to right, #000, #888, #fff);
    border: none;
}

.lightness-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--theme-bg);
    border-radius: 50%;
    cursor: pointer;
    margin-top: -7px;
    border: 2px solid var(--theme-fg);
    transition: all 0.15s ease;
}

.lightness-slider::-webkit-slider-thumb:hover {
    background: var(--theme-fg);
}

.lightness-slider::-moz-range-track {
    width: 100%;
    height: var(--rule-h);
    background: linear-gradient(to right, #000, #888, #fff);
    border: none;
}

.lightness-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--theme-bg);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid var(--theme-fg);
}

.lightness-slider::-moz-range-thumb:hover {
    background: var(--theme-fg);
}

.color-modal-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 12px 0;
}

.color-preview-box {
    width: 40px;
    height: 40px;
    border: 1px solid var(--theme-border);
}

.color-preview-hex {
    font-size: 14px;
    font-family: inherit;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.color-modal-apply {
    width: 100%;
    padding: 10px;
    font-size: 11px;
    font-family: inherit;
    border: 1px solid var(--theme-border);
    background: var(--theme-fg);
    color: var(--theme-bg);
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    transition: all 0.15s ease;
}

.color-modal-apply:hover {
    background: var(--theme-bg);
    color: var(--theme-fg);
}

/* ===========================================
   MOBILE TOP BAR (2 files)
   =========================================== */

.mobile-top-bar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 300;
    flex-direction: column;
    transition: background-color 0.3s ease;
}

/* Fila 1: Logo + Idiomes + Tema + Help */
.mobile-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    padding-top: calc(10px + env(safe-area-inset-top, 0));
}

.mobile-logo {
    font-family: 'kineVF', ui-monospace, monospace;
    font-size: 18px;
    letter-spacing: 0.02em;
}

.mobile-top-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

/* Botons quadrats per idioma */
.lang-btn-mobile {
    width: 32px;
    height: 32px;
    border: 1px solid currentColor;
    border-radius: 0;
    background: transparent;
    color: inherit;
    font-family: inherit;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: all 0.15s ease;
    opacity: 0.5;
}

.lang-btn-mobile.active {
    opacity: 1;
    background: var(--theme-fg);
    color: var(--theme-bg);
}

/* Botons icona quadrats */
.mobile-icon-btn {
    width: 32px;
    height: 32px;
    border: 1px solid currentColor;
    border-radius: 0;
    background: transparent;
    color: inherit;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    position: relative;
}

.mobile-icon-btn:active {
    opacity: 0.7;
}

/* Theme toggle icons - same as desktop */
.mobile-icon-btn .icon-light,
.mobile-icon-btn .icon-dark {
    position: absolute;
    transition: opacity 0.2s ease;
}

.mobile-icon-btn .icon-dark {
    opacity: 1;
}

.mobile-icon-btn .icon-light {
    opacity: 0;
}

[data-theme="dark"] .mobile-icon-btn .icon-dark {
    opacity: 0;
}

[data-theme="dark"] .mobile-icon-btn .icon-light {
    opacity: 1;
}

/* Fila 2: Presets */
.mobile-presets-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 12px;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.preset-chip {
    flex: 0 0 auto;
    min-width: 60px;
    padding: 10px 14px;
    border: 2px solid currentColor;
    background: transparent;
    color: inherit;
    font-family: inherit;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
}

.preset-chip:hover {
    opacity: 1;
    transform: scale(1.02);
}

.preset-chip:active {
    transform: scale(0.98);
}

.preset-chip.active {
    background: var(--theme-fg);
    color: var(--theme-bg);
    border-color: var(--theme-fg);
    opacity: 1;
}

/* Mobile Language Selector (in presets bar) */
.lang-selector-mobile {
    display: none;
    flex-shrink: 0;
    margin-left: auto;
    border: 1px solid var(--theme-border);
    border-radius: 20px;
    overflow: hidden;
    background: var(--theme-bg);
}

.lang-selector-mobile .lang-btn {
    padding: 8px 10px;
    font-size: 10px;
    border: none;
    border-right: 1px solid var(--theme-border);
    border-radius: 0;
}

.lang-selector-mobile .lang-btn:last-child {
    border-right: none;
}

/* Mobile Theme Toggle (in presets bar) */
.theme-toggle-mobile {
    display: none;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border: 1px solid var(--theme-border);
    border-radius: 50%;
    background: var(--theme-bg);
    color: var(--theme-fg);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}

.theme-toggle-mobile:hover {
    background: var(--theme-fg);
    color: var(--theme-bg);
}

.theme-toggle-mobile .icon-light,
.theme-toggle-mobile .icon-dark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: opacity 0.2s ease;
}

.theme-toggle-mobile .icon-dark {
    opacity: 1;
}

.theme-toggle-mobile .icon-light {
    opacity: 0;
}

[data-theme="dark"] .theme-toggle-mobile .icon-dark {
    opacity: 0;
}

[data-theme="dark"] .theme-toggle-mobile .icon-light {
    opacity: 1;
}

/* ===========================================
   MOBILE ACTION BAR & DRAWER
   =========================================== */

.mobile-action-bar {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 70px;
    background: var(--theme-bg);
    border-top: 1px solid var(--theme-border);
    justify-content: space-around;
    align-items: center;
    z-index: 300;
    padding: 0 10px;
    padding-bottom: env(safe-area-inset-bottom, 0); /* iPhone notch */
}

.mobile-btn {
    flex: 1;
    height: 56px;
    border: none;
    background: transparent;
    color: var(--theme-fg);
    font-size: 20px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.15s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.mobile-btn span {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.mobile-btn:hover,
.mobile-btn:active {
    background: var(--theme-fg);
    color: var(--theme-bg);
}

.mobile-btn:hover i,
.mobile-btn:active i,
.mobile-btn:hover span,
.mobile-btn:active span {
    color: var(--theme-bg);
}

/* Mobile Text Modal - HIDDEN by default on desktop */
.mobile-text-modal {
    display: none;
}

/* Hide drawer on mobile - no longer needed */
.mobile-drawer,
.drawer-overlay {
    display: none !important;
}

.mobile-text-actions button:active,
.mobile-text-actions button:hover {
    background: var(--theme-fg);
    color: var(--theme-bg);
}

#mobileTextApply {
    background: var(--theme-fg);
    color: var(--theme-bg);
}

/* Inline embed mode for editorial iframes */
html.embed-mode .lang-selector,
html.embed-mode .theme-toggle,
html.embed-mode .help-toggle,
html.embed-mode .fixed-logo,
html.embed-mode .format-info,
html.embed-mode .recording-indicator,
html.embed-mode .panel,
html.embed-mode .mobile-action-bar,
html.embed-mode #mobileTextModal,
html.embed-mode #helpToggleMobile {
    display: none !important;
}

html.embed-mode .mobile-top-bar {
    display: flex !important;
}

html.embed-mode .mobile-top-row {
    padding: 10px 12px 8px;
}

html.embed-mode .mobile-presets-row {
    justify-content: flex-start;
    padding-top: 0;
}

html.embed-mode .main-wrapper {
    padding-top: 78px !important;
    padding-bottom: 0 !important;
}

/* Hide drawer on mobile - no longer needed */
.mobile-drawer,
.drawer-overlay {
    display: none !important;
}

/* ===========================================
   RESPONSIVE - TABLET (768px - 1024px)
   =========================================== */

@media (max-width: 1024px) and (min-width: 769px) {
    :root {
        --rail-width: 200px;
    }
    
    .panel {
        width: 200px;
        max-height: calc(100vh - 30px);
    }
    
    .panel-left {
        left: 50px;
    }
    
    .panel-right {
        right: 15px;
    }
    
    .fixed-logo {
        width: 34px;
        padding: 50px 0;
    }
    
    .fixed-logo svg {
        width: 120px;
        height: 14px;
    }
    
    .section-title {
        font-size: 8px;
    }
    
    .control-group label {
        font-size: 9px;
    }
    
    button, .dropdown-toggle {
        font-size: 9px;
        padding: 6px 8px;
    }
    
    .lang-selector {
        top: 160px;
        width: 34px;
    }
    
    .lang-btn {
        width: 34px;
        height: 34px;
        font-size: 9px;
    }
    
    .theme-toggle {
        top: 294px;
        width: 34px;
        height: 34px;
        font-size: 12px;
    }
}

/* ===========================================
   RESPONSIVE - MOBILE (<768px)
   =========================================== */

@media (max-width: 768px) {
    /* Help Modal simplificat per mòbil */
    .help-modal-content {
        padding: 20px;
        max-height: 80vh;
    }
    
    .help-title {
        font-size: 14px;
        margin-bottom: 15px;
        padding-bottom: 10px;
    }
    
    .help-brand {
        font-size: 16px;
    }
    
    .help-sections {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }
    
    /* Només mostrar seccions essencials en mòbil */
    .help-section {
        margin-bottom: 10px;
    }
    
    .help-section h3 {
        font-size: 11px;
        margin-bottom: 4px;
    }
    
    .help-section p {
        font-size: 11px;
        line-height: 1.4;
    }
    
    /* Amagar seccions avançades en mòbil */
    .help-section.help-advanced {
        display: none;
    }
    
    .help-footer {
        margin-top: 15px;
        padding-top: 10px;
    }
    
    .help-footer p {
        font-size: 10px;
    }
    
    /* Hide desktop panels */
    .panel {
        display: none !important;
    }
    
    /* Hide desktop logo and theme toggle */
    .fixed-logo,
    .theme-toggle,
    .help-toggle {
        display: none;
    }
    
    /* Hide desktop language selector on mobile */
    .lang-selector {
        display: none;
    }
    
    /* Show mobile top bar with 2 rows */
    .mobile-top-bar {
        display: flex !important;
    }
    
    /* Show mobile action bar */
    .mobile-action-bar {
        display: flex !important;
    }
    
    .mobile-drawer {
        display: block;
    }
    
    .drawer-overlay {
        display: block;
        pointer-events: none;
    }
    
    .drawer-overlay.visible {
        pointer-events: auto;
    }
    
    /* Full screen canvas area */
    .main-wrapper {
        padding: 5px;
        padding-top: 100px; /* 2 files de top bar */
        padding-bottom: 80px; /* action bar + safe area */
        justify-content: center;
    }
    
    #canvas-container {
        width: auto !important;
        max-width: none !important;
        height: auto !important;
    }
    
    .format-info {
        bottom: 85px;
        font-size: 9px;
    }
    
    /* Drawer content styles */
    .drawer-content .section-title {
        font-size: 11px;
        padding: 16px 0 10px;
        margin-top: 0;
        border-bottom: 1px solid var(--theme-border);
        opacity: 0.6;
    }
    
    .drawer-content .section-title:first-child {
        padding-top: 8px;
    }
    
    .drawer-content .control-group {
        margin-bottom: 12px;
    }
    
    .drawer-content .control-group label {
        font-size: 12px;
        margin-bottom: 4px;
    }
    
    .drawer-content input[type="range"] {
        height: 44px;
        -webkit-appearance: none;
        appearance: none;
        background: transparent;
        cursor: pointer;
        touch-action: pan-x;
    }
    
    .drawer-content input[type="range"]::-webkit-slider-runnable-track {
        height: 4px;
        background: var(--theme-border);
        border-radius: 2px;
    }
    
    .drawer-content input[type="range"]::-webkit-slider-thumb {
        -webkit-appearance: none;
        appearance: none;
        width: 28px;
        height: 28px;
        background: var(--theme-fg);
        border-radius: 50%;
        margin-top: -12px;
        border: 3px solid var(--theme-bg);
        box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    }
    
    .drawer-content input[type="range"]::-moz-range-track {
        height: 4px;
        background: var(--theme-border);
        border-radius: 2px;
    }
    
    .drawer-content input[type="range"]::-moz-range-thumb {
        width: 28px;
        height: 28px;
        background: var(--theme-fg);
        border-radius: 50%;
        border: 3px solid var(--theme-bg);
        box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    }
    
    .drawer-content textarea {
        font-size: 14px;
        min-height: 60px;
    }
    
    .drawer-content button {
        padding: 12px;
        font-size: 12px;
    }
    
    .drawer-content .dropdown-toggle {
        padding: 12px;
        font-size: 12px;
    }
    
    .drawer-content .colors-row {
        gap: 20px;
    }
    
    .drawer-content .color-btn {
        width: 44px;
        height: 44px;
    }
    
    .drawer-content .align-btn {
        padding: 10px;
        font-size: 14px;
    }
    
    /* Color modal adjustments */
    .color-modal-content {
        width: 90%;
        max-width: 320px;
    }
    
    /* Drawer tabs */
    .drawer-tabs {
        display: flex;
        gap: 0;
        margin-bottom: 16px;
        border-bottom: 1px solid var(--theme-border);
    }
    
    .drawer-tab {
        flex: 1;
        padding: 12px;
        border: none;
        background: transparent;
        font-family: inherit;
        font-size: 11px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--theme-fg);
        opacity: 0.5;
        cursor: pointer;
        transition: opacity 0.15s;
        border-bottom: 2px solid transparent;
        margin-bottom: -1px;
    }
    
    .drawer-tab.active {
        opacity: 1;
        border-bottom-color: var(--theme-fg);
    }
    
    .drawer-tab i {
        margin-right: 6px;
    }
    
    .drawer-tab-content {
        padding-bottom: 20px;
    }
    
    /* Mobile Text Modal - ONLY visible on mobile */
    .mobile-text-modal {
        display: block;
        position: fixed;
        bottom: 70px;
        left: 0;
        right: 0;
        background: var(--theme-bg);
        border-top: 1px solid var(--theme-border);
        padding: 16px;
        z-index: 350;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0));
        transform: translateY(100%);
        transition: transform 0.3s ease;
        pointer-events: none;
    }
    
    .mobile-text-modal.active {
        transform: translateY(0);
        pointer-events: auto;
    }
    
    .mobile-text-content {
        display: flex;
        gap: 12px;
        align-items: flex-end;
    }
    
    #mobileTextInput {
        flex: 1;
        font-family: inherit;
        font-size: 16px;
        padding: 12px;
        border: 1px solid var(--theme-border);
        background: var(--theme-bg);
        color: var(--theme-fg);
        resize: none;
        border-radius: 8px;
        min-height: 80px;
    }
    
    .mobile-text-actions {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    
    .mobile-text-actions button {
        width: 44px;
        height: 44px;
        border: 1px solid var(--theme-border);
        background: var(--theme-bg);
        color: var(--theme-fg);
        font-size: 18px;
        cursor: pointer;
        border-radius: 8px;
    }
    
    #mobileTextApply {
        background: var(--theme-fg);
        color: var(--theme-bg);
    }
}

/* ===========================================
   MOBILE FORCE OVERRIDE - DEBUG
   This ensures mobile bar shows on small screens
   =========================================== */
@media screen and (max-width: 768px) {
    #mobileActionBar,
    .mobile-action-bar {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: 70px !important;
        background: var(--theme-bg) !important;
        z-index: 9999 !important;
    }
    
    #mobileTextModal.visible {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
}
