/* ==========================================================================
   CAUCHY THEME -- 2D Finite Element Structural Solver
   Dark-terminal aesthetic with structural amber accents.
   ========================================================================== */

:root {
  --bg-primary:   #0d1117;
  --bg-card:      #161b22;
  --bg-canvas:    #0a0e14;
  --border:       #21262d;
  --border-light: #30363d;

  --amber:        #ffb347;
  --amber-dim:    #cc8a2e;
  --amber-bright: #ffc870;
  --cyan:         #00d4ff;
  --cyan-dim:     #0099cc;
  --orange:       #ff6b35;
  --green:        #39d353;
  --red:          #ff4757;

  --fg:           #c9d1d9;
  --fg-dim:       #8b949e;
  --fg-muted:     #484f58;
}

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

body {
  background: var(--bg-primary);
  color: var(--fg);
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  line-height: 1.7;
  min-height: 100vh;
  font-size: 15px;
  transition: padding-left 0.25s ease;
}
body.sidebar-open { padding-left: 240px; }

h1 { color: var(--amber); font-size: 1.6em; margin-top: 0; }
h2 { color: var(--orange); font-size: 1.25em; margin: 2em 0 0.8em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
h3 { color: var(--amber); font-size: 1.05em; margin: 1.5em 0 0.5em; }
h4 { color: var(--fg); font-size: 0.95em; margin: 1.2em 0 0.4em; }
p { margin-bottom: 1em; font-size: 0.95em; color: var(--fg-dim); }
a { color: var(--amber); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--amber-bright); }
code { background: rgba(0,0,0,0.3); padding: 2px 6px; border-radius: 4px; color: var(--orange); font-size: 0.9em; }
pre code { background: none; padding: 0; }
ul, ol { padding-left: 1.5rem; margin-bottom: 1rem; }
li { margin-bottom: 0.3rem; font-size: 0.9em; color: var(--fg-dim); }
strong { color: var(--fg); }
img { max-width: 100%; border-radius: 4px; border: 1px solid var(--border); }

/* --- Sidebar --- */
.sidebar {
  position: fixed;
  left: 0; top: 0;
  width: 240px; height: 100vh;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(-240px);
  transition: transform 0.25s ease;
}
.sidebar.open { transform: translateX(0); }

.sidebar-toggle {
  display: block;
  position: fixed;
  top: 10px; left: 10px;
  z-index: 200;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--fg);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 4px;
  font-family: inherit;
}

.sidebar-brand {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand a {
  color: var(--amber);
  font-size: 0.78em;
  font-weight: 700;
  text-decoration: none;
  line-height: 1.3;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 0 24px;
  overflow-y: auto;
}
.nav-section { margin-bottom: 20px; }
.nav-heading {
  padding: 4px 20px;
  font-size: 0.55em;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 2px;
}
.nav-item {
  display: block;
  padding: 6px 20px 6px 28px;
  font-size: 0.75em;
  color: var(--fg-dim);
  text-decoration: none;
  transition: all 0.15s;
  border-left: 2px solid transparent;
}
.nav-item:hover {
  color: var(--amber);
  background: rgba(255, 179, 71, 0.05);
  border-left-color: var(--amber);
}
.nav-item.active {
  color: var(--amber);
  border-left-color: var(--amber);
  background: rgba(255, 179, 71, 0.08);
}

/* --- Main --- */
.main-content {
  max-width: 1000px;
  margin: 0 auto;
  padding: 2.5rem 30px 4rem;
}

.hero {
  text-align: center;
  padding: 2rem 0 1.5rem;
}
.hero h1 {
  font-size: clamp(1.4rem, 3.5vw, 2.2rem);
  font-weight: 700;
  color: var(--amber);
  margin: 0;
}
.hero h1 .accent-orange { color: var(--orange); }
.hero .subtitle {
  max-width: 720px;
  margin: 0.75rem auto 0;
  font-size: 0.8em;
  color: var(--fg-dim);
  line-height: 1.7;
}
.hero .status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 4px 14px;
  border: 1px solid var(--amber-dim);
  border-radius: 4px;
  font-size: 0.65em;
  color: var(--amber);
  background: rgba(255, 179, 71, 0.06);
}
.hero .status-badge .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--amber);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* --- Section intro --- */
.section-intro {
  max-width: 780px;
  margin: 0 auto 1.2rem;
  font-size: 0.85em;
  color: var(--fg-dim);
  line-height: 1.7;
}

/* --- Case grid --- */
.case-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 1.5rem 0;
}
@media (max-width: 900px) { .case-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .case-grid { grid-template-columns: 1fr; } }

.case-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  transition: border-color 0.2s, transform 0.15s;
  text-decoration: none;
  color: inherit;
}
.case-card:hover {
  border-color: var(--amber-dim);
  transform: translateY(-2px);
}
.case-thumb {
  width: 100%;
  height: 140px;
  object-fit: cover;
  background: var(--bg-canvas);
}
.case-info {
  padding: 12px 14px;
}
.case-info h3 {
  color: var(--amber);
  font-size: 0.85em;
  margin: 0 0 6px;
}
.case-info p {
  font-size: 0.72em;
  color: var(--fg-dim);
  margin: 0 0 8px;
  line-height: 1.5;
}
.case-link {
  font-size: 0.68em;
  color: var(--amber);
}

/* --- Feature grid --- */
.feature-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 1.5rem 0;
}
@media (max-width: 700px) { .feature-grid { grid-template-columns: 1fr; } }

.feature-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
}
.feature-item h4 {
  color: var(--amber);
  font-size: 0.82em;
  margin: 0 0 6px;
}
.feature-item p {
  font-size: 0.72em;
  color: var(--fg-dim);
  margin: 0;
  line-height: 1.5;
}

/* --- Callout --- */
.callout {
  background: rgba(255, 179, 71, 0.06);
  border-left: 3px solid var(--amber);
  padding: 12px 16px;
  margin: 1.5rem 0;
  border-radius: 0 4px 4px 0;
}
.callout p {
  font-size: 0.82em;
  color: var(--fg-dim);
  margin: 0;
}

/* --- Tables --- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.82em;
}
th {
  background: var(--bg-card);
  color: var(--amber);
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--fg-dim);
}
tr:hover td { background: rgba(255, 179, 71, 0.03); }

/* --- Equation box --- */
.eq-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px 20px;
  margin: 1rem 0;
  overflow-x: auto;
  text-align: center;
}

/* --- Module table --- */
.module-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
}
.module-table th {
  background: var(--bg-card);
  color: var(--amber);
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.82em;
}
.module-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.82em;
  color: var(--fg-dim);
}

/* --- Case Overview Table --- */
.overview-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.78em;
}
.overview-table th {
  background: var(--bg-card);
  color: var(--amber);
  text-align: left;
  padding: 6px 10px;
  border-bottom: 2px solid var(--border-light);
  white-space: nowrap;
}
.overview-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--fg-dim);
}
.overview-table tr:hover td {
  background: rgba(255, 179, 71, 0.04);
}
.overview-table .case-name {
  color: var(--amber);
  font-weight: 500;
}
.overview-table .tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.85em;
  margin-right: 4px;
}
.overview-table .tag-q4 { background: rgba(0, 212, 255, 0.15); color: var(--cyan); }
.overview-table .tag-q8 { background: rgba(255, 179, 71, 0.15); color: var(--amber); }
.overview-table .tag-bar { background: rgba(57, 211, 83, 0.15); color: var(--green); }
.overview-table .tag-stress { background: rgba(255, 107, 53, 0.12); color: var(--orange); }
.overview-table .tag-strain { background: rgba(255, 71, 87, 0.12); color: var(--red); }
.overview-table .tag-thermal { background: rgba(255, 200, 112, 0.15); color: var(--amber-bright); }

/* --- FEA Viewer --- */
.viewer-container {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  background: var(--bg-canvas);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin: 1.2rem 0;
  z-index: 2;
}

.viewer-container canvas {
  width: 100%;
  height: 100%;
}

/* --- Toolbar --- */
.fea-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  font-size: 0.72em;
}

.fea-toolbar-section {
  display: flex;
  align-items: center;
  gap: 6px;
}

.fea-toolbar-label {
  color: var(--amber);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 0.85em;
  white-space: nowrap;
}

.fea-toolbar-btn {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--fg-dim);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9em;
  transition: all 0.15s;
  white-space: nowrap;
}

.fea-toolbar-btn:hover {
  border-color: var(--amber);
  color: var(--amber);
  background: rgba(255, 179, 71, 0.06);
}

.fea-toolbar-select {
  background: var(--bg-canvas);
  border: 1px solid var(--border-light);
  color: var(--fg-dim);
  padding: 3px 6px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.9em;
  cursor: pointer;
}

.fea-toolbar-select:focus {
  outline: none;
  border-color: var(--amber);
}

.fea-toolbar-toggle {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--fg-muted);
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9em;
  transition: all 0.15s;
}

.fea-toolbar-toggle.active {
  border-color: var(--cyan);
  color: var(--cyan);
  background: rgba(0, 212, 255, 0.08);
}

.fea-toolbar-toggle:hover {
  border-color: var(--cyan-dim);
}

.fea-toolbar-toggles {
  display: flex;
  gap: 4px;
}

.fea-toolbar-slider {
  display: flex;
  align-items: center;
  gap: 6px;
}

.fea-toolbar-slider input[type="range"] {
  width: 100px;
  height: 4px;
  appearance: none;
  background: var(--border-light);
  border-radius: 2px;
  cursor: pointer;
}

.fea-toolbar-slider input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--amber);
  cursor: pointer;
}

.fea-toolbar-value {
  color: var(--fg-dim);
  font-size: 0.9em;
  min-width: 45px;
  text-align: right;
}

/* --- Convergence Chart --- */
.convergence-container {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--bg-canvas);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin: 1.2rem 0;
}

.convergence-container canvas {
  width: 100%;
  height: 100%;
}

/* --- Footer --- */
.site-footer {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.7em;
  color: var(--fg-muted);
}

/* --- Responsive --- */
@media (max-width: 600px) {
  .main-content { padding: 1.5rem 16px 3rem; }
  .hero h1 { font-size: 1.2rem; }
  .fea-toolbar { flex-direction: column; align-items: flex-start; }
  .fea-toolbar-section { width: 100%; }
  .fea-toolbar-slider input[type="range"] { width: 140px; }
}

/* --- Case Hero Image --- */
.case-hero-img {
  width: 100%;
  height: auto;
  max-height: 500px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin: 1rem 0;
  background: var(--bg-canvas);
}

/* --- Viewer Container (legacy, not currently used) --- */
.case-visualization {
  position: relative;
  width: 100%;
  height: 500px;
  margin: 1rem 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.static-fallback {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--bg-canvas);
  z-index: 1;
}

#fea-colorbar-container {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  z-index: 50;
}

/* --- Case Grid Thumbnails --- */
.case-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
  margin: 1.5rem 0;
}

.case-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  transition: border-color 0.2s, transform 0.2s;
}

.case-card:hover {
  border-color: var(--amber);
  transform: translateY(-2px);
}

.case-thumb {
  width: 100%;
  height: 220px;
  overflow: hidden;
  background: var(--bg-canvas);
}

.case-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.case-info {
  padding: 0.6rem;
}

.case-info h3 {
  color: var(--amber);
  font-size: 1rem;
  margin: 0 0 0.5rem;
}

.case-info p {
  color: var(--fg-dim);
  font-size: 0.85em;
  margin: 0 0 0.3rem;
}

.case-link {
  color: var(--amber);
  font-size: 0.8em;
}

/* --- Static Plots Section --- */
.static-plots {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin: 1.5rem 0;
}

.plot-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1rem;
}

.plot-item h3 {
  color: var(--amber);
  font-size: 0.95em;
  margin: 0 0 0.8rem;
}

.plot-item img {
  width: 100%;
  height: auto;
  border-radius: 4px;
  margin-bottom: 0.8rem;
  background: var(--bg-canvas);
}

.plot-item p {
  color: var(--fg-dim);
  font-size: 0.85em;
  margin: 0;
}
