body {
  font-family: 'Courier New', Courier, monospace;
  background: linear-gradient(180deg, #121212, #1b1b1b);
  color: #00ff11;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

.header {
  text-align: center;
  margin: 10px auto 0;
  padding: 4px;
  line-height: 1.1;
  background: none;
  border-bottom: 2px solid rgba(0,255,17,0.3);
  width: 100%;
  max-width: 420px;
}

.header h1 {
  font-weight: 700;
  color: #00ff11;
  font-size: clamp(16px, 3.8vw, 22px);
  margin: 0;
  text-shadow: 0 0 6px rgba(0,255,17,0.35);
  letter-spacing: 0.5px;
}

.header p {
  color: #a0a0a0;
  margin: 4px 0 0;
  font-size: clamp(11px, 2.5vw, 14px);
  font-weight: 400;
}

@media screen and (orientation: landscape), screen and (max-height: 450px) {
  .header {
    margin-top: 2px;
    padding: 2px 0;
    border-bottom-width: 1px;
  }
  .header h1 {
    font-size: clamp(12px, 2.8vw, 18px);
  }
  .header p {
    font-size: clamp(9px, 2vw, 12px);
    margin-top: 2px;
  }
}


/* Optimize header height for landscape and very small screens */
@media screen and (orientation: landscape) and (max-height: 450px) {
  .header {
    margin-top: 5px;
    padding: 5px 10px;
    transform: scale(0.85);
    transform-origin: top center;
  }
  .header h1 {
    font-size: clamp(14px, 3.2vw, 20px);
  }
  .header p {
    font-size: clamp(10px, 2.4vw, 16px);
    margin-top: 2px;
  }
}

/* Ultra-small screens fallback */
@media screen and (max-width: 480px) {
  .header h1 {
    font-size: clamp(16px, 6vw, 26px);
  }
  .header p {
    font-size: clamp(12px, 4vw, 18px);
  }
}

.header p {
  color: #ccc;
}

.player {
  background: #222;
  border: 3px solid #00ff11;
  border-radius: 10px;
  padding: 15px;
  width: 90%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0px 0px 15px #00ff11;
  margin-top: 20px;
}

.equalizer {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  height: 30px;
  margin-bottom: 10px;
}

.equalizer .bar {
  background: #00ff11;
  width: 4px;
  margin: 0 2px;
  animation: bounce 1s infinite ease-in-out;
}

@keyframes bounce {
  0%, 100% { height: 5px; }
  50% { height: 25px; }
}

.controls button {
  background: #00ff11;
  border: none;
  color: #000;
  font-size: 18px;
  margin: 5px;
  padding: 10px 15px;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.controls button:hover {
  transform: scale(1.1);
}

.controls input[type="file"] {
  color: #00ff11;
  margin-top: 10px;
}

.spinner {
  font-size: 18px;
  color: #ff0;
  margin-top: 15px;
  animation: pulse 1.2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.hidden {
  display: none;
}

.loops {
  margin-top: 25px;
  width: 90%;
  max-width: 500px;
  overflow-x: auto;
}

.loops h2 {
  text-align: center;
  color: #00ff11;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #111;
  color: #0f0;
}

th, td {
  border: 1px solid #0f0;
  padding: 6px;
  text-align: center;
}

tr:hover {
  background-color: #252;
  cursor: pointer;
}

@media (max-width: 400px) {
  .player, .loops {
    width: 95%;
    font-size: 14px;
  }
  table th, table td {
    padding: 4px;
  }
}

/* Full-screen analyzing overlay */
.analyzing-overlay {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999; /* above everything */
  padding: 24px;
}

.analyzing-overlay .overlay-content {
  text-align: center;
  max-width: 800px;
}

.analyzing-overlay .overlay-message {
  color: #00ff11;
  font-size: clamp(18px, 2.8vw, 28px); /* auto-resizing text */
  line-height: 1.5;
  margin: 0;
  text-shadow: 0 0 6px rgba(0, 255, 17, 0.35);
}

.analyzing-overlay .overlay-spinner {
  width: clamp(48px, 10vw, 96px);
  height: clamp(48px, 10vw, 96px);
  border: 6px solid rgba(0, 255, 17, 0.25);
  border-top-color: #00ff11;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 18px;
  box-shadow: 0 0 16px rgba(0, 255, 17, 0.35);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Prevent background scroll while overlay is visible */
body.overlay-active {
  overflow: hidden;
}


/* Fix loading overlay and scaling issues on mobile orientations */
html, body {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-text-size-adjust: 100%;
}

/* Force dark mode theme colors universally */
html, body {
  background-color: #000 !important;
  color-scheme: dark;
  color: #00ff11;
  -webkit-text-size-adjust: none;
}

@media (prefers-color-scheme: dark) {
  html, body {
    background-color: #000 !important;
    color: #00ff11 !important;
  }
  input, button, select, textarea {
    background-color: #111 !important;
    color: #00ff11 !important;
    border-color: #00ff11 !important;
  }
  ::placeholder {
    color: #0f0 !important;
    opacity: 0.8;
  }
}
#analyzingOverlay, .analyzing-overlay {
  max-width: 100vw;
  max-height: 100vh;
  overflow: hidden;
  box-sizing: border-box;
}

@supports (env(safe-area-inset-top)) {
  .analyzing-overlay {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

/* Selected Loop Section */
.selected-loop-section {
  width: 90%;
  max-width: 500px;
  margin-top: 25px;
  transition: opacity 0.3s ease;
}

.selected-loop-section.deactivated {
  opacity: 0.5;
  filter: grayscale(70%);
  pointer-events: none;
}

.selected-loop-section h2 {
  text-align: center;
  color: #00ff11;
  margin-bottom: 10px;
}

#selectedLoopTable {
  width: 100%;
  border-collapse: collapse;
  background: #111;
  color: #0f0;
  margin-top: 12px;
  margin-bottom: 12px;
  border-spacing: 0;
}

#selectedLoopTable th, #selectedLoopTable td {
  border: 1px solid #0f0;
  padding: 6px;
  text-align: center;
}
#selectedLoopTable td.length-row,
#selectedLoopTable td.score-row {
  border-top: none;
  font-style: italic;
  opacity: 0.9;
}

#selectedLoopTable tr.active {
  background-color: #252;
}

/* === Loop Detail Tables === */
.loop-detail-table,
.loop-detail-subtable {
  width: 100%;
  border-collapse: collapse;
  background: #111;
  color: #0f0;
}

.loop-detail-table {
  margin-top: 10px;
  margin-bottom: 4px;
}

.loop-detail-subtable {
  margin-top: 2px;
  margin-bottom: 8px;
}

.loop-detail-subtable th,
.loop-detail-subtable td {
  border: 1px solid #0f0;
  padding: 6px;
  text-align: center;
}

.loop-detail-subtable th {
  background-color: #131;
  font-weight: bold;
  font-size: 15px;
}

.loop-detail-subtable td {
  font-style: italic;
  font-size: 14px;
}


.version {
  position: fixed;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  color: #00ff11;
  font-size: 13px;
  opacity: 0.8;
  z-index: 10000; /* visible above overlay */
  text-shadow: 0 0 4px rgba(0, 255, 17, 0.4);
}
/* Shadow-box container for the media player */
.player-shadow-box {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 90%;
  max-width: 420px;
  background: #111;
  padding: 10px 15px;
  border-radius: 12px;
  box-shadow: 0 0 20px rgba(0, 255, 17, 0.4);
  border: 2px solid #00ff11;
  display: flex;
  justify-content: center;
  align-items: center;
}
/* Improved media player control layout */
.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#skipInterval {
  width: 50px;
  font-size: 16px;
  text-align: center;
  background: #000;
  color: #00ff11;
  border: 1px solid #00ff11;
  border-radius: 4px;
  padding: 4px;
}

#skipInterval:focus {
  outline: none;
  box-shadow: 0 0 6px #00ff11;
}
/* Revised layout for controls and skip interval row */
.button-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 6px;
}

.interval-row {
  display: block;
  text-align: center;
  margin-top: 8px;
  font-size: 15px;
}

.interval-row label {
  color: #0f0;
}

.interval-row input {
  width: 60px;
  font-size: 15px;
  text-align: center;
  background: #000;
  color: #00ff11;
  border: 1px solid #00ff11;
  border-radius: 4px;
  padding: 4px;
}
/* Animate equalizer bars only while playing */
@keyframes equalizerPulse {
  0% { transform: scaleY(0.3); }
  50% { transform: scaleY(1); }
  100% { transform: scaleY(0.3); }
}

.equalizer.playing .bar {
  animation: equalizerPulse 0.6s infinite ease-in-out;
  transform-origin: bottom;
}
/* Scroll container inside selected-loop-section for smaller screens */
.scroll-container {
  max-height: 80vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px;
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: #00ff11 #111;
}

/* Improve scroll snapping feel */
.scroll-container::-webkit-scrollbar {
  width: 6px;
}

.scroll-container::-webkit-scrollbar-thumb {
  background-color: #00ff11;
  border-radius: 3px;
}

.scroll-container::-webkit-scrollbar-track {
  background: #111;
}

/* On touch devices, maintain momentum scrolling */
@supports (-webkit-overflow-scrolling: touch) {
  .scroll-container {
    -webkit-overflow-scrolling: touch;
  }
}
/* === Segment-aware scrubber styles === */
.scrubber {
  width: 100%;
  max-width: 100%;
  margin: 10px 0 8px;
  user-select: none;
}

.scrubber-labels {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #00ff11;
  font-size: 13px;
  margin-bottom: 6px;
  opacity: 0.95;
}

.scrubber-track {
  position: relative;
  height: 16px;
  background: #0a0a0a;
  border: 1px solid rgba(0,255,17,0.55);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: inset 0 0 6px rgba(0,255,17,0.25);
}

.scrubber-segment {
  position: absolute;
  top: 0;
  bottom: 0;
}

.scrubber-segment.intro {
  background: rgba(0, 255, 17, 0.25);
}

.scrubber-segment.loop-even {
  background: rgba(0, 255, 17, 0.5);
}

.scrubber-segment.loop-odd {
  background: rgba(0, 255, 17, 0.33);
}

.scrubber-segment.outro {
  background: rgba(0, 255, 17, 0.2);
}

/* Visual separators between segments for clarity */
.scrubber-segment:not(:first-child) {
  box-shadow: -1px 0 0 rgba(0,255,17,0.5);
}

.scrubber-playhead {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 22px;
  background: #ffeb3b; /* high-contrast playhead */
  box-shadow: 0 0 6px rgba(255, 235, 59, 0.9), 0 0 2px rgba(0,0,0,0.6);
  pointer-events: none;
}

.scrubber-legend {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  font-size: 12px;
  color: #9cff9d;
  margin-top: 6px;
  opacity: 0.9;
}

.scrubber-legend .legend {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.scrubber-legend .legend::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  box-shadow: 0 0 4px rgba(0,255,17,0.6);
  border: 1px solid rgba(0,255,17,0.5);
}

.scrubber-legend .legend.intro::before {
  background: rgba(0, 255, 17, 0.25);
}

.scrubber-legend .legend.loop::before {
  background: rgba(0, 255, 17, 0.5);
}

.scrubber-legend .legend.outro::before {
  background: rgba(0, 255, 17, 0.2);
}

/* Compact on very small screens */
@media (max-width: 400px) {
  .scrubber-labels { font-size: 12px; }
  .scrubber-track { height: 14px; }
  .scrubber-playhead { height: 18px; top: -2px; }
}
/* === Compact metrics sub-rows for Detected Loop Points === */
#loopsTable {
  table-layout: fixed; /* prevent horizontal overflow with few compact columns */
}
#loopsTable th, #loopsTable td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#loopsTable .loop-metrics-row td {
  background: #0c0f0c;
  color: #9cff9d;
  font-size: 13px;
  padding: 6px 8px;
  border-top: none;     /* visually group with the main row above */
  white-space: normal;  /* allow wrapping inside the metrics cell */
}

#loopsTable .metrics {
  display: flex;
  flex-wrap: wrap;      /* wrap metrics on small screens */
  gap: 10px 16px;
  justify-content: center;
  align-items: center;
}

#loopsTable .metric strong {
  color: #0f0;
}

#loopsTable .loop-main-row.active td,
#loopsTable .loop-metrics-row.active td {
  background-color: #252; /* keep the active highlight for both rows */
}

@media (max-width: 420px) {
  #loopsTable .loop-metrics-row td {
    font-size: 12px;
    padding: 6px 6px;
  }
  #loopsTable .metrics {
    gap: 8px 12px;
  }
}