﻿:root {
  /* Premium Color Palette */
  --primary-hue: 210;
  --primary-color: hsl(var(--primary-hue), 80%, 60%);
  --primary-hover: hsl(var(--primary-hue), 80%, 50%);

  /* Glassmorphism Variables */
  --glass-bg: rgba(255, 255, 255, 0.65);
  --glass-border: rgba(255, 255, 255, 0.4);
  --glass-blur: 12px;
  --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.07);

  /* Text Colors */
  --text-main: #2c3e50;
  --text-muted: #64748b;
  --text-inverse: #ffffff;

  /* Layout */
  --sidebar-width: 60px;
  --toolbar-height: 60px;

  /* Typography */
  --font-ui: 'Inter', sans-serif;
  --font-editor: 'JetBrains Mono', monospace;

  /* Transitions */
  --ease-elastic: cubic-bezier(0.68, -0.55, 0.265, 1.55);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);

  /* Editor Colors - Default (will be overridden) */
  --editor-bg: #ffffff;
  --editor-text: #000000;
}

/* Dark Mode Variables */
@media (prefers-color-scheme: dark) {
  :root {
    --glass-bg: rgba(30, 30, 36, 0.7);
    --glass-border: rgba(255, 255, 255, 0.08);
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;

    /* Dark Mode Defaults */
    --editor-bg: #15151a;
    --editor-text: #ffffff;
  }
}

/* Explicit Mode Overrides */
body.dark-mode {
  --glass-bg: rgba(30, 30, 36, 0.7);
  --glass-border: rgba(255, 255, 255, 0.08);
  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  color: var(--text-main);

  /* Editor Specifics for Dark Mode */
  --editor-bg: #15151a;
  --editor-text: #ffffff;
}

body.light-mode {
  --glass-bg: rgba(255, 255, 255, 0.65);
  --glass-border: rgba(255, 255, 255, 0.4);
  --text-main: #2c3e50;
  --text-muted: #64748b;
  color: var(--text-main);

  /* Editor Specifics for Light Mode */
  --editor-bg: #ffffff;
  --editor-text: #000000;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-ui);
  height: 100vh;
  min-height: -webkit-fill-available;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  color: var(--text-main);
  transition: background 0.3s ease, color 0.3s ease;
}

body.dark-mode {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}

/* Animated Background Blobs */
.background-blobs {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.blob {
  position: absolute;
  filter: blur(80px);
  opacity: 0.6;
  border-radius: 50%;
  animation: blob-bounce 20s infinite ease-in-out alternate;
}

.blob-1 {
  top: -10%;
  left: -10%;
  width: 500px;
  height: 500px;
  background: #4a90e2;
  animation-delay: 0s;
}

.blob-2 {
  bottom: -10%;
  right: -10%;
  width: 600px;
  height: 600px;
  background: #9b59b6;
  animation-delay: -5s;
}

.blob-3 {
  top: 40%;
  left: 40%;
  width: 400px;
  height: 400px;
  background: #2ecc71;
  opacity: 0.4;
  animation-delay: -10s;
}

@keyframes blob-bounce {
  0% {
    transform: translate(0, 0) scale(1);
  }

  100% {
    transform: translate(100px, 50px) scale(1.1);
  }
}

/* App Layout */
.app-container {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  position: relative;
  z-index: 1;
}

/* Glass Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 20px 0;
  transition: all 0.3s ease;
  z-index: 10;
}

.logo-wrapper {
  color: var(--primary-color);
  margin-bottom: 20px;
  transition: transform 0.3s var(--ease-elastic);
}

.logo-wrapper:hover {
  transform: rotate(10deg) scale(1.1);
}

.line-numbers-container {
  flex: 1;
  width: 100%;
  overflow: hidden;
  padding: 20px 0;
  mask-image: linear-gradient(to bottom, transparent, black 10%, black 90%, transparent);
}

.line-numbers {
  text-align: center;
  color: var(--text-muted);
  font-family: var(--font-editor);
  font-size: 13px;
  opacity: 0.6;
}

.line-number {
  line-height: 1.6 !important;
  font-size: inherit;
  transition: color 0.2s;
}

.line-number.active {
  color: var(--primary-color);
  font-weight: bold;
  opacity: 1;
}

.sidebar-footer {
  display: flex !important;
  flex-direction: column !important;
  gap: 16px;
  align-items: center;
  flex-shrink: 0;
  padding-bottom: 20px;
  z-index: 20;
}

.sidebar-footer .icon-btn {
  color: var(--text-muted);
  display: flex !important;
  align-items: center;
  justify-content: center;
  opacity: 1 !important;
  visibility: visible !important;
  width: 100%;
}



/* Main Content Area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* Glass Toolbar */
.toolbar {
  height: var(--toolbar-height);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  border-bottom: 1px solid var(--glass-border);
  z-index: 5;
}

.tabs-scroll-wrapper {
  flex: 1;
  overflow: hidden;
  margin-right: 20px;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
  max-width: 150px;
  user-select: none;
}

.tab:hover {
  background: rgba(255, 255, 255, 0.2);
}

.tab.active {
  background: var(--primary-color);
  color: white;
  box-shadow: 0 4px 12px rgba(74, 144, 226, 0.3);
}

.tab-title {
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-title-input {
  width: 80px;
  background: transparent;
  border: none;
  border-bottom: 1px solid currentColor;
  /* Matches text color */
  color: inherit;
  font-size: inherit;
  font-family: inherit;
  outline: none;
  padding: 0;
}

.tab-close {
  opacity: 0.6;
  border-radius: 50%;
  padding: 2px;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.tab-close:hover {
  background: rgba(0, 0, 0, 0.1);
  opacity: 1;
}

.new-tab-btn {
  background: transparent;
  border: 1px dashed var(--text-muted);
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.6;
  transition: all 0.2s;
  flex-shrink: 0;
}

.new-tab-btn:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
  opacity: 1;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-main);
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  position: relative;
}

.icon-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--primary-color);
}

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

.separator {
  width: 1px;
  height: 24px;
  background: var(--text-muted);
  opacity: 0.2;
  margin: 0 4px;
}

/* Search Bar */
.search-bar {
  position: absolute;
  top: 70px;
  right: 20px;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  padding: 12px;
  border-radius: 12px;
  box-shadow: var(--glass-shadow);
  border: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 300px;
  z-index: 20;
  transform: translateY(-20px);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s var(--ease-smooth);
}

.search-bar.active {
  transform: translateY(0);
  opacity: 1;
  pointer-events: all;
}

.search-inputs {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.search-inputs input {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--text-main);
  font-size: 14px;
  outline: none;
  font-family: var(--font-ui);
}

.search-inputs input:focus {
  border-color: var(--primary-color);
  background: rgba(255, 255, 255, 0.1);
}

.search-controls {
  display: flex;
  gap: 6px;
}

.search-btn {
  flex: 1;
  padding: 6px;
  border: none;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-main);
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.2s;
}

.search-btn:hover {
  background: var(--primary-color);
  color: white;
}

.search-btn.close-search {
  flex: 0 0 24px;
  background: transparent;
  color: var(--text-muted);
}

.search-btn.close-search:hover {
  background: rgba(255, 0, 0, 0.1);
  color: red;
}

.search-stats {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

/* Editor Area - OPAQUE Background with Explicit Colors */
.editor-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--editor-bg);
  transition: background 0.3s ease;
  /* Fix for mobile text visibility */
  display: flex;
  flex-direction: column;
}

#editor {
  width: 100%;
  height: 100%;
  background: transparent;
  border: none;
  outline: none;
  padding: 20px 40px;
  font-family: var(--font-editor);
  font-size: 16px;
  /* Ensure consistent line height for alignment */
  line-height: 1.6 !important;
  color: var(--editor-text) !important;
  /* Force color */
  resize: none;
}

/* Status Bar */
.status-bar {
  height: 32px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  border-top: 1px solid var(--glass-border);
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  flex-shrink: 0;
  z-index: 10;
  padding-bottom: env(safe-area-inset-bottom);
  height: auto;
  min-height: 32px;
  padding-top: 4px;
}

.divider {
  margin: 0 8px;
  opacity: 0.5;
}

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

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  width: 400px;
  padding: 24px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
  transform: scale(0.95);
  transition: transform 0.3s var(--ease-elastic);
  background-color: #fff;
}

.dark-mode .modal {
  background-color: #1e1e24;
}

.modal-overlay.active .modal {
  transform: scale(1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.setting-group {
  margin-bottom: 20px;
}

.setting-group.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.setting-group label {
  display: block;
  font-size: 14px;
  margin-bottom: 8px;
  font-weight: 500;
}

/* Theme Toggles */
.theme-toggles {
  display: flex;
  background: rgba(0, 0, 0, 0.05);
  padding: 4px;
  border-radius: 8px;
}

.theme-btn {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.theme-btn.active {
  background: white;
  color: var(--primary-color);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.dark-mode .theme-btn.active {
  background: #333;
}

/* Range Slider */
input[type=range] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  height: 16px;
  width: 16px;
  border-radius: 50%;
  background: var(--primary-color);
  cursor: pointer;
  margin-top: -6px;
}

input[type=range]::-webkit-slider-runnable-track {
  width: 100%;
  height: 4px;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 2px;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

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

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

.dark-mode ::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
}

.dark-mode ::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 45px;
    --toolbar-height: 56px;
  }

  /* Fix body overflow on mobile */
  body {
    position: fixed;
    width: 100%;
    height: 100dvh;
  }

  /* Sidebar adjustments */
  .sidebar {
    padding: 10px 0;
  }

  .logo-wrapper svg {
    width: 20px;
    height: 20px;
  }

  /* Toolbar adjustments */
  .toolbar {
    padding: 0 10px;
    gap: 8px;
    overflow-x: auto;
    /* Allow scroll if actions overflow */
  }

  .toolbar-actions {
    gap: 4px;
  }


  .tabs-scroll-wrapper {
    margin-right: 5px;
    /* Ensure tabs have priority to show the 'New Tab' button */
    flex: 1 1 auto;
    width: 0;
    /* Important for flex container to shrink properly */
  }

  /* Make tabs smaller on mobile */
  .tab {
    padding: 4px 8px;
    max-width: 100px;
    font-size: 12px;
  }

  .tab-close {
    width: 14px;
    height: 14px;
    font-size: 12px;
  }

  /* Toolbar Actions - Compress them */
  .toolbar-actions {
    gap: 4px;
    flex-shrink: 0;
    /* Don't shrink buttons */
  }

  .icon-btn {
    padding: 6px;
  }

  .icon-btn svg {
    width: 16px;
    height: 16px;
  }

  /* Adjust Editor Padding */
  #editor {
    padding: 15px;
    font-size: 14px;
    /* Slightly smaller text for mobile */
  }

  /* Adjust Status Bar */
  .status-bar {
    font-size: 10px;
    padding: 0 10px;
  }

  .status-right span:not(#wordCount) {
    /* Hide some stats on very small screens for space */
    display: none;
  }

  .status-right #wordCount {
    display: inline;
  }

  /* Ensure modal fits on mobile */
  .modal {
    width: 90%;
    padding: 20px;
  }
}
