:root { 
    --editor-bg: #121212;
    --toolbar-bg: #121212;
    --accent: #3b82f6; 
    --text: #e2e8f0; 
    --text-muted: #64748b;
    --border: rgba(255, 255, 255, 0.08);
    --current-cursor-color: #3b82f6; 
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    --font-sans: "Nunito", sans-serif;
}

* { box-sizing: border-box; }
body { 
    touch-action: pan-y; margin: 0; 
    background: linear-gradient(180deg, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 1) 21%, rgba(0, 0, 0, 1) 23%, rgba(29, 29, 29, 1) 60%, rgba(29, 29, 29, 1) 75%, rgba(59, 63, 80, 1) 100%); 
    color: var(--text);
    font-family: var(--font-sans); display: flex; flex-direction: column; 
    overflow: hidden; user-select: none; height: 100dvh;
    -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
i { -webkit-user-select: none; user-select: none; }

/* --- Syntax Highlighting --- */
#highlighting-content { color: #c9d1d9; }
.token.special-tag { color: #79c0ff; } 
.token.tag { color: #7ee787; }         
.token.punctuation { color: #7b743a; }
.token.comment { color: #8b949e; font-style: italic; }     
.token.keyword { color: #ff7b72; }     
.token.string { color: #a5d6ff; }
.color-preview { display: inline-block; width: 0; height: 0; position: relative; vertical-align: middle; pointer-events: none; }
.color-preview::before { content: ''; display: block; position: absolute; left: -16px; top: -8px; width: 12px; height: 12px; background: inherit; border-radius: 50%; border: 1px solid rgba(255,255,255,0.2); z-index: 2; }

/* --- Editor Container (Kluczowe dla kursora) --- */
.editor-container { 
    z-index: 8; left: 50%; transform: translateX(-50%); 
    position: relative; width: 100%;
    flex-grow: 1; display: flex; align-items: stretch; 
    background: var(--editor-bg); overflow: hidden; 
    margin-bottom: 170px;
    border-radius: 0 0 40px 40px; 
}

.line-numbers { 
    flex-shrink: 0; margin: 0; white-space: pre; 
    font-family: var(--font-mono); font-weight: 400; font-size: 14px;
    position: relative; line-height: 22px; 
    padding: 10px 12px 26px 16px; /* <--- ZMIENIONY PADDING DOLNY */
    text-align: right; color: var(--text-muted); user-select: none; 
    min-width: 60px;
    overflow: hidden; pointer-events: none; background: transparent; 
}
.fast-scroll-active { will-change: transform, filter; filter: blur(1.8px); transform: scaleY(1.16) scaleX(0.98); transition: filter 0.2s ease, transform 0.2s ease; opacity: 0.8; }
.line-marker { 
    position: absolute; 
    left: 10px; 
    top: 0; /* JS sam ustala transform */
    width: 6px; height: 6px; 
    background-color: var(--accent); border-radius: 50%; 
    z-index: 20; pointer-events: none; 
}

.editor-wrapper { 
    transition: filter 0.2s ease-out; 
    position: relative; flex-grow: 1; 
    overflow: hidden; 
    margin-bottom: 0;
}

.content-blur { filter: blur(8px) !important; }

#highlighting, #editor {
    position: absolute; 
    top: 0; 
    bottom: 10px;
    left: 0; 
    width: 100%; 
    height: auto;
    margin: 0;
    padding: 10px 16px 10px 10px;
    font-weight: 400; font-size: 14px; 
    line-height: 22px;
    font-family: var(--font-mono) !important;
    white-space: pre; 
    word-break: normal; 
    overflow-wrap: normal;
    tab-size: 4; 
    outline: none; border: none;
    box-sizing: border-box;
    -webkit-text-size-adjust: none; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; 
}

#editor { 
    z-index: 2; color: transparent !important; 
    user-select: none !important; -webkit-user-select: none !important; 
    background: transparent !important; 
    transition: caret-color 0.3s; caret-color: var(--current-cursor-color); 
    overflow: auto;
}
#editor:focus { overflow-anchor: none; transform: translateZ(0); }
#highlighting { z-index: 0; overflow: hidden; pointer-events: none; }

/*.editor-container::-webkit-scrollbar, #editor::-webkit-scrollbar { width: 4px !important; height: 4px !important; }
.editor-container::-webkit-scrollbar-thumb, #editor::-webkit-scrollbar-thumb { background: #2d333b !important; border-radius: 10px; border: none !important; }
.editor-container::-webkit-scrollbar-track, #editor::-webkit-scrollbar-track { background: transparent; }*/

/* --- Toolbar Island (Bottom) --- */
.toolbar { 
    z-index: 100; position: fixed; 
    bottom: calc(46px + env(safe-area-inset-bottom)); 
    left: 50%; transform: translateX(-50%); 
    width: 320px; height: 100px; 
    padding: 0 16px; background: var(--toolbar-bg); 
    display: flex; justify-content: center; flex-direction: column; 
    border-radius: 32px; 
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.tool { 
    display: flex; justify-content: space-between; align-items: center; 
    width: 100%; transform: scale(0.9); padding-top: 10px;
}
.tool i { width: 24px; height: 24px; font-size: 18px; color: var(--text-muted); display: flex; justify-content: center; align-items: center; cursor: pointer; transition: color 0.2s ease; }
.tool i:hover, .tool i:active { color: var(--text); }
.tool i.fa-floppy-disk { color: var(--accent); }

.tabs { display: flex; justify-content: center; gap: 4px; width: 100%; }
.tab {
    position: relative; overflow: hidden;
    flex: 1; display: flex; font-family: var(--font-sans); font-weight: 600; font-size: 0.9rem;
    justify-content: center; align-items: center; gap: 8px; padding: 6px 0; border-radius: 20px;
    background: transparent; cursor: pointer; border: 1px solid transparent;
    transition: color 0.2s ease, background 0.2s ease; color: var(--text-muted);
}
.tab.active { color: var(--text); }
.tab.active i { color: var(--accent); }

/* Animacje */
.tab::after { content: ""; position: absolute; top: var(--mouse-y, 50%); left: var(--mouse-x, 50%); width: 0; height: 0; background: rgba(255, 255, 255, 0.1); border-radius: 50%; transform: translate(-50%, -50%); transition: width 0.4s ease, height 0.4s ease, opacity 0.4s ease; pointer-events: none; opacity: 0; }
.tab:active::after { width: 200px; height: 200px; opacity: 1; transition: 0s; }
.tab-transition-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: linear-gradient(to top, var(--current-cursor-color), transparent); opacity: 0; z-index: 10; pointer-events: none; transform: translateY(100%); }
@keyframes slideUpFade { 0% { transform: translateY(100%); opacity: 0.3; } 50% { opacity: 0.1; } 100% { transform: translateY(-100%); opacity: 0; } }
.animate-tab { animation: slideUpFade 0.4s cubic-bezier(0.4, 0, 0.2, 1); }
@keyframes iconClick { 0% { transform: rotate(0deg); } 40% { transform: rotate(-7deg); } 60% { transform: rotate(0deg); } 80% { transform: rotate(7deg); } 100% { transform: rotate(0deg); } }
.tab-icon-click { animation: iconClick 0.25s ease-out; }

/* --- Floating Buttons (Play / More) --- */
.fab { 
    transition: all 0.2s ease; color: #fff; background: #151515; 
    position: fixed; z-index: 99; bottom: calc(152px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); 
    width: 108px; height: 38px; border-radius: 50px; display: flex; justify-content: center; align-items: center; font-size: 18px; 
    cursor: pointer;
}
.fab:active { transform: translate(-50%, 2px) scale(0.95); }
.fab i { margin-left: 3px; }

.more-btn { 
    transition: all 0.2s ease; background: var(--editor-bg); border: 1px solid #111;
    color: var(--text-muted); width: 44px; height: 44px; display: flex; justify-content: center; align-items: center; 
    border-radius: 50%; position: fixed; bottom: calc(149px + env(safe-area-inset-bottom)); right: 20px; z-index: 99; 
    cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.more-btn:active { transform: scale(0.92); }

.menu { 
    transform: translateY(10px) scale(0.95); transition: all 0.2s ease; transform-origin: bottom right; 
    flex-direction: column; display: flex; gap: 6px; visibility: hidden; opacity: 0; 
    background: var(--toolbar-bg); border: 1px solid var(--border); border-radius: 16px; 
    bottom: calc(215px + env(safe-area-inset-bottom)); right: 20px; position: fixed; padding: 10px; z-index: 101; 
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.menu.show { visibility: visible; opacity: 1; transform: translateY(0) scale(1); }
.menu-tab { opacity: 0; transform: translateX(10px); transition: all 0.2s ease; font-family: var(--font-sans); width: 110px; padding: 10px 14px; background: transparent; border-radius: 8px; font-size: 0.85rem; color: var(--text); display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.menu-tab:hover { background: rgba(255,255,255,0.05); color: #fff; }
.menu.show .menu-tab { opacity: 1; transform: translateX(0); }
.menu.show .menu-tab:nth-child(1) { transition-delay: 0.05s; } .menu.show .menu-tab:nth-child(2) { transition-delay: 0.1s; } .menu.show .menu-tab:nth-child(3) { transition-delay: 0.15s; }

/* --- Preview & Modals --- */
#preview-container { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--editor-bg); z-index: 150; flex-direction: column; border-radius: 24px 24px 0 0; transition: transform .3s cubic-bezier(.25, 1, .5, 1); transform: translateZ(0); box-shadow: 0 -10px 40px rgba(0,0,0,0.5); }
.drag-handle { position: relative; width: 100%; height: 24px; display: flex; justify-content: center; align-items: center; touch-action: none; z-index: 101; }
.drag-handle::after { content: ''; width: 44px; height: 5px; background: rgba(255,255,255,0.2); border-radius: 10px; }
#preview-frame { border: none; flex-grow: 1; width: 100%; height: 100%; pointer-events: auto; background: #fff; }

.overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); z-index: 80; }
.locate, .console-panel, .file-explorer, .modal-overlay > div { background: var(--toolbar-bg); border: 1px solid var(--border); box-shadow: 0 10px 30px rgba(0,0,0,0.5); color: var(--text); }

.locate { position: absolute; transform: translate(-50%, -50%); left: 50%; top: 40%; padding: 16px; width: 85%; max-width: 400px; flex-direction: column; display: none; z-index: 98; border-radius: 20px; }
.locate-input { color: var(--text); text-align: center; flex-grow: 1; outline: none; background: rgba(0,0,0,0.2); border: 1px solid var(--border); border-radius: 12px; width: 100%; padding: 12px; font-family: var(--font-sans); }
.locate-input:focus { border-color: var(--accent); }
.search-line-item { padding: 10px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 0.85rem; border-radius: 8px; }
.search-line-item:hover { background: rgba(255,255,255,0.05); color: #fff; }
.search-line-number { color: var(--accent); font-weight: bold; margin-right: 10px; font-family: monospace; }

.console-panel { position: absolute; transform: translate(-50%, -50%); left: 50%; top: 45%; padding: 16px; width: 85%; max-width: 500px; min-height: 100px; max-height: 60vh; display: none; flex-direction: column; z-index: 99; border-radius: 20px; }
.console-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; color: #fff; font-weight: 600; }
.console-logs { overflow-y: auto; flex-grow: 1; font-family: monospace; font-size: 0.85rem; }
.log-item { padding: 10px; border-bottom: 1px solid var(--border); cursor: pointer; border-radius: 8px; margin-bottom: 4px; }
.log-error { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }
.log-info { color: #34d399; }
.log-line { font-weight: bold; margin-right: 8px; color: #fff; background: rgba(255,255,255,0.1); padding: 2px 6px; border-radius: 4px; }

.file-explorer { position: absolute; bottom: calc(220px + env(safe-area-inset-bottom)); right: 20px; width: 200px; border-radius: 20px; z-index: 101; display: none; flex-direction: column; padding: 12px; transform-origin: bottom right; }
.file-explorer.show { display: flex; }
@keyframes menuAppear { 0% { transform: scale(0.8); opacity: 0; }100% { transform: scale(1); opacity: 1; }}
.explorer-header { padding: 8px 10px; font-size: 0.75rem; font-weight: bold; letter-spacing: 1px; color: var(--text-muted); border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.file-list { max-height: 200px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.file-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; background: rgba(255,255,255,0.03); border-radius: 12px; color: var(--text); font-size: 0.8rem; }
.file-item:hover { background: rgba(255,255,255,0.06); }
.explorer-footer { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 10px; }
.btn-create-trigger { width: 100%; padding: 10px; border: none; border-radius: 12px; background: rgba(59,130,246,0.1); color: #60a5fa; font-size: 0.85rem; cursor: pointer; transition: 0.2s; }
.btn-create-trigger:hover { background: rgba(59,130,246,0.2); }

.modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); z-index: 150; justify-content: center; align-items: center; }
.modal-content { padding: 24px; border-radius: 24px; width: 80%; max-width: 360px; display: flex; flex-direction: column; gap: 16px; }
.modal-content h3 { margin: 0; font-family: var(--font-sans); color: #fff; font-size: 1.1rem; }
.modal-content input, .modal-content select { background: rgba(0,0,0,0.2); color: #fff; padding: 12px; border-radius: 12px; border: 1px solid var(--border); outline: none; font-family: var(--font-sans); }
.modal-content input:focus, .modal-content select:focus { border-color: var(--accent); }
.modal-buttons { display: flex; gap: 12px; margin-top: 8px; }
.btn-modal { flex: 1; padding: 12px; border-radius: 12px; border: none; font-weight: 600; cursor: pointer; font-family: var(--font-sans); transition: 0.2s; }
.btn-cancel { background: rgba(255,255,255,0.05); color: var(--text); }
.btn-cancel:hover { background: rgba(255,255,255,0.1); }
.btn-confirm { background: var(--accent); color: #fff; }
.btn-confirm:hover { filter: brightness(1.1); }

.format-sparkle-overlay { position: fixed; top: 50%; left: 50%; width: 2px; height: 2px; background: radial-gradient(circle, #fff 0%, var(--accent) 40%, transparent 70%); border-radius: 50%; transform: translate(-50%, -50%) scale(0); z-index: 200; pointer-events: none; box-shadow: 0 0 20px var(--accent); }
@keyframes sparkle-burst { 0% { transform: translate(-50%, -50%) scale(0); opacity: 1; } 50% { transform: translate(-50%, -50%) scale(500); opacity: 1; filter: brightness(2); } 100% { transform: translate(-50%, -50%) scale(1000); opacity: 0; }}
.animate-sparkle { animation: sparkle-burst 0.6s cubic-bezier(0.15, 0.85, 0.35, 1) forwards;}
.virtual-selection { background-color: rgba(59, 130, 246, 0.3); position: absolute; pointer-events: none; z-index: -1; border-radius: 2px; }