:root {
    --bg: #f6f7f9;
    --card: #fff;
    --muted: #6b7280;
    --border: #e5e7eb;
    --accent: #10b981;
    --danger: #ef4444;
  }
  
  * { box-sizing: border-box; }
  html, body { height: 100%; }
  body {
    margin: 0; padding: 20px;
    background: var(--bg);
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
    color: #111827;
  }
  
  h1 { margin: 0 0 16px; font-size: 22px; }
  
  .opts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
    background: var(--card);
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 16px;
  }
  .opts label {
    display: grid; gap: 6px; font-size: 12px; color: var(--muted);
  }
  .opts input, .opts select, .opts button {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
  }
  .opts button { background: #111827; color: white; cursor: pointer; }
  
  /* === GRID & TILE === */
  .grid {
    display: grid;
    /* Give each tile enough minimum width so charts/text never collide */
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 16px;
    align-items: start;     /* important: prevents equal-height stretching */
  }
  
  .tile {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    display: flex;          /* stack sections vertically */
    flex-direction: column;
    gap: 10px;
    min-height: 360px;      /* consistent feel; adjust if you like */
    overflow: hidden;       /* no visual bleed from Plotly */
  }
  
  .tile.best { outline: 2px solid var(--accent); outline-offset: 2px; }
  
  .hdr {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    min-height: 110px;      /* avoids crowding under the image */
  }
  
  .route { font-weight: 600; }
  .surv { font-weight: 600; text-align: right; white-space: nowrap; }
  .surv .up { color: var(--accent); }
  .surv .down { color: var(--danger); }
  
  .cardimg {
    width: 72px; height: 100px; object-fit: contain;
    border: 1px solid var(--border); border-radius: 8px; background: white;
  }
  
  /* Stats row */
  .stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }
  .statbox {
    border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
    display: grid; gap: 4px; justify-items: center;
  }
  .statbox .lbl { font-size: 11px; color: var(--muted); }
  .statbox .val { font-weight: 600; }
  
  /* Plot area gets its own fixed height; Plotly fills it */
  .plot {
    width: 100%;
    height: 220px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    overflow: hidden;
  }
  
  /* Make Plotly behave inside our container */
  .plot .js-plotly-plot, .plot .plot-container {
    width: 100% !important;
    height: 100% !important;
  }
  
  /* Knock section takes full width but same tile style */
  .knock-wrap { margin-top: 20px; }
  .knock-tile { width: 100%; }
  .knock-tile .plot { display: none; } /* no histogram for knock */
  