/**
 * ═══════════════════════════════════════════════════════════════════════════
 * WHITE MATTER TRACT EXPLORER
 * An interactive three-dimensional visualization of human neuroanatomy
 * ═══════════════════════════════════════════════════════════════════════════
 *
 * Typography:
 *   - Cinzel: Classical serif inspired by Roman inscriptions (Trajan-like)
 *   - Crimson Text: Refined serif with Garamond/Bembo characteristics
 *
 * Design Philosophy:
 *   - Classical proportions and restraint
 *   - Let the science speak through the visualization
 *   - Minimal interface, maximum clarity
 *
 * Author: Omar Chishti
 * Year: 2023
 */

/* ─────────────────────────────────────────────────────────────────────────
   BASE STYLES
   ───────────────────────────────────────────────────────────────────────── */

:not(:defined) > * {
  display: none;
}

html {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: 'Crimson Text', Georgia, serif;
  background-color: #fafafa;
  transition: background 0.5s ease, color 0.5s ease;
}

/* ─────────────────────────────────────────────────────────────────────────
   HEADER: Classical typography and refined presentation
   ───────────────────────────────────────────────────────────────────────── */

#page-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to bottom, #2c2c2c 0%, #1a1a1a 100%);
  color: #f5f5f5;
  padding: 12px 24px 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

#page-header h1 {
  margin: 0;
  font-family: 'Cinzel', serif;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-align: center;
  color: #f5f5f5;
}

#page-header .subtitle {
  margin: 4px 0 0 0;
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 13px;
  font-weight: 400;
  font-style: italic;
  text-align: center;
  color: rgba(245, 245, 245, 0.75);
  letter-spacing: 0.3px;
}

#page-header .author {
  margin: 3px 0 0 0;
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 11px;
  font-weight: 400;
  text-align: center;
  color: rgba(245, 245, 245, 0.6);
  letter-spacing: 0.2px;
}

#page-header .author a {
  color: rgba(245, 245, 245, 0.8);
  text-decoration: none;
  border-bottom: 1px solid rgba(245, 245, 245, 0.3);
  transition: all 0.2s ease;
}

#page-header .author a:hover {
  color: #fff;
  border-bottom-color: rgba(245, 245, 245, 0.6);
}

/* ─────────────────────────────────────────────────────────────────────────
   MODAL: Information dialog with classical typography
   ───────────────────────────────────────────────────────────────────────── */

.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.75);
  animation: fadeIn 0.3s ease;
}

.modal.active {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-content {
  background-color: #fafafa;
  border-radius: 4px;
  padding: 32px 36px;
  max-width: 520px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.4);
  animation: slideUp 0.3s ease;
  position: relative;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.dark-mode .modal-content {
  background-color: #1a1a1a;
  color: #e5e5e5;
  border-color: rgba(255, 255, 255, 0.1);
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 20px;
  font-size: 28px;
  font-weight: 300;
  color: #888;
  background: none;
  border: none;
  cursor: pointer;
  line-height: 1;
  padding: 0;
  width: 32px;
  height: 32px;
  transition: color 0.2s ease;
}

.modal-close:hover {
  color: #333;
}

.dark-mode .modal-close {
  color: #999;
}

.dark-mode .modal-close:hover {
  color: #fff;
}

.modal-content h2 {
  margin: 0 0 20px 0;
  font-family: 'Cinzel', serif;
  font-size: 22px;
  color: #2c2c2c;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.dark-mode .modal-content h2 {
  color: #f5f5f5;
}

.modal-content h3 {
  margin: 20px 0 10px 0;
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 17px;
  color: #333;
  font-weight: 600;
}

.modal-content h4 {
  margin: 14px 0 8px 0;
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 15px;
  color: #555;
  font-weight: 600;
}

.dark-mode .modal-content h3 {
  color: #e5e5e5;
}

.dark-mode .modal-content h4 {
  color: #ccc;
}

.modal-content section {
  margin-bottom: 18px;
}

.modal-content p {
  font-family: 'Crimson Text', Georgia, serif;
  line-height: 1.6;
  margin: 8px 0;
  font-size: 15px;
}

.modal-content ul {
  font-family: 'Crimson Text', Georgia, serif;
  line-height: 1.7;
  margin: 8px 0;
  padding-left: 24px;
  font-size: 15px;
}

.modal-content kbd {
  font-family: 'Monaco', 'Courier New', monospace;
  font-size: 13px;
  padding: 2px 6px;
  background-color: #e8e8e8;
  border: 1px solid #ccc;
  border-radius: 3px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
}

.dark-mode .modal-content kbd {
  background-color: #2a2a2a;
  border-color: #444;
  color: #e5e5e5;
}

.modal-content a {
  color: #2c2c2c;
  text-decoration: underline;
  font-weight: 500;
  transition: color 0.2s ease;
}

.modal-content a:hover {
  color: #000;
}

.dark-mode .modal-content a {
  color: #d5d5d5;
}

.dark-mode .modal-content a:hover {
  color: #fff;
}

.dark-mode .modal-content p[style*="Monaco"] {
  background-color: #2a2a2a !important;
  border-left-color: #e5e5e5 !important;
  color: #e5e5e5;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ─────────────────────────────────────────────────────────────────────────
   MODEL VIEWER: Primary 3D visualization canvas
   ───────────────────────────────────────────────────────────────────────── */

model-viewer {
  width: 100%;
  height: 100%;
  background-color: #ffffff;
  /* Account for fixed header height - creates breathing room */
  margin-top: 58px;
}

/* Progress Bar */
.progress-bar {
  display: block;
  width: 33%;
  height: 10%;
  max-height: 2%;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate3d(-50%, -50%, 0);
  border-radius: 25px;
  box-shadow: 0px 3px 10px 3px rgba(0, 0, 0, 0.5), 0px 0px 5px 1px rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.9);
  background-color: rgba(0, 0, 0, 0.5);
}

.progress-bar.hide {
  visibility: hidden;
  transition: visibility 0.3s;
}

.update-bar {
  background-color: rgba(255, 255, 255, 0.9);
  width: 0%;
  height: 100%;
  border-radius: 25px;
  float: left;
  transition: width 0.3s;
}

/* ─────────────────────────────────────────────────────────────────────────
   CONTROL PANEL: Tract selection and viewing options
   ───────────────────────────────────────────────────────────────────────── */

#controls {
  background-color: rgba(250, 250, 250, 0.97);
  color: #2c2c2c;
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 14px 18px;
  border-radius: 4px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(0, 0, 0, 0.08);
  z-index: 100;
  pointer-events: auto;
  min-width: 300px;
  max-width: 420px;
  transition: all 0.3s ease;
}

#controls label {
  font-family: 'Crimson Text', Georgia, serif;
  color: #2c2c2c;
  font-size: 14px;
  font-weight: 600;
  margin-right: 6px;
}

#controls select {
  background-color: #fff;
  color: #2c2c2c;
  border: 1px solid #ccc;
  padding: 8px 12px;
  border-radius: 3px;
  font-size: 14px;
  font-family: 'Crimson Text', Georgia, serif;
  cursor: pointer;
  width: 100%;
  margin-top: 4px;
  transition: all 0.2s ease;
}

#controls select:hover {
  border-color: #888;
  background-color: #fafafa;
}

#controls select:focus {
  outline: 2px solid #2c2c2c;
  border-color: #2c2c2c;
  outline-offset: 0;
}

#controls optgroup {
  font-family: 'Cinzel', serif;
  font-weight: 600;
  font-size: 13px;
  color: #2c2c2c;
  font-style: normal;
  padding: 4px 0;
}

#controls option {
  font-family: 'Crimson Text', Georgia, serif;
  font-weight: 400;
  padding: 4px 8px;
}

#controls-checkboxes {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: row;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
}

#controls-checkboxes label {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  margin: 0;
  white-space: nowrap;
}

#controls input[type="checkbox"] {
  margin-left: 6px;
  cursor: pointer;
  width: 15px;
  height: 15px;
  accent-color: #2c2c2c;
}

#info-button {
  background-color: transparent;
  color: #666;
  border: 1px solid #ccc;
  padding: 6px;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
}

#info-button:hover {
  background-color: #f5f5f5;
  border-color: #2c2c2c;
  color: #2c2c2c;
}

#info-button:active {
  transform: scale(0.96);
}

.dark-mode #controls {
  background-color: rgba(26, 26, 26, 0.97);
  color: #e5e5e5;
  border-color: rgba(255, 255, 255, 0.1);
}

.dark-mode #controls label {
  color: #e5e5e5;
}

.dark-mode #controls select {
  background-color: #2a2a2a;
  color: #e5e5e5;
  border-color: #444;
}

.dark-mode #controls select:hover {
  border-color: #666;
  background-color: #333;
}

.dark-mode #controls select:focus {
  outline-color: #e5e5e5;
  border-color: #e5e5e5;
}

.dark-mode #controls optgroup {
  color: #e5e5e5;
}

.dark-mode #controls option {
  color: #e5e5e5;
}

.dark-mode #controls-checkboxes {
  border-top-color: rgba(255, 255, 255, 0.1);
}

.dark-mode #controls input[type="checkbox"] {
  accent-color: #e5e5e5;
}

.dark-mode #info-button {
  color: #aaa;
  border-color: #555;
}

.dark-mode #info-button:hover {
  background-color: #333;
  border-color: #e5e5e5;
  color: #e5e5e5;
}

/* Dark Mode */
.dark-mode {
  background-color: #000;
  color: white;
}

.dark-mode model-viewer {
  background-color: #000;
}

.dark-mode #controls {
  background-color: #222;
  color: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.dark-mode #controls label {
  color: white;
}

.dark-mode #controls select {
  background-color: #333;
  color: white;
  border: 1px solid #555;
}

.dark-mode #controls select:hover {
  border-color: #4285f4;
}

.dark-mode #controls-checkboxes {
  border-top-color: #444;
}

/* AR Button */
#ar-button {
  background-image: url(ar_icon.png);
  background-repeat: no-repeat;
  background-size: 20px 20px;
  background-position: 12px 50%;
  background-color: #fff;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  bottom: 16px;
  padding: 0px 16px 0px 40px;
  font-family: Roboto Regular, Helvetica Neue, sans-serif;
  font-size: 14px;
  color: #4285f4;
  height: 36px;
  line-height: 36px;
  border-radius: 18px;
  border: 1px solid #DADCE0;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

#ar-button:active {
  background-color: #E8EAED;
}

#ar-button:focus {
  outline: none;
}

#ar-button:focus-visible {
  outline: 1px solid #4285f4;
}

/* AR Prompt Animations */
@keyframes circle {
  from { transform: translateX(-50%) rotate(0deg) translateX(50px) rotate(0deg); }
  to   { transform: translateX(-50%) rotate(360deg) translateX(50px) rotate(-360deg); }
}

@keyframes elongate {
  from { transform: translateX(100px); }
  to   { transform: translateX(-100px); }
}

model-viewer > #ar-prompt {
  position: absolute;
  left: 50%;
  bottom: 60px;
  animation: elongate 2s infinite ease-in-out alternate;
  display: none;
}

model-viewer[ar-status="session-started"] > #ar-prompt {
  display: block;
}

model-viewer > #ar-prompt > img {
  animation: circle 4s linear infinite;
}

/* Responsive Design */
@media only screen and (max-width: 800px) {
  #page-header {
    padding: 10px 16px 8px;
  }

  #page-header h1 {
    font-size: 19px;
  }

  #page-header .subtitle {
    font-size: 11px;
  }

  #page-header .author {
    font-size: 10px;
  }

  model-viewer {
    margin-top: 52px;
  }

  #controls {
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 20px);
    max-width: 350px;
    min-width: auto;
    top: 12px;
  }

  #controls label {
    font-size: 13px;
  }

  #controls select {
    font-size: 13px;
  }

  #controls-checkboxes {
    flex-wrap: wrap;
    gap: 8px;
  }

  .modal-content {
    padding: 20px;
    max-height: 85vh;
  }

  .modal-content h2 {
    font-size: 22px;
  }

  .modal-content h3 {
    font-size: 18px;
  }
}

/* Accessibility */
.js-focus-visible :focus:not(.focus-visible) {
  outline: none;
}

.js-focus-visible .focus-visible {
  outline: 2px solid #4285f4;
  outline-offset: 2px;
}
