/* Dark, dense, readable on a phone. No framework: the whole UI is a handful
   of tables and cards. */

:root {
  --bg: #11141a;
  --surface: #181c24;
  --surface-2: #1f2430;
  --border: #2a3040;
  --text: #e6e9ef;
  --muted: #8b93a7;
  --accent: #4ade80;
  --up: #4ade80;
  --down: #f87171;
  --danger: #ef4444;
  --warn: #fbbf24;
  /* The chart's single series. The UI accent (#4ade80) is too light for a
     mark on a dark surface — same hue, stepped down into the dark-mode
     lightness band, which also keeps it above the contrast floor. */
  --chart-line: #37ab62;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }

/* --- top bar --- */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .75rem 1rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; letter-spacing: .04em; color: var(--accent); text-decoration: none; }
.topbar nav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.topbar nav a { color: var(--muted); text-decoration: none; }
.topbar nav a:hover { color: var(--text); }
.inline { display: inline; }

/* --- headings --- */

h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
h2.group { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 2rem 0 .5rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }

/* --- cards & tiles --- */

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
}
.card.narrow { max-width: 420px; margin: 3rem auto; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.card.league { text-decoration: none; color: inherit; display: block; }
.card.league:hover { border-color: var(--accent); }

.tiles { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin: 1rem 0; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; }
.tile-label { display: block; font-size: .75rem; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); }
.tile-value { display: block; font-size: 1.35rem; font-weight: 600; margin-top: .25rem; }

dl { margin: .5rem 0 0; }
dl > div { display: flex; justify-content: space-between; padding: .2rem 0; }
dt { color: var(--muted); font-size: .85rem; }
dd { margin: 0; font-variant-numeric: tabular-nums; }
.facts { margin-bottom: 1rem; }

/* --- tables --- */

/* Wide tables scroll sideways on a phone instead of crushing every column. */
.table-scroll { overflow-x: auto; }

table.squad { width: 100%; border-collapse: collapse; font-size: .9rem; }

/* The Kader renders one table per position. Fixed layout plus the shared
   colgroup (partials/squad_cols.html) makes the groups line up with each
   other instead of each sizing itself to its own contents. */
table.squad.kader { table-layout: fixed; min-width: 1040px; }
table.squad.market { min-width: 780px; }
.c-name { width: 14%; }
.c-money { width: 9%; }
.c-points { width: 5%; }
/* Wide enough for "Angeschlagen" in one piece at the table's minimum width.
   The two points come out of the market column, whose meta line wraps. */
.c-status { width: 10%; }
.c-s11 { width: 8%; }
.c-market { width: 10%; }
.c-note { width: 7%; }
.c-actions { width: 14%; }
table.squad.kader td:not(.actions):not(.listing):not(.status-cell):not(.s11-cell),
table.squad.kader th {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Starting-eleven outlook, read off LigaInsider's lineup picture (lineup.py).
   Wraps like the status cell: "Nicht in Startelf" is longer than the column. */
td.s11-cell { white-space: normal; line-height: 1.25; }
/* A single word wider than its column ("Aufbautraining" on a narrow table)
   cannot wrap at a space, and would run into the next column. Hyphenate it
   (the page is lang="de"), and break it anywhere where hyphenation is not
   available. */
td.status-cell, td.s11-cell { hyphens: auto; overflow-wrap: anywhere; }
.s11.starts { color: var(--up); }
.s11.doubtful, .s11.alternative { color: var(--warn); }
.s11.out { color: var(--down); }
.s11.unknown, .s11.pending { color: var(--muted); }
table.squad th {
  text-align: left; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted); font-weight: 600;
  padding: .4rem .5rem; border-bottom: 1px solid var(--border);
}
table.squad td { padding: .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.squad tr:hover td { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.player-name { font-weight: 600; }

/* Sortable headers: the whole cell is the click target. */
table.squad th.sortable { padding: 0; }
table.squad th.sortable a {
  display: block; padding: .4rem .5rem; color: inherit; text-decoration: none;
  white-space: nowrap;
}
table.squad th.sortable.num a { text-align: right; }
table.squad th.sortable a:hover { color: var(--text); }
table.squad th.sortable.active a { color: var(--accent); }
table.squad th.sortable .arrow { margin-left: .25rem; font-size: .85em; }

/* Your own bid on a market listing — blank when you have none. */
.mine { color: var(--accent); font-weight: 600; }

/* A market row's player: photo, then the name with the seller beneath it. */
.market-player { display: flex; align-items: center; gap: .6rem; }
.market-photo {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  background: var(--surface-2); object-fit: cover; object-position: top;
}
.market-who { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.market-seller { color: var(--muted); font-size: .75rem; }

/* "on the market" state of one of your own players, in the Kader. */
td.listing { white-space: normal; }
td.listing .badge { margin-left: 0; }
.listing-meta { display: block; margin-top: .15rem; color: var(--muted); font-size: .72rem; }

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }

.badge {
  display: inline-block; margin-left: .4rem; padding: .05rem .4rem;
  font-size: .7rem; border-radius: 999px;
  background: rgba(74, 222, 128, .12); color: var(--accent);
}
/* Status labels like "Nicht im Kader" outrun the column, so this cell wraps
   instead of being clipped to an ellipsis like the other fixed-layout cells. */
td.status-cell { white-space: normal; line-height: 1.25; }
.status.ok { color: var(--muted); }
.status.bad { color: var(--down); }

/* --- player popup --- */

/* A player name is a button so it is keyboard-reachable, but it has to read as
   part of the table, not as a control. */
button.link-name {
  background: none; border: 0; padding: 0; margin: 0;
  font: inherit; font-weight: 600; color: var(--text);
  text-align: left; cursor: pointer;
}
button.link-name:hover { color: var(--accent); }

.player-dialog {
  width: min(640px, calc(100vw - 2rem));
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; position: relative;
}
.player-dialog::backdrop { background: rgba(6, 8, 12, .72); }
.dialog-close { position: absolute; top: .5rem; right: .75rem; margin: 0; }
.dialog-close button { font-size: 1rem; }

.player-head { display: flex; gap: 1rem; align-items: flex-start; margin-bottom: 1rem; }
.player-head h2 { margin: 0 0 .2rem; font-size: 1.25rem; }
.player-head p { margin: 0 0 .25rem; }
.player-photo {
  border-radius: 8px; background: var(--surface-2); object-fit: cover;
}
.player-sub { color: var(--muted); font-size: .88rem; display: flex; align-items: center; gap: .35rem; }
.club-badge { vertical-align: middle; }

.player-figures { display: flex; gap: 2rem; flex-wrap: wrap; margin-bottom: 1rem; }
.player-figures > div { display: flex; flex-direction: column; gap: .1rem; }
/* Proportional figures: tabular digits look loose at this size. */
.figure { font-size: 1.35rem; font-weight: 600; }

/* --- last matches and the next one --- */

.matches { margin: 0 0 1rem; }
.matches h3 { margin: .6rem 0 .3rem; font-weight: 600; }
.match-list { list-style: none; margin: 0; padding: 0; }
/* A grid per row so the columns line up across the list without a table. */
.match {
  display: grid; align-items: center; gap: .6rem;
  grid-template-columns: 3.2rem minmax(0, 1fr) 2.6rem 2.6rem 6.5rem;
  padding: .3rem 0; border-bottom: 1px solid var(--border); font-size: .88rem;
}
.match.next { grid-template-columns: 3.2rem minmax(0, 1fr) auto; }
.match-day { color: var(--muted); font-size: .78rem; font-variant-numeric: tabular-nums; }
/* "Leverkusen [logo] vs Union Berlin [logo]" — wraps rather than clips on a phone. */
.match-fixture { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem .4rem; min-width: 0; }
.match-club { display: inline-flex; align-items: center; gap: .3rem; }
.match-club img { flex: none; }
.match-club.own { font-weight: 600; }
.match-vs { color: var(--muted); font-size: .8rem; }
.match-score, .match-min, .match-points { text-align: right; font-variant-numeric: tabular-nums; }
.match-score.win { color: var(--up); }
.match-score.loss { color: var(--down); }
.match-score.draw, .match-min, .match-when { color: var(--muted); }
.match-points { font-weight: 600; }
.match-points.missed { font-weight: 400; color: var(--muted); font-size: .8rem; }

@media (max-width: 480px) {
  .match { grid-template-columns: 2.6rem minmax(0, 1fr) 2.3rem 5.2rem; gap: .4rem; }
  .match .match-min { display: none; }
}

/* --- predicted lineup --- */

.lineup { margin: 0 0 1rem; }
.lineup summary { cursor: pointer; font-size: .9rem; }
.lineup summary .muted { font-size: .8rem; margin-left: .35rem; }
/* LigaInsider draws the lineup on white; capped so it stays a glance, not a poster. */
.lineup img {
  display: block; width: 100%; max-width: 480px; height: auto;
  margin: .6rem auto 0; border-radius: 8px;
}

/* --- Aufstellung (the user's own eleven) --- */

.lineup-facts { margin: 0 0 1rem; }

/* A pitch drawn with gradients only: mowing stripes, halfway line and centre
   circle. Rows are the formation's lines, attack at the top. */
.pitch {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-around; gap: 1.1rem;
  padding: 1.5rem .5rem; border-radius: var(--radius);
  border: 2px solid rgba(255, 255, 255, .18);
  background:
    radial-gradient(circle at 50% 50%, transparent 0 4.4rem,
      rgba(255, 255, 255, .16) 4.4rem 4.55rem, transparent 4.55rem),
    linear-gradient(to bottom, transparent calc(50% - 1px),
      rgba(255, 255, 255, .16) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)),
    repeating-linear-gradient(to bottom, #1d4a2c 0 3rem, #1a4428 3rem 6rem);
}
.pitch-row { position: relative; display: flex; justify-content: space-evenly; gap: .35rem; }

.chip {
  display: flex; flex-direction: column; align-items: center; gap: .1rem;
  width: 6.5rem; min-width: 0; text-align: center; line-height: 1.2;
}
.chip-photo {
  position: relative; width: 3.4rem; height: 3.4rem; border-radius: 50%;
  background: var(--surface-2); border: 2px solid rgba(255, 255, 255, .55);
}
/* On a player the photo is a button; undo the global button look. */
button.chip-photo {
  display: block; margin: 0; padding: 0; font: inherit; color: inherit; cursor: pointer;
}
button.chip-photo:hover { border-color: var(--accent); filter: none; }
.chip-photo img { display: block; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.chip.unfit .chip-photo { border-color: var(--down); }
.chip-avg {
  position: absolute; right: -.55rem; bottom: -.2rem;
  padding: 0 .3rem; border-radius: 999px; font-size: .7rem; font-weight: 700;
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
/* The inline padding keeps overflow:hidden from shaving the first and last
   glyph off a bold name. */
button.chip-name {
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-align: center; font-size: .85rem; padding: 0 .15rem;
}
/* Wraps, and breaks a word too long for a narrow chip ("Aufbautraining"),
   rather than writing into the neighbouring chip. */
.chip-meta {
  max-width: 100%; hyphens: auto; overflow-wrap: anywhere;
  font-size: .72rem; color: var(--muted); min-height: 1.2em;
}
/* A chip shrinks when its row is crowded (six midfielders on a narrow window),
   but three point boxes do not. Wrapping them keeps them inside their own chip
   instead of spilling over the neighbour's. */
.chip-recent {
  display: flex; flex-wrap: wrap; justify-content: center; gap: .15rem; max-width: 100%;
  font-size: .66rem; font-variant-numeric: tabular-nums;
}
.chip-recent span {
  min-width: 1.7rem; padding: 0 .15rem; border-radius: 4px; background: rgba(0, 0, 0, .35);
}
.chip-recent .missed { color: var(--muted); }
.chip .s11 { font-size: .7rem; }

.chip.empty .chip-photo { background: transparent; border: 2px dashed rgba(255, 255, 255, .35); }
.chip.empty .chip-name { font-size: .85rem; font-weight: 600; color: var(--muted); }

.bench {
  display: grid; gap: 1rem .5rem; padding: 1rem .5rem;
  grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr)); justify-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}

@media (max-width: 640px) {
  .pitch { padding: 1rem .15rem; }
  .pitch-row { gap: .1rem; }
  .chip { width: auto; flex: 1 1 0; max-width: 6.5rem; }
  .chip-photo { width: 2.7rem; height: 2.7rem; }
  button.chip-name { font-size: .75rem; }
  .chip-recent { font-size: .6rem; }
  .chip-recent span { min-width: 0; }
}

/* --- market value chart --- */

.chart { margin: 0 0 1rem; }
.chart figcaption {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin-bottom: .35rem;
}
.mv-chart { width: 100%; height: auto; display: block; touch-action: none; }
.mv-chart .grid { stroke: var(--border); stroke-width: 1; }
.mv-chart .mv-line {
  fill: none; stroke: var(--chart-line); stroke-width: 2;
  stroke-linejoin: round; stroke-linecap: round;
}
.mv-chart .mv-marker { fill: var(--text); font-size: 11px; font-weight: 600; }
.mv-chart .mv-axis { fill: var(--muted); font-size: 10px; }
.mv-chart .mv-cursor line { stroke: var(--muted); stroke-width: 1; }
.mv-chart .mv-cursor circle {
  fill: var(--chart-line); stroke: var(--surface); stroke-width: 2;
}
.mv-chart .mv-hit { fill: transparent; }
.mv-readout {
  display: flex; gap: .6rem; min-height: 1.2em; margin: .2rem 0 0;
  font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums;
}
.mv-readout-value { color: var(--text); font-weight: 600; }

/* --- notes --- */

.note { cursor: pointer; border-bottom: 1px dotted var(--border); }
.note.empty { color: var(--muted); }
.note-form { display: flex; gap: .25rem; }
.note-form input { margin: 0; width: 10rem; }

/* --- forms & buttons --- */

label { display: block; margin: .9rem 0 .3rem; font-size: .85rem; color: var(--muted); }
input[type="text"], input[type="password"], input[type="email"] {
  width: 100%; padding: .55rem .7rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button, .button {
  display: inline-block; margin-top: 1rem; padding: .55rem 1rem;
  border: 0; border-radius: 8px; background: var(--accent); color: #06210f;
  font-weight: 600; font-size: .9rem; cursor: pointer; text-decoration: none;
}
button:hover { filter: brightness(1.08); }
button.ghost, .button.ghost {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  margin-top: 0; padding: .35rem .7rem; font-weight: 500;
}
button.danger { background: var(--danger); color: #fff; }
button.danger-outline, .button.danger-outline {
  background: transparent; border: 1px solid var(--danger); color: var(--down);
}
button.link {
  background: none; color: var(--muted); padding: 0; margin: 0; font-weight: 400;
}
button.link:hover { color: var(--text); }
/* A submit <button> and an <a class="button"> differ in padding and sit on
   different baselines, so side by side in a .row they have to be normalised
   explicitly — otherwise "Gebot abgeben" and "Abbrechen" end up staggered. */
.row { display: flex; align-items: stretch; gap: .5rem; margin-top: 1rem; }
.row > button, .row > .button {
  display: inline-flex; align-items: center; justify-content: center;
  margin-top: 0; padding: .55rem 1rem; font-size: .9rem; line-height: 1.2;
}
/* The ghost variant has a border and a filled button does not, which alone is
   enough to make the pair 2px different in height. */
.row > button:not(.ghost), .row > .button:not(.ghost) {
  border: 1px solid transparent;
}
.row input { margin: 0; }
/* The flex box is a div inside the cell, never the <td> itself: a flex <td>
   stops being a table cell, so it no longer stretches to the row's height and
   its border falls out of line with the rest of the row. */
.action-buttons { display: flex; flex-wrap: wrap; gap: .3rem; }
.action-buttons form { display: inline; }

/* --- messages --- */

.muted { color: var(--muted); font-size: .9rem; }
.login-hint { font-size: .8rem; margin: 1.25rem 0 0; }
.alert {
  background: rgba(239, 68, 68, .12); border: 1px solid rgba(239, 68, 68, .35);
  color: #fca5a5; padding: .6rem .8rem; border-radius: 8px;
}
.hint {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: .7rem .9rem; color: var(--muted); font-size: .88rem;
}
.hint a { color: var(--accent); }
code { background: var(--surface-2); padding: .1rem .3rem; border-radius: 4px; font-size: .85em; }

pre.json {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; overflow-x: auto; font-size: .82rem; line-height: 1.45;
}

@media (max-width: 640px) {
  table.squad { font-size: .82rem; }
  table.squad td, table.squad th { padding: .4rem .3rem; }
}
