/* ========== GRIDDLE — Total redesign ========== */
* { box-sizing: border-box; }

:root {
  --bg: #07080c;
  --bg-elevated: #0e1016;
  --bg-surface: #14171f;
  --bg-tile: #1a1e28;
  --border: #252a36;
  --border-focus: #3d4555;
  --text: #f2f3f6;
  --text-secondary: #9ca3b4;
  --text-muted: #6b7280;
  --accent: #e10600;
  --accent-soft: rgba(225, 6, 0, 0.18);
  --correct: #059669;
  --correct-soft: rgba(5, 150, 105, 0.25);
  --wrong: #dc2626;
  --partial: #d97706;
  --higher: #eab308;
  --lower: #7c3aed;
  --radius: 20px;
  --radius-md: 14px;
  --radius-tile: 10px;
  --font-display: "Syne", sans-serif;
  --font-ui: "Inter", sans-serif;
  --shadow-card: 0 24px 48px -12px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.04);
  --shadow-tile: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* ----- F1 ----- */
body.theme-f1 {
  --accent: #e10600;
  --accent-soft: rgba(225, 6, 0, 0.2);
}
body.theme-f1 .game { --card-glow: rgba(225, 6, 0, 0.06); }

/* ----- WEC ----- */
body.theme-wec {
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.2);
  --accent-gold: #d4af37;
}
body.theme-wec .game { --card-glow: rgba(37, 99, 235, 0.06); }
body.theme-wec .info a:hover,
body.theme-wec .info .icon-btn:hover { color: var(--accent-gold); }
body.theme-wec .btn { border-color: var(--accent-gold); color: var(--accent-gold); }
body.theme-wec .btn:hover { background: var(--accent-gold); color: #07080c; }
body.theme-wec .bar { background: linear-gradient(90deg, #1e40af, #2563eb); }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 100% 60% at 50% -15%, rgba(30, 35, 50, 0.5), transparent 45%),
    radial-gradient(ellipse 80% 50% at 80% 100%, rgba(20, 25, 40, 0.4), transparent 40%);
}

h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.85rem, 4.5vw, 2.6rem);
  letter-spacing: -0.02em;
  color: var(--text);
  margin: 0;
}

/* ----- Header ----- */
.title {
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: rgba(14, 16, 22, 0.85);
  backdrop-filter: blur(12px);
}
.title h1 { flex: 1; text-align: center; }
.left { flex: 1; }
.info {
  color: var(--text-secondary);
  font-size: 1.25rem;
  display: flex;
  gap: 0.5rem;
  flex: 1;
  justify-content: flex-end;
}
.info a, .info .icon-btn {
  color: inherit;
  background: none;
  border: none;
  padding: 0.4rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  transition: color 0.2s, background 0.2s;
}
.info a:hover, .info .icon-btn:hover {
  color: var(--accent);
  background: var(--accent-soft);
}
.info .icon-btn i { pointer-events: none; }
.info .icon-btn:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ----- Content + game card ----- */
.content {
  display: grid;
  grid-template-columns: 1fr minmax(320px, 460px) 1fr;
  align-items: start;
  min-height: 76vh;
  padding: 1.25rem 1rem 2rem;
}
.stewardle-notice {
  grid-column: 2;
  justify-self: stretch;
  margin: 0 0 1.25rem 0;
  padding: 0.7rem 1.1rem;
  font-size: 0.9rem;
  text-align: center;
  color: var(--text);
  line-height: 1.4;
  font-family: var(--font-ui);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  box-sizing: border-box;
}
.stewardle-notice a { color: var(--accent); text-decoration: underline; }
.stewardle-notice--back {
  margin-bottom: 1.25rem;
  margin-top: -0.25rem;
}
.stewardle-notice--back a { font-weight: 600; }
.game {
  grid-column: 2;
  justify-self: stretch;
  background: var(--bg-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 2rem 1.5rem;
  border: 1px solid var(--border);
  position: relative;
  overflow: visible;
  --card-glow: transparent;
}
.game::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--card-glow);
  pointer-events: none;
  border-radius: inherit;
}
.vertical-ad, .banner-ad { display: none; }

/* ----- Input ----- */
.input {
  width: 100%;
  margin: 1.5rem 0 1.75rem;
}
.autocomplete { position: relative; }
input[type="text"] {
  width: 100%;
  padding: 1rem 1.4rem;
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: 0;
  word-spacing: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="text"]::placeholder { color: var(--text-muted); }

.autocomplete-items {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 280px;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
  z-index: 200;
}
.autocomplete-items div {
  padding: 0.75rem 1.25rem;
  cursor: pointer;
  color: var(--text);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.autocomplete-items div:last-child { border-bottom: none; }
.autocomplete-items div:hover,
.autocomplete-active {
  background: var(--accent-soft);
  color: var(--text);
}

/* ----- Board ----- */
.board {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
}
.row {
  display: flex;
  flex-direction: row;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 8px;
}
.row.header {
  margin-bottom: 4px;
}
.row.header .frame {
  background: var(--bg-tile);
  border-color: var(--border-focus);
}
.row.header .text {
  color: var(--text-secondary);
  font-size: clamp(0.55rem, 1.8vw, 0.75rem);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1.25;
  padding: 0 1px;
}

.tutorial .row.tutorial-example,
.shareScreen .row.tutorial-example {
  align-items: center;
  justify-content: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.tutorial .row.tutorial-example .frame,
.shareScreen .row.tutorial-example .frame { flex-shrink: 0; }
.tutorial .row.tutorial-example p,
.shareScreen .row.tutorial-example p { margin: 0; flex: 1; min-width: 0; }
.tutorial p, .shareScreen p { margin: 0.5em 0; color: var(--text); font-weight: 500; }
.tutorial > p:first-of-type, .shareScreen > p:first-of-type { margin-top: 0; }

.frame {
  width: 54px;
  height: 54px;
  min-width: 54px;
  border-radius: var(--radius-tile);
  border: 1px solid var(--border);
  background: var(--bg-tile);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-tile);
  transition: background 0.3s ease, border-color 0.25s, box-shadow 0.25s, transform 0.2s;
}
.frame:hover { border-color: var(--border-focus); }

.text {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text);
  line-height: 1.15;
  text-align: center;
}

.frame.correct {
  background: var(--correct);
  border-color: #047857;
  color: #fff;
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.4);
}
.frame.correct .text,
.frame.correct .team-name,
.frame.correct .team-text { color: #fff; }

.frame.incorrect {
  background: var(--wrong);
  border-color: #b91c1c;
  color: #fff;
  box-shadow: 0 4px 14px rgba(220, 38, 38, 0.35);
}
.frame.incorrect .text,
.frame.incorrect .team-name { color: #fff; }

.frame.previous {
  background: var(--partial);
  border-color: #b45309;
  color: #fff;
}
.frame.previous .text,
.frame.previous .team-name { color: #fff; }

.frame.up {
  background: var(--higher);
  border-color: #ca8a04;
  color: #0a0a0a;
  border-radius: var(--radius-tile) var(--radius-tile) 0 0;
}
.frame.up .text { color: #0a0a0a; }

.frame.down {
  background: var(--lower);
  border-color: #6d28d9;
  color: #fff;
  border-radius: 0 0 var(--radius-tile) var(--radius-tile);
}
.frame.down .text { color: #fff; }

.flag, .flag-img {
  max-width: 42px;
  max-height: 42px;
  border-radius: 6px;
  object-fit: cover;
}
.team-logo {
  max-width: 42px;
  max-height: 42px;
  object-fit: contain;
}
.team-name, .team-text {
  font-family: var(--font-ui);
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--text);
  text-align: center;
  word-break: break-all;
  line-height: 1.2;
}

/* ----- Modals ----- */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(7, 8, 12, 0.82);
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.25s;
  z-index: 10;
  pointer-events: none;
}
.tutorial, .shareScreen {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 94%;
  max-width: 400px;
  max-height: 88vh;
  padding: 1.75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  opacity: 0;
  transition: opacity 0.25s;
  z-index: 20;
  overflow-y: auto;
  pointer-events: none;
}
.splitter {
  height: 1px;
  background: var(--border);
  margin: 0.35rem 0;
}
.close, .closeShare {
  position: absolute;
  top: 1rem;
  right: 1rem;
  color: var(--text-muted);
  font-size: 1.35rem;
  cursor: pointer;
  transition: color 0.2s;
}
.close:hover, .closeShare:hover { color: var(--accent); }
.shareScreen b { color: var(--text); margin-right: 0.25em; }

.btn {
  font-family: var(--font-ui);
  font-weight: 600;
  padding: 0.6rem 1.2rem;
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.btn:hover {
  background: var(--accent);
  color: #fff;
}
.score-title { margin: 0 0 0.5rem 0; }
#copyable { margin: 0 0 0.25rem 0; }
.share-copy-row { margin-top: 1.25rem !important; margin-bottom: 0 !important; }
#copied { margin-left: 0.5rem; color: var(--text-muted); font-size: 0.85rem; }

.stats {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.35rem;
}
.stats p { margin: 0; min-width: 1em; font-weight: 600; }
.bar {
  flex: 1;
  height: 20px;
  min-width: 0;
  border-radius: 6px;
  background: var(--correct);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  text-align: right;
  padding-right: 6px;
  line-height: 20px;
  transition: width 0.5s ease;
}
#time { font-variant-numeric: tabular-nums; }

.credits {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 2rem;
  margin-bottom: 1.5rem;
  padding: 0 1rem;
}
.credits p { margin: 0.15em 0; }
a { color: var(--text); text-decoration: none; }
p a { color: var(--accent); }
p a:hover { text-decoration: underline; }

.gg {
  padding: 1.25rem;
  text-align: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-top: 2rem;
  margin-bottom: 1.5rem;
  line-height: 1.6;
}
.gg .p { display: flex; align-items: baseline; justify-content: center; gap: 0.5rem; flex-wrap: wrap; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
@keyframes pulse {
  25% { transform: scale(0.98); }
  75% { transform: scale(1.02); }
}

/* ----- WEC 8 columns (base) ----- */
.board--wec .frame {
  width: 48px;
  height: 48px;
  min-width: 48px;
}
.board--wec .header .text { font-size: clamp(0.5rem, 1.6vw, 0.68rem); }
.board--wec .text { font-size: 0.72rem; }
.board--wec .team-name, .board--wec .team-text { font-size: 0.54rem; }
.board--wec .flag, .board--wec .flag-img { max-width: 38px; max-height: 38px; }
.board--wec .team-logo { max-width: 38px; max-height: 38px; }

/* ========== Responsive ========== */

/* Large screens: cap width, more breathing room */
@media (min-width: 1200px) {
  .content {
    padding: 1.5rem 1.5rem 2rem;
  }
  .stewardle-notice {
    max-width: 520px;
    justify-self: center;
    width: 100%;
  }
  .game {
    padding: 2.25rem 1.75rem;
    max-width: 520px;
    justify-self: center;
    width: 100%;
  }
}

/* Tablet */
@media (max-width: 991px) {
  .content {
    grid-template-columns: 1fr;
    padding: 1rem 1rem 2rem;
    min-height: 72vh;
  }
  .stewardle-notice {
    grid-column: 1;
    justify-self: stretch;
    max-width: none;
    width: 100%;
  }
  .game {
    grid-column: 1;
    justify-self: stretch;
    max-width: none;
    width: 100%;
    padding: 1.75rem 1.25rem;
  }
  .title {
    padding: 0.9rem 1.25rem;
  }
  h1 {
    font-size: clamp(1.6rem, 5vw, 2.2rem);
  }
}

/* Small tablet / large phone */
@media (max-width: 767px) {
  .content {
    padding: 1rem 1rem 2rem;
  }
  .game {
    padding: 1.5rem 1rem;
    border-radius: 16px;
  }
  .frame {
    width: 50px;
    height: 50px;
    min-width: 50px;
  }
  .row { gap: 6px; }
  .header .text { font-size: clamp(0.52rem, 1.5vw, 0.7rem); }
  .text { font-size: 0.76rem; }
  input[type="text"] {
    padding: 0.9rem 1.2rem;
    font-size: 0.95rem;
  }
  .tutorial, .shareScreen {
    width: 96%;
    max-height: 90vh;
    padding: 1.5rem 1.25rem;
    border-radius: 16px;
  }
  .tutorial .frame, .shareScreen .frame {
    width: 42px;
    height: 42px;
    min-width: 42px;
  }
  .credits {
    font-size: 0.7rem;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
  }
  /* WEC: 8 columns a bit smaller */
  .board--wec .frame {
    width: 44px;
    height: 44px;
    min-width: 44px;
  }
  .board--wec .header .text { font-size: clamp(0.48rem, 1.4vw, 0.62rem); }
  .board--wec .text { font-size: 0.68rem; }
  .board--wec .team-name, .board--wec .team-text { font-size: 0.5rem; }
  .board--wec .flag, .board--wec .flag-img { max-width: 34px; max-height: 34px; }
  .board--wec .team-logo { max-width: 34px; max-height: 34px; }
}

/* Phone */
@media (max-width: 540px) {
  body {
    font-size: 14px;
  }
  .content {
    padding: 0.75rem 1rem 1.5rem;
  }
  .game {
    padding: 1.25rem 0.75rem;
    border-radius: 14px;
    margin-left: 0.5rem;
    margin-right: 0.5rem;
    width: calc(100% - 1rem);
    max-width: none;
  }
  .title {
    padding: 0.75rem 1rem;
  }
  h1 {
    font-size: 1.5rem;
    letter-spacing: 0.02em;
  }
  .info {
    font-size: 1.1rem;
    gap: 0.35rem;
  }
  .info a, .info .icon-btn {
    padding: 0.3rem;
  }
  .frame {
    width: 44px;
    height: 44px;
    min-width: 44px;
  }
  .row { gap: 5px; }
  .header .text { font-size: clamp(0.5rem, 1.2vw, 0.65rem); }
  .text { font-size: 0.7rem; }
  .flag, .flag-img { max-width: 32px; max-height: 32px; }
  input[type="text"] {
    padding: 0.85rem 1rem;
    font-size: 0.9rem;
  }
  .input { margin-bottom: 1.25rem; }
  .tutorial, .shareScreen {
    width: 98%;
    padding: 1.25rem 1rem 2rem;
    max-height: 92vh;
    border-radius: 14px;
  }
  .close, .closeShare {
    top: 0.75rem;
    right: 0.75rem;
    font-size: 1.25rem;
  }
  .tutorial .frame, .shareScreen .frame {
    width: 38px;
    height: 38px;
    min-width: 38px;
  }
  .gg {
    padding: 1rem;
    margin-bottom: 1rem;
  }
  .credits {
    font-size: 0.65rem;
    margin-top: 1.25rem;
    margin-bottom: 0.75rem;
    padding: 0 0.5rem;
  }
  .credits p { margin: 0.1em 0; }
  /* WEC: 8 columns fit on small phone */
  .board--wec .frame {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }
  .board--wec .row { gap: 4px; }
  .board--wec .header .text { font-size: clamp(0.44rem, 1.1vw, 0.56rem); }
  .board--wec .text { font-size: 0.58rem; }
  .board--wec .team-name, .board--wec .team-text { font-size: 0.42rem; }
  .board--wec .flag, .board--wec .flag-img { max-width: 26px; max-height: 26px; }
  .board--wec .team-logo { max-width: 26px; max-height: 26px; }
}

/* Very small phone */
@media (max-width: 380px) {
  .content {
    padding: 0.5rem 0.75rem 1.5rem;
  }
  .game {
    padding: 1rem 0.5rem;
    margin-left: 0.5rem;
    margin-right: 0.5rem;
    width: calc(100% - 1rem);
  }
  .frame {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }
  .row { gap: 4px; }
  .header .text { font-size: clamp(0.48rem, 1vw, 0.58rem); }
  .text { font-size: 0.65rem; }
  .flag, .flag-img { max-width: 28px; max-height: 28px; }
  .board--wec .frame {
    width: 32px;
    height: 32px;
    min-width: 32px;
  }
  .board--wec .header .text { font-size: clamp(0.4rem, 0.95vw, 0.5rem); }
  .board--wec .text { font-size: 0.52rem; }
  .board--wec .team-name, .board--wec .team-text { font-size: 0.38rem; }
  .board--wec .flag, .board--wec .flag-img { max-width: 22px; max-height: 22px; }
  .board--wec .team-logo { max-width: 22px; max-height: 22px; }
  .board--wec .row { gap: 3px; }
  h1 { font-size: 1.35rem; }
  .credits {
    font-size: 0.6rem;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
  }
}

/* Safe area for notched devices */
@supports (padding: max(0px)) {
  .content {
    padding-bottom: max(2rem, env(safe-area-inset-bottom, 0px) + 1rem);
  }
  .credits {
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom, 0px));
  }
}
