@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;600&display=swap");

:root {
  --viz-bg: var(--color-bg-app, #050507);
  --viz-surface: var(--color-bg-surface, #101010);
  --viz-surface-elevated: color-mix(in srgb, var(--viz-surface) 82%, white 18%);
  --viz-text: var(--color-text, #f2f2f2);
  --viz-text-muted: var(--color-text-secondary, #b8b3b0);
  --viz-text-subtle: var(--color-text-muted, #9fa0a0);
  --viz-border: var(--color-border, #3d3a39);
  --viz-border-strong: color-mix(in srgb, var(--viz-border) 75%, white 25%);
  --viz-accent: var(--color-accent, #00d992);
  --viz-accent-2: var(--color-accent-mint, #2fd6a1);
  --viz-danger: var(--color-danger, #fb565b);
  --viz-focus-ring: color-mix(in srgb, var(--viz-accent) 40%, transparent 60%);
  --viz-shadow-1: 0 2px 10px rgba(0, 0, 0, 0.35);
  --viz-shadow-2: 0 8px 20px rgba(0, 0, 0, 0.45);
  --viz-font-sans: var(--font-sans, "Inter", "Segoe UI", system-ui, sans-serif);
  --viz-font-mono: var(--font-mono, "JetBrains Mono", "Consolas", monospace);
  --viz-transition-fast: 140ms;
  --viz-transition-medium: 220ms;
  --viz-measure-gap: 0.55rem;
  --viz-row-gap: 0.9rem;
  --viz-prima-color: var(--viz-text);
  --viz-behean-color: var(--viz-accent);
  --viz-volt-color: #ffd869;
}

@media (prefers-color-scheme: light) {
  :root {
    --viz-bg: #f5f7fa;
    --viz-surface: #ffffff;
    --viz-surface-elevated: #f2f4f7;
    --viz-text: #18222f;
    --viz-text-muted: #425466;
    --viz-text-subtle: #5f7286;
    --viz-border: #c2cad4;
    --viz-border-strong: #8695a6;
    --viz-focus-ring: rgba(0, 166, 110, 0.24);
    --viz-prima-color: #202a37;
    --viz-behean-color: #017f63;
    --viz-volt-color: #935700;
  }
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--viz-bg);
  color: var(--viz-text);
  font-family: var(--viz-font-sans);
  box-sizing: border-box;
  touch-action: manipulation;
}

*,
*::before,
*::after {
  box-sizing: inherit;
}

.is-hidden,
.hidden {
  display: none;
}

#upload-overlay {
  position: absolute;
  inset: 0;
  background: var(--viz-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

#drop-zone {
  border: 2px dashed var(--viz-border);
  border-radius: 16px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--viz-surface) 92%, white 8%), var(--viz-surface));
  padding: 40px;
  max-width: 620px;
  width: min(92vw, 620px);
  max-height: calc(100vh - 120px);
  overflow: auto;
  text-align: center;
  transition: border-color var(--viz-transition-medium) ease, box-shadow var(--viz-transition-medium) ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: var(--viz-shadow-1);
}

#drop-zone.dragover {
  border-color: var(--viz-accent);
  box-shadow: 0 0 0 4px var(--viz-focus-ring), var(--viz-shadow-2);
}

.header-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
}

#drop-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--viz-surface-elevated), var(--viz-surface));
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.05), var(--viz-shadow-1);
  color: var(--viz-accent);
}

#drop-icon svg {
  width: 40px;
  height: 40px;
  fill: currentColor;
}

.header-text {
  text-align: center;
}

#drop-zone h2 {
  margin: 0;
  font-weight: 700;
  font-size: 24px;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--viz-text), #fff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-text .subtitle {
  margin: 6px 0 0;
  font-size: 15px;
  color: var(--viz-text-subtle);
}

#drop-zone p[id^="tab-"] {
  margin: 0;
  color: var(--viz-text-subtle);
}

#file-input,
#file-input-combined {
  opacity: 0;
  width: 0.1px;
  height: 0.1px;
  position: absolute;
  z-index: -1;
}

#file-label,
.btn-submit,
.btn-file-combined,
#controls button {
  border: 1px solid transparent;
  transition: transform var(--viz-transition-fast) ease, box-shadow var(--viz-transition-medium) ease, border-color var(--viz-transition-fast) ease, filter var(--viz-transition-fast) ease;
}

#file-label,
.btn-submit {
  display: inline-block;
  background: linear-gradient(90deg, var(--viz-accent), var(--viz-accent-2));
  color: #04130e;
  padding: 12px 24px;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--viz-shadow-1);
}

.btn-file-combined {
  display: inline-block;
  background-color: var(--viz-surface-elevated);
  color: var(--viz-text);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  border-color: var(--viz-border);
}

#file-label:hover,
.btn-submit:hover,
.btn-file-combined:hover,
#controls button:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
  box-shadow: var(--viz-shadow-2);
}

#file-label:active,
.btn-submit:active,
.btn-file-combined:active,
#controls button:active {
  transform: translateY(0) scale(0.98);
}

#file-label:focus-visible,
.btn-submit:focus-visible,
.btn-file-combined:focus-visible,
.tab-btn:focus-visible,
#controls button:focus-visible,
#speed-select:focus-visible,
#html-input:focus-visible,
#html-input-combined:focus-visible,
#bpm-input:focus-visible,
#seek-bar:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--viz-focus-ring);
  border-color: var(--viz-accent);
}

#visualizer {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#info-panel {
  position: fixed;
  top: 56px;
  left: 0;
  width: 100%;
  background-color: color-mix(in srgb, var(--viz-bg) 86%, transparent);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  font-size: 14px;
  z-index: 100;
  border-bottom: 1px solid color-mix(in srgb, var(--viz-border) 80%, transparent);
  gap: 12px;
}

#song-name {
  font-weight: 700;
}

#song-info {
  color: var(--viz-text-subtle);
}

#bellows-indicator {
  padding: 4px 12px;
  border-radius: 999px;
  font-weight: 700;
  background-color: color-mix(in srgb, var(--viz-surface) 82%, transparent);
  font-size: 12px;
  letter-spacing: 0.04em;
}

#bellows-indicator.opening {
  color: var(--viz-accent);
}

#bellows-indicator.closing {
  color: #ffd32a;
}

#instrument-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 110px 24px 94px;
  overflow: auto;
}

#trikitixa-svg {
  width: 100%;
  max-width: 900px;
  height: auto;
  touch-action: manipulation;
  overflow: visible;
}

#trikitixa-svg circle[id^="treble-btn-"],
#trikitixa-svg circle[id^="bass-btn-"] {
  fill: var(--btn-bg, #101010) !important;
  stroke: var(--btn-stroke, #3d3a39) !important;
  stroke-width: var(--btn-stroke-width, 2) !important;
  transition: fill 0.05s ease, filter 0.1s ease;
  cursor: pointer;
}

.btn-active {
  filter: drop-shadow(0 0 10px var(--btn-bg, #ffffff)) brightness(1.2);
}

#trikitixa-svg circle[id^="treble-btn-"]:hover,
#trikitixa-svg circle[id^="bass-btn-"]:hover,
#trikitixa-svg circle[id^="treble-btn-"]:focus,
#trikitixa-svg circle[id^="bass-btn-"]:focus {
  filter: brightness(1.4);
  stroke: var(--color-accent, #00d992) !important;
  outline: none;
}

.note-label {
  fill: #050507;
  font-size: 7px;
  text-anchor: middle;
  pointer-events: none;
  font-weight: 800;
  font-family: var(--font-sans, system-ui, sans-serif);
}

.finger-indicator {
  fill: #050507;
  font-size: 5px;
  text-anchor: middle;
  pointer-events: none;
  font-weight: 600;
  font-family: var(--font-sans, system-ui, sans-serif);
  opacity: 0.5;
}

#controls {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  width: min(960px, calc(100% - 24px));
  background: color-mix(in srgb, var(--viz-surface) 72%, transparent);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  z-index: 120;
  border: 1px solid color-mix(in srgb, var(--viz-border) 85%, transparent);
  border-radius: 12px;
}

#controls button {
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
}

#btn-play {
  width: 40px;
  height: 40px;
  background-color: var(--viz-accent);
  color: #061811;
  font-size: 16px;
  border-color: color-mix(in srgb, var(--viz-accent) 55%, black 45%);
}

#btn-new-file,
#btn-download-midi,
#btn-generate-video {
  width: 32px;
  height: 32px;
  background-color: var(--viz-surface-elevated);
  color: var(--viz-text);
  border-color: var(--viz-border);
  font-size: 14px;
}

#btn-generate-video:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

#time-current,
#time-total {
  font-family: var(--viz-font-mono);
  font-size: 13px;
  color: var(--viz-text-muted);
  min-width: 45px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

#seek-bar {
  flex: 1;
  appearance: none;
  width: 100%;
  background: transparent;
}

#seek-bar::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--viz-border);
  border-radius: 2px;
  transition: background var(--viz-transition-fast) ease;
}

#seek-bar:hover::-webkit-slider-runnable-track {
  background: var(--viz-border-strong);
}

#seek-bar::-webkit-slider-thumb {
  appearance: none;
  height: 14px;
  width: 14px;
  border-radius: 50%;
  background: var(--viz-accent);
  margin-top: -5px;
}

#seek-bar:hover::-webkit-slider-thumb,
#seek-bar:active::-webkit-slider-thumb {
  box-shadow: 0 0 0 5px var(--viz-focus-ring);
}

#seek-bar::-moz-range-track {
  height: 4px;
  background: var(--viz-border);
  border-radius: 2px;
}

#seek-bar::-moz-range-thumb {
  height: 14px;
  width: 14px;
  border-radius: 50%;
  border: none;
  background: var(--viz-accent);
}

#speed-select,
#bpm-input,
#html-input,
#html-input-combined {
  background-color: var(--viz-surface);
  color: var(--viz-text);
  border: 1px solid var(--viz-border);
}

#speed-select {
  border-radius: 6px;
  padding: 6px 10px;
  font-family: var(--viz-font-sans);
  font-size: 13px;
}

#speed-select:hover {
  border-color: var(--viz-accent);
}

#tab-nav {
  display: flex;
  width: 100%;
  background: color-mix(in srgb, var(--viz-surface) 60%, transparent);
  border: 1px solid var(--viz-border);
  border-radius: 999px;
  padding: 6px;
  margin-bottom: 24px;
  position: relative;
  gap: 4px;
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  border: none;
  border-radius: 999px;
  color: var(--viz-text-subtle);
  padding: 10px 16px;
  cursor: pointer;
  font-family: var(--viz-font-sans);
  font-size: 14px;
  font-weight: 600;
  transition: all var(--viz-transition-fast) ease;
}

.tab-btn:hover {
  color: var(--viz-text);
  background: color-mix(in srgb, var(--viz-surface-elevated) 60%, transparent);
}

.tab-btn.active {
  color: #04130e;
  background: linear-gradient(90deg, var(--viz-accent), var(--viz-accent-2));
  box-shadow: 0 4px 12px rgba(0, 217, 146, 0.25);
}

.tab-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  opacity: 0.8;
  transition: opacity 0.2s ease;
}

.tab-btn.active svg {
  opacity: 1;
}

.tab-panel {
  display: none;
  width: 100%;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

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

#tab-midi-help,
#tab-html-midi-help {
  max-width: 48ch;
  line-height: 1.45;
}

#html-input,
#html-input-combined {
  width: 100%;
  max-width: 500px;
  border-radius: 8px;
  padding: 12px;
  font-family: var(--viz-font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  resize: vertical;
}

.bpm-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.bpm-row label,
.file-name-display {
  color: var(--viz-text-subtle);
}

#bpm-input {
  width: 80px;
  border-radius: 6px;
  padding: 6px 10px;
  font-family: var(--viz-font-sans);
  font-size: 14px;
  text-align: center;
}

.combined-midi-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.file-picker-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  flex-wrap: wrap;
}

.file-name-display {
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  min-height: 32px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px dashed color-mix(in srgb, var(--viz-border) 82%, transparent);
  background: color-mix(in srgb, var(--viz-surface-elevated) 55%, transparent);
}

.file-name-display:empty::after {
  content: "Ningun archivo seleccionado";
  color: var(--viz-text-subtle);
  font-style: italic;
}

.fit-metrics {
  display: none;
  margin-top: 10px;
  font-size: 13px;
  color: var(--viz-text-muted);
  text-align: left;
  font-family: var(--viz-font-mono);
}

.video-status {
  display: none;
  text-align: center;
  padding: 8px 0;
}

.video-progress {
  width: 200px;
  vertical-align: middle;
}

.video-progress-text {
  margin-left: 8px;
  color: var(--viz-text-muted);
}

.btn-cancel-video {
  margin-left: 8px;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--viz-border);
  background: var(--viz-surface);
  color: var(--viz-text);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.main-page.shadow,
.tablature-viewer {
  background: color-mix(in srgb, var(--viz-surface) 90%, transparent);
  border: 1px solid color-mix(in srgb, var(--viz-border) 85%, transparent);
  border-radius: 14px;
  padding: 0.9rem;
  color: var(--viz-text);
}

.main-page .mt-1 {
  margin-top: 0;
  margin-bottom: var(--viz-row-gap);
}

.main-page .mt-1 > .d-flex.flex-wrap {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(2.2rem, max-content);
  column-gap: var(--viz-measure-gap);
  align-items: start;
  justify-content: start;
}

.main-page .mt-1 > .d-flex.flex-wrap > .nota-osoa {
  margin: 0;
}

.main-page .mt-1 > .d-flex.flex-wrap > .nota-osoa:nth-child(4n) {
  margin-right: 0.65rem;
  position: relative;
}

.main-page .mt-1 > .d-flex.flex-wrap > .nota-osoa:nth-child(4n)::after {
  content: "";
  position: absolute;
  right: -0.38rem;
  top: 0.1rem;
  width: 1px;
  height: 2.7rem;
  background: color-mix(in srgb, var(--viz-border-strong) 65%, transparent);
}

.main-page .nota,
.tablature-viewer .nota {
  min-width: 2rem;
  min-height: 2rem;
  font-weight: 700;
  color: var(--viz-prima-color);
  background: color-mix(in srgb, var(--viz-surface-elevated) 90%, transparent);
}

.main-page .tresillo .nota,
.tablature-viewer .tresillo .nota {
  border-style: dashed;
}

.main-page .behean,
.main-page .behebehean,
.main-page .goigoian,
.tablature-viewer .behean,
.tablature-viewer .behebehean,
.tablature-viewer .goigoian {
  width: 100%;
  text-align: center;
  font-family: var(--viz-font-mono);
  font-size: 0.84rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  line-height: 1.2;
  white-space: pre;
}

.main-page .behean,
.tablature-viewer .behean {
  color: var(--viz-behean-color);
  font-weight: 600;
}

.main-page .behebehean,
.tablature-viewer .behebehean {
  color: var(--viz-text-muted);
}

.main-page .goigoian,
.tablature-viewer .goigoian {
  color: var(--viz-prima-color);
  font-weight: 600;
}

.main-page .borobil-hutsa,
.tablature-viewer .borobil-hutsa {
  color: var(--viz-volt-color);
  font-size: 0.95rem;
  line-height: 1;
  filter: drop-shadow(0 0 4px color-mix(in srgb, var(--viz-volt-color) 45%, transparent));
}

@media (max-width: 768px) {
  #drop-zone {
    padding: 20px 16px;
    width: 94%;
    gap: 12px;
  }

  #drop-icon {
    font-size: 56px;
  }

  #tab-nav {
    flex-wrap: wrap;
    border-radius: 12px;
  }

  .tab-btn {
    min-width: 50%;
  }

  #info-panel {
    padding: 10px 12px;
    font-size: 12px;
    flex-wrap: wrap;
    justify-content: center;
  }

  #song-name,
  #song-info,
  #bellows-indicator {
    max-width: 100%;
    overflow-wrap: anywhere;
    text-align: center;
  }

  #controls {
    flex-wrap: wrap;
    justify-content: center;
    padding: 10px 12px;
    gap: 8px;
    bottom: 10px;
  }

  #seek-bar {
    order: -1;
    flex-basis: 100%;
    margin-bottom: 8px;
  }

  .combined-midi-row {
    flex-wrap: wrap;
    justify-content: center;
  }

  .file-picker-row {
    justify-content: center;
  }

  .file-name-display {
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .main-page .mt-1 > .d-flex.flex-wrap {
    grid-auto-columns: minmax(1.8rem, max-content);
    column-gap: 0.42rem;
  }
}

/* Mobile: Convert fixed position elements to normal flow below 768px */
@media (max-width: 767px) {
  #info-panel {
    position: static;
    top: auto;
    width: 100%;
    margin-bottom: 0;
  }

  #controls {
    position: static;
    left: auto;
    transform: none;
    width: calc(100% - 24px);
    margin: 0 auto 12px;
  }

  #instrument-container {
    padding: 24px;
  }
}

/* Mobile: Tighter controls spacing for small viewports (< 640px) */
@media (max-width: 640px) {
  #controls {
    gap: 6px;
    padding: 8px;
  }
  #btn-play {
    min-width: 40px;
    min-height: 40px;
  }
  #btn-new-file,
  #btn-download-midi,
  #btn-generate-video {
    width: 28px;
    height: 28px;
  }
}

/* Small phone: Compact everything below 480px */
@media (max-width: 480px) {
  #drop-icon {
    width: 48px;
    height: 48px;
  }
  #drop-icon svg {
    width: 24px;
    height: 24px;
  }
  #drop-zone h2 {
    font-size: 18px;
  }
  .header-text .subtitle {
    font-size: 13px;
  }
  #tab-nav {
    border-radius: 12px;
  }
  .tab-btn {
    padding: 8px 10px;
    font-size: 12px;
    min-width: 100%;
  }
  .tab-btn svg {
    width: 14px;
    height: 14px;
  }
  #info-panel {
    padding: 8px;
    font-size: 11px;
    gap: 6px;
  }
  #instrument-container {
    padding: 12px;
  }
  #controls {
    padding: 6px;
    gap: 4px;
  }
  #time-current,
  #time-total {
    font-size: 11px;
    min-width: 35px;
  }
  #speed-select {
    font-size: 11px;
    padding: 4px 6px;
  }
}

/* PHASE 3 UI PATTERNS */
input[type="text"],
input[type="number"],
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--viz-border);
  border-radius: 8px;
  background-color: var(--viz-surface);
  color: var(--viz-text);
  font-family: var(--viz-font-mono);
  font-size: 13px;
  transition: border-color var(--viz-transition-fast) ease, box-shadow var(--viz-transition-fast) ease;
}

input[type="text"]::placeholder,
input[type="number"]::placeholder,
textarea::placeholder {
  color: var(--viz-text-subtle);
  opacity: 0.6;
}

input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--viz-accent);
  box-shadow: 0 0 0 3px var(--viz-focus-ring);
}

.file-picker-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  align-items: center;
}

.file-name-display {
  display: block;
  font-size: 13px;
  color: var(--viz-text-muted);
  background: var(--viz-surface-elevated);
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--viz-border);
  width: 100%;
  max-width: 100%;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 34px;
}
.file-name-display:empty::after {
  content: "No file selected";
  color: var(--viz-text-subtle);
  opacity: 0.7;
}

.bpm-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  width: 100%;
}
.bpm-row label {
  font-size: 13px;
  font-weight: 600;
  color: var(--viz-text);
}

.combined-midi-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.btn-submit:disabled, 
.btn-submit.loading,
.btn-submit[data-loading="true"] {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
  filter: grayscale(0.5);
  box-shadow: none;
}
.btn-submit.loading::after,
.btn-submit[data-loading="true"]::after {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-left: 8px;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
