/* ── Reset & Tokens ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #121212;
  --surface:      #1e1e1e;
  --surface2:     #2a2a2a;
  --border:       #333;
  --text:         #f0f0f0;
  --text-muted:   #888;
  --accent:       #ff6b00;   /* IPL orange */
  --accent-dim:   #cc5500;
  --green:        #538d4e;
  --green-text:   #6aaf65;
  --yellow:       #b59f3b;
  --yellow-text:  #d4b945;
  --grey:         #3a3a3c;
  --clue-bg:      #2a1e00;
  --clue-border:  #f0b429;
  --clue-text:    #f5d78e;
  --radius:       8px;
  --row-h:        52px;
  --transition:   0.2s ease;
}

html, body { overflow-x: hidden; }
html { font-size: 16px; }
html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Header ──────────────────────────────────────────────────── */
.site-header {
  width: 100%;
  max-width: 680px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

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

.logo {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--accent);
  line-height: 1;
}

.tagline {
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-top: 2px;
}

.icon-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--border); }
.icon-btn-placeholder { width: 36px; height: 36px; flex-shrink: 0; }

/* ── Main layout ─────────────────────────────────────────────── */
main {
  width: 100%;
  max-width: 680px;
  padding: 12px 8px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  overflow-x: hidden;
  min-width: 0;
}

.puzzle-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
  align-self: flex-start;
  padding-left: 4px;
}

/* ── Grid ────────────────────────────────────────────────────── */
.grid-header-row,
.guess-row {
  display: grid;
  grid-template-columns: minmax(0, 2.4fr) repeat(5, minmax(0, 1fr));
  gap: 4px;
  width: 100%;
  min-width: 0;
}

/* grid wrapper — constrain to viewport */
.grid-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.grid-header-row {
  padding: 0 2px;
  margin-bottom: 4px;
}

.col-player,
.col-attr {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  text-align: center;
  padding: 4px 2px;
}
.col-player { text-align: left; padding-left: 8px; }

/* ── Guess Row ───────────────────────────────────────────────── */
.guess-row {
  animation: slide-in 0.35s ease both;
}

@keyframes slide-in {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.cell-player {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  height: var(--row-h);
  display: flex;
  align-items: center;
  padding: 0 8px;
  font-size: 0.8rem;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  min-width: 0;
}

.cell-attr {
  border-radius: var(--radius);
  height: var(--row-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  gap: 2px;
  text-align: center;
  line-height: 1.2;
  padding: 4px 2px;
  transition: background var(--transition);
}

.cell-attr .attr-value { font-size: 0.68rem; font-weight: 600; }
.cell-attr .attr-arrow { font-size: 0.8rem; line-height: 1; }

/* Cell colours */
.cell-green  { background: var(--green);  border: 1px solid var(--green);  color: #fff; }
.cell-yellow { background: var(--yellow); border: 1px solid var(--yellow); color: #fff; }
.cell-grey   { background: var(--grey);   border: 1px solid var(--border); color: var(--text-muted); }
.cell-pending { background: var(--surface2); border: 1px solid var(--border); color: var(--text-muted); animation: pulse 1s ease infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ── Clue Card ───────────────────────────────────────────────── */
.clue-card {
  width: 100%;
  background: var(--clue-bg);
  border: 1px solid var(--clue-border);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: clue-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes clue-in {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.clue-icon { font-size: 1.2rem; flex-shrink: 0; margin-top: 1px; }

.clue-body { flex: 1; }
.clue-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--clue-border);
  margin-bottom: 4px;
}
.clue-text {
  font-size: 0.88rem;
  color: var(--clue-text);
  line-height: 1.5;
}

/* ── Search Input ────────────────────────────────────────────── */
#input-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.search-wrapper {
  position: relative;
  width: 100%;
  max-width: 460px;
}

#search-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  padding: 10px 14px;
  outline: none;
  transition: border-color var(--transition);
}
#search-input:focus { border-color: var(--accent); }
#search-input::placeholder { color: var(--text-muted); }
#search-input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Dropdown ────────────────────────────────────────────────── */
.dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  list-style: none;
  z-index: 100;
  max-height: min(52dvh, 380px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.dropdown.hidden { display: none; }

.dropdown li {
  min-height: 44px;
  padding: 10px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.dropdown li > span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dropdown li:hover,
.dropdown li.active { background: var(--surface2); }
.dropdown li .drop-team {
  font-size: 0.7rem;
  color: var(--accent);
  font-weight: 700;
  flex-shrink: 0;
}

.guess-counter {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ── Game-over Banner ────────────────────────────────────────── */
.game-over-banner {
  width: 100%;
  max-width: 460px;
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: slide-in 0.4s ease both;
}
.game-over-banner.hidden { display: none; }

.game-over-banner.win {
  background: linear-gradient(135deg, #1a3a17, #2d5a28);
  border: 1px solid var(--green-text);
}
.game-over-banner.lose {
  background: linear-gradient(135deg, #1e1010, #2e1a1a);
  border: 1px solid #a33;
}

.banner-title { font-size: 1.4rem; font-weight: 800; }
.banner-msg   { font-size: 0.9rem; color: var(--text-muted); }
.banner-answer {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
}
.banner-tomorrow {
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.banner-clues {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.share-btn {
  background: #25d366;
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 10px 24px;
  cursor: pointer;
  transition: background var(--transition);
  align-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
}
.share-btn:hover { background: #1ebe5d; }

/* ── Stats modal content ─────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 12px 0;
}
.stat-box {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 10px 4px;
  text-align: center;
}
.stat-num { font-size: 1.6rem; font-weight: 800; color: var(--accent); }
.stat-lbl { font-size: 0.62rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

.dist-title { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; margin: 16px 0 8px; letter-spacing: 1px; }
.dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.85rem;
}
.dist-num { width: 16px; text-align: right; color: var(--text-muted); flex-shrink: 0; }
.dist-bar-wrap { flex: 1; background: var(--surface2); border-radius: 4px; height: 20px; }
.dist-bar {
  background: var(--grey);
  border-radius: 4px;
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 6px;
  font-size: 0.75rem;
  font-weight: 700;
  min-width: 28px;
  transition: width 0.5s ease;
}
.dist-bar.highlight { background: var(--green); }

.no-stats { color: var(--text-muted); font-size: 0.9rem; margin: 16px 0; text-align: center; }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
  animation: fade-in 0.2s ease;
}
.modal-overlay.hidden { display: none; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 400px;
  position: relative;
  max-height: 90dvh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  background: none; border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}
.modal-close:hover { color: var(--text); }

.modal-box h2 {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 12px;
}
.modal-box p { font-size: 0.9rem; color: var(--text-muted); line-height: 1.6; margin-bottom: 8px; }

.htp-list { list-style: none; margin: 8px 0; display: flex; flex-direction: column; gap: 8px; }
.htp-list li { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; color: var(--text-muted); }
.swatch { display: inline-block; width: 20px; height: 20px; border-radius: 4px; flex-shrink: 0; }
.swatch.green  { background: var(--green); }
.swatch.yellow { background: var(--yellow); }
.swatch.grey   { background: var(--grey); border: 1px solid var(--border); }
.htp-footer { font-size: 0.8rem !important; margin-top: 12px !important; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 680px) {
  .grid-header-row,
  .guess-row {
    grid-template-columns: minmax(0, 2.2fr) repeat(5, minmax(0, 1fr));
    gap: 3px;
  }
  main { padding: 10px 6px 24px; }
  .col-player { padding-left: 4px; }
  .col-attr { font-size: 0.6rem; letter-spacing: 0.5px; }
  .cell-player { font-size: 0.72rem; padding: 0 5px; }
  .cell-attr { font-size: 0.62rem; padding: 3px 1px; }
  .cell-attr .attr-value { font-size: 0.58rem; }
}

@media (max-width: 400px) {
  :root { --row-h: 44px; }
  main { padding: 8px 4px 20px; }

  .grid-header-row,
  .guess-row {
    grid-template-columns: minmax(0, 2fr) repeat(5, minmax(0, 1fr));
    gap: 2px;
  }
  .cell-player { font-size: 0.65rem; padding: 0 4px; }
  .cell-attr { font-size: 0.55rem; padding: 2px 1px; }
  .cell-attr .attr-value { font-size: 0.52rem; }
  .col-attr { font-size: 0.55rem; }

  .logo { font-size: 1.3rem; }
  .tagline { font-size: 0.6rem; }
  .site-header { padding: 10px 10px; }

  .dropdown {
    max-height: min(56dvh, 340px);
  }
}

@media (max-width: 680px) {
  .dropdown.dropdown-mobile {
    z-index: 1000;
  }
}
