/* ==========================================================================
   Cricket Scorer — mobile-first dark theme
   Designed for 320px–480px phones, one-handed scoring, high contrast.
   ========================================================================== */

:root {
  --bg: #0d1117;
  --surface: #161c26;
  --surface-2: #1e2633;
  --border: rgba(255, 255, 255, 0.08);
  --text: #eef2f8;
  --muted: #8b96a8;
  --accent: #2fe06e;
  --accent-dim: rgba(47, 224, 110, 0.14);
  --danger: #ff4d5e;
  --danger-dim: rgba(255, 77, 94, 0.14);
  --amber: #ffc46b;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

input {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  width: 100%;
  outline: none;
}

input:focus {
  border-color: var(--accent);
}

.hidden { display: none !important; }

/* ============================== VIEWS ============================== */

.back-btn {
  align-self: flex-start;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
}

.view {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.view-header h1 {
  margin: 4px 0 0;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.view-header.center { text-align: center; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.card h3 {
  margin: 12px 0 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.field {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.field input { margin-top: 6px; }

.hint {
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0 4px;
}

.foot-note {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}

/* ============================== BUTTONS ============================== */

.btn {
  display: block;
  width: 100%;
  padding: 13px 16px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--border);
  text-align: center;
}

.btn.primary {
  background: var(--accent);
  color: #04240f;
  border-color: transparent;
  font-weight: 800;
}

.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.big { padding: 17px 16px; font-size: 18px; }
.btn.full { width: 100%; }
.btn:disabled { opacity: 0.45; }

.btn:active,
.control-btn:active,
.tool-btn:active,
.chip:active,
.slot:active {
  transform: scale(0.97);
}

/* ============================== PLAYER CHIPS ============================== */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 40px;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 15px;
  font-weight: 600;
  touch-action: none; /* required for pointer-event dragging on touch */
}

.chip.dragging {
  opacity: 0.5;
  transform: scale(1.08);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.45);
}

.chip.picked {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  opacity: 0.75;
}

/* ============================== DROPZONES ============================== */

.dropzone {
  border: 1px dashed rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 8px 12px 12px;
  margin-top: 6px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone.drop-target {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.add-row {
  display: flex;
  gap: 8px;
}

.add-row input { flex: 1; }

/* ============================== OPENERS ============================== */

.opener-slots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.slot {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 96px;
}

.slot-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.slot-name {
  font-size: 18px;
  font-weight: 800;
}

.slot.filled {
  border-color: var(--accent);
  background: var(--accent-dim);
}

/* ============================== SCORING ============================== */

.sc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sc-team {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sc-tools { display: flex; gap: 8px; }

.tool-btn {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 12px;
}

.sc-score-wrap {
  text-align: center;
  position: relative;
  padding: 6px 0 2px;
}

.sc-score {
  font-size: clamp(56px, 19vw, 88px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 4px 24px rgba(47, 224, 110, 0.12);
  display: inline-block;
}

.sc-meta {
  display: flex;
  justify-content: center;
  gap: 12px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.sc-meta .muted { font-weight: 600; }

.sc-target {
  margin-top: 6px;
  font-size: 14px;
  font-weight: 800;
  color: var(--amber);
  letter-spacing: 0.02em;
}

/* Floating "+N" pill near the score */
.plus-pill {
  position: absolute;
  right: 8px;
  top: 18px;
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
  pointer-events: none;
}

/* ============================== BATSMEN ============================== */

.batsmen {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.batsman {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.batsman .b-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 4px;
}

.batsman .b-name {
  font-size: 16px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.batsman .b-runs {
  font-size: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

/* The striker is visually prominent */
.batsman.striker {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 4px 16px rgba(47, 224, 110, 0.12);
}

.batsman.striker .b-name { color: var(--accent); }

/* ============================== SCORING CONTROLS ============================== */

.controls {
  position: sticky;
  bottom: calc(10px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: auto;
  padding-top: 10px;
}

.control-btn {
  height: 62px;
  border-radius: var(--radius);
  font-size: 24px;
  font-weight: 800;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.control-btn.accent {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.control-btn.wicket {
  grid-column: span 2;
  background: var(--danger);
  border-color: transparent;
  color: #fff;
  font-size: 19px;
}

.control-btn.wide {
  grid-column: span 2;
  color: var(--amber);
  font-size: 19px;
}

.control-btn.undo {
  grid-column: 1 / -1;
  height: 50px;
  color: var(--danger);
  border-color: rgba(255, 77, 94, 0.35);
  font-size: 17px;
  font-weight: 800;
}

.control-btn:disabled {
  opacity: 0.4;
}

/* ============================== MODAL ============================== */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 12, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 70; /* above the resume overlay (60) so confirms are clickable there */
}

.modal-box {
  width: 100%;
  max-width: 420px;
  max-height: 82vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}

.modal-box h2 {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 800;
}

.modal-box p { margin: 6px 0 14px; }

.modal-box .btn { margin-bottom: 10px; }
.modal-box .btn:last-child { margin-bottom: 0; }

.sum-line {
  font-size: 34px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.sum-top {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}

/* ============================== SCORECARD TABLE ============================== */

.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.score-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 6px 6px;
  border-bottom: 1px solid var(--border);
}

.score-table td {
  padding: 9px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.score-table td.num { text-align: right; }
.score-table th.num { text-align: right; }

.score-table tr.current td { background: var(--accent-dim); }

.score-table tfoot td {
  font-weight: 800;
  border-bottom: none;
  padding-top: 10px;
}

/* ============================== RESUME / OVERLAYS ============================== */

.overlay-cover {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
}

.resume-card { width: 100%; max-width: 380px; }

.resume-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 800;
}

.res-line {
  font-size: 32px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  margin: 4px 0;
}

.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

/* ============================== TOAST & FLASH ============================== */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 700;
  z-index: 80;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.flash {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 40%, rgba(255, 77, 94, 0.55), rgba(255, 77, 94, 0.15));
  pointer-events: none;
  z-index: 40;
  opacity: 0;
}

/* ============================== REDUCED MOTION ============================== */

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
