:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --border: #2b2f3a;
  --text: #e6e8ee;
  --muted: #9aa3b2;
  --accent: #4f7cff;
  --good: #3ec46d;
  --warn: #e0b341;
  --bad: #e05f5f;
}
/* Line colors are supplied per-system by the API and applied inline. */

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  justify-content: center;
  padding: 2rem 1rem;
  -webkit-text-size-adjust: 100%;
}

main { width: 100%; max-width: 720px; }

header { text-align: center; margin-bottom: 1.5rem; }
h1 { margin: 0; font-size: 2.2rem; }
.tagline { color: var(--muted); margin: 0.25rem 0 0; }

.controls, .guesses, footer {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.35rem; }

.guess-row { display: flex; gap: 0.5rem; }
input {
  width: 100%;
  background: #0c0e12;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  font-size: 1rem;
}
input:focus { outline: 2px solid var(--accent); }

.system-select {
  width: 100%;
  background: #0c0e12;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  font-size: 1rem;
  margin-bottom: 1rem;
  cursor: pointer;
}
.system-select:focus { outline: 2px solid var(--accent); }

/* Bottom settings panel: no trailing margin on the last control. */
.settings .line-details { margin-bottom: 0; }

/* Collapsible line filter */
.line-details { margin-bottom: 1rem; }
.line-details summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0.15rem 0;
  user-select: none;
}
.line-details summary::-webkit-details-marker { display: none; }
.line-details summary::before {
  content: "▸";
  display: inline-block;
  transition: transform 0.15s ease;
}
.line-details[open] summary::before { transform: rotate(90deg); }
.line-summary { color: var(--text); }

/* Line filter chips */
.line-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.6rem 0 0.25rem;
}
.line-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.6rem 0.3rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #0c0e12;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
}
.line-chip[aria-pressed="false"] { opacity: 0.4; }
.line-chip:hover { border-color: var(--accent); }

/* Custom autocomplete combobox */
.combobox { position: relative; flex: 1; }

.suggestions {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  max-height: 280px;
  overflow-y: auto;
  background: #0c0e12;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
}
.suggestions[hidden] { display: none; }

.suggestions li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.95rem;
}
.suggestions li .name { flex: 1; }
.suggestions li .dots { display: inline-flex; gap: 0.15rem; }
.suggestions li[aria-selected="true"],
.suggestions li:hover { background: rgba(79, 124, 255, 0.18); }
.suggestions li .match { color: var(--accent); font-weight: 700; }
.suggestions .no-results { color: var(--muted); cursor: default; }
.suggestions .no-results:hover { background: transparent; }

button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.1rem;
  font-size: 1rem;
  cursor: pointer;
}
button:hover { filter: brightness(1.1); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.secondary { background: transparent; border: 1px solid var(--border); color: var(--muted); }

.actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.message { min-height: 1.2rem; margin: 0.75rem 0 0; font-weight: 600; }
.message:empty { display: none; }   /* no reserved space when there's no message */
.message.good { color: var(--good); }
.message.bad { color: var(--bad); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.55rem 0.5rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
td.dir { font-weight: 700; font-size: 1.1rem; }

/* The match pill holds the line-color dots on the left, match text on the right. */
.badge .dots { display: inline-flex; gap: 0.2rem; }

.line-marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.2rem; height: 1.2rem;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
  vertical-align: middle;
  border: 1px solid rgba(0, 0, 0, 0.35);
}
.line-marker.shape-circle { border-radius: 50%; }
.line-marker.shape-square { border-radius: 3px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: capitalize;
}
.badge.all { background: rgba(62,196,109,0.18); color: var(--good); }
.badge.some { background: rgba(224,179,65,0.18); color: var(--warn); }
.badge.none { background: rgba(224,95,95,0.18); color: var(--bad); }

tr.correct td { background: rgba(62,196,109,0.12); }

.empty { color: var(--muted); text-align: center; margin: 0.5rem 0; }
footer input { font-size: 0.85rem; }

/* Let long station names wrap rather than force the table wide. */
#guess-table td:nth-child(2) { overflow-wrap: anywhere; }

/* ---- Mobile ---- */
@media (max-width: 520px) {
  body { padding: 1rem 0.75rem; }
  header { margin-bottom: 1rem; }
  h1 { font-size: 1.8rem; }

  .controls, .guesses { padding: 0.85rem 0.9rem; }

  /* Comfortable touch targets */
  .line-chip { padding: 0.45rem 0.7rem 0.45rem 0.5rem; font-size: 0.9rem; }
  .guess-row button, .actions button { padding: 0.65rem 0.9rem; }

  /* Tighten the 4-column results table so it fits a phone */
  th, td { padding: 0.45rem 0.3rem; }
  th { font-size: 0.7rem; }
  td { font-size: 0.88rem; }
  td.dir { font-size: 1rem; }
  #guess-table th:first-child, #guess-table td:first-child { width: 1.2rem; }

  .badge { padding: 0.3rem 0.5rem; gap: 0.35rem; font-size: 0.78rem; }
  .badge .dots { gap: 0.15rem; }
  .line-marker { width: 1.05rem; height: 1.05rem; font-size: 0.62rem; }
}
