:root {
  --bg: #0e1116;
  --bg-2: #161b22;
  --fg: #e6edf3;
  --fg-dim: #8b949e;
  --accent: #2f81f7;
  --ok: #3fb950;
  --warn: #d29922;
  --err: #f85149;
  --border: #30363d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .8rem 1.2rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
header h1 { margin: 0; font-size: 1.1rem; letter-spacing: .03em; }
#user-bar { margin-left: auto; display: flex; gap: .6rem; align-items: center; color: var(--fg-dim); }

main { padding: 1.2rem; max-width: 1100px; margin: 0 auto; }

section h2, section h3 { margin: 1.4rem 0 .6rem; font-weight: 500; color: var(--fg-dim); }

form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
input, button {
  background: var(--bg-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .5rem .75rem;
  font: inherit;
}
input { flex: 1; min-width: 240px; }
button { cursor: pointer; }
button:hover { background: #1f242c; }
button:disabled { opacity: .5; cursor: not-allowed; }

#cooldown { color: var(--fg-dim); font-size: .9em; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  table-layout: fixed;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
th, td { text-align: left; padding: .5rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: #11161d; color: var(--fg-dim); font-weight: 500; font-size: .85rem; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #1a2029; }

/* Hide less-important columns on narrow viewports so the table fits.
   Results table cols: 1=Server  2=Author  3=Title  4=Size  5=Action */
@media (max-width: 640px) {
  main { padding: .8rem; }
  header { padding: .6rem .8rem; }
  header h1 { font-size: 1rem; }

  /* Smaller cell padding everywhere on mobile. */
  th, td { padding: .4rem .45rem; font-size: .9rem; }

  /* Searches table: drop "When" column. */
  #searches-table th:nth-child(4),
  #searches-table td:nth-child(4) { display: none; }

  /* Results table: drop Server column to free horizontal space. */
  #results-table th:nth-child(1),
  #results-table td:nth-child(1) { display: none; }

  /* Truncate the long download filename (col 1) to a single line; the
     row is tap-to-expand. max-width:0 lets ellipsis work inside a
     table-layout:fixed cell. */
  #downloads-table td:nth-child(1) {
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  #downloads-table tr.expanded td:nth-child(1) {
    white-space: normal;
    overflow: visible;
    overflow-wrap: anywhere;
  }
  #downloads-table tbody tr { cursor: pointer; }
}

.pill {
  display: inline-flex;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .8rem;
  border: 1px solid var(--border);
  margin-left: auto;
}
.pill-off { color: var(--err); }
.pill-on { color: var(--ok); }

.status-queued, .status-searching, .status-downloading { color: var(--warn); }
.status-complete { color: var(--ok); }
.status-failed { color: var(--err); }

.error { color: var(--err); margin: .5rem 0 0; min-height: 1.1em; }
.dim { color: var(--fg-dim); }

.spinner {
  display: inline-block;
  width: 10px; height: 10px;
  margin-right: .45rem;
  border: 2px solid var(--warn);
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -1px;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@keyframes flash-bg {
  0%   { background: rgba(47, 129, 247, .35); }
  100% { background: transparent; }
}
tr.flash > td { animation: flash-bg 1.4s ease-out; }

tr[data-status="queued"] > td,
tr[data-status="downloading"] > td {
  background: rgba(210, 153, 34, .07);
}

tr.show-more td {
  text-align: center;
  cursor: pointer;
  color: var(--accent);
  font-size: .9em;
  padding: .65rem;
}
tr.show-more:hover td { background: #1a2029; }
