:root {
  /* Color Palette - Light (Default) */
  --primary-color: #0052cc;
  --primary-variant: #0056b3;
  --secondary-color: #03dac6;

  --bg-color: #f8f9fa; /* Soft off-white instead of pure white */
  --header-bg: #e8edf2; /* Softer light blue-gray */
  --surface-color: #f0f4f8; /* Much lighter, softer blue-gray for preview */
  --surface-color-2: #e8ecf0;

  --text-primary: #1a202c; /* Softer black */
  --text-secondary: #4a5568;
  --text-on-primary: #ffffff;

  --border-color: #cbd5e0;
  --divider-color: #a0aec0;

  --app-bar-height: 64px;
  --transition-speed: 0.3s;
}

body.dark-mode {
  /* Color Palette - Dark */
  --primary-color: #bb86fc;
  --primary-variant: #3700b3;
  --secondary-color: #03dac6;

  --bg-color: #1a1d23; /* Softer dark blue-gray instead of pure black */
  --header-bg: #1f2229; /* Slightly lighter header */
  --surface-color: #181b20; /* Softer dark background for preview */
  --surface-color-2: #2a2d35;

  --text-primary: #e1e4e8; /* Slightly brighter text */
  --text-secondary: #9ba3af;
  --text-on-primary: #000000;

  --border-color: #3a3f4a;
  --divider-color: #4a5060;
}

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

body {
  font-family: 'Roboto', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: background-color var(--transition-speed), color var(--transition-speed);
}

/* App Bar */
.top-app-bar {
  height: var(--app-bar-height);
  background-color: var(--header-bg);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1); /* Subtle shadow */
  z-index: 10;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-color);
}

.app-bar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 32px;
  color: var(--primary-color); /* Accent color for logo */
}

.app-title {
  font-size: 20px;
  font-weight: 500;
  white-space: nowrap;
}

.app-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Buttons */
.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary); /* Darker icons on light bg */
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s, color 0.2s;
}

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

.icon-btn:active {
  background-color: rgba(0, 0, 0, 0.1);
}

.github-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
}

/* Toggle Switch */
.control-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 8px;
}

.icon-label {
  font-size: 20px;
  opacity: 0.9;
}

.switch {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 20px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #cbd5e0;
  transition: .4s;
  border-radius: 34px;
  border: 1px solid #a0aec0;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: #ffffff;
  transition: .4s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

input:checked + .slider {
  background-color: var(--secondary-color);
}

input:checked + .slider:before {
  transform: translateX(14px);
}

/* Main Container */
.split-container {
  display: flex;
  flex: 1;
  position: relative;
  height: calc(100vh - var(--app-bar-height));
}

.pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0; /* Prevent flex items from overflowing */
  height: 100%;
}

.editor-pane {
  background-color: var(--bg-color);
}

.preview-pane {
  background-color: var(--surface-color);
}

#editor-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#editor {
  width: 100%;
  height: 100%;
}

#preview-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 0; /* GitHub markdown css handles padding inside usually, but we might want some */
}

.markdown-body {
  box-sizing: border-box;
  min-width: 200px;
  max-width: 980px;
  margin: 0 auto;
  padding: 45px;
  transition: background-color 0.3s, color 0.3s;
  outline: none; /* Remove default outline on focus */
}

/* Light Mode Code Block Overrides (Better contrast) */
.markdown-body pre {
    background-color: #d4dce6; /* Darker slate gray for better contrast */
    border: 1px solid #b8c5d4;
}

.markdown-body code, .markdown-body tt {
    background-color: #d4dce6;
    color: #1a202c;
    border: 1px solid #b8c5d4;
    padding: 0.2em 0.4em;
    border-radius: 3px;
}

.markdown-body pre code {
    background-color: transparent;
    border: none;
    padding: 0;
}

/* Visual cue that preview is editable */
.markdown-body:focus {
    box-shadow: 0 0 0 2px var(--primary-color) inset; 
}

/* Modal / Dialog */
.modal {
  border: none;
  border-radius: 8px;
  padding: 0;
  background-color: var(--bg-color);
  color: var(--text-primary);
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  max-width: 400px;
  width: 90%;
  position: fixed; /* Fallback */
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.modal::backdrop {
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

.modal-content {
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--header-bg);
}

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 500;
  margin: 0;
}

.modal-body {
  padding: 16px;
}

.modal-body p {
  margin: 0;
  line-height: 1.6;
  color: var(--text-primary);
}

.shortcut-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-color);
}

.shortcut-row:last-child {
  border-bottom: none;
}

kbd {
  background-color: var(--surface-color-2);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.1);
  color: var(--text-primary);
  font-family: 'Roboto Mono', monospace;
  font-size: 0.85rem;
  padding: 2px 6px;
}

.modal-footer {
  padding: 16px;
  border-top: 1px solid var(--border-color);
  text-align: center;
  background-color: var(--header-bg);
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.modal-footer p {
  margin: 4px 0;
}

.modal-footer a {
  color: var(--primary-color);
  text-decoration: none;
}

.modal-footer a:hover {
  text-decoration: underline;
}

/* Dark Mode Overrides for Modal */
body.dark-mode .modal {
  background-color: #1f2229; /* Match header color */
  border: 1px solid var(--border-color);
}

body.dark-mode .modal-header {
  background-color: #2a2d35;
}

body.dark-mode .modal-footer {
  background-color: #2a2d35;
}

/* Modal Buttons */
.modal-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: 'Roboto', sans-serif;
}

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

.modal-btn.primary:hover {
  background-color: #1565c0;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(25, 118, 210, 0.3);
}

.modal-btn.primary:active {
  transform: translateY(0);
}

.modal-btn.secondary {
  background-color: var(--surface-color-2);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.modal-btn.secondary:hover {
  background-color: var(--surface-color-3);
  border-color: var(--text-secondary);
}

/* Dark mode button overrides */
body.dark-mode .modal-btn.secondary {
  background-color: #2a2d35;
  border-color: #444;
}

body.dark-mode .modal-btn.secondary:hover {
  background-color: #353842;
  border-color: #666;
}

/* Split Divider */
.split-divider {
  width: 6px;
  background-color: var(--border-color);
  cursor: col-resize;
  transition: background-color 0.2s, width 0.2s;
  z-index: 5;
}

.split-divider:hover, .split-divider.active {
  background-color: var(--primary-color);
}

.divider-vertical {
  width: 1px;
  height: 24px;
  background-color: rgba(255, 255, 255, 0.3);
  margin: 0 8px;
}

/* Mobile Only Styles */
.mobile-only {
  display: none;
}

/* Desktop Only Styles */
.desktop-only {
  display: flex; /* or block depending on context */
}

/* Responsive / Mobile Styles */
@media (max-width: 768px) {
  .desktop-only {
    display: none !important;
  }
  
  .mobile-only {
    display: flex !important;
  }

  .app-title {
    display: none; /* Save space on small screens */
  }

  .app-bar-center {
    flex: 1;
    justify-content: center;
  }

  /* Tab Group */
  .tab-group {
    display: flex;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    padding: 2px;
  }

  .tab-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    padding: 6px 24px;
    border-radius: 18px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
  }

  .tab-btn.active {
    background-color: var(--text-on-primary);
    color: var(--primary-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  }

  /* Hide inactive panes on mobile */
  .pane {
    display: none;
    width: 100% !important; /* Override split widths */
  }
  
  .pane.active-tab {
    display: flex;
  }

  .markdown-body {
    padding: 16px; /* Less padding on mobile */
  }
}

/* Dark Mode Overrides for Markdown */
/* These overrides try to mimic github-markdown-dark.css behavior manually */
body.dark-mode .markdown-body {
  color: #e1e4e8;
  background-color: #181b20;
}

body.dark-mode .markdown-body a {
  color: #58a6ff;
}

body.dark-mode .markdown-body h1,
body.dark-mode .markdown-body h2,
body.dark-mode .markdown-body h3,
body.dark-mode .markdown-body h4,
body.dark-mode .markdown-body h5,
body.dark-mode .markdown-body h6 {
  color: #e1e4e8;
  border-bottom-color: #2a2d35;
}

body.dark-mode .markdown-body blockquote {
  color: #9ba3af;
  border-left-color: #3a3f4a;
}

body.dark-mode .markdown-body table tr {
  background-color: #181b20;
  border-top-color: #3a3f4a;
}

body.dark-mode .markdown-body table tr:nth-child(2n) {
  background-color: #1f2229;
}

body.dark-mode .markdown-body table th,
body.dark-mode .markdown-body table td {
  border-color: #3a3f4a;
}

body.dark-mode .markdown-body code,
body.dark-mode .markdown-body tt {
  background-color: rgba(135, 140, 149, 0.3); /* Softer transparency */
  color: #e1e4e8; /* Consistent text color */
}

body.dark-mode .markdown-body pre {
  background-color: #2a2d35; /* Softer dark gray */
}

body.dark-mode .markdown-body pre code {
  color: #e1e4e8; /* Consistent text color */
  background-color: transparent; /* Inherit from pre */
}

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

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

::-webkit-scrollbar-thumb {
  background: #bbb;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #999;
}

body.dark-mode ::-webkit-scrollbar-thumb {
  background: #555;
}
