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

:root {
  --bg-dark: #1a1a1d;
  --bg-panel: #242428;
  --bg-card: #2d2d32;
  --gold: #d4a843;
  --gold-light: #e8c96a;
  --teal: #2a9d8f;
  --teal-dark: #1e7268;
  --cream: #f0e6d3;
  --red: #e63946;
  --green: #2a9d8f;
  --text: #e8e8e8;
  --text-dim: #9a9a9f;
  --mono: 'IBM Plex Mono', monospace;
  --sans: 'IBM Plex Sans', sans-serif;
  --radius: 8px;
}

html {
  font-size: 14px;
}

body {
  font-family: var(--sans);
  background: var(--bg-dark);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Header */
#header {
  background: linear-gradient(135deg, #1a1a1d 0%, #2d2d32 50%, #1a1a1d 100%);
  border-bottom: 2px solid var(--gold);
  padding: 1.2rem 2rem;
  text-align: center;
  position: relative;
}

#header::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
}

.header-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
}

.slug-icon {
  font-size: 2rem;
  animation: slugBounce 3s ease-in-out infinite;
}

@keyframes slugBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

h1 {
  font-family: var(--mono);
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: -0.02em;
}

.subtitle {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--teal);
  margin-top: 0.2rem;
  font-weight: 500;
}

.tagline {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 0.3rem;
  font-style: italic;
}

/* Main Layout */
#main {
  display: flex;
  flex: 1;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  padding: 1rem;
  gap: 1rem;
}

.left-column, .right-column {
  flex: 1;
  min-width: 0;
}

/* Panels */
.panel {
  background: var(--bg-panel);
  border-radius: var(--radius);
  border: 1px solid #3a3a40;
  overflow: hidden;
}

.drawing-panel {
  display: flex;
  flex-direction: column;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.6rem 0.8rem;
  background: var(--bg-card);
  border-bottom: 1px solid #3a3a40;
  flex-wrap: wrap;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toolbar label {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.toolbar input[type="range"] {
  width: 70px;
  accent-color: var(--gold);
  height: 4px;
}

.toolbar button {
  background: var(--bg-dark);
  border: 1px solid #4a4a50;
  color: var(--text);
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.15s;
}

.toolbar button:hover {
  background: var(--gold);
  color: var(--bg-dark);
  border-color: var(--gold);
}

.toolbar select {
  background: var(--bg-dark);
  border: 1px solid #4a4a50;
  color: var(--text);
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  font-size: 0.72rem;
  font-family: var(--mono);
}

/* Canvas */
.canvas-wrapper {
  position: relative;
  background: #faf8f0;
  aspect-ratio: 1;
  max-height: 500px;
}

#drawCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

/* Quick Glyphs */
.quick-glyphs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  padding: 0.6rem 0.8rem;
  background: var(--bg-card);
  border-top: 1px solid #3a3a40;
}

.quick-glyphs button {
  width: 32px;
  height: 32px;
  background: var(--bg-dark);
  border: 1px solid #4a4a50;
  color: var(--gold);
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.15s;
}

.quick-glyphs button:hover {
  background: var(--gold);
  color: var(--bg-dark);
  border-color: var(--gold);
  transform: scale(1.1);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  border: 1px solid #3a3a40;
  border-bottom: none;
  overflow-x: auto;
  scrollbar-width: thin;
}

.tab {
  padding: 0.6rem 0.9rem;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab:hover {
  color: var(--text);
  background: rgba(212, 168, 67, 0.08);
}

.tab.active {
  color: var(--gold);
  border-bottom-color: var(--gold);
  background: rgba(212, 168, 67, 0.12);
}

/* Tab Content */
.tab-content {
  background: var(--bg-panel);
  border: 1px solid #3a3a40;
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  min-height: 500px;
  max-height: 600px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--gold) var(--bg-dark);
}

.tab-panel {
  display: none;
  padding: 1rem;
  animation: fadeIn 0.25s ease;
}

.tab-panel.active {
  display: block;
}

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

/* Root Eligibility Table */
.root-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.75rem;
  margin-bottom: 1rem;
}

.root-table th {
  background: var(--teal-dark);
  color: white;
  padding: 0.4rem 0.5rem;
  text-align: center;
  font-weight: 600;
}

.root-table td {
  padding: 0.35rem 0.5rem;
  text-align: center;
  border-bottom: 1px solid #3a3a40;
}

.root-table tr:nth-child(even) td {
  background: rgba(255,255,255,0.03);
}

.root-table tr.highlight td {
  background: rgba(212, 168, 67, 0.2);
}

.root-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.root-dot.red { background: var(--red); }
.root-dot.green { background: var(--green); }

/* Class diagrams */
.class-diagrams {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-top: 1rem;
}

.class-diagram {
  background: var(--bg-card);
  border-radius: 4px;
  padding: 0.3rem;
  border: 1px solid #3a3a40;
  text-align: center;
}

.class-diagram canvas {
  width: 100%;
  aspect-ratio: 1;
  display: block;
}

.class-diagram .class-label {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--gold);
  margin-top: 0.2rem;
  font-weight: 600;
}

/* Winding panel */
.winding-canvas-wrap {
  position: relative;
  background: #faf8f0;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.8rem;
}

.winding-canvas-wrap canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
}

.formula-box {
  background: var(--bg-card);
  border: 1px solid #3a3a40;
  border-radius: 4px;
  padding: 0.6rem 0.8rem;
  margin-bottom: 0.6rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--cream);
  line-height: 1.7;
}

.formula-box .formula-title {
  color: var(--teal);
  font-weight: 600;
  margin-bottom: 0.3rem;
  font-size: 0.75rem;
}

.formula-highlight {
  color: var(--gold);
  font-weight: 600;
}

/* Bands panel */
.bands-controls {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}

.bands-controls label {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}

.bands-controls input[type="range"] {
  flex: 1;
  accent-color: var(--gold);
}

.bands-display {
  display: flex;
  gap: 0.8rem;
}

.bands-display canvas {
  flex: 1;
  border-radius: 4px;
  background: #faf8f0;
}

/* Bounding panel */
.bounding-controls {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}

.bounding-controls button {
  background: var(--bg-card);
  border: 1px solid #4a4a50;
  color: var(--text);
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.72rem;
  transition: all 0.15s;
}

.bounding-controls button.active {
  background: var(--teal-dark);
  border-color: var(--teal);
  color: white;
}

/* Dilation panel */
.dilation-controls {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}

.dilation-controls label {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}

.dilation-controls input[type="range"] {
  flex: 1;
  accent-color: var(--gold);
}

.dilation-canvases {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.dilation-canvases .dil-wrap {
  flex: 1;
  text-align: center;
}

.dilation-canvases .dil-wrap span {
  display: block;
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-top: 0.3rem;
}

.dilation-canvases canvas {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 4px;
  background: #faf8f0;
}

/* Bottom Bar */
.bottom-bar {
  display: flex;
  gap: 1.5rem;
  padding: 0.6rem 2rem;
  background: var(--bg-card);
  border-top: 1px solid #3a3a40;
  justify-content: center;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.stat-label {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--gold);
  font-weight: 600;
}

.stat-badges {
  display: flex;
  gap: 0.2rem;
}

.class-badge {
  display: inline-block;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 0.6rem;
  font-weight: 700;
  color: white;
}

.class-badge.A { background: #555; }
.class-badge.B { background: #e63946; }
.class-badge.C { background: #457b9d; }
.class-badge.D { background: #2a9d8f; }
.class-badge.E { background: #e9c46a; color: #1a1a1d; }
.class-badge.F { background: #f4a261; color: #1a1a1d; }
.class-badge.G { background: #264653; }
.class-badge.H { background: #6a4c93; }

/* Footer */
#footer {
  text-align: center;
  padding: 0.8rem 1rem;
  font-size: 0.7rem;
  color: var(--text-dim);
  border-top: 1px solid #2a2a30;
}

#footer a {
  color: var(--gold);
  text-decoration: none;
}

#footer a:hover {
  text-decoration: underline;
}

.sep {
  margin: 0 0.4rem;
  opacity: 0.4;
}

.slug-footer {
  font-style: italic;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
  background: #4a4a50;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--gold);
}

/* Tooltip */
.tooltip {
  position: absolute;
  background: #1a1a1dee;
  color: var(--cream);
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.65rem;
  border: 1px solid var(--gold);
  pointer-events: none;
  z-index: 100;
  max-width: 250px;
  line-height: 1.4;
}

/* Section headers inside tabs */
.section-title {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--teal);
  font-weight: 600;
  margin-bottom: 0.6rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid #3a3a40;
}

.info-text {
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.6;
  margin-bottom: 0.6rem;
}

.hex-ref {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--gold);
  text-align: center;
  margin-top: 0.5rem;
}

/* Click instruction */
.click-instruction {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--teal);
  text-align: center;
  padding: 0.4rem;
  background: rgba(42, 157, 143, 0.1);
  border-radius: 4px;
  margin-bottom: 0.6rem;
}

/* Responsive */
@media (max-width: 900px) {
  #main {
    flex-direction: column;
  }
  .left-column, .right-column {
    flex: none;
    width: 100%;
  }
  .class-diagrams {
    grid-template-columns: repeat(2, 1fr);
  }
  .canvas-wrapper {
    max-height: none;
  }
  h1 {
    font-size: 1.6rem;
  }
  .tab {
    font-size: 0.62rem;
    padding: 0.5rem 0.6rem;
  }
}

@media (max-width: 500px) {
  #main {
    padding: 0.5rem;
  }
  .class-diagrams {
    grid-template-columns: repeat(2, 1fr);
  }
  .bottom-bar {
    gap: 0.6rem;
    padding: 0.5rem 0.8rem;
  }
  h1 {
    font-size: 1.3rem;
  }
}