:root {
  --primary: #2E7D32;
  /* Cricket Green */
  --dark: #1B5E20;
  --light: #E8F5E9;
  --accent: #FFD600;
  /* Yellow for highlights */
  --danger: #D32F2F;
  --bg: #121212;
  --text: #ffffff;
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Prevent scrolling in app mode */
}

/* --- Screens --- */
.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  padding: 20px;
}

.screen.active {
  display: flex;
}

/* --- Setup Screen --- */
.setup-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

h1,
h2 {
  text-align: center;
  margin: 0;
  color: var(--primary);
}

input[type="text"],
input[type="number"] {
  padding: 15px;
  font-size: 1.2rem;
  border-radius: 8px;
  border: none;
  background: #333;
  color: white;
  width: 100%;
}

.overs-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.overs-btn {
  padding: 15px;
  background: #333;
  border: 2px solid transparent;
  color: white;
  border-radius: 8px;
  font-size: 1.1rem;
  cursor: pointer;
}

.overs-btn.selected {
  border-color: var(--accent);
  background: var(--dark);
  color: var(--accent);
  font-weight: bold;
}

.start-btn {
  background: var(--primary);
  color: white;
  font-size: 1.5rem;
  padding: 20px;
  border: none;
  border-radius: 50px;
  margin-top: 20px;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

/* --- Match Screen --- */
#match-screen {
  padding: 10px;
}

/* Top Bar */
.header-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 10px;
}

.fs-btn {
  background: none;
  border: 1px solid #555;
  color: #888;
  padding: 5px 10px;
  border-radius: 4px;
}

/* Scoreboard */
.scoreboard {
  background: linear-gradient(135deg, var(--dark), var(--primary));
  border-radius: 15px;
  padding: 20px;
  text-align: center;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}

.score-main {
  font-size: 4rem;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 5px;
}

.score-meta {
  font-size: 1.2rem;
  opacity: 0.9;
  display: flex;
  justify-content: space-around;
}

.teams-display {
  font-size: 0.9rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 5px;
}

.this-over {
  margin: 10px 0;
  min-height: 30px;
  display: flex;
  gap: 5px;
  overflow-x: auto;
  align-items: center;
  padding: 0 5px;
  cursor: pointer;
}

.ball-badge {
  background: #333;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.ball-badge.wicket {
  background: var(--danger);
  color: white;
}

.ball-badge.four {
  background: var(--accent);
  color: black;
  font-weight: bold;
}

.ball-badge.six {
  background: #E040FB;
  color: white;
  font-weight: bold;
}

/* Controls Area */
.controls-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

/* Modifiers Row (Wide, NB, Wicket) */
.modifiers-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  height: 10%;
  margin: 1% 1% 2% 1%;
}

.mod-btn {
  background: #333;
  color: #aaa;
  border: 2px solid #333;
  border-radius: 10px;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.1s;
}

/* Active State for Toggles */
.mod-btn.active {
  background: var(--accent);
  color: black;
  border-color: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.mod-btn.active-red {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

/* Keypad (Runs) */
.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  height: 50%;
}

.run-btn {
  background: #444;
  border: none;
  border-radius: 12px;
  color: white;
  font-size: 2rem;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 0 #222;
}

.run-btn:active {
  transform: translateY(4px);
  box-shadow: none;
}

.run-btn.four {
  color: var(--accent);
  border: 1px solid var(--accent);
}

.run-btn.six {
  color: #E040FB;
  border: 1px solid #E040FB;
}

/* Footer Controls */
.footer-controls {
  display: flex;
  gap: 10px;
  height: 50px;
}

.action-btn {
  flex: 1;
  background: #333;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
}

/* --- Popup --- */
.popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.popup-content {
  background: var(--bg);
  border: 1px solid #555;
  padding: 20px;
  border-radius: 15px;
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 5px 25px rgba(0, 0, 0, 0.5);
}

.popup-close {
  position: absolute;
  top: 10px;
  right: 15px;
  background: none;
  border: none;
  color: white;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
}

#full-history-content .over-group {
  margin-bottom: 15px;
  border-bottom: 1px solid #444;
  padding-bottom: 10px;
}

#full-history-content .over-header {
  font-weight: bold;
  color: var(--primary);
  margin-bottom: 5px;
}

#full-history-content .balls-container {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}