/* ============================================================================
   VM-tipping — styles
   ========================================================================== */
:root {
  --bg: #0f1923;
  --bg-2: #14222f;
  --panel: #1b2c3b;
  --panel-2: #223847;
  --line: #2c4356;
  --text: #e8eef3;
  --muted: #92a7b8;
  --accent: #14b86c;       /* pitch green */
  --accent-2: #0e9a58;
  --gold: #f5c518;
  --red: #e0443e;
  --blue: #2f7dd1;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0,0,0,.28);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overflow-x: auto; }
body {
  background: linear-gradient(180deg, var(--bg), var(--bg-2)) fixed;
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  line-height: 1.45;
  min-height: 100vh;
}

/* ---------- nav ---------- */
#nav {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .7rem 1.2rem;
  background: rgba(15,25,35,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
#nav .brand { font-weight: 800; font-size: 1.15rem; color: var(--text); text-decoration: none; letter-spacing: .3px; }
.nav-links { display: flex; gap: .4rem; flex-wrap: wrap; }
.nav-links a {
  color: var(--muted); text-decoration: none; padding: .45rem .8rem;
  border-radius: 8px; font-weight: 600; font-size: .95rem;
}
.nav-links a:hover { color: var(--text); background: var(--panel); }
.nav-links a.active { color: #fff; background: var(--accent); }

/* ---------- layout ---------- */
.wrap { max-width: 1080px; margin: 0 auto; padding: 1.4rem 1.1rem 5rem; }
/* full-bleed page for the tippeskjema so the bracket can spread out */
.wrap-wide { max-width: none; padding-left: 1.6rem; padding-right: 1.6rem; }

/* three columns: group list | standings | bracket canvas */
.layout { display: flex; flex-wrap: wrap; gap: 1.4rem; align-items: flex-start; }
.col-left { flex: 0 0 420px; max-width: 420px; min-width: 0; }
.col-mid { flex: 0 0 380px; max-width: 380px; min-width: 0; }
.col-right { flex: 1 1 600px; min-width: 0; }
/* medium screens: bracket drops to its own full-width row below the two lists */
@media (max-width: 1400px) {
  .col-right { flex: 1 1 100%; order: 3; }
}
/* small screens: prevent column stacking — page scrolls horizontally as a canvas */
@media (max-width: 900px) {
  .layout { flex-wrap: nowrap; }
  .col-left { flex: 0 0 420px; }
  .col-mid { flex: 0 0 380px; }
  .col-right { flex: 0 0 700px; order: 0; }
}
.page-head { margin: .4rem 0 1.4rem; }
.page-head h1 { margin: 0 0 .3rem; font-size: 1.7rem; }
.page-head p { margin: 0; color: var(--muted); }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem; margin-bottom: 1.2rem;
}
.card > h2 { margin: 0 0 .2rem; font-size: 1.15rem; }
.card > .sub { color: var(--muted); margin: 0 0 .9rem; font-size: .9rem; }

.section-title {
  display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap;
  margin: 1.6rem 0 .7rem; padding-bottom: .4rem; border-bottom: 2px solid var(--line);
}
.section-title h2 { margin: 0; font-size: 1.25rem; }
.section-title .pts { color: var(--gold); font-weight: 700; font-size: .9rem; }

/* ---------- CSV import drop zone ---------- */
.csv-drop-zone {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: .9rem 1.2rem; margin-bottom: 1.2rem;
  transition: border-color .15s, background .15s;
  cursor: default;
}
.csv-drop-zone.drag-over {
  border-color: var(--accent); background: rgba(20,184,108,.07);
}
.csv-drop-inner {
  display: flex; gap: .8rem; align-items: center; flex-wrap: wrap;
  color: var(--muted);
}
.csv-drop-inner svg { flex: none; opacity: .7; }
.csv-drop-label { flex: 1; font-size: .92rem; }
.csv-file-label { cursor: pointer !important; flex: none; }
.csv-preview { margin-bottom: 1.2rem; }
.csv-preview.hidden { display: none; }
.csv-result-card { padding: .9rem 1.1rem; margin-bottom: 0; }

/* ---------- name bar ---------- */
.namebar {
  display: flex; gap: .7rem; align-items: center; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .9rem 1.1rem; margin-bottom: 1.2rem;
}
.namebar label { font-weight: 700; }
.namebar input { flex: 1; min-width: 200px; }

/* ---------- forms ---------- */
input[type=text], input[type=number], input[type=password], select, textarea {
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: .5rem .6rem; font-size: .95rem; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.score-input { width: 3rem; text-align: center; font-weight: 700; font-size: 1rem; }

/* ---------- buttons ---------- */
button, .btn {
  cursor: pointer; border: 1px solid var(--line); background: var(--panel-2);
  color: var(--text); padding: .55rem .9rem; border-radius: 9px;
  font-weight: 700; font-size: .92rem; font-family: inherit;
}
button:hover, .btn:hover { background: #2a4356; }
.btn-primary { background: var(--accent); border-color: var(--accent-2); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn-danger { background: var(--red); border-color: #b63a35; color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { padding: .3rem .55rem; font-size: .82rem; }
.btn-row { display: flex; gap: .6rem; flex-wrap: wrap; }

.sticky-actions {
  position: sticky; bottom: 0; z-index: 30;
  display: flex; gap: .8rem; align-items: center; flex-wrap: wrap;
  background: rgba(15,25,35,.95); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); padding: .8rem 1.1rem; margin: 1.5rem -1.1rem -5rem;
}
.sticky-actions .spacer { flex: 1; }

/* ---------- group matches ---------- */
.group-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 1rem; }
.group-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.group-card h3 { margin: 0; padding: .55rem .8rem; background: var(--panel-2); font-size: 1rem; border-bottom: 1px solid var(--line); }

.match {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  gap: .4rem; padding: .5rem .7rem; border-bottom: 1px solid var(--line);
}
.match:last-child { border-bottom: none; }
.match .meta { grid-column: 1 / -1; font-size: .72rem; color: var(--muted); margin-bottom: .15rem; }
.match .team { display: flex; align-items: center; gap: .4rem; min-width: 0; }
.match .team.home { justify-content: flex-end; text-align: right; }
.match .team .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .9rem; }
.match .vs { display: flex; align-items: center; gap: .25rem; }
.match .vs .dash { color: var(--muted); }
.flag { width: 22px; height: 16px; border-radius: 2px; object-fit: cover; box-shadow: 0 0 0 1px rgba(0,0,0,.3); flex: none; }
.flag-lg { width: 30px; height: 22px; }

/* ---------- chronological match list (tippeskjema) ---------- */
.match-list { display: flex; flex-direction: column; }
.ml-row {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  grid-template-areas: "when when when when" "no home score away";
  align-items: center; gap: 0 .4rem;
  padding: .18rem .3rem .2rem; border-bottom: 1px solid var(--line);
}
.ml-row:last-child { border-bottom: none; }
.ml-row:nth-child(even) { background: rgba(255,255,255,.015); }
.ml-when {
  grid-area: when; font-size: .64rem; color: var(--muted);
  line-height: 1.1; padding-bottom: .1rem; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.ml-no {
  grid-area: no;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.4rem; height: 1.4rem; padding: 0 .28rem; border-radius: 5px;
  background: var(--panel-2); color: var(--muted); font-weight: 700; font-size: .72rem;
}
.ml-home { grid-area: home; display: flex; align-items: center; justify-content: flex-end; gap: .35rem; min-width: 0; padding: .18rem .4rem .18rem .2rem; border-radius: 5px; }
.ml-away { grid-area: away; display: flex; align-items: center; justify-content: flex-start; gap: .35rem; min-width: 0; padding: .18rem .2rem .18rem .4rem; border-radius: 5px; }
.ml-home .nm, .ml-away .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .82rem; font-weight: 600; }
.ml-home.win  { background: linear-gradient(to left,  rgba(20,184,108,.22) 0%, rgba(20,184,108,.06) 100%); }
.ml-away.win  { background: linear-gradient(to right, rgba(20,184,108,.22) 0%, rgba(20,184,108,.06) 100%); }
.ml-home.win .nm, .ml-away.win .nm { color: #14b86c; }
.ml-home.loss { background: linear-gradient(to left,  rgba(220,50,50,.18) 0%, rgba(220,50,50,.05) 100%); }
.ml-away.loss { background: linear-gradient(to right, rgba(220,50,50,.18) 0%, rgba(220,50,50,.05) 100%); }
.ml-home.loss .nm, .ml-away.loss .nm { color: #e05555; }
.ml-home.draw { background: linear-gradient(to left,  rgba(220,220,220,.12) 0%, rgba(220,220,220,.03) 100%); }
.ml-away.draw { background: linear-gradient(to right, rgba(220,220,220,.12) 0%, rgba(220,220,220,.03) 100%); }
.ml-score { grid-area: score; display: flex; align-items: center; gap: .25rem; }
.ml-score .dash { color: var(--muted); }
.flag-wrap { display: inline-flex; flex: none; }

input.sc {
  width: 1.9rem; height: 1.9rem; text-align: center; font-weight: 800; font-size: .95rem;
  padding: 0; border-radius: 7px; background: var(--bg-2); border: 1px solid var(--line);
  -webkit-appearance: none; appearance: none; touch-action: none; caret-color: transparent;
}
input.sc:focus { outline: 2px solid var(--accent); border-color: var(--accent); background: #0c1620; }
input.sc:hover { border-color: var(--accent-2); }

@media (max-width: 600px) {
  .ml-home .nm, .ml-away .nm { font-size: .78rem; }
  input.sc { width: 2.1rem; height: 2.1rem; font-size: 1rem; }
}

/* ---------- knockout picker ---------- */
.ko-round { margin-bottom: 1.1rem; }
.ko-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .55rem; }
.ko-head h3 { margin: 0; font-size: 1.1rem; }
.ko-count { font-size: .85rem; color: var(--muted); }
.ko-count.full { color: var(--accent); font-weight: 700; }
.ko-count.over { color: var(--red); font-weight: 700; }
.team-chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .35rem .6rem; border-radius: 999px; cursor: pointer;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  font-size: .85rem; user-select: none;
}
.chip:hover { border-color: var(--accent); }
.chip.sel { background: var(--accent); border-color: var(--accent-2); color: #fff; }
.chip.disabled { opacity: .35; cursor: not-allowed; }
.chip .flag { width: 18px; height: 13px; }

/* ---------- group standings tables (middle column) ---------- */
.stbl { width: 100%; border-collapse: collapse; margin-bottom: 1rem; font-size: .78rem; }
.stbl thead th { background: #0a0f15; color: #fff; padding: .35rem .25rem; text-align: center; font-weight: 700; }
.stbl thead th.gname { text-align: left; padding-left: .5rem; }
.stbl td { padding: .28rem .25rem; text-align: center; border-bottom: 1px solid var(--line); }
.stbl td.tname { text-align: left; padding-left: .5rem; }
.stbl td.tname .flag { width: 18px; height: 13px; vertical-align: -2px; margin-right: .35rem; }
.stbl td.goals { white-space: nowrap; color: var(--muted); }
.stbl td.pts { font-weight: 800; }
.stbl tr.adv td { background: rgba(47,125,209,.14); }   /* qualify */
.stbl tr.out td { background: rgba(245,197,24,.06); }   /* eliminated */
.stbl.third-tbl tr.adv td { background: rgba(20,184,108,.14); }

/* ---------- knockout bracket ---------- */
.bracket-card { overflow: hidden; }
.bracket {
  display: flex; gap: 2.5rem; padding: .4rem 0 1rem;
  align-items: stretch; position: relative;
}
.bracket-card { overflow: visible; }
/* rounds grow to fill the wide right column on big screens, but keep a
   minimum so they pan/scroll on small screens */
.round { display: flex; flex-direction: column; flex: 1 1 220px; min-width: 215px; max-width: 360px; }
.round-title {
  text-align: center; font-weight: 800; letter-spacing: .3px;
  background: #0a0f15; color: #fff; border-radius: 6px; padding: .4rem .3rem; margin-bottom: .5rem;
}
.matches { flex: 1; display: flex; flex-direction: column; justify-content: space-around; gap: .55rem; }

.bpair { display: flex; flex-direction: column; gap: .55rem; }
.bmatch { display: flex; flex-direction: column; }

/* SVG connector overlay — drawn by JS after each render */
.bracket-svg {
  position: absolute; inset: 0;
  pointer-events: none; overflow: visible;
}
.bmeta { font-size: .68rem; color: var(--muted); margin-bottom: .15rem; padding-left: .25rem; }
.bbox { border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); overflow: hidden; }
.bbox.final { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(245,197,24,.25); }
.bslot {
  display: flex; align-items: center; gap: .4rem; padding: .3rem .4rem;
  border-bottom: 1px solid var(--line); min-height: 36px;
}
.bslot:last-child { border-bottom: none; }
.bslot.win { background: rgba(20,184,108,.16); }
.bslot .flag-wrap { width: 20px; justify-content: center; }
.bteam { flex: 1; font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bteam.empty { color: var(--muted); font-weight: 400; }
.bteam-sel { flex: 1; min-width: 0; font-size: .82rem; padding: .28rem .3rem; }
.winchk { flex: none; width: 26px; height: 26px; padding: 0; border-radius: 6px; font-size: .8rem; line-height: 1; background: var(--panel); }
.winchk.on { background: var(--accent); border-color: var(--accent-2); color: #fff; }
.winchk:disabled { opacity: .3; cursor: default; }

/* ---------- bonus questions ---------- */
.q { padding: .7rem .2rem; border-bottom: 1px solid var(--line); }
.q:last-child { border-bottom: none; }
.q .qtext { font-weight: 600; margin-bottom: .45rem; }
.q .qtext .qpts { color: var(--gold); font-weight: 700; font-size: .8rem; margin-left: .4rem; }
.duel, .yesno { display: flex; gap: .6rem; flex-wrap: wrap; }
.opt {
  text-align: center; padding: .55rem .7rem;
  border-radius: 9px; border: 1px solid var(--line); background: var(--bg-2); cursor: pointer; font-weight: 600;
}
.opt:hover { border-color: var(--accent); }
.opt.sel { background: var(--accent); border-color: var(--accent-2); color: #fff; }
.opt.readonly { cursor: default; opacity: .75; }
.opt.readonly:hover { border-color: var(--line); }
.duel .opt { flex: 1; min-width: 130px; }
.yesno .opt { min-width: 70px; }

/* ---------- searchable autocomplete (player / country) ---------- */
.ac-wrap { position: relative; }
.ac-input { width: 100%; }
.ac-menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 60;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
  box-shadow: var(--shadow); max-height: 240px; overflow-y: auto;
}
.ac-item { display: flex; align-items: baseline; justify-content: space-between; gap: .6rem; padding: .45rem .65rem; cursor: pointer; }
.ac-item:hover, .ac-item.hi { background: var(--accent); color: #fff; }
.ac-item .ac-name { font-weight: 600; }
.ac-item .ac-sub { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.ac-item.hi .ac-sub, .ac-item:hover .ac-sub { color: rgba(255,255,255,.8); }

/* ---------- tables (admin) ---------- */
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th, table.tbl td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); text-align: left; }
table.tbl th { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .04px; }
table.tbl tr:hover td { background: var(--panel-2); }
.rank { font-weight: 800; color: var(--gold); }

/* ---------- admin scoring toggles ---------- */
.mark { display: inline-flex; gap: .3rem; }
.mark button { padding: .25rem .5rem; font-size: .8rem; }
.mark .ok.on { background: var(--accent); border-color: var(--accent-2); color: #fff; }
.mark .no.on { background: var(--red); border-color: #b63a35; color: #fff; }
.score-row { display: grid; grid-template-columns: 1fr auto auto; gap: .6rem; align-items: center; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.score-row .pick { font-size: .9rem; }
.score-row .pick .q { color: var(--muted); }
.score-row .pick .a { color: #fff; font-weight: 800; margin-left: .45rem; background: rgba(20,184,108,.2); padding: .05rem .45rem; border-radius: 6px; }
.score-row .pick .keyinfo { color: var(--muted); font-size: .78rem; margin-left: .55rem; }

/* ---------- misc ---------- */
.pill { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 700; }
.pill.green { background: rgba(20,184,108,.18); color: var(--accent); }
.pill.gray { background: rgba(146,167,184,.18); color: var(--muted); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.banner { padding: .7rem 1rem; border-radius: 9px; margin-bottom: 1rem; font-weight: 600; }
.banner.warn { background: rgba(245,197,24,.14); color: var(--gold); border: 1px solid rgba(245,197,24,.4); }
.banner.info { background: rgba(47,125,209,.14); color: #8ec0f3; border: 1px solid rgba(47,125,209,.4); }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 3vh 1rem; overflow: auto;
}
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); max-width: 780px; width: 100%; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: .9rem 1.1rem; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 1.1rem; }
.modal-foot { padding: .9rem 1.1rem; border-top: 1px solid var(--line); display: flex; gap: .6rem; justify-content: flex-end; }

/* ---------- toast ---------- */
#toast-host { position: fixed; bottom: 1rem; right: 1rem; z-index: 200; display: flex; flex-direction: column; gap: .5rem; }
.toast { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); padding: .7rem 1rem; border-radius: 9px; box-shadow: var(--shadow); opacity: 0; transform: translateY(10px); transition: .25s; }
.toast.show { opacity: 1; transform: none; }
.toast.success { border-color: var(--accent); }
.toast.error { border-color: var(--red); }

/* ---------- admin config editor rows ---------- */
.cfg-q { display: grid; grid-template-columns: auto 1fr auto auto auto; gap: .5rem; align-items: center; padding: .45rem; border: 1px solid var(--line); border-radius: 9px; margin-bottom: .45rem; background: var(--bg-2); }
.cfg-q .handle { cursor: grab; color: var(--muted); font-size: 1.1rem; padding: 0 .2rem; }
.cfg-q input[type=text] { width: 100%; }
.cfg-q .pts-in { width: 4rem; }
.cfg-q.dragging { opacity: .4; }
.cfg-q.dragover { outline: 2px dashed var(--accent); }

@media (max-width: 560px) {
  .match { grid-template-columns: 1fr auto 1fr; }
  .sticky-actions { margin-left: -1.1rem; margin-right: -1.1rem; }
}
