:root {
  --bg: #0b0f14;
  --panel: #151b23;
  --panel2: #1d2530;
  --line: #26303c;
  --text: #eef3f8;
  --muted: #8d9bab;
  --a: #22c55e;
  --a-soft: #123020;
  --b: #ff6b4a;
  --b-soft: #3a1a12;
  --radius: 20px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(1200px 620px at 50% -12%, #17222d 0%, var(--bg) 62%) fixed, var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, system-ui, -apple-system, "Noto Sans Arabic", "Noto Kufi Arabic", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  font-size: 16px;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }

.app {
  min-height: 100dvh;
  max-width: 620px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
}

.topbar { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.brand { font-weight: 800; font-size: 20px; letter-spacing: .2px; margin-inline-end: auto; }
.brand span { color: var(--a); }
.ghost {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  min-height: 40px;
}
.ghost:active { background: var(--panel2); }
.ghost.icon { width: 44px; padding: 0; font-size: 20px; }

.lead { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; background: var(--panel); padding: 6px; border-radius: 16px; border: 1px solid var(--line); }
.mode { padding: 12px 8px; border-radius: 12px; font-weight: 700; color: var(--muted); font-size: 15px; }
.mode.is-on { background: var(--panel2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }

.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.team { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.team-a { box-shadow: inset 0 0 0 1px rgba(34,197,94,.25); }
.team-b { box-shadow: inset 0 0 0 1px rgba(255,107,74,.25); }
.team label { font-size: 13px; font-weight: 700; letter-spacing: .2px; }
.team-a label { color: var(--a); }
.team-b label { color: var(--b); }
.team input {
  width: 100%;
  background: #0f151c;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 10px;
  font-size: 15px;
  outline: none;
}
.team input:focus { border-color: #3a4757; }
.team input::placeholder { color: #5b6878; }

.primary {
  width: 100%;
  padding: 18px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #2ad06a, #1aa855);
  color: #04170c;
  font-weight: 800;
  font-size: 18px;
  box-shadow: 0 10px 26px rgba(34,197,94,.18);
}
.primary:active { transform: translateY(1px); }

.resume {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.resume .txt { flex: 1; min-width: 0; }
.resume .t1 { font-weight: 700; font-size: 15px; }
.resume .t2 { color: var(--muted); font-size: 13px; margin-top: 2px; }
.resume button { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; font-weight: 700; font-size: 14px; }

.setup-body { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 12px; padding: 6px 0; }
.foot { color: #6d7b8b; font-size: 12.5px; line-height: 1.7; text-align: center; }
.foot button { color: #9fb0c2; text-decoration: underline; text-underline-offset: 3px; font-size: 12.5px; }

/* Match */
.board { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; min-height: 0; }
.side {
  display: flex;
  flex-direction: column;
  border-radius: 24px;
  padding: 10px;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  min-height: 320px;
}
.side-a { border-color: rgba(34,197,94,.35); background: linear-gradient(180deg, var(--a-soft), var(--panel) 70%); }
.side-b { border-color: rgba(255,107,74,.35); background: linear-gradient(180deg, var(--b-soft), var(--panel) 70%); }
.side-names { font-size: 13.5px; font-weight: 700; line-height: 1.45; text-align: center; color: #d6e0ea; padding: 6px 2px 0; min-height: 34px; word-break: break-word; }
.side-hit {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 18px;
  background: rgba(255,255,255,.03);
  transition: transform .06s ease, background .15s ease;
  touch-action: manipulation;
}
.side-a .side-hit { background: rgba(34,197,94,.10); }
.side-b .side-hit { background: rgba(255,107,74,.12); }
.plus { font-size: 22px; font-weight: 700; line-height: 1; color: rgba(255,255,255,.28); }
.side-hit:active { transform: scale(.98); background: rgba(255,255,255,.09); }
.score {
  font-size: clamp(64px, 26vw, 132px);
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -2px;
}
.side-a .score { color: #d6ffe6; text-shadow: 0 0 30px rgba(34,197,94,.35); }
.side-b .score { color: #ffe0d8; text-shadow: 0 0 30px rgba(255,107,74,.3); }
.score.bump { animation: bump .18s ease; }
@keyframes bump { 0% { transform: scale(1); } 45% { transform: scale(1.14); } 100% { transform: scale(1); } }
.side-minus {
  align-self: center;
  width: 64px;
  height: 40px;
  border-radius: 999px;
  background: var(--panel2);
  border: 1px solid var(--line);
  font-size: 20px;
  font-weight: 700;
  color: var(--muted);
}
.side-minus:active { background: #2a3542; }

.actions { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; }
.save { padding: 17px; border-radius: 18px; background: linear-gradient(180deg, #2ad06a, #1aa855); color: #04170c; font-weight: 800; font-size: 17px; }
.newbtn { padding: 17px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); font-weight: 700; font-size: 16px; }
.save:active, .newbtn:active { transform: translateY(1px); }

/* History */
.list { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 12px; }
.row .main { flex: 1; min-width: 0; }
.row .names { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { color: var(--muted); font-size: 12.5px; margin-top: 3px; display: flex; gap: 6px; align-items: center; }
.row .sc { font-weight: 900; font-size: 18px; font-variant-numeric: tabular-nums; letter-spacing: .5px; }
.row .sc .w { color: var(--a); }
.row .sc .l { color: var(--b); }
.row .go { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-weight: 700; font-size: 13.5px; }
.row .del { color: #ff8b74; border-radius: 12px; padding: 10px 8px; font-size: 13px; }
.empty { text-align: center; color: var(--muted); font-size: 14px; padding: 40px 12px; line-height: 1.8; }

.toast {
  position: fixed;
  inset-inline: 0;
  bottom: calc(18px + env(safe-area-inset-bottom));
  margin: 0 auto;
  width: max-content;
  max-width: 88vw;
  background: #22303c;
  color: #eaf2f8;
  border: 1px solid #33424f;
  padding: 11px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  z-index: 10;
}
.toast.on { opacity: 1; transform: translateY(0); }

@media (max-width: 359px) {
  .teams { grid-template-columns: 1fr; }
  .score { font-size: 64px; }
}
