@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;700&display=swap');

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* --- Design Tokens --- */
:root {
  /* Background */
  --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);

  --bg-primary: #0f172a;
  --bg-secondary: #181a23;
  --bg-surface: #1e2030;
  --bg-elevated: #252839;

  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.2);
  --border-active: rgba(130, 143, 255, 0.4);

  /* Text */
  --text-primary: #e2e4f0;
  --text-secondary: #8b8fa8;
  --text-muted: #5c6078;
  /* Accents */
  --accent: #667eea;
  --accent-hover: #9aa4ff;
  --accent-glow: rgba(130, 143, 255, 0.15);

  /* Misc */
  --danger: #ff6b8a;
  --success: #6bffb8;
  --timestamp-color: #f0a050;
  --timestamp-bg: rgba(240, 160, 80, 0.08);
  --segment-color: #50c8a0;
  --segment-bg: rgba(80, 200, 160, 0.08);

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;

  /* Header Controls */
  --control-height: 2.4rem;
  --control-height-sm: 1.78rem;
  --control-height-xs: 1.64rem;

  /* Shadows */
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3), 0 1px 4px rgba(0, 0, 0, 0.2);
  --shadow-glow: 0 0 30px rgba(59, 130, 246, 0.08);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;

  /* Transitions */
  --transition: 0.2s ease;
}

/* ===== Light Theme Overrides ===== */
:root.light-theme {
  --bg-primary: #f1f5f9;
  --bg-secondary: #ffffff;
  --bg-surface: #ffffff;
  --bg-elevated: #ffffff;
  --border-subtle: rgba(148, 163, 184, 0.5);
  --border-active: rgba(102, 126, 234, 0.5);
  --text-primary: #1e2030;
  --text-secondary: #5c6078;
  --text-muted: #8b8fa8;
  --accent: #5a70df;
  --accent-hover: #455bc2;
  --accent-glow: rgba(90, 112, 223, 0.15);
  --danger: #e6395b;
  --success: #10b981;

  --timestamp-color: #d97706;
  --timestamp-bg: rgba(217, 119, 6, 0.1);
  --segment-color: #059669;
  --segment-bg: rgba(5, 150, 105, 0.1);

  --shadow-card: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-glow: 0 0 25px rgba(59, 130, 246, 0.1);
}

:root.light-theme body {
  background-image:
    radial-gradient(circle at 0% 0%, rgba(99, 102, 241, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 100% 100%, rgba(168, 85, 247, 0.1) 0%, transparent 50%);
}

body {
  background-color: var(--bg-primary);
  background-image:
    radial-gradient(circle at 0% 0%, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 100% 100%, rgba(168, 85, 247, 0.15) 0%, transparent 50%);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem;
  overflow-x: hidden;
}

/* ============================================
   HEADER
   ============================================ */
.header {
  width: 100%;
  max-width: 960px;
  margin-bottom: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.header-main {
  display: flex;
  align-items: center;
  gap: 16px;
}

.title {
  font-family: 'Outfit', sans-serif;
  font-size: 2.2rem;
  font-weight: 700;
  text-align: center;
  margin: 0 1rem 0.5rem;
  background: var(--gradient-primary);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.subtitle {
  font-size: 0.9rem;
  text-align: center;
  color: var(--text-secondary);
  margin: 0 1rem 1rem;
}

.title-icon {
  height: 2rem;
  width: auto;
  vertical-align: middle;
  margin-right: 1rem;
  filter: drop-shadow(0 4px 12px rgba(99, 102, 241, 0.3));
  transition: transform 0.3s ease;
  animation: float 3s ease-in-out infinite;
}

.title:hover .title-icon {
  transform: scale(1.1) rotate(15deg);
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-5px);
  }
}

/* ============================================
   THEME AND LANGUAGE SWITCHER
   ============================================ */
.theme-lang-switcher {
  position: absolute;
  top: 1.2rem;
  right: 1.2rem;
  display: flex;
  gap: 0.5rem;
  z-index: 100;
}

/* ===== THEME TOGGLE GROUP ===== */
.theme-toggle-group {
  background: var(--bg-card);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 0.2rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.theme-toggle-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--gradient-primary);
  border: 1px solid var(--border-subtle);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  transform: translateY(0) scale(0.94);
  opacity: 0.5;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
}

.theme-toggle-btn svg {
  width: 16px;
  height: 16px;
  transition: transform 0.3s ease;
}

.theme-toggle-btn:hover {
  transform: translateY(-1px) scale(1.04);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  opacity: 0.95;
}

.theme-toggle-btn:hover svg {
  transform: translateY(-1px);
}

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

.theme-toggle-btn:focus-visible {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35), 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.theme-toggle-btn.is-active {
  opacity: 1;
  transform: translateY(-1px) scale(1);
}

.light-theme .theme-toggle-btn {
  box-shadow: 0 8px 22px rgba(59, 130, 246, 0.24);
}

.version-badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 2px 10px;
  border-radius: 100px;
}

/* ===== LANGUAGE SELECTOR ===== */
.lang-select {
  box-sizing: border-box;
  background: transparent;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  height: var(--control-height);
  padding: 0 2.5rem 0 1rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  transition: all 0.3s ease;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 14px 14px;
  outline: none;
}

.lang-select:hover {
  border-color: var(--border-highlight);
  color: var(--text-primary);
  transform_: translateY(-2px);
}

.lang-select:focus {
  box-shadow: 0 0 0 2px var(--shadow-glow);
}

.lang-select option {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  padding: 10px;
}

.light-theme .lang-select {
  box-shadow: 0 1px 1px rgba(59, 130, 246, 0.06);
}

/* ============================================
   MAIN
   ============================================ */
#app-main {
  width: 100%;
  max-width: 960px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
  margin-bottom: 2rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

/* ===== TOP BAR: TABS + PERSISTENT ACTIONS ===== */
.topbar {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 8px;
  gap: 0;
  flex-shrink: 0;
}

.tab-buttons {
  display: flex;
  gap: 0;
  flex: 1;
}

.tab-btn {
  position: relative;
  padding: 10px 18px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition);
  display: flex;
  align-items: center;
  gap: 7px;
}

.tab-btn:hover {
  color: var(--text-secondary);
}

.tab-btn.active {
  color: var(--accent);
}

.tab-btn::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 12px;
  right: 12px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  opacity: 0;
  transition: opacity var(--transition);
}

.tab-btn.active::after {
  opacity: 1;
}

.tab-btn svg {
  width: 15px;
  height: 15px;
}

.persistent-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
}

/* ============================================
   TOOLBAR PANEL
   ============================================ */
.toolbar-panel {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  min-height: 50px;
  flex-shrink: 0;
}

.toolbar-panel.active {
  display: flex;
}

.toolbar-panel .divider {
  width: 1px;
  height: 26px;
  background: var(--border-subtle);
  margin: 0 4px;
  flex-shrink: 0;
}

.toolbar-panel .group-label {
  font-size: 0.63rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0 4px;
  user-select: none;
  flex-shrink: 0;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  user-select: none;
}

.btn:hover {
  background: rgba(130, 143, 255, 0.1);
  color: var(--text-primary);
}

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

.btn.active {
  background: var(--accent-glow);
  color: var(--accent);
}

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn.icon-only {
  padding: 0;
  width: 32px;
}

.btn-action {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.btn-action:hover {
  background: rgba(130, 143, 255, 0.1);
  border-color: var(--border-active);
  color: var(--text-primary);
}

.btn-action svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  opacity: 0.7;
}

/* ===== INLINE SELECT ===== */
.toolbar-select {
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.74rem;
  cursor: pointer;
  transition: all var(--transition);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%238b8fa8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 24px;
}

.toolbar-select:hover {
  border-color: var(--border-active);
}

.toolbar-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* ===== INLINE INPUT ===== */
.toolbar-input {
  width: 54px;
  height: 30px;
  padding: 0 6px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.74rem;
  text-align: center;
  transition: all var(--transition);
}

.toolbar-input:hover {
  border-color: var(--border-active);
}

.toolbar-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* ===== SEARCH/REPLACE ROW ===== */
.search-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
}

.search-input {
  flex: 1;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.76rem;
  transition: all var(--transition);
  min-width: 0;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.search-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  flex-shrink: 0;
  min-width: 52px;
}

/* ===== EDITOR BODY WITH LINE NUMBERS ===== */
.editor-body {
  flex: 1;
  display: flex;
  flex-direction: row;
  min-height: 0;
  position: relative;
}

/* Line numbers gutter */
.line-numbers {
  width: 48px;
  flex-shrink: 0;
  padding: 24px 8px 24px 0;
  text-align: right;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  line-height: 1.75;
  color: var(--text-muted);
  user-select: none;
  overflow: hidden;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
}

.line-numbers .line-num {
  display: block;
  height: calc(16px * 1.75);
  line-height: calc(16px * 1.75);
}

#editor {
  flex: 1;
  padding: 24px 28px 24px 16px;
  outline: none;
  font-family: 'Inter', sans-serif;
  font-size: 16px;
  line-height: 1.75;
  color: var(--text-primary);
  background: transparent;
  overflow-y: auto;
  resize: none;
  border: none;
  min-height: 0;
}

#editor:empty::before {
  content: attr(placeholder);
  color: var(--text-muted);
  font-style: italic;
}

#editor:focus {
  background: rgba(130, 143, 255, 0.015);
}

/* ===== TIME MARKER HIGHLIGHTING ===== */
.marker-block {
  color: var(--timestamp-color);
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.88em;
  background: var(--timestamp-bg);
  border-radius: 3px;
  padding: 1px 4px;
  display: inline;
}

.marker-segment {
  color: var(--segment-color);
  font-weight: 500;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.88em;
  background: var(--segment-bg);
  border-radius: 3px;
  padding: 1px 4px;
  display: inline;
}

/* ===== STATUS BAR ===== */
.status-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 8px 16px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  font-size: 0.72rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.status-bar .stat {
  display: flex;
  align-items: center;
  gap: 5px;
}

.status-bar .stat .value {
  color: var(--text-secondary);
  font-weight: 500;
}

/* ============================================
   SCROLLBAR
   ============================================ */
#editor::-webkit-scrollbar {
  width: 6px;
}

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

#editor::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
}

#editor::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* ============================================
   FOOTER
   ============================================ */
.app-footer {
  width: 100%;
  max-width: 1100px;
  margin-top: auto;
  padding: 1.5rem 0;
  color: var(--text-secondary);
  font-size: 0.85rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: center;
}

.footer-content {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  width: 100%;
  padding: 0 1rem;
  color: var(--text-secondary);
}

.footer-title {
  font-weight: 500;
  font-size: 0.85rem;
}

.footer-separator {
  color: var(--border-subtle);
  user-select: none;
}

.footer-content a {
  color: #a78bfa;
  text-decoration: none;
  font-size: 0.85rem;
  transition: all 0.2s ease;
}

.footer-content a:hover {
  color: #764ba2;
  filter: brightness(1.2);
}

/* ============================================
   SCROLL-TO-TOP BUTTON
   ============================================ */
.scroll-top-btn {
  position: fixed;
  right: 2rem;
  bottom: 2rem;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--gradient-primary);
  border: 1px solid var(--border-subtle);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1000;
}

.scroll-top-btn.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.scroll-top-btn svg {
  transition: transform 0.3s ease;
}

.scroll-top-btn:hover {
  transform: translateY(-5px) scale(1.1);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}

.scroll-top-btn:hover svg {
  transform: translateY(-2px);
}

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

/* ============================================
   TOAST
   ============================================ */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 10px 18px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-active);
  border-radius: var(--radius-md);
  color: var(--accent-hover);
  font-size: 0.8rem;
  font-weight: 500;
  box-shadow: var(--shadow-glow);
  opacity: 0;
  transform: translateY(12px);
  transition: all 300ms ease;
  pointer-events: none;
  z-index: 1000;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1000px) {
  .theme-lang-switcher {
    top: 0.55rem;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    gap: 0.4rem;
  }

  .header {
    padding-top: 3.1rem;
  }

  .title {
    font-size: 1.8rem;
    line-height: 1.2;
  }
}

@media (max-width: 800px) {
  .theme-lang-switcher {
    top: 0.5rem;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    gap: 0.35rem;
  }

  .theme-toggle-group {
    height: var(--control-height-sm);
    padding: 0 0.16rem;
    gap: 0.22rem;
  }

  .theme-toggle-btn {
    width: 1.72rem;
    height: 1.72rem;
  }

  .theme-toggle-btn svg {
    width: 13px;
    height: 13px;
  }

  .lang-select {
    height: var(--control-height-sm);
    font-size: 0.82rem;
    padding: 0 2.2rem 0 0.7rem;
    background-position: right 0.6rem center;
  }

  .header-inner {
    padding: var(--space-sm) var(--space-md);
  }
}

@media (max-width: 600px) {
  .footer-content {
    gap: 0.75rem;
  }
}

@media (max-width: 640px) {
  body {
    padding: 12px;
  }

  .scroll-top-btn {
    right: 1.5rem;
    bottom: 1.5rem;
  }

  #editor {
    padding: 16px 18px 16px 12px;
  }

  .tab-btn {
    padding: 10px 12px;
    font-size: 0.72rem;
  }

  .line-numbers {
    width: 36px;
    font-size: 10px;
  }
}

@media (max-width: 380px) {
  .theme-lang-switcher {
    top: 0.45rem;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }

  .theme-toggle-btn {
    width: 1.58rem;
    height: 1.58rem;
  }

  .lang-select {
    height: var(--control-height-xs);
    max-width: 7.9rem;
    font-size: 0.78rem;
  }

  .theme-toggle-group {
    height: var(--control-height-xs);
  }
}

