:root {
  /* Default: Dark Theme */
  --bg-color: #0F172A;
  --bg-surface: rgba(30, 41, 59, 0.7);
  --border-color: rgba(99, 102, 241, 0.2);
  --border-highlight: rgba(139, 92, 246, 0.4);
  
  --primary: #6366F1;
  --primary-hover: #4F46E5;
  --secondary: #8B5CF6;
  --accent: #22D3EE;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  
  --text-main: #F8FAFC;
  --text-muted: #94A3B8;
  --text-inverse: #0F172A;
  
  /* Heatmap Colors (Dark) */
  --heat-easy: rgba(16, 185, 129, 0.2);
  --heat-medium: rgba(245, 158, 11, 0.2);
  --heat-hard: rgba(244, 63, 94, 0.3);
  --heat-very-hard: rgba(225, 29, 72, 0.5);
  
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.1);
  
  --transition: all 0.2s ease;
  --font-sans: 'Inter', system-ui, sans-serif;
}

[data-theme="light"] {
  --bg-color: #F8FAFC;
  --bg-surface: rgba(255, 255, 255, 0.8);
  --border-color: rgba(99, 102, 241, 0.2);
  --border-highlight: rgba(139, 92, 246, 0.3);
  
  --text-main: #0F172A;
  --text-muted: #64748B;
  --text-inverse: #F8FAFC;
  
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);

  /* Heatmap Colors (Light) */
  --heat-easy: rgba(16, 185, 129, 0.15);
  --heat-medium: rgba(245, 158, 11, 0.15);
  --heat-hard: rgba(244, 63, 94, 0.2);
  --heat-very-hard: rgba(225, 29, 72, 0.3);
}

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

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: var(--font-sans);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Glassmorphism */
.glass-panel {
  background: var(--bg-surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
}

/* Utilities */
.hidden { display: none !important; }
.text-primary { color: var(--primary); }
.text-secondary { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.border-t { border-top: 1px solid var(--border-color); }
.pt-4 { padding-top: 1rem; }
.text-right { text-align: right; }
.scrollable { overflow-y: auto; }
.flex-1 { flex: 1; min-height: 0; }
.flex-col { display: flex; flex-direction: column;}

/* Layout */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 1rem;
  gap: 1rem;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-radius: var(--radius);
  flex-shrink: 0;
}

.logo { display: flex; align-items: center; gap: 0.75rem; }
.logo h1 { font-size: 1.25rem; font-weight: 700; background: linear-gradient(90deg, var(--primary), var(--accent)); -webkit-background-clip: text; -webkit-text-fill-color: transparent;}

.header-actions { display: flex; align-items: center; gap: 1rem; }

.main-content {
  display: flex;
  gap: 1rem;
  flex: 1;
  min-height: 0;
}

.editor-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  overflow: hidden;
}

.analysis-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 400px;
}

/* Editor */
.editor-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.editor-header h2 { font-size: 1.1rem; }
.editor-stats { display: flex; gap: 0.75rem; font-size: 0.85rem; color: var(--text-muted); }

.editor-body { flex: 1; display: flex; }
textarea {
  flex: 1;
  background: transparent;
  border: none;
  padding: 1.5rem;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  resize: none;
  outline: none;
}
textarea::placeholder { color: var(--text-muted); opacity: 0.7; }

.editor-footer {
    padding: 0.5rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  flex-shrink: 0;
}

.stat-card {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}
.stat-icon { position: absolute; top: 1.25rem; right: 1.25rem; opacity: 0.5; }
.stat-val { font-size: 2rem; font-weight: 700; line-height: 1; margin-bottom: 0.25rem; }
.stat-label { font-size: 0.9rem; font-weight: 500; }
.stat-sub { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.25rem; }

/* Tabs */
.tabs-header {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  padding: 0 1rem;
}
.tab-btn {
  background: none;
  border: none;
  padding: 1rem 1.25rem;
  color: var(--text-muted);
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
}
.tab-btn:hover { color: var(--text-main); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.tabs-content {
  flex: 1;
  padding: 1.5rem;
  position: relative;
}

.tab-pane { display: none; }
.tab-pane.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

.empty-state { text-align: center; color: var(--text-muted); padding: 3rem 1rem; font-style: italic; }

/* Heatmap */
.heatmap-legend { display: flex; gap: 1rem; margin-bottom: 1rem; font-size: 0.8rem; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 0.4rem; }
.color-box { width: 12px; height: 12px; border-radius: 2px; }
.bg-easy { background: var(--heat-easy); border: 1px solid var(--success);}
.bg-medium { background: var(--heat-medium); border: 1px solid var(--warning);}
.bg-hard { background: var(--heat-hard); border: 1px solid var(--danger); }
.bg-very-hard { background: var(--heat-very-hard); border: 1px solid var(--danger); }

.heatmap-text {
  line-height: 2;
  font-size: 0.95rem;
  white-space: pre-wrap;
}
.heatmap-sentence {
  padding: 0.15rem 0.25rem;
  border-radius: 4px;
  cursor: pointer;
  transition: var(--transition);
}
.heatmap-sentence:hover { box-shadow: 0 0 0 1px var(--border-highlight); }

/* Issues */
.issues-list { display: flex; flex-direction: column; gap: 1rem; }
.issue-card {
  padding: 1rem;
  border-radius: var(--radius-sm);
  background: rgba(0,0,0,0.2);
  border-left: 3px solid var(--border-color);
}
.issue-card.warning { border-left-color: var(--warning); }
.issue-card.danger { border-left-color: var(--danger); }
.issue-card.info { border-left-color: var(--accent); }

.issue-header { display: flex; justify-content: space-between; margin-bottom: 0.5rem; font-weight: 500; font-size:0.9rem;}
.issue-type { display: inline-flex; align-items: center; gap: 0.25rem;}
.issue-desc { font-size: 0.85rem; color: var(--text-muted); }
.issue-quote { background: rgba(0,0,0,0.3); padding: 0.5rem; border-radius: 4px; font-style: italic; font-size: 0.85rem; margin-top: 0.5rem; display:block; border: 1px solid var(--border-color);}

/* Words */
.word-freq-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.word-pill {
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid var(--border-highlight);
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.word-pill .count { background: var(--primary); color: white; border-radius: 50%; width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center; font-size: 0.7rem; font-weight:600;}

/* Buttons */
button { font-family: var(--font-sans); cursor: pointer; transition: var(--transition); display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; }
.icon-btn { background: none; border: none; color: var(--text-muted); padding: 0.5rem; border-radius: 50%; }
.icon-btn:hover { background: rgba(128,128,128,0.1); color: var(--text-main); }
.btn-primary { background: var(--primary); color: white; border: none; padding: 0.6rem 1.2rem; border-radius: var(--radius-sm); font-weight: 500; font-size: 0.85rem;}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); transform: translateY(-1px); box-shadow: var(--shadow-sm);}
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-text { background: none; border: none; font-size: 0.85rem; padding: 0.4rem 0.8rem; font-weight: 500;}
.btn-text:hover { color: var(--text-main); }
.btn-outline { background: transparent; border: 1px solid var(--border-color); color: var(--text-main); padding: 0.6rem 1.2rem; border-radius: var(--radius-sm); font-weight: 500; font-size: 0.85rem; width: 100%;}
.btn-outline:hover { border-color: var(--primary); background: rgba(99, 102, 241, 0.1); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 1rem; backdrop-filter: blur(4px);}
.modal-content { width: 100%; max-width: 400px; padding: 1.5rem; }
.export-options { display: flex; flex-direction: column; gap: 1rem; }

/* Responsive */
@media (max-width: 900px) {
  .main-content { flex-direction: column; }
  .editor-col { height: 40vh; flex: none; }
  .analysis-col { min-width: 0; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Print Styles */
.hidden-print { display: none; }
@media print {
  body * { visibility: hidden; }
  #printReport, #printReport * { visibility: visible; }
  #printReport { position: absolute; left: 0; top: 0; width: 100%; padding: 2rem; color: black; background: white; font-family: sans-serif;}
  
  .print-header { border-bottom: 2px solid #ccc; margin-bottom: 2rem; padding-bottom: 1rem;}
  #printReport h1 { font-size: 24pt; margin-bottom: 0.5rem; color: black;}
  #printReport h2 { font-size: 16pt; margin-top: 2rem; margin-bottom: 1rem; color: #333; border-bottom: 1px solid #eee; padding-bottom: 0.5rem;}
  .print-table { width: 100%; border-collapse: collapse; margin-bottom: 2rem;}
  .print-table th, .print-table td { border: 1px solid #ddd; padding: 8px; text-align: left;}
  .print-table th { background-color: #f2f2f2; width: 40%;}
  #printSuggestions li { margin-bottom: 0.5rem; }
}
