/* Outfit (the club website's typeface), self-hosted for offline use. SIL OFL 1.1, see fonts/OFL.txt. */
@font-face {
  font-family: "Outfit";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("../fonts/outfit-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Outfit";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("../fonts/outfit-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --bg: #000;
  --fg: #fff;
  --muted: #a8a8a8;
  --card: #151515;
  --line: #333;
  /* Club colours (KSV Sottegem): yellow + blue, on a black sun-readable base. */
  --club-yellow: #f6db2d;
  --club-blue: #306ab5;
  --club-blue-light: #7aa5e6; /* readable blue text on black */
  --primary: var(--club-blue);
  --primary-fg: #fff;
  --goal: var(--club-yellow);
  --opp: #3a3a3a;
  --danger: #ff3b30;
  --overtime: #ff8c1a;
  --radius: 14px;
  --tap: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 18px/1.35 "Outfit", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

input, textarea, select { -webkit-user-select: text; user-select: text; }

[hidden] { display: none !important; }

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 8px 12px 12px;
  gap: 10px;
}

.view-center { align-items: center; justify-content: center; }

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 48px;
}

h1 { font-size: 1.3rem; margin: 0; flex: 1; }
.club-logo { height: 44px; width: auto; border-radius: 6px; }
h2 { font-size: 1.15rem; margin: 0 0 6px; }
h3 { font-size: 1rem; margin: 12px 0 4px; }
.muted { color: var(--muted); margin: 0; }
.error { color: var(--danger); white-space: pre-wrap; margin: 0; }

/* Buttons */
.btn {
  appearance: none;
  border: 2px solid transparent;
  border-radius: var(--radius);
  min-height: var(--tap);
  padding: 8px 14px;
  font: inherit;
  font-weight: 700;
  color: var(--fg);
  background: #2a2a2a;
  cursor: pointer;
}
.btn:active { filter: brightness(1.3); transform: scale(0.98); }
.btn:disabled { opacity: 0.35; }
.btn-small { min-height: 44px; padding: 6px 12px; font-size: 0.95rem; }
.btn-xl { font-size: 1.6rem; min-height: 84px; }
.btn-primary { background: var(--primary); color: var(--primary-fg); }
.btn-secondary { background: #2a2a2a; border-color: #555; }
.btn-goal { background: var(--goal); color: #000; }
.btn-opp { background: var(--opp); border-color: #666; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger.armed { background: var(--danger); color: #fff; }
.icon-btn {
  appearance: none;
  background: none;
  border: 0;
  color: var(--fg);
  font-size: 1.8rem;
  min-width: 52px;
  min-height: 52px;
}
.file-btn { display: flex; align-items: center; justify-content: center; }

.row { display: flex; gap: 10px; }
.row > .btn { flex: 1; }

/* Selection */
.team-name { font-size: 1.4rem; font-weight: 800; margin: 0; color: var(--club-yellow); }
.field { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 0.95rem; }
.field input, .field textarea, .field select {
  font: inherit;
  font-size: 1.1rem;
  color: var(--fg);
  background: #111;
  border: 2px solid #444;
  border-radius: 10px;
  padding: 12px;
  min-height: 52px;
}
.sel-tools { display: flex; align-items: center; gap: 8px; }
.segmented { display: flex; gap: 8px; }
.segmented .btn { flex: 1; font-size: 1.15rem; border-color: #555; }
.segmented .btn[aria-pressed="true"] { background: var(--club-yellow); border-color: var(--club-yellow); color: #000; }
.sel-tools .muted { flex: 1; }

.player-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.player-btn {
  width: 100%;
  min-height: var(--tap);
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
}
.player-btn .num {
  display: inline-block;
  min-width: 2ch;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.player-btn[aria-pressed="true"] { background: var(--goal); color: #000; }
.player-btn[aria-pressed="true"] .num { color: #000; }
.player-btn[aria-pressed="false"] { opacity: 0.6; }
.empty { text-align: center; padding: 20px 0; }

.actions { display: flex; flex-direction: column; }

/* Tab bar (hidden during a match) */
.tabbar { display: flex; border-top: 1px solid var(--line); padding: 0 8px; }
.tabbar button {
  flex: 1;
  appearance: none;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  min-height: 52px;
}
.tabbar button[aria-current="page"] { color: var(--club-yellow); }

.plan-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 2px solid var(--club-blue);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-weight: 700;
}
.plan-banner span { flex: 1; }

/* Calendar and history rows */
.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rows li { display: flex; align-items: center; gap: 8px; }
.row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  background: var(--card);
}
.row-main.past { opacity: 0.6; }
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row-text .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-text .sub { color: var(--muted); font-weight: 400; font-size: 0.9rem; }
.row-score { font-size: 1.5rem; font-weight: 900; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-score.W { color: var(--club-yellow); }
.row-score.L { color: var(--danger); }
.row-score.D { color: var(--muted); }
.field.grow { flex: 1; min-width: 0; }

.swipe { position: relative; overflow: hidden; border-radius: var(--radius); }
.swipe .row-main { position: relative; z-index: 1; touch-action: pan-y; }
.swipe-delete {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 96px;
  appearance: none;
  border: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--danger);
  color: #fff;
  font: inherit;
  font-weight: 800;
}
.swipe:not(.revealed) .swipe-delete { visibility: hidden; }

.inactive summary { color: var(--muted); font-weight: 700; padding: 8px 0; }
.inactive .player-btn { opacity: 0.6; }

/* Live */
.live-bar .quarter { font-size: 1.6rem; font-weight: 900; min-width: 3ch; }
.badges { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.badge {
  font-size: 0.85rem;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 999px;
  border: 2px solid var(--muted);
  white-space: nowrap;
}
.badge.ok { border-color: var(--goal); color: var(--goal); }
.badge.warn { border-color: var(--overtime); color: var(--overtime); }
.badge.bad { border-color: var(--danger); color: var(--danger); }
.badge.debug { border-color: #c06cff; color: #c06cff; }

.clock-wrap { text-align: center; }
.clock {
  font-size: clamp(4.5rem, 27vw, 9rem);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.clock.paused { color: var(--muted); }
.clock.overtime-on { color: var(--overtime); }
.overtime {
  font-size: 2rem;
  font-weight: 900;
  color: var(--overtime);
  font-variant-numeric: tabular-nums;
}
.status-line { font-size: 1.1rem; font-weight: 700; color: var(--muted); min-height: 1.4em; }
.status-line.paused { color: var(--club-yellow); }

.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 8px 12px;
}
.side { display: flex; align-items: center; gap: 10px; min-width: 0; }
.side.left { justify-content: flex-end; }
.side.mine .team, .side.mine .goals { color: var(--club-yellow); }
.side .team { font-weight: 700; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .goals { font-size: 3rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.dash { font-size: 2rem; color: var(--muted); }

.goal-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  margin: 0;
  padding: 0;
  min-height: 2em;
}
.goal-list li {
  display: flex;
  gap: 10px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 1.05rem;
}
.goal-list .min { min-width: 4.5ch; font-variant-numeric: tabular-nums; color: var(--muted); }
.goal-list .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.goal-list .at { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.95rem; white-space: nowrap; }
.goal-list .them { color: var(--muted); }

/* Controls grid. Tall phones: 3 rows; short phones (SE): Pause/Resume joins the Undo/End row. */
.controls {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-areas:
    "goal goal goal goal goal opp opp opp"
    "undo undo undo undo end end end end"
    "main main main main main main main main";
  gap: 10px;
}
#btn-goal { grid-area: goal; }
#btn-opp-goal { grid-area: opp; white-space: nowrap; font-size: 1.05rem; padding: 8px 6px; }
#btn-undo { grid-area: undo; }
#btn-end, #btn-share { grid-area: end; }
#btn-main { grid-area: main; }
.controls .btn-end-hidden { visibility: hidden; }
.btn-main.pause { background: #fff; color: #000; }

/* Sheets & dialogs */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: flex-end;
}
.sheet-body {
  width: 100%;
  max-height: 92dvh;
  overflow-y: auto;
  background: #111;
  border-top: 2px solid #444;
  border-radius: 18px 18px 0 0;
  padding: 14px 12px calc(14px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sheet-body h2 { font-size: 1.4rem; }
.btn-cancel { background: none; border-color: #555; }
.btn-share { background: var(--club-yellow); color: #000; }
.share-card { display: block; width: 100%; height: auto; flex-shrink: 0; border-radius: 12px; border: 2px solid #333; }
.share-text {
  flex-shrink: 0;
  width: 100%;
  font: inherit;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--fg);
  background: #000;
  border: 2px solid #444;
  border-radius: 10px;
  padding: 12px;
  resize: none;
}
.dialog p { font-size: 1.15rem; margin: 0 0 8px; }

/* Flash alert: alternates at 2 Hz (< 3 Hz photosensitivity guideline). */
.flash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 24px;
  background: var(--club-yellow);
  color: #000;
}
.flash.flashing { animation: flash 0.5s steps(1, end) infinite; }
@keyframes flash {
  0% { background: var(--club-yellow); color: #000; }
  50% { background: #000; color: var(--club-yellow); }
}
.flash-title { font-size: clamp(2.2rem, 11vw, 5rem); font-weight: 900; line-height: 1.05; }
.flash-detail { font-size: 1.6rem; font-weight: 800; }
.flash-hint { font-size: 1rem; opacity: 0.8; }

.toast {
  position: fixed;
  left: 50%;
  top: 56%;
  transform: translateX(-50%);
  z-index: 50;
  pointer-events: none;
  max-width: 90vw;
  background: #fff;
  color: #000;
  font-weight: 800;
  padding: 12px 18px;
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
}

.update-banner {
  position: fixed;
  top: calc(8px + var(--safe-top));
  left: 12px;
  right: 12px;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--club-blue);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-weight: 700;
}

/* Settings */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.diag {
  font-size: 0.75rem;
  line-height: 1.3;
  white-space: pre-wrap;
  word-break: break-word;
  background: #0b0b0b;
  padding: 8px;
  border-radius: 8px;
  max-height: 50dvh;
  overflow-y: auto;
  -webkit-user-select: text;
  user-select: text;
}

/* iOS ignores the manifest orientation lock, so cover small landscape screens. */
.rotate { display: none; }
@media (orientation: landscape) and (max-height: 500px) {
  .rotate {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 90;
    align-items: center;
    justify-content: center;
    background: #000;
    font-size: 1.5rem;
    font-weight: 800;
  }
}

/* Small phones (iPhone SE, 375×667): fit controls in two rows and tighten vertical space. */
@media (max-height: 700px) {
  .view { gap: 6px; padding-top: 4px; padding-bottom: 8px; }
  .bar { min-height: 40px; }
  .live-bar .quarter { font-size: 1.35rem; }
  .badge { font-size: 0.8rem; padding: 3px 7px; }
  .clock { font-size: clamp(4.5rem, 27vw, 6.5rem); }
  .overtime { font-size: 1.5rem; }
  .status-line { font-size: 1rem; min-height: 0; }
  .scoreboard { padding: 4px 10px; }
  .side .goals { font-size: 2.2rem; }
  .side .team { font-size: 0.95rem; }
  .goal-list li { padding: 4px; font-size: 1rem; }
  .btn-xl { min-height: 64px; font-size: 1.4rem; }
  .controls {
    gap: 8px;
    grid-template-areas:
      "goal goal goal goal goal opp opp opp"
      "undo undo end end main main main main";
  }
  #btn-undo, #btn-end, #btn-share { min-height: 64px; padding: 6px 4px; font-size: 0.95rem; line-height: 1.15; }
  #btn-main { font-size: 1.35rem; }
}
