:root {
  --bg: #060d0a;
  --bg-2: #0b1611;
  --card: #102019;
  --line: #1e3a2c;
  --text: #e8f3ec;
  --muted: #8fb3a0;
  --accent: #34d399;
  --accent-2: #10b981;
  --danger: #ef4444;
  --opp: #ef4444;
  --ball: #fbbf24;
  --pitch: #0e5c36;
  --pitch-line: rgba(255,255,255,.55);
}

* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.hidden { display: none !important; }

h1, h2, h3, .login-title, .app-title { font-family: 'Fredoka', 'Inter', sans-serif; }

button { font: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 0.6rem 0.75rem;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }

.btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  padding: 0.55rem 1rem;
  font-weight: 600;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent-2); border-color: var(--accent-2); color: #04140d; }
.btn-primary:hover { background: var(--accent); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); }
.btn-danger { color: #fca5a5; border-color: #7f1d1d; }
.btn-danger:hover { background: #450a0a; }
.btn-block { width: 100%; padding: 0.8rem; font-size: 1.05rem; }
.btn:disabled { opacity: .45; cursor: default; }

.status { margin-top: 0.75rem; min-height: 1.2rem; font-size: 0.9rem; color: var(--muted); }
.status.err { color: #fca5a5; }
.status.ok { color: var(--accent); }
.muted { color: var(--muted); font-size: 0.85rem; }

/* ---------- Login ---------- */
.center-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(52,211,153,.12), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 2rem 1.75rem;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
.login-logo {
  width: 64px; height: 64px;
  margin: 0 auto 0.75rem;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--accent), var(--accent-2) 70%);
  color: #04140d;
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 1.5rem;
  display: flex; align-items: center; justify-content: center;
}
.login-title { font-size: 1.8rem; font-weight: 600; }
.login-sub { color: var(--muted); margin: 0.25rem 0 1.5rem; font-size: 0.9rem; }
.login-card form { display: grid; gap: 0.9rem; text-align: left; }
.login-card label { font-size: 0.85rem; color: var(--muted); display: grid; gap: 0.35rem; }
.back-link { display: inline-block; margin-top: 1.25rem; color: var(--muted); font-size: 0.85rem; text-decoration: none; }
.back-link:hover { color: var(--text); }

/* ---------- App shell ---------- */
.app-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  position: sticky; top: 0; z-index: 20;
}
.app-title { font-size: 1.25rem; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-user { display: flex; align-items: center; gap: 0.5rem; color: var(--muted); font-size: 0.85rem; }

#app-main { padding: 1rem; max-width: 760px; margin: 0 auto; }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 1.25rem 0 0.6rem;
}
.section-head h2 { font-size: 1.1rem; font-weight: 600; }

.card-list { display: grid; gap: 0.6rem; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem 1rem;
  display: flex; align-items: center; gap: 0.75rem;
}
.card .main { flex: 1; min-width: 0; }
.card .main strong { font-size: 1.02rem; display: block; }
.card .main .sub { color: var(--muted); font-size: 0.82rem; margin-top: 0.15rem; }
.card .actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
.card.clickable { cursor: pointer; transition: border-color .15s; }
.card.clickable:hover { border-color: var(--accent); }

.badge {
  display: inline-block;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.72rem;
  padding: 0.12rem 0.55rem;
  margin-left: 0.4rem;
  vertical-align: middle;
}
.badge.green { color: var(--accent); border-color: var(--accent-2); }

.inline-form { display: grid; gap: 0.6rem; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 1rem; }
.inline-form label { font-size: 0.82rem; color: var(--muted); display: grid; gap: 0.3rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }

/* guided flows */
.flow-card {
  max-width: 540px;
  margin: 1.5rem auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.3rem 1.2rem;
}
.flow-title { font-family: 'Fredoka', sans-serif; font-size: 1.25rem; font-weight: 600; }
.flow-steps { display: flex; gap: 0.4rem; margin: 0.6rem 0 0.2rem; }
.fs-dot { width: 28px; height: 5px; border-radius: 3px; background: var(--line); }
.fs-dot.on { background: var(--accent); }
.fs-dot.done { background: var(--accent-2); opacity: 0.55; }
.flow-sub { color: var(--muted); font-size: 0.88rem; margin: 0.3rem 0 1rem; }
.flow-body { display: grid; gap: 0.7rem; }
.fl-label { font-size: 0.82rem; color: var(--muted); display: grid; gap: 0.3rem; }
.flow-foot { display: flex; justify-content: space-between; gap: 0.6rem; margin-top: 1.1rem; }
.flow-foot .btn { min-width: 110px; }

/* squad picker */
.squad-pick { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.squad-pick .chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-2);
  color: var(--muted);
  padding: 0.4rem 0.85rem;
  font-weight: 600; font-size: 0.88rem;
}
.squad-pick .chip.on { background: var(--accent-2); border-color: var(--accent-2); color: #04140d; }

/* tabs */
.tabs { display: flex; gap: 0.4rem; margin: 1rem 0; }
.tab-btn {
  flex: 1;
  padding: 0.6rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-2);
  color: var(--muted);
  font-weight: 600;
}
.tab-btn.active { background: var(--card); color: var(--accent); border-color: var(--accent-2); }

/* match stats */
.stats-box {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.6rem;
  margin: 1rem 0;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
}
.stat .k { color: var(--muted); font-size: 0.75rem; }
.stat .v { font-family: 'Fredoka', sans-serif; font-size: 1.05rem; font-weight: 600; margin-top: 0.15rem; }

/* goal steppers in match form */
.steppers { display: grid; gap: 0.4rem; max-height: 220px; overflow-y: auto; }
.stepper { display: flex; align-items: center; gap: 0.5rem; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 0.4rem 0.6rem; }
.stepper .who { flex: 1; font-size: 0.9rem; }
.stepper button { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-weight: 700; }
.stepper .n { width: 1.5rem; text-align: center; font-weight: 700; }

/* ---------- Tactic board ---------- */
/* fixed + overflow hidden — the board can never scroll; the pitch is sized
   in JS (fitPitch) to fill exactly the space between toolbar and hint */
#view-board {
  display: flex; flex-direction: column;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 100vh; height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}
.tactic-name { flex: 1; min-width: 0; font-weight: 600; }

.board-toolbar {
  display: flex; align-items: center; gap: 0.45rem;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  flex-wrap: wrap;
}
.mode-toggle { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.mode-btn { border: 0; background: var(--bg-2); color: var(--muted); padding: 0.5rem 0.9rem; font-weight: 700; }
.mode-btn.active { background: var(--accent-2); color: #04140d; }
.btn-tool { padding: 0.5rem 0.7rem; font-size: 0.85rem; }
.btn-opp { color: #fca5a5; }

.board-body { flex: 1; display: flex; min-height: 0; }
.board-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 0.6rem; min-height: 0; min-width: 0; overflow: hidden; }

/* side panel — squad picker + notes */
.side-head { display: none; }
.side-scrim { display: none; }
.board-side {
  width: 250px;
  flex-shrink: 0;
  border-left: 1px solid var(--line);
  background: var(--bg-2);
  padding: 0.85rem;
  overflow-y: auto;
}
.board-side h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.4rem; }
.board-side .side-sub { color: var(--muted); font-size: 0.75rem; margin-bottom: 0.6rem; line-height: 1.4; }
.board-side textarea { min-height: 140px; font-size: 0.88rem; }

.squad-list { display: grid; gap: 0.4rem; }
.sq-item {
  display: flex; align-items: center; gap: 0.55rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.45rem 0.6rem;
  cursor: pointer;
  font-size: 0.88rem;
  transition: border-color .15s;
}
.sq-item:hover { border-color: var(--accent); }
.sq-item .who { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sq-item .sq-state {
  font-size: 0.68rem; font-weight: 700;
  border-radius: 999px; padding: 0.1rem 0.5rem;
  background: var(--bg); color: var(--muted);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.sq-item.placed { border-color: var(--accent-2); }
.sq-item.placed .sq-state { background: var(--accent-2); border-color: var(--accent-2); color: #04140d; }
.pitch {
  position: relative;
  /* fallback size before fitPitch() sets exact px dimensions */
  width: min(96vw, calc(80dvh * 400 / 620));
  aspect-ratio: 400 / 620;
  background: linear-gradient(180deg, #0f6b3e, var(--pitch));
  border-radius: 10px;
  touch-action: none;
  user-select: none;
}
.pitch svg { position: absolute; inset: 0; width: 100%; height: 100%; }
#arrows-svg { pointer-events: none; }
#arrows-svg line { stroke: var(--ball); stroke-width: 4; stroke-linecap: round; marker-end: url(#arrowhead); }
#arrows-svg line.preview { opacity: .5; }
#arrows-svg line.selected { stroke: #fff; }
/* pointer-events: none lets taps pass through empty areas to the arrow
   hit-lines below; the dots themselves re-enable events. */
#dots-layer { position: absolute; inset: 0; pointer-events: none; }

.dot {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center;
  touch-action: none;
  pointer-events: auto;
}
.dot .circle {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Fredoka', sans-serif;
  font-weight: 700; font-size: 0.95rem;
  border: 2px solid rgba(255,255,255,.85);
  box-shadow: 0 3px 8px rgba(0,0,0,.45);
}
.dot.player .circle { background: var(--accent-2); color: #04140d; }
.dot.opponent .circle { background: var(--opp); color: #fff; }
.dot.ball .circle { width: 18px; height: 18px; background: var(--ball); border-color: #92400e; }
.dot .lbl {
  margin-top: 2px;
  font-size: 0.68rem; font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.8);
  white-space: nowrap;
  pointer-events: none;
}
.dot.selected .circle { outline: 3px solid #fff; }

.board-hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0.45rem;
  border-top: 1px solid var(--line);
}

/* ---------- match cards ---------- */
.match-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.95rem 1.05rem;
  display: grid;
  gap: 0.6rem;
}
.match-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.6rem; flex-wrap: wrap; }
.match-teams { font-family: 'Fredoka', sans-serif; font-size: 1.08rem; font-weight: 600; }
.match-score {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.08rem 0.6rem;
  margin: 0 0.55rem;
  font-size: 1.05rem;
}
.match-score.win { border-color: var(--accent); color: var(--accent); }
.match-score.draw { border-color: #fbbf24; color: #fbbf24; }
.match-score.loss { border-color: var(--danger); color: #fca5a5; }
.match-date { color: var(--muted); font-size: 0.78rem; }
.match-events { display: grid; gap: 0.3rem; font-size: 0.9rem; }
.match-events .k { color: var(--muted); display: inline-block; min-width: 58px; }
.match-note {
  font-size: 0.85rem; color: var(--muted);
  border-left: 2px solid var(--line);
  padding-left: 0.6rem;
  font-style: italic;
  white-space: pre-wrap;
}
.match-actions { display: flex; gap: 0.4rem; justify-content: flex-end; }

/* shared notes */
.note-text { font-size: 0.92rem; white-space: pre-wrap; word-break: break-word; padding-right: 1.2rem; }

/* tactic comment thread */
.thread {
  margin-top: -0.35rem;
  padding: 0.75rem 0.85rem;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: grid;
  gap: 0.55rem;
}
.comment-list { display: grid; gap: 0.45rem; }
.comment {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
}
.comment .c-text { font-size: 0.9rem; white-space: pre-wrap; word-break: break-word; padding-right: 1.2rem; }
.comment .c-meta { display: flex; align-items: center; gap: 0.45rem; margin-top: 0.35rem; }
.comment .c-who { flex: 1; min-width: 0; color: var(--muted); font-size: 0.75rem; }
.like-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-2);
  color: var(--muted);
  padding: 0.12rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 700;
}
.like-btn.on { border-color: var(--accent-2); color: var(--accent); }
/* hover-to-delete × on note cards and tactic comments */
.card, .comment { position: relative; }
.xdel {
  position: absolute;
  top: 0.35rem;
  right: 0.45rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
  padding: 0.1rem 0.4rem;
  opacity: 0;
  transition: opacity .15s;
}
.card:hover > .xdel, .comment:hover > .xdel { opacity: 1; }
.xdel:hover { color: #fca5a5; background: #450a0a; }
@media (hover: none) { .xdel { opacity: 0.75; } }
.thread-foot { display: flex; align-items: center; gap: 0.6rem; }
.thread-foot .c-status { margin-top: 0; min-height: 0; }
.thread .c-input { min-height: 46px; font-size: 0.85rem; }
.board-side .thread { padding: 0; background: transparent; border: 0; margin-top: 0; }

@media (max-width: 860px) {
  .board-side {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: 280px;
    max-width: 85vw;
    transform: translateX(105%);
    transition: transform .2s ease;
    z-index: 60;
    box-shadow: -12px 0 40px rgba(0,0,0,.5);
  }
  .board-side.open { transform: none; }

  /* dimmed backdrop — tap it to close the panel */
  .side-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 55;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }
  .board-side.open ~ .side-scrim { opacity: 1; pointer-events: auto; }

  .side-head { display: flex; align-items: center; justify-content: space-between; }
  .side-close {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
    padding: 0.1rem 0.5rem;
  }
}

@media (max-width: 560px) {
  .app-header { flex-wrap: wrap; }
  .dot .circle { width: 30px; height: 30px; font-size: 0.85rem; }
  .board-toolbar { gap: 0.35rem; }

  /* phone layout */
  #app-main { padding: 0.8rem 0.6rem; }
  .section-head { flex-wrap: wrap; gap: 0.4rem; }
  .card { padding: 0.75rem 0.8rem; flex-wrap: wrap; }
  .card .actions { flex-wrap: wrap; }
  .form-row { grid-template-columns: 1fr; }
  .flow-card { margin: 0.8rem auto; padding: 1rem 0.9rem; }
  .flow-foot .btn { min-width: 0; flex: 1; }
  .match-actions { justify-content: flex-start; }
  .stats-box { grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); }
}

/* comfortable touch targets on phones/tablets */
@media (pointer: coarse) {
  .btn, .tab-btn, .squad-pick .chip, .like-btn { min-height: 42px; }
  .mode-btn, .btn-tool { min-height: 40px; }
  .stepper { padding: 0.5rem 0.6rem; }
  .stepper button { width: 38px; height: 38px; }
}
