/* Layout: one centered column (max 1040px), sticky top bar with tabs;
   game screen splits into two pitches side by side on wide screens. */
:root {
  --bg: #f2f5f0;
  --surface: #ffffff;
  --surface-2: #e8ede6;
  --ink: #16201a;
  --muted: #5a685e;
  --line: #d7ded4;
  --accent: #1f6b3f;      /* pitch green */
  --accent-ink: #ffffff;
  --pitch: #2c7a47;
  --pitch-2: #287142;
  --pitch-line: rgba(255,255,255,.55);
  --red: #d42d40;
  --red-soft: #fbe3e6;
  --blue: #2559d6;
  --blue-soft: #e1e9fb;
  --warn: #9a6a00;
  --warn-soft: #fbf0d2;
  --bad: #b3261e;
  --bad-soft: #fbe2df;
  --shadow: 0 1px 2px rgba(20,40,25,.08), 0 4px 14px rgba(20,40,25,.06);
  --font-body: "Heebo", "Arial Hebrew", Arial, system-ui, sans-serif;
  --font-display: "Rubik", "Heebo", "Arial Hebrew", Arial, sans-serif;
  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1411; --surface: #161e19; --surface-2: #1e2822; --ink: #e6ede7; --muted: #95a59a;
    --line: #2a362f; --accent: #3a9a62; --accent-ink: #06140b; --pitch: #22603a; --pitch-2: #1f5735;
    --pitch-line: rgba(255,255,255,.4); --red: #ff5a6c; --red-soft: #3a1a1f; --blue: #6b97ff; --blue-soft: #18233d;
    --warn: #e7b84a; --warn-soft: #33290f; --bad: #ff7b70; --bad-soft: #3a1714;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1411; --surface: #161e19; --surface-2: #1e2822; --ink: #e6ede7; --muted: #95a59a;
  --line: #2a362f; --accent: #3a9a62; --accent-ink: #06140b; --pitch: #22603a; --pitch-2: #1f5735;
  --pitch-line: rgba(255,255,255,.4); --red: #ff5a6c; --red-soft: #3a1a1f; --blue: #6b97ff; --blue-soft: #18233d;
  --warn: #e7b84a; --warn-soft: #33290f; --bad: #ff7b70; --bad-soft: #3a1714;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 var(--font-body);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
h1, h2, h3 { font-family: var(--font-display); line-height: 1.2; margin: 0; text-wrap: balance; }
h1 { font-size: 1.6rem; font-weight: 800; }
h2 { font-size: 1.2rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.wrap {
  max-width: 1040px; margin: 0 auto;
  padding-block: 20px 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 20px;
}
.wrap:focus { outline: none; }
.loading { color: var(--muted); }

/* top bar */
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); background: var(--accent); z-index: 10; }
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--accent); color: #fff; }
.topbar-inner {
  max-width: 1040px; margin: 0 auto; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding-block: 8px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font: 800 1.25rem var(--font-display); }
.brand svg { width: 30px; height: 30px; }
.brand-pitch { fill: rgba(255,255,255,.14); stroke: #fff; stroke-width: 1.6; }
.brand-line { fill: none; stroke: #fff; stroke-width: 1.6; }
.tabs { display: flex; gap: 2px; margin-inline-start: auto; overflow-x: auto; }
.tabs a {
  text-decoration: none; padding: 6px 12px; border-radius: 999px; font-weight: 500; white-space: nowrap;
  color: rgba(255,255,255,.85);
}
.tabs a:hover { background: rgba(255,255,255,.12); }
.tabs a[aria-current="page"] { background: #fff; color: #1f6b3f; font-weight: 700; }
@media (max-width: 520px) {
  .topbar-inner { gap: 6px; }
  .tabs { margin-inline-start: 0; width: 100%; justify-content: space-between; }
  .tabs a { padding: 6px 10px; font-size: .95rem; }
}

/* generic */
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }
.sub { color: var(--muted); font-size: .92rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.section-label { font-size: .78rem; font-weight: 700; letter-spacing: .04em; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 8px; padding: 8px 14px; font-weight: 500; cursor: pointer; min-height: 40px;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { padding: 12px 20px; font-size: 1.05rem; min-height: 48px; }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: .9rem; }
.btn.wa { background: #1fa855; color: #fff; border-color: transparent; font-weight: 700; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; flex: none; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: .85rem; font-weight: 500; color: var(--muted); }
.input, select.input {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: 8px 10px; min-height: 42px;
}
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.search { position: relative; }
.search .input { padding-inline-start: 36px; }
.search svg { position: absolute; inset-inline-start: 10px; top: 50%; translate: 0 -50%; width: 18px; height: 18px; color: var(--muted); }

.empty { text-align: center; padding: 28px 16px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty strong { color: var(--ink); font-size: 1.05rem; }

/* position chips */
.pos { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 999px; font-size: .78rem; font-weight: 500; border: 1px solid transparent; white-space: nowrap; }
.pos.pref { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--ink); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.pos.extra { border: 1px dashed var(--line); color: var(--muted); }
.pos-list { display: flex; flex-wrap: wrap; gap: 4px; }

/* guests */
.guest-tag { font-size: .72rem; font-weight: 700; padding: 0 7px; border-radius: 5px; line-height: 1.6; border: 1px dashed var(--muted); color: var(--muted); }
.guests .list { border-top: 1px solid var(--line); }
.guests .row > .grow { min-width: 240px; }
.guests .item:last-child { border-bottom: 0; }

/* rating */
.lvl { display: inline-flex; align-items: center; padding: 0 7px; border-radius: 5px; font-size: .74rem; font-weight: 700; line-height: 1.6; white-space: nowrap; }
.lvl-good { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--ink); }
.lvl-mid { background: var(--surface-2); color: var(--muted); }
.lvl-weak { background: var(--warn-soft); color: var(--warn); }
.name-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 10px; }
.seg button { border: 0; background: transparent; border-radius: 7px; padding: 8px; font-weight: 500; cursor: pointer; color: var(--muted); min-height: 40px; }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: var(--shadow); }
.seg button.lvl-good[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }
.seg button.lvl-weak[aria-checked="true"] { background: var(--warn-soft); color: var(--warn); }
.team-levels { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.team-levels .strength { margin-inline-start: auto; font-size: .85rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--muted); }
/* small rating mark on lineup cards: filled = good, hollow = weak */
.chip.lv-good::before, .chip.lv-weak::before {
  content: ""; position: absolute; bottom: 3px; inset-inline-start: 4px; width: 7px; height: 7px; border-radius: 50%;
}
.chip.lv-good::before { background: var(--accent); }
.chip.lv-weak::before { border: 1.5px solid var(--warn); }

/* lists grouped by line */
.group { display: flex; flex-direction: column; }
.group-head { display: flex; align-items: baseline; gap: 8px; padding: 14px 4px 6px; border-bottom: 1px solid var(--line); }
.group-head h3 { font-size: .95rem; }
.group-head .count { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.list { list-style: none; margin: 0; padding: 0; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line);
  cursor: pointer; min-height: 52px;
}
.item:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.item .name { font-weight: 500; }
.item .meta { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.item .end { margin-inline-start: auto; color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }
.item.check { user-select: none; }
.box {
  width: 24px; height: 24px; border-radius: 6px; border: 2px solid var(--line); flex: none;
  display: grid; place-items: center; background: var(--surface);
}
.item.on .box { background: var(--accent); border-color: var(--accent); }
.item.on .box::after { content: ""; width: 10px; height: 6px; border: solid var(--accent-ink); border-width: 0 0 2.5px 2.5px; rotate: -45deg; translate: 0 -1px; }
.item.on { background: color-mix(in srgb, var(--accent) 7%, transparent); }

/* games list */
.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.game-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px;
  text-decoration: none; display: flex; flex-direction: column; gap: 6px;
}
.game-card:hover { border-color: var(--accent); }
.game-card .when { font: 600 1.1rem var(--font-display); }
.game-card .stats { display: flex; gap: 8px; flex-wrap: wrap; color: var(--muted); font-size: .9rem; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: .78rem; font-weight: 700; }
.tag.ok { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--ink); }
.tag.past { background: var(--surface-2); color: var(--muted); }
.hero-new {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  background: var(--pitch); color: #fff; border-radius: var(--r); padding: 20px;
  background-image: repeating-linear-gradient(90deg, transparent 0 44px, rgba(255,255,255,.05) 44px 88px);
}
.hero-new p { opacity: .85; }
.hero-new .btn { background: #fff; color: #1f6b3f; border: 0; font-weight: 700; }

/* game screen */
.game-head { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; }
.game-head .title { flex: 1 1 220px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.game-head .field { flex: 0 1 220px; }
.steps { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 10px; overflow-x: auto; }
.steps button {
  flex: 1; border: 0; background: transparent; padding: 8px 12px; border-radius: 7px; font-weight: 500; cursor: pointer; white-space: nowrap;
  color: var(--muted);
}
.steps button[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: var(--shadow); }
.steps .n { font-variant-numeric: tabular-nums; }

.counter { font-variant-numeric: tabular-nums; font-weight: 700; }
.counter.full { color: var(--bad); }
.sticky-bar {
  position: sticky; bottom: 0; z-index: 3; margin-inline: -4px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  padding: 10px 4px calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; border-top: 1px solid var(--line);
}
.sticky-bar .grow { font-size: .95rem; }

.notice { border-radius: 8px; padding: 10px 12px; display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; font-size: .95rem; }
.notice.warn { background: var(--warn-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); }
.notice.bad { background: var(--bad-soft); border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent); }
.notice.info { background: var(--surface-2); }
.notice ul { margin: 4px 0 0; padding-inline-start: 18px; }
.notice .grow { min-width: 200px; display: flex; flex-direction: column; gap: 4px; }
.pref-list { list-style: none; padding: 0 !important; display: flex; flex-direction: column; gap: 4px; }
.pref-list li { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 6px; }
.fit-tag { font-size: .75rem; font-weight: 700; padding: 0 7px; border-radius: 5px; line-height: 1.6; }
.fit-tag.extra { background: var(--warn-soft); color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn); }
.fit-tag.off { background: var(--bad-soft); color: var(--bad); box-shadow: inset 0 0 0 1px var(--bad); }

/* rules (constraints / pins) */
.rule { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid var(--line); }
.rule:last-child { border-bottom: 0; }
.rule .kind { font-size: .8rem; font-weight: 700; padding: 2px 8px; border-radius: 6px; }
.kind.together { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.kind.apart { background: var(--bad-soft); color: var(--bad); }
.kind.prefer-together, .kind.prefer-apart { background: var(--surface-2); color: var(--muted); }
.kind.pin { background: var(--surface-2); }
.rule .del { margin-inline-start: auto; }
.rule-form { display: grid; grid-template-columns: 1fr 150px 1fr auto; gap: 8px; align-items: end; }
.pin-form { display: grid; grid-template-columns: 1.4fr 1fr 1fr auto; gap: 8px; align-items: end; }
@media (max-width: 640px) {
  .rule-form, .pin-form { grid-template-columns: 1fr 1fr; }
  .rule-form > :last-child, .pin-form > :last-child { grid-column: 1 / -1; }
}
.team-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.team-dot.red { background: var(--red); }
.team-dot.blue { background: var(--blue); }

/* lineup */
.swap-dots { display: inline-flex; align-items: center; }
.swap-dots .team-dot { width: 12px; height: 12px; border: 2px solid var(--surface); }
.swap-dots .team-dot + .team-dot { margin-inline-start: -5px; }
.lineup-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .teams { grid-template-columns: 1fr; } }
.team { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.team-title { display: flex; align-items: center; gap: 8px; }
.team-title h2 { font-size: 1.15rem; }
.team-title .count { color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }
.team-title .btn { margin-inline-start: auto; }
.team.red .team-title h2 { color: var(--red); }
.team.blue .team-title h2 { color: var(--blue); }

.pitch {
  position: relative; aspect-ratio: 68 / 82; max-width: 100%; border-radius: 10px; overflow: hidden;
  background: repeating-linear-gradient(180deg, var(--pitch) 0 10%, var(--pitch-2) 10% 20%);
  touch-action: pan-y;
}
.pitch svg.marks { position: absolute; inset: 0; width: 100%; height: 100%; }
.pitch svg.marks * { fill: none; stroke: var(--pitch-line); stroke-width: .5; }
.slot {
  position: absolute; translate: -50% -50%; width: 22%; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.slot .lbl { font-size: .66rem; color: rgba(255,255,255,.8); font-weight: 500; line-height: 1; }
.slot.empty .hole {
  width: 100%; min-height: 34px; border: 1.5px dashed rgba(255,255,255,.6); border-radius: 8px; display: grid; place-items: center;
  color: rgba(255,255,255,.85); font-size: .72rem;
}
.chip {
  position: relative; width: 100%; min-height: 34px; padding: 4px 6px; border-radius: 8px; background: var(--surface); color: var(--ink);
  font-size: .8rem; font-weight: 700; line-height: 1.15; text-align: center; display: grid; place-items: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.25); cursor: grab; user-select: none; -webkit-user-select: none; touch-action: none;
  border-top: 4px solid var(--teamc);
  overflow-wrap: anywhere;
}
.team.red { --teamc: var(--red); }
.team.blue { --teamc: var(--blue); }
.pool { --teamc: var(--muted); }
.chip.fit-extra { box-shadow: 0 0 0 2px var(--warn), 0 1px 3px rgba(0,0,0,.25); }
.chip.fit-off { box-shadow: 0 0 0 2px var(--bad), 0 1px 3px rgba(0,0,0,.25); }
.chip.selected { outline: 3px solid #ffd23f; outline-offset: 1px; }
.chip .lock {
  position: absolute; top: -9px; inset-inline-end: -9px; width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; padding: 0; cursor: pointer;
  color: var(--muted); opacity: .9;
}
.chip .lock svg { width: 12px; height: 12px; }
.chip .lock.on { background: var(--ink); color: var(--surface); border-color: var(--ink); opacity: 1; }
.chip.over, .slot.over .hole, .bench.over, .pool-list.over { outline: 3px solid #ffd23f; outline-offset: 2px; }
.drag-ghost { position: fixed; z-index: 50; pointer-events: none; width: 110px; translate: -50% -60%; rotate: -3deg; opacity: .95; }

.bench, .pool-list {
  display: flex; flex-wrap: wrap; gap: 6px; min-height: 52px; padding: 8px; border-radius: 8px;
  background: var(--surface-2); align-items: center;
}
.bench .chip, .pool-list .chip { width: auto; min-width: 84px; padding: 6px 10px; }
.bench .hint, .pool-list .hint { color: var(--muted); font-size: .85rem; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--muted); }
.legend i { display: inline-block; width: 14px; height: 10px; border-radius: 3px; margin-inline-end: 4px; vertical-align: -1px; background: var(--surface); }
.legend .l-extra { box-shadow: 0 0 0 2px var(--warn); }
.legend .l-off { box-shadow: 0 0 0 2px var(--bad); }
.legend .l-good, .legend .l-weak { width: 8px; height: 8px; border-radius: 50%; vertical-align: 0; }
.legend .l-good { background: var(--accent); }
.legend .l-weak { background: transparent; border: 1.5px solid var(--warn); }

/* position picker in the player form */
.pos-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
@media (max-width: 420px) { .pos-picker { grid-template-columns: repeat(2, 1fr); } }
.pos-picker button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px; min-height: 52px;
}
.pos-picker button small { font-size: .72rem; color: var(--muted); }
.pos-picker button[data-state="pref"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pos-picker button[data-state="pref"] small { color: inherit; opacity: .85; }
.pos-picker button[data-state="extra"] { border-style: dashed; border-color: var(--warn); background: var(--warn-soft); }

/* modal */
dialog {
  border: 0; border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 32px);
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(10,20,14,.45); }
#modal-form { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.modal-actions .spacer { flex: 1; }

#toast {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); left: 50%; translate: -50% 0; z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 500;
  max-width: calc(100vw - 32px); box-shadow: 0 8px 30px rgba(0,0,0,.25);
}
#toast.bad { background: var(--bad); color: #fff; }

.share-preview { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.share-preview img { width: 100%; border-radius: 8px; border: 1px solid var(--line); }

@media (prefers-reduced-motion: no-preference) {
  .chip { transition: box-shadow .15s; }
  #toast { animation: rise .2s ease-out; }
  @keyframes rise { from { translate: -50% 8px; opacity: 0; } }
}
