/* ============================================================
   Cricket Captain — dark stadium theme
   ============================================================ */
:root {
  --bg-0: #0a0f1e;
  --bg-1: #0f1830;
  --bg-2: #16223f;
  --card: rgba(255, 255, 255, 0.045);
  --card-border: rgba(255, 255, 255, 0.09);
  --ink: #eaf0ff;
  --ink-dim: #9fb0d0;
  --ink-faint: #6b7a9c;
  --gold: #ffce4a;
  --gold-2: #f5a623;
  --green: #35d07f;
  --red: #ff5a6e;
  --blue: #4aa8ff;
  --radius: 16px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 80% -10%, rgba(53, 208, 127, 0.14), transparent 60%),
    radial-gradient(1000px 600px at 10% 110%, rgba(74, 168, 255, 0.14), transparent 60%),
    linear-gradient(160deg, var(--bg-0), var(--bg-1) 55%, var(--bg-2));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* ---------- screens ---------- */
.screen { display: none; width: 100%; }
.screen.active { display: block; animation: fade 0.35s ease; }
@keyframes fade {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px;
  backdrop-filter: blur(6px);
}
.card-title {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 12px var(--gold);
}

/* ---------- buttons ---------- */
.btn-primary {
  font-family: var(--font);
  font-weight: 800;
  font-size: 15px;
  color: #1a1405;
  background: linear-gradient(180deg, var(--gold), var(--gold-2));
  border: none;
  border-radius: 12px;
  padding: 12px 20px;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.2s ease, filter 0.2s ease;
  box-shadow: 0 8px 24px rgba(245, 166, 35, 0.35);
}
.btn-primary:hover { filter: brightness(1.06); box-shadow: 0 10px 30px rgba(245, 166, 35, 0.5); }
.btn-primary:active { transform: translateY(1px) scale(0.99); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; filter: grayscale(0.3); }
.btn-lg { padding: 15px 28px; font-size: 17px; border-radius: 14px; }
.btn-block { width: 100%; margin-top: 10px; }

/* ---------- segmented control ---------- */
.seg {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}
.seg button {
  font-family: var(--font);
  font-weight: 700;
  font-size: 14px;
  color: var(--ink-dim);
  background: transparent;
  border: none;
  border-radius: 9px;
  padding: 8px 16px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.seg button:hover { color: var(--ink); }
.seg button.active {
  color: #1a1405;
  background: linear-gradient(180deg, var(--gold), var(--gold-2));
  box-shadow: 0 4px 14px rgba(245, 166, 35, 0.4);
}
.seg.speed { margin-left: auto; }
.seg.speed button { padding: 6px 12px; font-size: 13px; }

/* ============================================================
   SETUP
   ============================================================ */
.setup-card {
  max-width: 520px;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  padding: 34px 30px;
  box-shadow: var(--shadow);
  text-align: center;
}
.logo {
  font-size: 38px;
  font-weight: 900;
  margin: 0 0 4px;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #fff, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.tagline { color: var(--ink-dim); margin: 0 0 26px; font-size: 15px; }
.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}
.field { text-align: left; margin-bottom: 18px; }
.field label {
  display: block;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 700;
  margin-bottom: 8px;
}
select {
  width: 100%;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239fb0d0' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
select:focus { outline: none; border-color: var(--gold); }
.toss-row { display: flex; gap: 12px; }
.toss-row .seg { flex: 1; }
.toss-row .seg button { flex: 1; }
#btn-start { width: 100%; margin-top: 6px; }

/* ghost (secondary) button */
.btn-ghost {
  font-family: var(--font);
  font-weight: 700;
  font-size: 14px;
  color: var(--ink-dim);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 10px 16px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-ghost:hover { color: var(--ink); background: rgba(255, 255, 255, 0.06); }
.btn-ghost:disabled { opacity: 0.45; cursor: not-allowed; }

/* ============================================================
   XI SELECTION
   ============================================================ */
.xi-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.xi-count {
  font-size: 15px;
  font-weight: 800;
  color: var(--gold);
  letter-spacing: 0.02em;
}
.xi-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 46vh;
  overflow-y: auto;
  padding-right: 4px;
  text-align: left;
}
.xi-list::-webkit-scrollbar { width: 8px; }
.xi-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 8px; }
.xi-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.12s ease;
  font-size: 14px;
}
.xi-item:hover { background: rgba(255, 255, 255, 0.06); }
.xi-item.on { border-color: var(--gold); background: rgba(255, 206, 74, 0.1); }
.xi-item .xi-name { font-weight: 700; }
.xi-item .xi-role {
  font-size: 11px;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.xi-item .xi-skill {
  margin-left: auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-dim);
  text-transform: capitalize;
}
.xi-item .xi-fit {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  border-radius: 20px;
}
.xi-item .xi-fit.good { background: rgba(53, 208, 127, 0.2); color: var(--green); }
.xi-item .xi-fit.bad { background: rgba(255, 90, 110, 0.18); color: var(--red); }

/* ============================================================
   MATCH
   ============================================================ */
.match-layout {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.match-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px 22px;
}
.team-badge {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.team-badge:last-child { justify-content: flex-end; }
.team-short {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.02em;
  color: var(--gold);
}
.team-score { font-size: 30px; font-weight: 900; letter-spacing: -0.01em; }
.team-overs { font-size: 13px; color: var(--ink-faint); font-weight: 600; }
.match-center { text-align: center; }
.match-format {
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--blue);
  border: 1px solid rgba(74, 168, 255, 0.4);
  border-radius: 20px;
  padding: 3px 12px;
  margin-bottom: 6px;
}
.match-status { font-size: 18px; font-weight: 800; }
.match-pitch { font-size: 12px; color: var(--ink-faint); margin-top: 3px; }

.match-main {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 16px;
  align-items: start;
}
.col-left { display: flex; flex-direction: column; gap: 16px; }
.col-right { display: flex; flex-direction: column; gap: 16px; }

/* video highlights */
.video-card { padding: 14px; }
.card-sub {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 58%;
}
.video-wrap { display: flex; justify-content: center; }
#video-canvas {
  width: 100%;
  max-width: 340px;
  height: auto;
  border-radius: 12px;
  background: #0d1a12;
  border: 1px solid var(--card-border);
}

/* commentary */
.commentary {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}
.commentary::-webkit-scrollbar { width: 8px; }
.commentary::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 8px; }
.ball-line {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0,0,0,0.2);
  animation: slidein 0.3s ease;
}
@keyframes slidein {
  from { opacity: 0; transform: translateX(-6px); }
  to { opacity: 1; transform: translateX(0); }
}
.ball-tag {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 800;
  min-width: 52px;
  text-align: center;
  padding: 3px 6px;
  border-radius: 7px;
  background: rgba(255,255,255,0.08);
  color: var(--ink-dim);
}
.ball-line .txt { font-size: 14px; line-height: 1.4; color: var(--ink); }
.ball-line.wkt .ball-tag { background: rgba(255,90,110,0.2); color: var(--red); }
.ball-line.bnd .ball-tag { background: rgba(53,208,127,0.2); color: var(--green); }
.ball-line.dot .ball-tag { background: rgba(255,255,255,0.05); color: var(--ink-faint); }

/* highlights */
.hl-filter { margin: 10px 0 4px; display: flex; width: 100%; }
.hl-filter button { flex: 1; font-size: 12px; padding: 6px 8px; }
.highlights {
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
  margin-top: 8px;
}
.highlights::-webkit-scrollbar { width: 8px; }
.highlights::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 8px; }
.hl-item {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(0,0,0,0.2);
  animation: slidein 0.3s ease;
}
.hl-item .hl-pos {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 800;
  min-width: 40px;
  text-align: center;
  padding: 3px 5px;
  border-radius: 6px;
  background: rgba(255,255,255,0.08);
  color: var(--ink-dim);
}
.hl-item .hl-txt { font-size: 13px; line-height: 1.35; color: var(--ink); }
.hl-item.bnd .hl-pos { background: rgba(53,208,127,0.2); color: var(--green); }
.hl-item.wkt .hl-pos { background: rgba(255,90,110,0.2); color: var(--red); }
.hl-empty { color: var(--ink-faint); font-size: 13px; padding: 6px 4px; }

/* batsmen */
.batsmen { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.bat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(0,0,0,0.22);
}
.bat-row.striker { background: rgba(255,206,74,0.12); border: 1px solid rgba(255,206,74,0.3); }
.bat-name { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.bat-name .strike { color: var(--gold); font-size: 12px; }
.bat-score { font-weight: 800; font-size: 15px; color: var(--gold); }
.bat-score .balls { color: var(--ink-faint); font-weight: 600; font-size: 12px; margin-left: 6px; }
.bowler-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 10px;
  border-top: 1px solid var(--card-border);
  font-size: 14px;
}
.bowler-info .lbl { color: var(--ink-faint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; }
.bowler-info .fig { font-weight: 800; color: var(--blue); }
.target-line {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(74,168,255,0.12);
  border: 1px solid rgba(74,168,255,0.3);
  font-weight: 700;
  font-size: 14px;
  color: var(--blue);
  text-align: center;
}
.target-line.hidden { display: none; }

/* decision */
.decision-card { min-height: 120px; }
.decision-body { display: flex; flex-direction: column; gap: 14px; }
.dec-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-faint); font-weight: 700; margin-bottom: 8px; }
.choice-list { display: flex; flex-direction: column; gap: 8px; }
.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0,0,0,0.22);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.12s ease;
  font-size: 14px;
}
.choice:hover { background: rgba(255,255,255,0.06); }
.choice.active { border-color: var(--gold); background: rgba(255,206,74,0.1); }
.choice .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ink-faint); flex-shrink: 0; }
.choice.active .dot { background: var(--gold); box-shadow: 0 0 10px var(--gold); }
.choice .meta { margin-left: auto; color: var(--ink-faint); font-size: 12px; font-weight: 600; }
.choice.disabled { opacity: 0.4; cursor: not-allowed; }
.order-list { display: flex; flex-direction: column; gap: 6px; }
.order-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 9px;
  background: rgba(0,0,0,0.2);
  font-size: 14px;
}
.order-item .rank { color: var(--ink-faint); font-weight: 800; width: 18px; }
.order-item .nm { font-weight: 600; }
.order-item .role { margin-left: auto; font-size: 11px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.06em; }
.order-item .up {
  background: none; border: none; color: var(--ink-dim); cursor: pointer;
  font-size: 14px; padding: 2px 6px; border-radius: 6px;
}
.order-item .up:hover { color: var(--gold); background: rgba(255,255,255,0.06); }
.order-item .up:disabled { opacity: 0.3; cursor: not-allowed; }

/* controls */
.controls-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 700; font-size: 14px; color: var(--ink-dim); user-select: none; }
.toggle input { width: 18px; height: 18px; accent-color: var(--gold); cursor: pointer; }
.play-row { display: flex; gap: 10px; margin-top: 12px; }
.play-row .btn-primary { flex: 1.4; }
.play-row .btn-ghost { flex: 1; }

/* scorecard */
.scorecard { display: flex; flex-direction: column; gap: 14px; }
.sc-section h4 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-faint); margin: 0 0 8px; }
.sc-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sc-table th { text-align: right; color: var(--ink-faint); font-weight: 700; padding: 4px 6px; border-bottom: 1px solid var(--card-border); }
.sc-table th:first-child { text-align: left; }
.sc-table td { padding: 5px 6px; text-align: right; border-bottom: 1px solid rgba(255,255,255,0.04); }
.sc-table td:first-child { text-align: left; font-weight: 600; }
.sc-table .out { color: var(--red); }
.sc-table .notout { color: var(--gold); }
.sc-table .dim { color: var(--ink-faint); }

/* ============================================================
   RESULT
   ============================================================ */
.result-card {
  max-width: 560px;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  padding: 40px 34px;
  box-shadow: var(--shadow);
  text-align: center;
}
.result-emoji { font-size: 64px; margin-bottom: 8px; }
#result-title { font-size: 32px; font-weight: 900; margin: 0 0 8px; }
#result-desc { color: var(--ink-dim); font-size: 16px; margin: 0 0 24px; line-height: 1.5; }
.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 26px;
  text-align: left;
}
.rs-item {
  background: rgba(0,0,0,0.25);
  border-radius: 12px;
  padding: 14px;
}
.rs-item .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-faint); font-weight: 700; }
.rs-item .val { font-size: 16px; font-weight: 800; margin-top: 4px; }
.rs-item .sub { font-size: 12px; color: var(--ink-dim); margin-top: 2px; }

/* result: match summary */
.result-summary { margin: 4px 0 20px; text-align: left; }
.sum-head {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 700;
  margin-bottom: 10px;
}
.sum-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sum-item { background: rgba(0,0,0,0.25); border-radius: 12px; padding: 12px 14px; }
.sum-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-faint); font-weight: 700; }
.sum-value { font-size: 14px; font-weight: 800; margin-top: 4px; }

/* result: commentary / scorecard tabs */
.result-tabs { margin-bottom: 26px; text-align: left; }
.result-tab-btns { display: flex; width: 100%; margin-bottom: 12px; }
.result-tab-btns button { flex: 1; }
.tab-panel {
  max-height: 340px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-right: 4px;
}
.tab-panel[hidden] { display: none; }
.tab-panel::-webkit-scrollbar { width: 8px; }
.tab-panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 8px; }
.tab-section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
  font-weight: 700;
  margin-bottom: 8px;
}
.tab-panel .commentary { max-height: none; }
.tab-panel .scorecard { gap: 12px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 860px) {
  .match-main { grid-template-columns: 1fr; }
  .match-header { grid-template-columns: 1fr; gap: 8px; text-align: center; }
  .team-badge, .team-badge:last-child { justify-content: center; }
  .setup-grid { grid-template-columns: 1fr; }
  .result-stats { grid-template-columns: 1fr; }
  .sum-grid { grid-template-columns: 1fr; }
  .card-sub { max-width: 50%; }
}

/* Rotate hint: nudge portrait phone users toward landscape */
.rotate-hint { display: none; }
@media (orientation: portrait) and (max-width: 860px) {
  .rotate-hint {
    display: block;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    color: var(--gold);
    background: rgba(255, 206, 74, 0.1);
    border: 1px solid rgba(255, 206, 74, 0.3);
    border-radius: 10px;
    padding: 8px 12px;
    margin-bottom: 12px;
  }
}

/* Landscape phone: keep scoring + play side by side, no vertical scrolling.
   Placed after the max-width:860px block so it wins the cascade. */
@media (orientation: landscape) and (max-width: 900px) and (max-height: 560px) {
  .match-main { grid-template-columns: 1fr 1fr; gap: 10px; }
  .col-right { order: 1; }
  .col-left { order: 2; }
  .video-card, .scorecard { display: none; }
  .commentary { max-height: 130px; }
  .highlights { max-height: 130px; }
  .decision-card { max-height: 150px; overflow-y: auto; }
  .match-header { padding: 10px 16px; }
  .team-score { font-size: 24px; }
  .card { padding: 10px; }
}

/* Voice segmented control (compact, matches the speed control) */
.seg.voice button { padding: 6px 12px; font-size: 13px; }

/* ---------- custom field editor (tap-to-place fielders) ---------- */
.field-editor { margin-top: 12px; }
.field-editor-hint { font-size: 11px; color: var(--ink-faint); margin-bottom: 8px; }
.field-svg {
  width: 100%;
  max-width: 240px;
  aspect-ratio: 1 / 1;
  display: block;
  margin: 0 auto;
  touch-action: manipulation;
  cursor: crosshair;
}
.field-boundary { fill: rgba(53, 208, 127, 0.07); stroke: rgba(255, 255, 255, 0.4); stroke-width: 1; }
.field-ring { fill: none; stroke: rgba(255, 255, 255, 0.18); stroke-width: 0.6; stroke-dasharray: 2 2; }
.field-pitch { fill: rgba(201, 168, 106, 0.5); }
.field-batsman { fill: #ff5a6e; }
.field-bowler { fill: #ffce4a; }
.field-dot { fill: #4aa8ff; stroke: #fff; stroke-width: 0.8; }
.field-editor-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.field-editor-actions button {
  flex: 1;
  min-width: 56px;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 700;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink-dim);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.field-editor-actions button:hover { background: rgba(255, 255, 255, 0.12); color: var(--ink); }
