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

body {
  background: #1a1a2e;
  color: #e0e0e0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 1rem;
}

.container {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.main-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 1rem;
  width: 100%;
}

.tabs-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  background: #16213e;
  border: 1px solid #2a2a4a;
  border-radius: 12px;
  padding: 0.8rem;
  max-height: var(--tabs-max-h, none);
}

.tabs-header {
  font-size: 0.85rem;
  font-weight: 600;
  color: #c0c0d0;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid #2a2a4a;
}

.replay-tabs {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-height: 0;
  overflow-y: auto;
}

.replay-tab {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: #0f3460;
  border: 1px solid #2a2a5a;
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
  font-size: 0.8rem;
  color: #e0e0e0;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
  user-select: none;
}

.replay-tab:hover {
  background: #173a6b;
}

.replay-tab:focus-visible {
  outline: 2px solid #e879a0;
  outline-offset: -2px;
}

.replay-tab.active {
  background: #2a2a5a;
  border-color: #e879a0;
}

.replay-tab-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.replay-tab-remove {
  background: transparent;
  color: #a0a0b0;
  border: none;
  border-radius: 3px;
  width: 1.4rem;
  height: 1.4rem;
  flex-shrink: 0;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.replay-tab-remove:hover {
  background: #3a3a6a;
  color: #ff6b6b;
}

.canvas-column {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 1280px;
}

.sidebar {
  grid-column: 3;
  justify-self: start;
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.left-panel {
  grid-column: 1;
  justify-self: end;
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  max-height: var(--canvas-col-h, none);
  min-height: 0;
}

.input-panel-wrap {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.input-panel {
  background: #16213e;
  border: 1px solid #2a2a4a;
  border-radius: 12px;
  padding: 1.2rem;
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.tab-content {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.tab-content.hidden {
  visibility: hidden;
}

.panel-tabs {
  display: flex;
  justify-content: center;
  margin-top: -1px;
}

.panel-tab {
  background: #0f1c35;
  border: 1px solid #2a2a4a;
  border-radius: 0;
  color: #a0a0b0;
  padding: 0.4rem 1.3rem;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
  position: relative;
  z-index: 1;
}

.panel-tab + .panel-tab {
  margin-left: -1px;
}

.panel-tab:hover:not(.active) {
  background: #16213e;
  color: #c0c0d0;
}

.panel-tab.active {
  background: #2a2a5a;
  color: #e879a0;
  border-color: #e879a0;
  cursor: default;
  z-index: 2;
}

.auth-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.auth-state {
  font-size: 0.85rem;
  color: #c0c0d0;
  word-break: break-word;
}

.auth-btn {
  background: #e879a0;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.45rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.auth-btn:hover {
  background: #d4609a;
}

.auth-btn.hidden {
  display: none;
}

.input-panel input[type="text"] {
  background: #0f3460;
  border: 1px solid #2a2a5a;
  border-radius: 6px;
  color: #e0e0e0;
  padding: 0.5rem 0.8rem;
  font-size: 0.85rem;
  width: 100%;
  font-family: inherit;
}

.input-panel input[type="text"]::placeholder {
  color: #707080;
}

#fetch-btn {
  background: #e879a0;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.5rem;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  align-self: center;
  transition: background 0.15s ease;
  letter-spacing: 0.03em;
}

#fetch-btn:hover:not(:disabled) {
  background: #d4609a;
}

#fetch-btn:disabled {
  background: #7a4060;
  cursor: not-allowed;
  opacity: 0.6;
}

.file-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.file-row label {
  font-size: 0.9rem;
  font-weight: 600;
  color: #c0c0d0;
}

.file-row .required {
  color: #e879a0;
}

.file-row .optional {
  color: #808090;
}

.file-drop {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 2.3rem;
  padding: 0.45rem 0.8rem;
  background: #0f3460;
  border: 1px dashed #2a2a5a;
  border-radius: 6px;
  color: #7a7a90;
  font-size: 0.85rem;
  cursor: pointer;
  text-align: center;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.file-drop:hover {
  background: #143a6b;
  border-color: #3a3a6a;
  color: #b0b0c0;
}

.file-drop.dragover {
  background: #2a2a5a;
  border-style: solid;
  border-color: #e879a0;
  color: #e879a0;
}

.file-drop.has-file {
  border-style: solid;
  color: #e0e0e0;
}

.file-drop input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.file-drop-text {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.file-row .skin-select {
  background: #0f3460;
  border: 1px solid #2a2a5a;
  border-radius: 6px;
  color: #e0e0e0;
  font-size: 0.85rem;
  padding: 0.4rem 0.6rem;
  width: 100%;
}

#load-btn {
  background: #e879a0;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.5rem;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  align-self: center;
  margin-top: 0.2rem;
  transition: background 0.15s ease;
  letter-spacing: 0.03em;
}

#load-btn:hover {
  background: #d4609a;
}

#load-btn:disabled {
  background: #7a4060;
  cursor: not-allowed;
}

.status {
  min-height: 1.5rem;
  font-size: 0.85rem;
  color: #e0e0e0;
  text-align: center;
}

.load-progress {
  align-self: center;
  width: 70%;
  max-width: 260px;
  height: 4px;
  margin-top: 0.55rem;
  background: rgba(232, 121, 160, 0.15);
  border-radius: 2px;
  overflow: hidden;
  display: none;
}

.load-progress.active {
  display: block;
}

.load-progress-bar {
  width: 40%;
  height: 100%;
  background: linear-gradient(90deg, transparent 0%, #e879a0 50%, transparent 100%);
  animation: load-progress-slide 1.2s ease-in-out infinite;
}

@keyframes load-progress-slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

.player-controls.hidden {
  display: none;
}

.play-pause-btn {
  background: #e879a0;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.45rem 0;
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease;
  line-height: 1;
  width: 2.4rem;
  text-align: center;
}

.play-pause-btn:hover {
  background: #d4609a;
}

.scrub-bar-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  height: 16px;
}

.scrub-bar {
  width: 100%;
  cursor: pointer;
  height: 4px;
  margin: 0;
  position: relative;
  z-index: 1;
}

.scrub-markers {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 12px;
  pointer-events: none;
  z-index: 2;
}

.scrub-marker {
  position: absolute;
  top: 0;
  width: 2px;
  height: 12px;
  transform: translateX(-50%);
  border-radius: 1px;
}

.scrub-marker.miss {
  background: #ff4d4d;
}

.scrub-marker.sliderbreak {
  background: #ffdd33;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: #2a2a4a;
  border-radius: 2px;
}

input[type="range"]::-moz-range-track {
  height: 4px;
  background: #2a2a4a;
  border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 3px;
  height: 16px;
  background: #e879a0;
  border: none;
  border-radius: 1px;
  margin-top: -6px;
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 3px;
  height: 16px;
  background: #e879a0;
  border: none;
  border-radius: 1px;
  cursor: pointer;
}

.time-display {
  font-size: 0.85rem;
  color: #a0a0b0;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 7ch;
  text-align: right;
}

.render-options {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  width: 100%;
  background: #16213e;
  border: 1px solid #2a2a4a;
  border-radius: 8px;
  padding: 0.6rem 1rem;
}

.render-options.hidden {
  display: none;
}

.option-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: #c0c0d0;
  cursor: pointer;
  user-select: none;
}

.option-toggle input[type="checkbox"] {
  accent-color: #e879a0;
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.option-dim {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: #c0c0d0;
  margin-left: auto;
}

.option-dim input[type="range"] {
  accent-color: #e879a0;
  width: 110px;
  cursor: pointer;
}

.option-dim span {
  font-size: 0.8rem;
  color: #a0a0b0;
  font-variant-numeric: tabular-nums;
  min-width: 3.5ch;
  text-align: right;
}

.volume-stack {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-left: auto;
}

.volume-stack .option-dim {
  margin-left: 0;
}

.vol-label {
  width: 4.5rem;
  display: inline-block;
}

.option-offset {
  gap: 0.35rem;
}

.option-offset span {
  min-width: 5ch;
}

.offset-btn {
  background: transparent;
  border: 1px solid #2a2a4a;
  border-radius: 5px;
  color: #c0c0d0;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0.2rem 0.4rem;
  cursor: pointer;
  font-family: inherit;
  flex-shrink: 0;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.offset-btn:hover {
  background: #2a2a5a;
  color: #e879a0;
  border-color: #e879a0;
}

.offset-btn:active {
  background: #3a3a6a;
}

.offset-reset {
  font-size: 0.95rem;
  padding: 0.15rem 0.35rem;
}

.sync-btn {
  background: transparent;
  border: 1px solid #2a2a4a;
  border-radius: 6px;
  color: #c0c0d0;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0.25rem 0.45rem;
  cursor: pointer;
  font-family: inherit;
  flex-shrink: 0;
  margin-left: auto;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.sync-btn:hover {
  background: #2a2a5a;
  color: #e879a0;
  border-color: #e879a0;
}

.sync-btn:active {
  background: #3a3a6a;
}

.info-panel {
  position: relative;
  background: #16213e;
  border: 1px solid #2a2a4a;
  border-radius: 12px;
  padding: 1rem 1.1rem 1.1rem;
  overflow: hidden;
  flex: 0 1 auto;
  min-height: 0;
}

.info-header {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  border-bottom: 1px solid #2a2a4a;
  padding-bottom: 0.55rem;
  margin-bottom: 0.7rem;
}

.info-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: #e879a0;
  letter-spacing: 0.02em;
  line-height: 1;
}

.info-version {
  font-size: 0.7rem;
  color: #808095;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.info-body {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  font-size: 0.78rem;
  color: #c0c0d0;
  line-height: 1.4;
}

.info-body p {
  margin: 0;
}

.info-author {
  color: #a0a0b0;
}

.info-author strong {
  color: #e0e0e0;
  font-weight: 600;
}

.info-notes {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  color: #a0a0b0;
  font-size: 0.75rem;
}

.info-notes li {
  position: relative;
  padding-left: 0.8rem;
}

.info-notes li::before {
  content: "•";
  position: absolute;
  left: 0.1rem;
  color: #e879a0;
}

.info-unsupported {
  color: #a0a0b0;
  font-size: 0.75rem;
}

.info-unsupported-label {
  color: #e879a0;
  font-weight: 600;
}

.info-contact {
  margin-top: 0.15rem;
  color: #c0c0d0;
}

.info-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.1rem;
}

.info-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
  background: #0f3460;
  border: 1px solid #2a2a5a;
  border-radius: 6px;
  color: #e0e0e0;
  text-decoration: none;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.info-link:hover {
  background: #2a2a5a;
  border-color: #e879a0;
  color: #e879a0;
}

.info-link-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.info-horse {
  position: absolute;
  right: 24px;
  bottom: -4px;
  width: 70px;
  height: auto;
  opacity: 0.18;
  pointer-events: none;
  filter: saturate(0.9);
}

#replay-canvas {
  border: 2px solid #2a2a4a;
  border-radius: 8px;
  background: #0a0a1a;
  display: block;
}

#replay-canvas.hidden {
  display: none;
}

/* ─── Responsive: stack layout + scale canvas on narrow viewports ──────────────
   The native desktop layout needs ≈1872px (1280 canvas + 2×280 side panels +
   gaps). Below that we collapse the 3-column grid into a single stack and let
   the canvas scale down to viewport width via CSS (backing store stays
   1280×720 — browser downscales the bitmap). */
@media (max-width: 1880px) {
  body { padding: 0.6rem; }

  .main-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.8rem;
  }

  .canvas-column,
  .left-panel,
  .sidebar {
    grid-column: auto;
    justify-self: center;
    width: 100%;
    max-width: 1280px;
  }

  /* Stack order: canvas first (primary content), loaded-replay tabs, then
     input + info panels. */
  .canvas-column { order: 1; }
  .sidebar       { order: 2; }
  .left-panel    { order: 3; }

  #replay-canvas {
    width: 100%;
    height: auto;
    max-width: 1280px;
  }

  /* JS ties these caps to canvas-column height — meaningful only in the
     3-column layout. Release them when stacked. */
  .left-panel { max-height: none; }
  .tabs-panel { max-height: none; }
}

/* Small phones: tighten padding and wrap controls onto multiple rows. */
@media (max-width: 600px) {
  body { padding: 0.4rem; }
  .main-row { gap: 0.6rem; }
  .input-panel { padding: 0.9rem; }
  .tabs-panel { padding: 0.6rem; }
  .render-options { padding: 0.5rem 0.7rem; gap: 0.8rem; }
  .player-controls { gap: 0.6rem; }
  .time-display { min-width: 6ch; font-size: 0.8rem; }
  .info-panel { padding: 0.9rem 0.9rem 2.8rem; }
  .info-horse { width: 56px; right: 14px; }
}
