:root {
  --primary: #1751a3;
  --primary-dark: #0d2f5a;
  --secondary: #8d2c45;
  --accent: #3a7ca5;
  --light-bg: #f8f9fa;
  --panel-bg: #ffffff;
  --text: #2d3748;
  --text-light: #718096;
  --border: #e2e8f0;
  --success: #2d7d45;
  --danger: #c53030;
  --warning: #d69e2e;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Source Sans Pro', sans-serif;
  background-color: var(--light-bg);
  color: var(--text);
  line-height: 1.6;
  transition: background-color 0.3s, color 0.3s;
}

body.dark-mode {
  --light-bg: #1a202c;
  --panel-bg: #1f2632;
  --text: #e2e8f0;
  --text-light: #a0aec0;
  --border: #4a5568;
}

.wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

.site-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 1.5rem 0;
  margin-bottom: 1.5rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.site-header h1 {
  font-family: 'Source Serif Pro', serif;
  font-weight: 600;
  font-size: 1.8rem;
  margin-bottom: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.tag {
  font-size: 1rem;
  opacity: 0.9;
}

.main-grid {
  display: grid;
  grid-template-columns: 1fr 450px;
  gap: 24px;
}

.panel {
  background: var(--panel-bg);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border);
  transition: background-color 0.3s, border-color 0.3s;
}

.panel h2 {
  font-family: 'Source Serif Pro', serif;
  color: var(--primary);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
  font-size: 1.4rem;
}

.panel h3 {
  font-family: 'Source Serif Pro', serif;
  color: var(--primary);
  margin: 20px 0 12px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 1.2rem;
}

.muted {
  color: var(--text-light);
  margin-bottom: 16px;
  font-size: 0.95rem;
}

#operators-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 16px 0;
}

.op-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 15px;
}

.op-row label {
  font-weight: 600;
  color: var(--primary);
}

.op-row input, .op-row select {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: 'Source Sans Pro', sans-serif;
  font-size: 1rem;
  background-color: var(--panel-bg);
  color: var(--text);
  transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}

.btn {
  padding: 12px 16px;
  border-radius: 6px;
  border: none;
  font-family: 'Source Sans Pro', sans-serif;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.95rem;
  flex: 1;
  min-width: fit-content;
}

.btn.primary {
  background: var(--primary);
  color: white;
}

.btn.primary:hover {
  background: var(--primary-dark);
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn.ghost:hover {
  background: rgba(0, 0, 0, 0.05);
}

body.dark-mode .btn.ghost:hover {
  background: rgba(255, 255, 255, 0.05);
}

.btn.danger {
  background: var(--danger);
  color: white;
  font-size: 0.85rem;
  padding: 8px 12px;
}

.btn.danger:hover {
  background: #9b2c2c;
}

.btn.warning {
  background: var(--warning);
  color: white;
}

.btn.warning:hover {
  background: #b7791f;
}

.row {
  display: flex;
  gap: 10px;
  margin: 16px 0;
  flex-wrap: wrap;
}

.row.small-gap {
  gap: 8px;
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.preset-chip {
  background: #edf2f7;
  padding: 10px 14px;
  border-radius: 20px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
}

body.dark-mode .preset-chip {
  background: #2d3748;
}

.preset-chip:hover {
  background: #e2e8f0;
}

body.dark-mode .preset-chip:hover {
  background: #4a5568;
}

.preview-box {
  background: #f8fafc;
  padding: 16px;
  border-radius: 6px;
  min-height: 120px;
  border: 1px solid var(--border);
  font-family: monospace;
  font-size: 0.95rem;
  line-height: 1.5;
  overflow: auto;
  margin-bottom: 20px;
  white-space: pre-wrap;
  transition: background-color 0.3s, border-color 0.3s;
}

body.dark-mode .preview-box {
  background: #2d3748;
}

.disclaimer {
  background: #fff8f0;
  padding: 14px;
  border-radius: 6px;
  border-left: 4px solid #dd6b20;
  font-size: 0.9rem;
  margin: 20px 0;
  transition: background-color 0.3s;
}

body.dark-mode .disclaimer {
  background: #443227;
}

.help {
  background: #f0f9ff;
  padding: 16px;
  border-radius: 6px;
  border-left: 4px solid var(--accent);
  margin-top: 20px;
  transition: background-color 0.3s;
}

body.dark-mode .help {
  background: #2a3c47;
}

.help summary {
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 10px;
}

.help ul {
  padding-left: 20px;
}

.help li {
  margin-bottom: 8px;
  font-size: 0.9rem;
}

code {
  background: #edf2f7;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9rem;
  transition: background-color 0.3s;
}

body.dark-mode code {
  background: #4a5568;
}

.history {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.hist-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-radius: 6px;
  background: #f8fafc;
  border: 1px solid var(--border);
  transition: all 0.2s;
  flex-wrap: wrap;
  gap: 10px;
}

body.dark-mode .hist-item {
  background: #2d3748;
}

.hist-item-content {
  flex: 1;
  cursor: pointer;
  font-size: 0.9rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hist-item-content:hover {
  color: var(--primary);
}

.hist-item-actions {
  display: flex;
  gap: 8px;
}

.hist-delete {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 4px;
}

.hist-delete:hover {
  color: var(--danger);
}

.site-footer {
  text-align: center;
  margin-top: 40px;
  padding: 20px;
  color: var(--text-light);
  font-size: 0.9rem;
}

/* Research-specific elements */
.research-badge {
  display: inline-block;
  background: var(--secondary);
  color: white;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.7rem;
  margin-left: 8px;
  vertical-align: middle;
}

.academic-icon {
  display: inline-block;
  width: 24px;
  height: 24px;
  margin-right: 8px;
  vertical-align: middle;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ffffff'%3E%3Cpath d='M12 14l9-5-9-5-9 5 9 5z'/%3E%3Cpath d='M12 14l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14z'/%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M12 14l9-5-9-5-9 5 9 5zm0 0l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14zm-4 6v-7.5l4-2.222'/%3E%3C/svg%3E") no-repeat center;
}

.clear-history-btn {
  font-size: 0.8rem;
  padding: 6px 10px;
}

/* Advanced features */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  flex-shrink: 0;
}

.tab.active {
  border-bottom: 3px solid var(--primary);
  font-weight: 600;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.export-options {
  display: flex;
  gap: 10px;
  margin-top: 15px;
  flex-wrap: wrap;
}

.stats {
  display: flex;
  gap: 15px;
  margin: 15px 0;
  padding: 12px;
  background: #f8fafc;
  border-radius: 6px;
  transition: background-color 0.3s;
  justify-content: space-around;
}

body.dark-mode .stats {
  background: #2d3748;
}

.stat-item {
  text-align: center;
  flex: 1;
}

.stat-value {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--primary);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-light);
}

.suggestions {
  margin-top: 15px;
}

.suggestion-item {
  padding: 10px;
  border-radius: 6px;
  background: #f0f9ff;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

body.dark-mode .suggestion-item {
  background: #2a3c47;
}

.suggestion-item:hover {
  background: #e6f4ff;
}

body.dark-mode .suggestion-item:hover {
  background: #345267;
}

.query-complexity {
  height: 6px;
  background: #e2e8f0;
  border-radius: 3px;
  margin: 10px 0;
  overflow: hidden;
  transition: background-color 0.3s;
}

body.dark-mode .query-complexity {
  background: #4a5568;
}

.complexity-bar {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.3s;
}

.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted var(--text-light);
  cursor: help;
}

.tooltip .tooltiptext {
  visibility: hidden;
  width: 200px;
  background-color: var(--text);
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px;
  position: absolute;
  z-index: 1;
  bottom: 125%;
  left: 50%;
  margin-left: -100px;
  opacity: 0;
  transition: opacity 0.3s;
  font-size: 0.8rem;
  font-weight: normal;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
  opacity: 1;
}

.favorite-btn {
  color: #ccc;
  cursor: pointer;
  transition: color 0.2s;
  font-size: 1.2rem;
}

.favorite-btn.active {
  color: #ffc107;
}

.share-options {
  display: flex;
  gap: 10px;
  margin-top: 15px;
  flex-wrap: wrap;
}

.share-btn {
  flex: 1;
  text-align: center;
  min-width: 120px;
}

.dark-mode-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 15px;
  justify-content: center;
}

.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #ccc;
  transition: .4s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 4px;
  bottom: 4px;
  background: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .slider {
  background: var(--primary);
}

input:checked + .slider:before {
  transform: translateX(26px);
}

.search-tips {
  background: #f0fff4;
  border-left: 4px solid #38a169;
  padding: 12px;
  margin: 15px 0;
  border-radius: 4px;
  transition: background-color 0.3s;
  font-size: 0.9rem;
}

body.dark-mode .search-tips {
  background: #2a3c2f;
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--primary);
  color: white;
  padding: 12px 20px;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 1000;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.3s, transform 0.3s;
  max-width: calc(100% - 40px);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: var(--panel-bg);
  border-radius: 8px;
  padding: 20px;
  width: 100%;
  max-width: 500px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-light);
}

.modal-body {
  margin-bottom: 20px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Mobile-specific styles */
.mobile-tab-select {
  display: none;
  width: 100%;
  padding: 12px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background-color: var(--panel-bg);
  color: var(--text);
  font-family: 'Source Sans Pro', sans-serif;
  font-size: 1rem;
}

.mobile-only {
  display: none;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
  .main-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  
  .panel {
    padding: 18px;
  }
}

@media (max-width: 768px) {
  .wrap {
    padding: 15px;
  }
  
  .site-header {
    padding: 1rem 0;
    margin-bottom: 1rem;
  }
  
  .site-header h1 {
    font-size: 1.5rem;
  }
  
  .tag {
    font-size: 0.9rem;
  }
  
  .tabs {
    display: none;
  }
  
  .mobile-tab-select {
    display: block;
  }
  
  .panel h2 {
    font-size: 1.3rem;
  }
  
  .panel h3 {
    font-size: 1.1rem;
  }
  
  .btn {
    padding: 10px 14px;
    font-size: 0.9rem;
  }
  
  .stats {
    gap: 10px;
    padding: 10px;
  }
  
  .stat-value {
    font-size: 1.1rem;
  }
  
  .stat-label {
    font-size: 0.7rem;
  }
  
  .preview-box {
    font-size: 0.9rem;
    padding: 12px;
  }
  
  .row {
    gap: 8px;
  }
  
  .share-btn {
    min-width: calc(50% - 5px);
  }
}

@media (max-width: 480px) {
  .site-header h1 {
    font-size: 1.3rem;
  }
  
  .research-badge {
    font-size: 0.6rem;
    padding: 3px 8px;
  }
  
  .panel {
    padding: 15px;
  }
  
  .op-row {
    margin-bottom: 12px;
  }
  
  .op-row input, .op-row select {
    padding: 10px;
  }
  
  .btn {
    padding: 10px 12px;
    font-size: 0.85rem;
  }
  
  .preset-chip {
    padding: 8px 12px;
    font-size: 0.85rem;
  }
  
  .stats {
    flex-wrap: wrap;
  }
  
  .stat-item {
    flex: 0 0 calc(50% - 10px);
    margin-bottom: 5px;
  }
  
  .share-btn {
    min-width: 100%;
  }
  
  .mobile-only {
    display: block;
  }
  
  .desktop-only {
    display: none;
  }
}

@media (max-width: 360px) {
  .wrap {
    padding: 10px;
  }
  
  .site-header h1 {
    font-size: 1.2rem;
  }
  
  .panel {
    padding: 12px;
  }
  
  .btn {
    padding: 8px 10px;
    font-size: 0.8rem;
  }
}