/* styles.css */

#dataFreshness {
    position: fixed;
    top: 10px;
    left: 10px;
    padding: 5px 10px;
    background-color: rgba(0, 0, 0, 0.7);
    color: #fff;
    border-radius: 5px;
    font-size: 12px;
    z-index: 1000;
}

/* =====================================================
   GLOBAL
   ===================================================== */
   body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #121212;
    margin: 0;
    padding: 0;
    color: #e0e0e0;
  }
  
  /* Screen-reader-only utility */
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
  }
  
  /* =====================================================
     LAYOUT / CONTAINER
     ===================================================== */
  .container {
    width: 90%;
    max-width: 1400px;
    margin: 40px auto;
    padding: 20px;
    background: #1e1e1e;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
  }
  
  /* Header */
  header h1 {
    text-align: center;
    margin-bottom: 20px;
    color: #f39c12;
  }
  
  /* =====================================================
     THREE-COLUMN layout for ranking / chart+status / params
     ===================================================== */
  .chart-params-container {
    display: grid;
    /* LEFT column now auto-sized to its content */
    grid-template-columns: auto minmax(800px, 2fr) minmax(200px, 3fr);
    gap: 20px;
    align-items: start;
  }
  
  /* allow the left & right panels to shrink */
  .chart-params-container > .ranking-section,
  .chart-params-container > .params-section {
    min-width: 0;
  }
  
  /* keep the middle (chart) column at least as wide as the canvas */
  .chart-params-container > .chart-status-section {
    min-width: 800px;
  }
  

  
  /* =====================================================
     RANKING SECTION
     ===================================================== */
  .ranking-section {
    background: rgba(0,0,0,0.3);
    padding: 1em;
    border-radius: 4px;
    color: white;
  }
  .ranking-section h2 {
    margin-top: 0;
  }
  .ranking-section ol {
    list-style: none;
    padding-left: 0;
  }
  
  /* each item is one line, no wrapping, with ellipsis */
  .ranking-section li {
    position: relative;
    padding-right: 4.5em;    /* leave room for the percent */
    margin-bottom: 0.5em;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  
  /* percentage always at right, vertically centered */
  .ranking-section .rank-pct {
    position: absolute;
    right: 0.5em;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.9em;
    color: #ccc;
    white-space: nowrap;
  }
  
  /* =====================================================
     Chart + status section container
     ===================================================== */
  .chart-status-section {
    display: flex;
    flex-direction: column;
    gap: 1em;
  }
  
  /* =====================================================
     Chart box
     ===================================================== */
  .chart-box {
    background: #333;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    position: relative; /* for overlay positioning */
  }
  #playerCountDisplay {
    margin-top: 10px;
    font-size: 18px;
  }
  /* make canvases scale down to the container width */
  .chart-box canvas {
    max-width: 100%;
    height: auto !important;
    display: block;
    margin: 0 auto;
  }
  /* =====================================================
     TIMELINE (date range selector)
     ===================================================== */
  .timeline-container {
    position: relative;
    width: 100%;
    user-select: none;
    padding: 6px 0; /* breathing room for thumbs */
  }
  /* Make the timeline container flex like inputs in the form row */
  .form-group .timeline-container { flex: 2 1 300px; }
  .timeline-scroll {
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
    border: 1px solid #444;
    border-radius: 4px;
    background: #1e1e1e;
  }
  .timeline-inner {
    position: relative;
    height: 28px; /* enough room for thumbs */
    min-width: 100%;
  }
  .timeline-track {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 0; right: 0;
    height: 12px;
    background: #444;
    border-radius: 6px;
    overflow: hidden;
    z-index: 1;
  }
  .timeline-coverage {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #c0392b; /* default red; JS will set gradient */
    pointer-events: none;
    z-index: 1;
  }
  .timeline-selection {
    position: absolute;
    top: 0;
    height: 100%;
    left: 0;
    width: 0;
    background: rgba(243, 156, 18, 0.25);
    border: 2px solid #f39c12;
    border-radius: 6px;
    pointer-events: none;
    box-sizing: border-box;
    z-index: 2;
    display: none; /* no fill; we only show start/end markers */
  }
  .timeline-range {
    position: absolute;
    left: 0; right: 0;
    top: 50%; transform: translateY(-50%);
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    outline: none;
    height: 24px; /* for thumb */
    margin: 0;
    pointer-events: auto;
  }
  /* Stack the ranges on top of each other */
  #timelineStart.timeline-range { z-index: 3; }
  #timelineEnd.timeline-range   { z-index: 2; }
  /* WebKit */
  .timeline-range::-webkit-slider-runnable-track {
    height: 0; /* hide native track */
    background: transparent;
    border-radius: 0;
    border: 0;
  }
  .timeline-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: #f39c12;
    border: 2px solid #fff;
    margin-top: -8px; /* center over 12px track (thumb 16px) */
    cursor: pointer;
  }
  /* Firefox */
  .timeline-range::-moz-range-track {
    height: 0; /* hide native track */
    background: transparent;
    border: 0;
  }
  /* IE/Edge legacy */
  .timeline-range::-ms-track {
    height: 0;
    background: transparent;
    border-color: transparent;
    color: transparent;
  }
  .timeline-range::-moz-range-thumb {
    width: 16px; height: 16px;
    border-radius: 50%;
    background: #f39c12;
    border: 2px solid #fff;
    cursor: pointer;
  }

  /* Bracket markers near slider handles */
  .timeline-bracket {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    color: #f6f6f6;
    font-size: 16px;
    line-height: 1;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    z-index: 4;
    pointer-events: none;
  }
  .timeline-bracket.bracket-start { color: #f39c12; }
  .timeline-bracket.bracket-end { color: #f39c12; }
  .timeline-labels {
    display: flex;
    justify-content: space-between;
    color: #ccc;
    font-size: 12px;
    margin-top: 6px;
  }
  /* =====================================================
     CHART LOADING OVERLAY
     ===================================================== */
  .chart-overlay {
    position: absolute;
    inset: 0;
    display: none; /* shown via JS */
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: rgba(0,0,0,0.35);
    z-index: 10;
  }
  .chart-overlay .spinner {
    width: 28px; height: 28px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: #f39c12;
    border-radius: 50%;
    animation: spin 1s linear infinite;
  }
  .chart-overlay .overlay-text {
    color: #fff;
    font-size: 14px;
    letter-spacing: 0.3px;
  }
  @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
  
  /* =====================================================
     Buttons
     ===================================================== */
  .btn-group {
    display: inline-flex;
    gap: 10px;
    margin-bottom: 15px;
  }
  .btn {
    padding: 10px 20px;
    background-color: #f39c12;
    border: none;
    border-radius: 4px;
    color: #fff;
    cursor: pointer;
    font-size: 16px;
    transition: background-color .3s ease;
  }
  .btn:hover {
    background-color: #d35400;
  }
  
  /* =====================================================
     Status panel
     ===================================================== */
  .status-section {
    background: #333;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
  }
  .status-section h2 {
    color: #f39c12;
    margin-bottom: 15px;
  }
  .status-section p {
    margin: 5px 0;
    font-size: 16px;
  }
  
  /* =====================================================
     Parameters panel
     ===================================================== */
  .params-section {
    background: #2c2c2c;
    padding: 20px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
  }
  .params-section h2 {
    text-align: center;
    margin-bottom: 20px;
    color: #f39c12;
  }
  
  .form-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 15px;
  }
  .form-group label {
    flex: 1 1 200px;
    margin-right: 10px;
    text-align: right;
  }
  .form-group > * {
    min-width: 0;
  }
  .form-group input,
  .form-group select {
    flex: 2 1 300px;
    padding: 8px;
    border: 1px solid #444;
    border-radius: 4px;
    background: #1e1e1e;
    color: #e0e0e0;
  }
  /* Do not apply text-input styling to range sliders */
  .form-group input[type="range"] {
    padding: 0;
    border: 0;
    background: transparent;
  }
  #fastWriteGroup,
  #runtimeMinutesGroup {
    display: none;
  }
  @media (max-width: 600px) {
    .form-group {
      flex-direction: column;
      align-items: flex-start;
    }
    .form-group label {
      text-align: left;
      margin-bottom: 5px;
    }
  }
  
  /* =====================================================
     FOOTER
     ===================================================== */
  footer {
    background: #1e1e1e;
    padding: 20px 0;
    color: #e0e0e0;
    margin-top: 40px;
  }
  /* =====================================================
     GITHUB CORNER (top-right “notch”)
     ===================================================== */
  .github-corner svg {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 1000;
    width: 100px;
    height: 100px;
    fill: #f39c12;
    color: #ffffff;
    transition: transform .3s ease;
  }
  .github-corner:hover svg {
    transform: scale(1.1);
  }
  .github-corner .octo-arm {
    transform-origin: 130px 106px;
  }
  .github-corner:hover .octo-arm {
    animation: octo-wave 560ms ease-in-out;
  }
  @keyframes octo-wave {
    0%,100% { transform: rotate(0deg); }
    20%,60% { transform: rotate(-25deg); }
    40%,80% { transform: rotate(10deg); }
  }
  @media (max-width: 500px) {
    .github-corner:hover .octo-arm { animation: none; }
    .github-corner .octo-arm       { animation: octo-wave 560ms ease-in-out; }
  }
  
  /* Connection status colours */
  #connectionStatus.connected    { color: #14c521; }
  #connectionStatus.disconnected { color: #e02424; }


  /* make the chart container scrollable if it still overflows */