:root {
  --bg: #121417;
  --panel-bg: #1a1e24;
  --card-bg: #21262d;
  --border: #30363d;
  --text: #c9d1d9;
  --text-dim: #8b949e;
  --link: #58a6ff;
  --link-hover: #79c0ff;
  --flash: #f0883e;

  /* Theme Accents */
  --bus-accent: #7ee787;
  --bus-border: #234d31;
  --duck-accent: #d2a8ff;
  --duck-border: #5a2850;
  --duck-badge-bg: #3d1f3b;
  --fx-accent: #56d364;
  --fx-border: #234d31;
  --rtpc-accent: #e3b341;
  --rtpc-border: #594419;
  --props-accent: #58a6ff;
  --props-border: #2c4263;
}

* { 
  box-sizing: border-box; 
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 24px;
  font-size: 15px; /* Bumped base font size */
  line-height: 1.5;
  user-select: text;
  -webkit-user-select: text;
  -webkit-tap-highlight-color: transparent;
}

/* Base SVGs */
.svg-icon {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

.icon-brand { width: 26px; height: 26px; stroke: #58a6ff; }
.icon-sm { width: 14px; height: 14px; }
.icon-duck { stroke: #d2a8ff; }
.icon-shield { stroke: #ff7b72; }
.icon-fx { stroke: #56d364; }
.icon-rtpc { stroke: #e3b341; }
.icon-bus { stroke: #7ee787; }
.icon-file { stroke: #79c0ff; }

header {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 22px;
  margin-bottom: 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
}

.title-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

h1 {
  margin: 0;
  font-size: 1.45rem;
  color: #fff;
  letter-spacing: -0.3px;
}

.status-pill {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 14px;
  border: 1px solid var(--border);
}

.status-pill.loading { background: #2d2613; color: #e3b341; border-color: #594419; }
.status-pill.ready { background: #162c20; color: #56d364; border-color: #234d31; }
.status-pill.error { background: #3d1618; color: #f85149; border-color: #671e21; }

.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.btn-group {
  display: flex;
  gap: 8px;
}

.search-box {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.search-box .svg-icon {
  position: absolute;
  left: 12px;
  stroke: var(--text-dim);
}

input#search {
  background: #0d1117;
  border: 1px solid var(--border);
  color: #fff;
  padding: 8px 14px 8px 36px;
  border-radius: 6px;
  min-width: 260px;
  font-size: 14px;
}

input#search:focus {
  outline: 1px solid var(--link);
  border-color: var(--link);
}

button {
  background: #21262d;
  border: 1px solid var(--border);
  color: #c9d1d9;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  touch-action: manipulation;
}

button:hover { background: #30363d; }
button:active { background: #1b1f24; }

/* Bus Node Wrapper */
details.bus-node {
  margin: 8px 0;
  padding-left: 0;
  border-left: none;
}

/* Continuous Hierarchy Line */
.bus-contents { 
  margin-left: 5px;
  padding-left: 19px; 
  border-left: 2px solid var(--border);
  margin-top: 6px; 
}

/* Universal Expanding Carets */
summary.bus-header,
details.section-details > summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  position: relative;
  margin: 5px 0;
  user-select: none;
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
  min-height: 34px;
}

summary.bus-header::-webkit-details-marker,
details.section-details > summary::-webkit-details-marker { 
  display: none; 
}

summary.bus-header::before,
details.section-details > summary::before {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 7px solid var(--text-dim);
  margin-right: 4px;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

details[open] > summary.bus-header::before,
details[open] > summary::before {
  transform: rotate(90deg);
}

/* Bus Header Card */
.bus-card {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  background: #0d1117;
  border: 1px solid var(--bus-border);
  padding: 7px 16px;
  border-radius: 6px;
  transition: all 0.2s ease;
}

summary.bus-header:hover .bus-card {
  background: #162c20;
  border-color: var(--bus-accent);
}

.bus-name { font-weight: 600; color: var(--bus-accent); font-size: 14.5px; }
.bus-id { color: var(--text-dim); font-size: 13px; }

details.section-details { margin: 8px 0; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.badge-duck { background: var(--duck-badge-bg); color: var(--duck-accent); border: 1px solid var(--duck-border); }
.badge-fx { background: #162c20; color: #56d364; border: 1px solid #234d31; }
.badge-rtpc { background: #342813; color: #e3b341; border: 1px solid #594419; }
.badge-props { background: #1c2738; color: #58a6ff; border: 1px solid #2c4263; }
.badge-files { background: #19232d; color: #79c0ff; border: 1px solid #28415d; }
.badge-bypassed { color: #f85149; font-weight: bold; font-size: 11px; }

.badge-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.badge-attenuation { background: #1a273a; color: #79c0ff; border: 1px solid #2f4b71; }
.badge-interp { font-size: 11px; color: #a5d6ff; background: rgba(88, 166, 255, 0.12); padding: 2px 6px; border-radius: 4px; }

/* Jump Link */
a.jump-link {
  color: var(--link);
  text-decoration: underline;
  cursor: pointer;
  font-weight: 500;
}
a.jump-link:hover { color: var(--link-hover); }
.meta { color: var(--text-dim); font-size: 13px; }
.text-danger { color: #ff7b72; }

.targeted-flash {
  outline: 2px solid var(--flash) !important;
  background: rgba(240, 136, 62, 0.25) !important;
  box-shadow: 0 0 12px rgba(240, 136, 62, 0.6);
}

.empty-prompt {
  padding: 48px;
  text-align: center;
  color: var(--text-dim);
  border: 2px dashed var(--border);
  border-radius: 8px;
  font-size: 15px;
}

/* Window Boxes */
.boxes-container {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding-left: 20px;
  margin: 8px 0 10px 0;
}

.window-box {
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  min-width: 280px;
  max-width: 100%;
}

.window-box-title {
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 5px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sub-header-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 10px 0 5px 0;
}

/* Theme Accents */
.window-box.box-duck .window-box-title { color: var(--duck-accent); }
.window-box.box-duck { border-color: var(--duck-border); }

.window-box.box-props .window-box-title { color: var(--props-accent); }
.window-box.box-props { border-color: var(--props-border); }

.window-box.box-fx .window-box-title { color: var(--fx-accent); }
.window-box.box-fx { border-color: var(--fx-border); }

.window-box.box-rtpc .window-box-title { color: var(--rtpc-accent); }
.window-box.box-rtpc { border-color: var(--rtpc-border); }

/* Parameter & Curve Tables */
.fx-param-table, .curve-table {
  border-collapse: collapse;
  font-size: 13px;
  width: 100%;
}

.fx-param-table tr:nth-child(even), .curve-table tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

.fx-param-table td, .curve-table td, .curve-table th {
  padding: 4px 10px;
  border-bottom: 1px solid #1e2228;
}

.curve-table th {
  text-align: left;
  color: var(--text-dim);
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}

.fx-param-table td.param-name {
  color: #8b949e;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  white-space: nowrap;
  padding-right: 20px;
}

.fx-param-table td.param-val code, .curve-table td code {
  color: #79c0ff;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-weight: 600;
  white-space: nowrap;
}

.fx-driven {
  font-size: 13px;
  color: #e3b341;
  margin-bottom: 8px;
}

.game-param-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #252012;
  color: #e3b341;
  border: 1px solid #594419;
  padding: 2px 9px;
  border-radius: 12px;
  font-size: 12px;
  margin-top: 2px;
}

/* File References */
ul.file-list {
  list-style: none;
  padding-left: 20px;
  margin: 8px 0 10px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

ul.file-list li {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 6px 12px;
  width: fit-content;
  max-width: 100%;
}

.file-path {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  word-break: break-all;
}

.file-name {
  color: #e6edf3;
  font-weight: 500;
}

/* =======================================================
   Mobile & Small Screen Optimizations (< 768px)
   ======================================================= */
@media (max-width: 768px) {
  body {
    padding: 12px;
    font-size: 14.5px;
  }

  header {
    padding: 14px;
    margin-bottom: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(8px);
    background: rgba(26, 30, 36, 0.94);
  }

  .title-area {
    width: 100%;
    justify-content: space-between;
  }

  h1 {
    font-size: 1.2rem;
  }

  .controls {
    width: 100%;
    flex-direction: column;
    gap: 10px;
  }

  .search-box {
    width: 100%;
  }

  input#search {
    width: 100%;
    min-width: 100%;
    font-size: 16px; /* Prevents auto-zoom on iOS */
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .btn-group {
    width: 100%;
    display: flex;
  }

  .btn-group button {
    flex: 1;
    justify-content: center;
    padding: 10px 8px;
  }

  /* Tighten indentation so nested busses don't push off-screen */
  .bus-contents {
    margin-left: 2px;
    padding-left: 9px; /* Halved from desktop */
  }

  .boxes-container {
    padding-left: 4px;
    gap: 8px;
  }

  .window-box {
    width: 100%;
    min-width: 100%;
    overflow-x: auto; /* Scroll horizontally if tables have long values */
  }

  .bus-card {
    padding: 6px 10px;
    font-size: 13.5px;
    gap: 6px;
  }

  .badge-pill {
    padding: 1px 6px;
    font-size: 10px;
  }

  ul.file-list {
    padding-left: 4px;
  }

  ul.file-list li {
    width: 100%;
  }
}