/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html.theme-transition,
html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease !important;
}

:root {
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;

  --csk: #f7d000;
  --mi: #004ba0;
  --rcb: #c8102e;
  --kkr: #3a225d;
  --srh: #ff6600;
  --rr: #f15a29;
  --gt: #1d4d8e;
  --dc: #004c97;
  --lsg: #00b4c8;
  --pbks: #aa1e22;
}

[data-theme="dark"] {
  --bg: #0f0f13;
  --surface: #1a1a22;
  --border: #2e2e3a;
  --text: #f0f0f5;
  --muted: #8888a0;
}

[data-theme="light"] {
  --bg: #f4f4f8;
  --surface: #ffffff;
  --border: #d8d8e8;
  --text: #1a1a2e;
  --muted: #666688;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== HEADER ===== */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 56px;
}
.header-inner {
  max-width: 560px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}
.header-left {
  display: flex;
  gap: 8px;
  align-items: center;
}

.nav-link {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--border); color: var(--text); }

.logo {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
}
.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 36px; height: 36px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--border); }

/* ===== MAIN ===== */
main {
  flex: 1;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
  padding: 20px 16px 80px;
}

.day-nav-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.15s;
}
.day-nav-btn:hover:not(:disabled) { color: var(--text); }
.day-nav-btn:disabled { opacity: 0.25; cursor: default; }

.archive-badge {
  display: block;
  text-align: center;
  font-size: 0.75rem;
  color: var(--yellow);
  font-weight: 600;
  margin-top: -10px;
  margin-bottom: 10px;
}

.subtitle {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 20px;
}

.streak-badge {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.strikes-display {
  font-size: 1.1rem;
  letter-spacing: 3px;
  vertical-align: middle;
}

.btn-give-up {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 0.75rem;
  cursor: pointer;
  margin-left: 8px;
  font-family: 'DM Sans', sans-serif;
  transition: background 0.15s, color 0.15s;
}
.btn-give-up:hover { background: var(--border); color: var(--text); }

/* ===== GRID ===== */
.grid-container {
  display: grid;
  grid-template-columns: 80px repeat(3, 1fr);
  grid-template-rows: 80px repeat(3, 1fr);
  gap: 6px;
}

.grid-corner {
  background: transparent;
}

/* Column headers */
.col-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px 6px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1.3;
}

/* Row headers */
.row-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px;
  position: relative;
  overflow: hidden;
}
.row-header .team-stripe {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  border-radius: 10px 0 0 10px;
}
.row-header .team-name {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
}

/* Grid cells */
.grid-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
  position: relative;
  overflow: hidden;
  font-size: 0.78rem;
  padding: 8px;
}
.grid-cell:hover:not(.filled):not(.game-over) {
  border-color: #555570;
  background: #1e1e2a;
}
.grid-cell:active:not(.filled) { transform: scale(0.96); }

.grid-cell.active {
  border-color: #a0a0c8;
  box-shadow: 0 0 0 2px rgba(160,160,200,0.2);
  animation: pulse-border 1.5s ease-in-out infinite;
}

@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 0 2px rgba(160,160,200,0.2); }
  50%       { box-shadow: 0 0 0 4px rgba(160,160,200,0.3); }
}

.grid-cell.filled {
  background: var(--green);
  border-color: var(--green);
  cursor: default;
}
.grid-cell.just-filled {
  animation: pop-in 0.4s ease;
}
@keyframes pop-in {
  0%   { transform: scale(0.7); opacity: 0.5; }
  50%  { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}
.grid-cell.filled .player-fill {
  font-weight: 600;
  font-size: 0.78rem;
  color: #fff;
  text-align: center;
  line-height: 1.3;
}

.grid-cell.wrong-flash {
  animation: flash-red 0.5s ease forwards;
}
@keyframes flash-red {
  0%   { background: var(--red); border-color: var(--red); }
  100% { background: var(--surface); border-color: var(--border); }
}

.grid-cell.game-over { cursor: default; }
.grid-cell.game-over .player-fill.revealed {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.65rem;
  line-height: 1.4;
  opacity: 0.7;
  max-height: 100%;
  overflow-y: auto;
}

/* Plus icon for empty cells */
.grid-cell:not(.filled):not(.game-over)::after {
  content: '+';
  font-size: 1.6rem;
  color: var(--border);
  font-weight: 300;
}
.grid-cell.active::after { color: var(--muted); }

/* Rarity badge */
.rarity-badge {
  position: absolute;
  bottom: 4px;
  right: 5px;
  font-size: 0.62rem;
  color: rgba(255,255,255,0.7);
}

/* ===== SEARCH PANEL ===== */
.search-panel {
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}
.search-context {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 12px;
  text-align: center;
  line-height: 1.4;
}
.search-context strong { color: var(--text); }

.search-wrap { position: relative; }
#search-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 1rem;
  font-family: 'DM Sans', sans-serif;
  outline: none;
}
#search-input:focus { border-color: #7070c0; }

#autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  list-style: none;
  overflow: hidden;
  z-index: 50;
  display: none;
}
#autocomplete-list.open { display: block; }
#autocomplete-list li {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 0.92rem;
  transition: background 0.1s;
}
#autocomplete-list li:hover,
#autocomplete-list li.active { background: var(--border); }
#autocomplete-list li.used { color: var(--muted); font-style: italic; pointer-events: none; }

.btn-cancel {
  margin-top: 10px;
  width: 100%;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 10px;
  padding: 10px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-cancel:hover { background: var(--border); }

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  max-width: 360px;
  width: 90%;
  position: relative;
}
.modal h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.3rem;
  margin-bottom: 14px;
  text-align: center;
}
.modal p {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 10px;
  line-height: 1.5;
}
.modal-close {
  position: absolute;
  top: 14px; right: 14px;
  background: none; border: none;
  color: var(--muted); font-size: 1.1rem; cursor: pointer;
}

/* stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}
.stat-box {
  background: var(--bg);
  border-radius: 10px;
  padding: 12px 8px;
  text-align: center;
}
.stat-num {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.6rem;
  font-weight: 700;
  display: block;
}
.stat-label {
  font-size: 0.7rem;
  color: var(--muted);
  display: block;
  margin-top: 2px;
}

/* share */
.share-preview {
  font-size: 1.5rem;
  letter-spacing: 3px;
  line-height: 1.8;
  text-align: center;
  margin: 10px 0 16px;
  white-space: pre;
}
.btn-share {
  width: 100%;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
}
.btn-share:hover { opacity: 0.85; }

.btn-reveal {
  width: 100%;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 10px;
  padding: 10px;
  font-size: 0.9rem;
  cursor: pointer;
  margin-top: 8px;
  font-family: 'DM Sans', sans-serif;
  transition: background 0.15s, color 0.15s;
}
.btn-reveal:hover { background: var(--border); color: var(--text); }

/* Wide result modal to fit answers grid */
.modal-result-wide { max-width: 520px; }

/* Answers reveal */
.answers-reveal {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  max-height: 340px;
  overflow-y: auto;
}

.answers-grid {
  display: grid;
  grid-template-columns: 48px repeat(3, 1fr);
  gap: 4px;
  font-size: 0.72rem;
}

.answers-corner { }

.answers-col-header {
  background: var(--bg);
  border-radius: 6px;
  padding: 5px 4px;
  text-align: center;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.answers-row-header {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--text);
}

.answers-cell {
  background: var(--bg);
  border-radius: 6px;
  padding: 5px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.answers-cell.answered { border: 1px solid var(--green); }

.answer-name {
  display: block;
  color: var(--muted);
  line-height: 1.4;
  font-size: 0.7rem;
}
.answer-name.your-answer {
  color: var(--green);
  font-weight: 600;
}
.no-answer { color: var(--red); font-style: italic; }
.copied-msg {
  text-align: center;
  color: var(--green);
  font-size: 0.85rem;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.2s;
}
.copied-msg.show { opacity: 1; }

.countdown-label {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 10px;
}
.main-countdown {
  font-size: 0.95rem;
  margin: 16px 0 8px;
}

.result-time {
  text-align: center;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--green);
  margin-bottom: 4px;
}

.timer-display {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  min-width: 36px;
  text-align: center;
}

/* result title */
#result-title { font-size: 1.2rem; }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s;
  z-index: 300;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Team color map */
.team-csk  { background-color: #f7d000; }
.team-mi   { background-color: #004ba0; }
.team-rcb  { background-color: #c8102e; }
.team-kkr  { background-color: #3a225d; }
.team-srh  { background-color: #ff6600; }
.team-rr   { background-color: #f15a29; }
.team-gt   { background-color: #1d4d8e; }
.team-dc   { background-color: #004c97; }
.team-lsg  { background-color: #00b4c8; }
.team-pbks { background-color: #aa1e22; }

/* ===== FOOTER ===== */
footer {
  margin-top: 48px;
  padding: 24px 16px 32px;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
}

.footer-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 12px;
}

.footer-links a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.2s;
}
.footer-links a:hover { color: var(--text); }

.footer-links svg {
  width: 20px;
  height: 20px;
  display: block;
}

.footer-momo span {
  font-size: 0.82rem;
  font-weight: 600;
  background: #e8714a;
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 6px 16px;
  transition: background 0.2s;
}
.footer-momo:hover span {
  background: #d4613e;
}

footer p { line-height: 1.6; }
footer p a { color: var(--muted); text-decoration: underline; }
footer p a:hover { color: var(--text); }
