:root{
  /* Dark mode colors (default) */
  --bg:#0b0d12;
  --panel:#141926;
  --border:#1f2640;
  --text:#e6ecff;
  --muted:#9fb0d8;
  --accent:#4da3ff;
  --accent-2:#7bd389;
  --danger:#ff6b6b;
  --card-radius:16px;
  --shadow:0 8px 24px rgba(0,0,0,.35);
  
  /* Visualization colors and properties */
  --primary: #4da3ff;
  --success: #7bd389;
  --warning: #ffc107;
  --viz-bar-height: 20px;
  --viz-font-size: 12px;
  --viz-font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  --viz-line-width: 2px;
  --viz-point-radius: 3px;
  --viz-cell-size: 40px;
  --viz-border-radius: 4px;
  --viz-spacing: 2px;
}

/* Light mode colors */
:root.light-mode {
  --bg:#f8f9fa;
  --panel:#ffffff;
  --border:#e1e5eb;
  --text:#1a1d23;
  --muted:#6c757d;
  --accent:#0066cc;
  --accent-2:#28a745;
  --danger:#dc3545;
  --shadow:0 4px 12px rgba(0,0,0,.08);
  
  /* Light mode visualization colors */
  --primary: #0066cc;
  --success: #28a745;
  --warning: #ffc107;
}

*{ box-sizing: border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: ui-sans-serif,system-ui,Segoe UI,Roboto,Helvetica,Apple Color Emoji,Segoe UI Emoji,Arial,sans-serif;
  color:var(--text);
  background:var(--bg);
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Dark mode gradient background */
body:not(.light-mode) {
  background:radial-gradient(60rem 60rem at 120% -20%, #1b2442 10%, transparent 60%),
             radial-gradient(50rem 40rem at -20% 0%, #13203a 10%, transparent 60%),
             var(--bg);
}

.site-header{
  padding:32px 20px 8px;
  text-align:center;
}
.site-header h1{
  margin:0 0 6px;
  font-size: clamp(22px, 3vw, 34px);
  letter-spacing:.3px;
}
.subtitle{
  margin:0 0 14px;
  color:var(--muted);
}
.badges img{ vertical-align: middle; margin: 0 4px 8px; }

.container{
  width:min(1100px, 92vw);
  margin: 0 auto;
  padding: 12px 0 48px;
}

.card{
  background:var(--panel);
  border:1px solid var(--border);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow);
  padding: 18px 16px;
  margin: 14px 0;
  transition: background-color 0.3s ease, border-color 0.3s ease;
  position: relative; /* Establish stacking context */
  z-index: 1; /* Low z-index for cards */
}

:root:not(.light-mode) .card {
  background:linear-gradient(180deg, rgba(255,255,255,.02), rgba(255,255,255,.00));
}
.card h2{ margin: 0 0 10px; font-size: clamp(18px, 2.2vw, 22px); }

.grid{
  display:grid;
  gap:12px;
}
.grid.one{ grid-template-columns: 1fr; }
.grid.two{ grid-template-columns: repeat(2, 1fr); }
.grid.three{ grid-template-columns: repeat(3, 1fr); }
@media (max-width: 720px){
  .grid.two, .grid.three{ grid-template-columns: 1fr; }
}

label{ display:block; margin: 6px 0 6px; color: var(--muted); font-size: 14px; }
input[type="text"], select, textarea{
  width:100%;
  border:1px solid var(--border);
  background:var(--panel);
  color:var(--text);
  border-radius:12px;
  padding:10px 12px;
  margin-top: 4px;
  outline:none;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

:root:not(.light-mode) input[type="text"],
:root:not(.light-mode) select,
:root:not(.light-mode) textarea {
  background:#0e1320;
}
textarea.editor{
  width:100%;
  margin-top:10px;
  min-height:140px;
  resize: vertical;
}

.controls{ display:flex; gap:10px; flex-wrap: wrap; margin: 6px 0; }
button{
  appearance:none;
  border:1px solid var(--border);
  background:var(--panel);
  color:var(--text);
  border-radius: 12px;
  padding:10px 14px;
  cursor:not-allowed;
  opacity:.7;
  transition: all 0.3s ease;
}

:root:not(.light-mode) button {
  background:#0f172a;
}
button.primary{
  background: var(--accent);
  border-color:var(--accent);
  color:white;
}

:root:not(.light-mode) button.primary {
  background: linear-gradient(180deg, #1b3a6a, #0d2246);
  border-color:#1e3a8a;
  color:#eaf2ff;
}
button:enabled{ cursor:pointer; opacity:1; }

.stat{
  background:var(--panel);
  border:1px dashed var(--border);
  border-radius:12px;
  padding:10px 12px;
  transition: background-color 0.3s ease;
}

:root:not(.light-mode) .stat {
  background:#0f1422;
}
.stat__label{ color: var(--muted); font-size: 12px; }
.stat__value{ font-size: 18px; margin-top: 2px; }

.viz-grid{
  display:grid;
  grid-template-columns: 1fr;
  gap:16px;
  overflow-x: auto;
  scroll-behavior: smooth;
}

.viz-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.viz-header {
  display: flex;
  align-items: center;
  gap: 8px; /* Space between title and help icon */
  padding: 0 4px;
}

.viz-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.viz-header .viz-help {
  position: static !important;
  margin: 0 !important;
  cursor: help;
  background: var(--accent);
  color: white;
  width: 18px; /* Slightly smaller for inline placement */
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
  opacity: 0.8;
  transition: opacity 0.2s;
  flex-shrink: 0; /* Prevent shrinking when space is tight */
}

.viz-header .viz-help:hover {
  opacity: 1;
}
.viz-box{
  border:1px dashed var(--border);
  background:var(--panel);
  border-radius:12px;
  padding:14px;
  min-height:140px;
  color: var(--muted);
  transition: background-color 0.3s ease;
  overflow-x: auto;
  overflow-y: hidden;
  position: relative;
}

/* Different sizes for different visualizations */
#heatmap {
  min-height: 240px;
}

#timeline {
  min-height: 140px;
}

#rhythm {
  min-height: 180px;
}

:root:not(.light-mode) .viz-box {
  background:#0f1422;
}

/* Custom scrollbar for visualizations */
.viz-box::-webkit-scrollbar {
  height: 8px;
}

.viz-box::-webkit-scrollbar-track {
  background: var(--border);
  border-radius: 4px;
}

.viz-box::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 4px;
  transition: background 0.2s ease;
}

.viz-box::-webkit-scrollbar-thumb:hover {
  background: var(--accent-2);
}

/* Firefox scrollbar */
.viz-box {
  scrollbar-width: thin;
  scrollbar-color: var(--accent) var(--border);
}

.table-wrap{ overflow:auto; border-radius:12px; border:1px solid var(--border); }
table{ border-collapse: collapse; width: 100%; font-size: 14px; }
thead th{ 
  text-align:left; 
  background:var(--panel); 
  color:var(--text);
  font-weight: 600;
}

:root:not(.light-mode) thead th {
  background:#0f1422; 
  color:#bcd;
}
th, td{ padding:10px 12px; border-bottom:1px solid var(--border); }
.center{ text-align:center; }

.footer{
  text-align:center;
  padding: 24px 12px 40px;
  color:var(--muted);
}
.footer a{ color: var(--accent); text-decoration: none; }
.footer a:hover{ text-decoration: underline; }

.muted{ color: var(--muted); }
.small{ font-size: 12px; }
/* Theme toggle button */
.theme-toggle {
  position: absolute;
  top: 20px;
  right: max(4vw, calc(50vw - 550px + 20px));
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--panel);
  border: 2px solid var(--border);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: var(--shadow);
  transition: all 0.3s ease;
}

@media (max-width: 1200px) {
  .theme-toggle {
    right: 20px;
  }
}

.theme-toggle:hover {
  transform: scale(1.1);
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.sr-only{
  position:absolute !important; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0;
}

.note{ margin: 8px 0 0 20px; }
.note li{ margin: 4px 0; }

/* Note box for important information */
.note-box {
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 20px;
  transition: all 0.3s ease;
}

.note-box strong {
  color: var(--text);
}

:root.light-mode .note-box {
  background: rgba(0, 102, 204, 0.05);
  border-color: var(--accent);
}

/* Help icon and tooltip styles */
.help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 12px;
  font-weight: bold;
  cursor: help;
  position: relative;
  vertical-align: middle;
  transition: all 0.2s ease;
}

.help-icon:hover {
  transform: scale(1.1);
  background: var(--accent-2);
}

.tooltip {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.4;
  width: 300px;
  box-shadow: var(--shadow);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
  pointer-events: none;
}

.tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--border);
}

.tooltip::before {
  content: '';
  position: absolute;
  top: calc(100% - 1px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--panel);
}

.help-icon:hover .tooltip {
  opacity: 1;
  visibility: visible;
}

/* Inline help for form elements */
.form-help {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.form-help label {
  margin: 0;
}

/* Better spacing for form elements */
.grid > div {
  margin-bottom: 16px;
}

.grid.one > div:last-child,
.grid.two > div:last-child,
.grid.three > div:last-child {
  margin-bottom: 0;
}

/* Button help text */
button[data-tooltip] {
  position: relative;
}

button[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  box-shadow: var(--shadow);
  z-index: 1000;
  pointer-events: none;
}

/* Section header with help */
.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.section-header h2 {
  margin: 0;
}

/* Improved stat cards */
.stat {
  position: relative;
  overflow: visible;
  z-index: 1;
}

.stat-help {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--muted);
  color: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  cursor: help;
  opacity: 0.6;
  transition: opacity 0.2s;
  border: none;
  outline: none;
}

.stat-help:hover {
  opacity: 1;
}

.stat-help:hover::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 11px;
  line-height: 1.3;
  width: 180px;
  box-shadow: var(--shadow);
  z-index: 1000;
  white-space: normal;
  text-align: center;
  opacity: 1;
  visibility: visible;
}

.stat-help:hover::before {
  content: '';
  position: absolute;
  top: calc(100% - 3px);
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: var(--border);
  z-index: 1001;
  opacity: 1;
  visibility: visible;
}

/* Visualization help overlay */
.viz-box {
  position: relative;
}

.viz-help {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--accent);
  color: white;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  cursor: help;
  opacity: 0.7;
  transition: opacity 0.2s;
  z-index: 10;
}

.viz-help:hover {
  opacity: 1;
}

/* CSS tooltips disabled - using JavaScript implementation for better control */
.viz-help:hover::after,
.viz-help:hover::before,
.viz-help.active::after,
.viz-help.active::before {
  display: none !important;
}

/* Enhanced styling for JavaScript-generated tooltips */
.active-viz-tooltip,
.custom-viz-tooltip {
  font-family: var(--font-mono, 'Monaco', 'Menlo', 'Ubuntu Mono', monospace) !important;
  letter-spacing: 0.3px !important;
  backdrop-filter: blur(8px) !important;
  -webkit-backdrop-filter: blur(8px) !important;
}

.active-viz-tooltip:before,
.custom-viz-tooltip:before {
  content: '' !important;
  position: absolute !important;
  top: 100% !important;
  left: 50% !important;
  margin-left: -5px !important;
  border: 5px solid transparent !important;
  border-top-color: var(--border) !important;
  z-index: 2147483647 !important; /* Maximum z-index */
}

/* Force tooltip to be above everything */
.custom-viz-tooltip {
  z-index: 2147483647 !important;
  position: fixed !important;
}

/* Mobile touch support - viz-help tooltips disabled, handled by JavaScript */
@media (hover: none) and (pointer: coarse) {
  .help-icon.active .tooltip,
  .stat-help.active::after {
    opacity: 1;
    visibility: visible;
  }
  
  /* viz-help tooltips disabled for mobile - JavaScript handles all cases */
  .viz-help.active::after,
  .viz-help.active::before {
    display: none !important;
  }
  
  .stat-help.active::after {
    content: attr(title);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 11px;
    line-height: 1.3;
    width: 180px;
    white-space: normal;
    text-align: center;
    box-shadow: var(--shadow);
    z-index: 1000;
  }
  
  .stat-help.active::before {
    content: '';
    position: absolute;
    top: calc(100% - 3px);
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: var(--border);
    z-index: 1001;
  }
  
  .viz-help.active::after {
    content: attr(title);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 11px;
    white-space: nowrap;
    box-shadow: var(--shadow);
    z-index: 1000;
  }
}

/* Improved accessibility */
.help-icon:focus,
.stat-help:focus,
.viz-help:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.help-icon:focus .tooltip,
.stat-help:focus::after {
  opacity: 1;
  visibility: visible;
}

.stat-help:focus::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 11px;
  line-height: 1.3;
  width: 180px;
  box-shadow: var(--shadow);
  z-index: 1000;
  white-space: normal;
  text-align: center;
}

.stat-help:focus::before {
  content: '';
  position: absolute;
  top: calc(100% - 3px);
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: var(--border);
  z-index: 1001;
}

/* Better tooltip positioning on small screens */
@media (max-width: 768px) {
  .tooltip {
    width: 250px;
    font-size: 12px;
    padding: 8px 10px;
  }
  
  .viz-help:hover::after {
    width: 180px;
    font-size: 11px;
    padding: 6px 10px;
  }
  
  button[data-tooltip]:hover::after {
    font-size: 11px;
    padding: 4px 8px;
  }
}

/* Analysis Results Section */
.analysis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.analysis-card {
  background: linear-gradient(135deg, var(--panel) 0%, rgba(255,255,255,0.02) 100%);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  transition: all 0.3s ease;
}

.analysis-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

:root:not(.light-mode) .analysis-card {
  background: linear-gradient(135deg, #1a1f2e 0%, rgba(255,255,255,0.02) 100%);
}

.analysis-card h3 {
  margin: 0 0 12px 0;
  color: var(--accent);
  font-size: 16px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.analysis-metrics {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.metric {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
}

.metric-label {
  color: var(--muted);
  font-size: 13px;
  flex: 1;
}

.metric-value {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  min-width: 60px;
  text-align: right;
}

.metric-value.highlight {
  color: var(--accent);
}

.metric-value.good {
  color: var(--accent-2);
}

.metric-value.warning {
  color: #FFA726;
}

.analysis-summary {
  background: var(--panel);
  border: 1px dashed var(--accent);
  border-radius: 12px;
  padding: 16px;
  margin-top: 16px;
}

:root:not(.light-mode) .analysis-summary {
  background: #141926;
}

.analysis-summary h3 {
  margin: 0 0 10px 0;
  color: var(--accent);
  font-size: 16px;
}

.analysis-summary p {
  margin: 0;
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
}

@media (max-width: 768px) {
  .analysis-grid {
    grid-template-columns: 1fr;
  }
  
  .metric {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  
  .metric-value {
    text-align: left;
  }
}
