html {
  height: var(--app-height);
  overflow: hidden;
  overscroll-behavior: none;
}

@font-face {
  font-family: 'Fontin'; /* A font by Jos Buivenga (exljbris) -> www.exljbris.com */
  src: url('Fontin.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
}

:root {
  --app-height: 100dvh;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --sidebar-width: 210px;
  --sidebar-current-width: var(--sidebar-width);
  --wave-panel-height: 220px;
  --wave-panel-height-mobile: 220px;
  --wave-panel-current-height: var(--wave-panel-height);
  --wave-panel-gap: 14px;
  --wave-panel-gap-mobile: 8px;
  --scene-min-height: 320px;
  --scene-min-height-mobile: 280px;
}

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

body {
  background: #0A0C11;
  color: #b3abab;
  font-family: 'Courier New', monospace;
  display: flex;
  flex-direction: column;
  height: var(--app-height);
  min-height: var(--app-height);
  overflow: hidden;
  overscroll-behavior: none;
}

#header {
  background: #111318;
  border-bottom: 1px solid #323438;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-shrink: 0;
}

#header .brand {
  display: flex;
  align-items: center;
  gap: 6px;
}

#header .brand .logo-link {
  display: block;
  line-height: 0;
}

#header .brand img {
  width: 28px;
  height: 28px;
  display: block;
  object-fit: contain;
}

#header h1 {
  color: #e90048;
  font-size: 18px;
  letter-spacing: 3px;
  font-family: 'Fontin', 'Times New Roman', serif;
  font-weight: 400;
}

#header h1 .next-word {
  color: #fff;
  letter-spacing: 1px;
  text-decoration: none;
  transition: color 0.15s;
}

#header h1 .next-word:hover {
  color: #e90048;
}

#header .sub {
  font-size: 11px;
  color: #555;
}

#header .badge {
  margin-left: auto;
}

#header .badge a {
  display: block;
  background: #0e1118;
  color: #888;
  border: 1px solid #252830;
  padding: 5px 8px;
  font-family: inherit;
  font-size: 11px;
  text-decoration: none;
  letter-spacing: 0.3px;
  transition: all 0.15s;
}

#header .badge a:hover {
  background: #1a2030;
  color: #fff;
  border-color: #e90048;
}

#main {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

#sidebar {
  width: var(--sidebar-current-width);
  background: #111318;
  border-right: 1px solid #323438;
  padding: 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
}

.sidebar-controls {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#canvas-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.panel-resizer {
  position: relative;
  flex-shrink: 0;
  touch-action: none;
}

.panel-resizer::before {
  content: '';
  position: absolute;
  inset: 0;
  transition: background 0.15s;
}

.panel-resizer.vertical {
  width: 8px;
  cursor: col-resize;
  background: #111318;
}

.panel-resizer.vertical::before {
  left: 3px;
  right: 3px;
  background: #252830;
}

.panel-resizer.horizontal {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 10px;
  cursor: row-resize;
  z-index: 3;
}

.panel-resizer.horizontal::before {
  top: 3px;
  bottom: 3px;
  left: 10px;
  right: 10px;
  background: #252830;
}

.panel-resizer:hover::before,
.panel-resizer.active::before {
  background: #e90048;
}

body.is-resizing-col,
body.is-resizing-col * {
  cursor: col-resize !important;
  user-select: none;
}

body.is-resizing-row,
body.is-resizing-row * {
  cursor: row-resize !important;
  user-select: none;
}

canvas#c {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  touch-action: none;
}

#wave-panel {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: calc(var(--wave-panel-gap) + var(--safe-bottom));
  height: var(--wave-panel-current-height);
  border: 1px solid #252830;
  background: rgba(14, 17, 24, 0.92);
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(4px);
  overflow: hidden;
}

#wave-head {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  grid-template-areas: 'sec tools meta';
  align-items: center;
  column-gap: 10px;
  padding: 12px 10px 7px;
  border-bottom: 1px solid #252830;
}

#wave-head .sec {
  grid-area: sec;
  margin-bottom: 0;
  border-bottom: 0;
  padding-bottom: 0;
}

#wave-tools {
  grid-area: tools;
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
  justify-content: flex-end;
  min-width: 0;
  overflow-x: auto;
  flex-shrink: 0;
}

.wave-trigger-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 2px 0 4px;
  font-size: 10px;
  color: #888;
  white-space: nowrap;
}

.wave-trigger-input {
  width: 68px;
  padding: 4px 6px;
  border: 1px solid #323843;
  background: #0e1118;
  color: #cfd6df;
  font: inherit;
}

.wave-trigger-input::placeholder {
  color: #6c7480;
}

.wave-trigger-input:focus {
  border-color: #e90048;
  outline: none;
}

.wave-trigger-input.invalid {
  border-color: #e90048;
  color: #e90048;
}

.wave-trigger-input:disabled {
  opacity: 0.55;
}

.mini-btn {
  width: auto;
  margin-bottom: 0;
  padding: 4px 7px;
  font-size: 10px;
  text-align: center;
}

#wave-meta {
  grid-area: meta;
  font-size: 10px;
  color: #666;
  letter-spacing: 0.3px;
  min-width: 0;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#wave-tools::-webkit-scrollbar {
  display: none;
}

canvas#wf {
  width: 100%;
  display: block;
  flex: 1;
  min-height: 0;
}

.sec {
  font-size: 10px;
  font-weight: bold;
  color: #e90048;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  border-bottom: 1px solid #1e2128;
  padding-bottom: 3px;
  margin-bottom: 7px;
}

.row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 5px;
  cursor: pointer;
}

.row:hover .lbl {
  color: #fff;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-vessel {
  background: transparent;
  border: 1px solid #444;
}

.dot-cathode {
  background: #b3abab;
}

.dot-pmts {
  background: #0693e3;
}

.dot-sipms {
  background: #00d084;
}

.dot-panels {
  background: #22cc55;
}

.dot-axes {
  background: #666;
  border-radius: 0;
}

.lbl {
  font-size: 11px;
  flex: 1;
}

input[type=checkbox] {
  accent-color: #e90048;
  width: 13px;
  height: 13px;
}

button {
  background: #0e1118;
  color: #888;
  border: 1px solid #252830;
  padding: 5px 8px;
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  margin-bottom: 4px;
  letter-spacing: 0.3px;
  transition: all 0.15s;
}

button:hover {
  background: #1a2030;
  color: #fff;
  border-color: #e90048;
}

button.active {
  background: #1a0810;
  color: #e90048;
  border-color: #e90048;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
  color: #555;
  border-color: #1d2027;
}

button:disabled:hover {
  background: #0e1118;
  color: #555;
  border-color: #1d2027;
}

.button-row {
  display: flex;
  gap: 4px;
}

.button-row button {
  flex: 1;
}

.event-selector-form {
  margin: 4px 0 6px;
}

.event-selector-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 4px;
}

.event-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.event-field span {
  font-size: 9px;
  color: #666;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.event-field input {
  width: 100%;
  background: #0e1118;
  color: #b3abab;
  border: 1px solid #252830;
  padding: 5px 6px;
  font-family: inherit;
  font-size: 11px;
  outline: none;
}

.event-field input:focus {
  border-color: #e90048;
}

.event-field input::placeholder {
  color: #4f5661;
}

.event-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18px;
  gap: 2px;
  align-items: stretch;
}

.event-input-row input {
  min-width: 0;
}

.event-input-row input[type=number] {
  appearance: textfield;
  -moz-appearance: textfield;
}

.event-input-row input[type=number]::-webkit-outer-spin-button,
.event-input-row input[type=number]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.event-stepper {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 2px;
}

.event-step-btn {
  width: 18px;
  min-width: 18px;
  margin: 0;
  padding: 0;
  text-align: center;
  font-size: 8px;
  line-height: 1;
}

.slider-row {
  margin-bottom: 8px;
}

.slider-row .slbl {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: #555;
  margin-bottom: 2px;
}

input[type=range] {
  width: 100%;
  accent-color: #e90048;
}

#ev-info {
  font-size: 10px;
  color: #555;
  line-height: 1.8;
}

#data-status {
  font-size: 10px;
  color: #888;
  line-height: 1.5;
  margin-bottom: 8px;
}

#data-status.error {
  color: #e90048;
}

.sidebar-footer {
  margin-top: auto;
}

.json-format {
  font-size: 9px;
  color: #444;
  line-height: 1.6;
}

.file-input-hidden {
  display: none;
}

#cbwrap {
  position: absolute;
  right: 14px;
  bottom: calc(var(--wave-panel-current-height) + var(--wave-panel-gap) + 14px + var(--safe-bottom));
  --colorbar-height: 140px;
  --colorbar-stack-gap: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--colorbar-stack-gap);
}

#cbwrap canvas {
  border: 1px solid #252830;
  width: 16px;
  height: var(--colorbar-height);
}

#cbwrap .cbgrp {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 6px;
}

#cbwrap .cbttl {
  font-size: 9px;
  color: #666;
  text-align: right;
  margin-bottom: 2px;
  letter-spacing: 0.4px;
}

#cblbls,
#pcblbls,
#scblbls {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: var(--colorbar-height);
  font-size: 9px;
  gap: 6px;
  width: 68px;
  font-size: 10px;
  color: #aaa;
}

.cb-input {
  width: 100%;
  min-width: 0;
  background: rgba(14, 17, 24, 0.96);
  color: #c6c0c0;
  border: 1px solid #2b303b;
  padding: 3px 5px;
  font-family: inherit;
  font-size: 10px;
  line-height: 1.2;
  text-align: right;
  outline: none;
}

.cb-input::placeholder {
  color: #6c7480;
}

.cb-input:focus {
  border-color: #e90048;
}

.cb-input.invalid {
  border-color: #e90048;
  color: #e90048;
}

#dropover {
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 17, 0.88);
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px dashed #e90048;
  pointer-events: none;
}

#dropover.on {
  display: flex;
}

#dropover span {
  color: #e90048;
  font-size: 22px;
  letter-spacing: 3px;
}

#tip {
  position: absolute;
  bottom: calc(var(--wave-panel-current-height) + var(--wave-panel-gap) + 8px + var(--safe-bottom));
  left: 8px;
  font-size: 9px;
  color: #333;
}

#ev-stamp {
  position: absolute;
  top: 10px;
  left: 14px;
  font-size: 11px;
  color: #fff;
  letter-spacing: 0.4px;
  background: rgba(14, 17, 24, 0.78);
  border: 1px solid #252830;
  padding: 6px 10px;
  pointer-events: none;
}

@media (max-height: 760px) {
  #main {
    overflow: hidden;
  }

  #canvas-container {
    min-height: 0;
  }
}

.run-browser {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 4px;
}

.browser-select {
  background: #0e1118;
  color: #b3abab;
  border: 1px solid #323438;
  font-family: inherit;
  font-size: 11px;
  padding: 4px 6px;
  width: 100%;
  cursor: pointer;
  letter-spacing: 0.3px;
}

.browser-select:focus {
  outline: none;
  border-color: #e90048;
}

.browser-select option {
  background: #111318;
}

@media (max-width: 900px) {
  html,
  body {
    position: fixed;
    inset: 0;
    width: 100%;
  }

  #header {
    padding: 6px 10px;
    gap: 8px;
    flex-wrap: nowrap;
  }

  #header h1 {
    font-size: 15px;
    letter-spacing: 1.5px;
  }

  #header .brand img {
    width: 22px;
    height: 22px;
  }

  #header .sub {
    display: none;
  }

  #main {
    flex-direction: column;
    overflow: hidden;
    height: 100%;
  }

  #sidebar {
    width: 100%;
    max-height: min(30vh, 228px);
    border-right: 0;
    border-bottom: 1px solid #323438;
    padding: 8px;
    gap: 8px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  #sidebar::-webkit-scrollbar {
    display: none;
  }

  .sidebar-section-detector,
  .sidebar-section-view,
  .sidebar-section-info,
  .sidebar-section-json {
    display: none;
  }

  #permalink-btn,
  #load-json-btn,
  #demo-event-btn,
  #clear-event-btn {
    display: none;
  }

  #sidebar-resizer,
  #wave-resizer {
    display: none;
  }

  #wave-panel {
    left: 8px;
    right: 8px;
    bottom: calc(var(--wave-panel-gap-mobile) + var(--safe-bottom));
    height: var(--wave-panel-current-height);
    max-height: calc(100% - 16px - var(--safe-bottom));
  }

  #canvas-container {
    flex: 1 1 auto;
    min-height: 0;
  }

  .sec {
    margin-bottom: 5px;
  }

  .event-selector-form {
    margin: 2px 0 4px;
  }

  .event-selector-grid {
    gap: 3px;
    margin-bottom: 3px;
  }

  .event-field span {
    font-size: 8px;
  }

  .event-field input {
    padding: 4px 5px;
    font-size: 10px;
  }

  .event-step-btn {
    font-size: 7px;
  }

  button {
    padding: 4px 7px;
    margin-bottom: 3px;
  }

  #latest-event-btn,
  #prev-event-btn,
  #next-event-btn {
    padding: 10px 12px;
    font-size: 14px;
  }

  #data-status {
    font-size: 9px;
    margin-top: 2px;
    line-height: 1.35;
  }

  #wave-head {
    grid-template-columns: 1fr;
    grid-template-areas:
      'sec'
      'tools';
    row-gap: 4px;
    padding: 4px 6px 5px;
  }

  #wave-tools {
    justify-content: flex-start;
  }

  #wave-meta {
    display: none;
  }

  #cbwrap {
    display: none;
    right: 8px;
    bottom: calc(var(--wave-panel-current-height) + var(--wave-panel-gap-mobile) + 6px + var(--safe-bottom));
    --colorbar-stack-gap: 8px;
  }

  #ev-stamp {
    top: 8px;
    left: 8px;
    max-width: calc(100% - 110px);
    font-size: 10px;
  }

  #tip {
    display: none;
  }
}
