/* =========================================================
   NBAdle — Design System
   Aesthetic: Poeltl-inspired clean sports game UI
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Chakra+Petch:ital,wght@0,400;0,600;0,700;1,400;1,700&family=Teko:wght@400;500;600&display=swap');

/* =========================================================
   CSS Custom Properties
   ========================================================= */
:root {
  /* Palette — warm beige + dark purple + gold */
  --bg:           #F5ECDF;
  --bg-dark:      #f0e7d5;
  --surface:      #ffffff;
  --surface-2:    #faf6f0;
  --border:       #d6c9b8;
  --border-dark:  #b8a899;

  /* State colors */
  --correct:      #9DFF00;
  --correct-bg:   rgba(157, 255, 0, 0.15);
  --close:        #ffaa00;
  --close-bg:     rgba(255, 170, 0, 0.15);
  --wrong:        #d6c9b8;
  --wrong-bg:     #ece4d9;

  /* Brand */
  --gold:         #DAA84F;
  --gold-dark:    #c4943a;
  --dark:         #0f0024;
  --dark-2:       #2a1a40;
  --red:          #ff2121;

  /* Text */
  --text:         #0f0024;
  --text-dim:     #7a6a8a;
  --text-muted:   #b8a8c8;

  /* Typography */
  --font-display: 'Chakra Petch', 'Arial', sans-serif;
  --font-body:    'Chakra Petch', 'Arial', sans-serif;
  --font-sub:     'Teko', sans-serif;

  /* Layout */
  --max-width:    860px;
  --radius:       6px;
  --radius-lg:    10px;
  --cell-gap:     5px;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 400;
  min-height: 100vh;
  overflow-x: hidden;

  /* Dot grid pattern */
  --dot: 0.17rem;
  --grid: 1rem;
  background-image:
    radial-gradient(circle at center, var(--bg-dark) var(--dot), transparent 0),
    radial-gradient(circle at center, var(--bg-dark) var(--dot), transparent 0);
  background-size: var(--grid) var(--grid);
  background-position: 0 0, calc(var(--grid) / 2) calc(var(--grid) / 2);
  background-repeat: repeat;
}

/* =========================================================
   Layout
   ========================================================= */
#app {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 clamp(12px, 4vw, 24px) 60px;
}

/* =========================================================
   Header
   ========================================================= */
.site-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 0 16px;
  border-bottom: 2px solid var(--dark);
  margin-bottom: 28px;
}

.title-scoreboard {
  font-family: var(--font-display);
  font-size: clamp(28px, 6vw, 52px);
  font-weight: 700;
  font-style: italic;
  letter-spacing: 0.04em;
  line-height: 1;
  color: var(--dark);
  display: inline-flex;
  gap: 0;
}

/* Gold drop-shadow effect */
.title-scoreboard .title-letter {
  display: inline-block;
  text-shadow: 3px 3px 0 var(--gold), 4px 4px 0 var(--gold-dark);
  opacity: 0;
  -webkit-transform: rotateX(90deg) scaleY(0.4);
  transform: rotateX(90deg) scaleY(0.4);
  -webkit-transform-origin: bottom center;
  transform-origin: bottom center;
  -webkit-animation: letter-flip-in 0.35s cubic-bezier(0.23, 1, 0.32, 1) forwards;
  animation: letter-flip-in 0.35s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

.title-letter:nth-child(1) { -webkit-animation-delay: 0.04s; animation-delay: 0.04s; }
.title-letter:nth-child(2) { -webkit-animation-delay: 0.10s; animation-delay: 0.10s; }
.title-letter:nth-child(3) { -webkit-animation-delay: 0.16s; animation-delay: 0.16s; }
.title-letter:nth-child(4) { -webkit-animation-delay: 0.22s; animation-delay: 0.22s; }
.title-letter:nth-child(5) { -webkit-animation-delay: 0.28s; animation-delay: 0.28s; }
.title-letter:nth-child(6) { -webkit-animation-delay: 0.34s; animation-delay: 0.34s; }

/* =========================================================
   Player Mystery — silhouette above the board
   ========================================================= */
.player-mystery {
  display: flex;
  justify-content: center;
  margin: 0 0 20px;
}

.silhouette-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* Fluid 160×117 ratio, shrinks on small screens */
.player-img {
  width: clamp(100px, 22vw, 160px);
  /* aspect-ratio fallback: use padding-top trick isn't needed since
     we're using a background-image div — height drives from width */
  aspect-ratio: 160 / 117;
  background-size: cover;
  background-position: top center;
  background-repeat: no-repeat;
  border-radius: var(--radius);
  opacity: 0;
  transition: filter 0.6s ease, opacity 0.3s ease;
}

/* aspect-ratio not supported in Safari < 15 — provide explicit height fallback */
@supports not (aspect-ratio: 1) {
  .player-img {
    height: clamp(73px, 16vw, 117px);
  }
}

.player-img.loaded {
  opacity: 1;
}

.player-img.silhouette {
  filter: brightness(0) contrast(1);
}

.player-img.hidden {
  display: none;
}

.btn-reveal {
  position: relative;
  z-index: 2;
  font-family: var(--font-display);
  font-size: clamp(11px, 1.5vw, 13px);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--surface);
  color: var(--text-dim);
  border: 2px solid var(--border-dark);
  border-radius: var(--radius);
  padding: 0.45em 0.9em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-reveal:hover {
  border-color: var(--dark);
  color: var(--dark);
  background: var(--bg);
}

/* =========================================================
   Mode Switcher (host element handles layout)
   ========================================================= */
mode-switcher {
  display: flex;
  justify-content: center;
  margin: 0 0 24px;
}

/* =========================================================
   Guess Grid — column layout lives in game-board shadow DOM
   ========================================================= */
.guess-grid {
  display: flex;
  flex-direction: column;
  gap: var(--cell-gap);
}

/* =========================================================
   Guess Input / Autocomplete
   ========================================================= */
.guess-input-wrap {
  position: relative;
  margin: 0 0 8px;
}

/* =========================================================
   Submit Button + Action Row
   ========================================================= */
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.btn-submit {
  flex: 1 1 120px;
  background: var(--dark);
  color: #fff;
  border: 2px solid var(--dark);
  border-radius: var(--radius);
  font-family: var(--font-display);
  font-size: clamp(13px, 1.8vw, 15px);
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 0.75em 1.5em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, -webkit-transform 0.1s, transform 0.1s;
  text-transform: uppercase;
}

.btn-submit:hover:not(:disabled) {
  background: var(--gold);
  border-color: var(--gold-dark);
  color: var(--dark);
}

.btn-submit:active:not(:disabled) {
  -webkit-transform: scale(0.98);
  transform: scale(0.98);
}

.btn-submit:disabled {
  background: var(--surface);
  border-color: var(--border-dark);
  color: var(--text-muted);
  cursor: not-allowed;
}

.btn-hint,
.btn-random-inline {
  flex: 0 0 auto;
  background: var(--surface);
  color: var(--text-dim);
  border: 2px solid var(--border-dark);
  border-radius: var(--radius);
  font-family: var(--font-display);
  font-size: clamp(11px, 1.5vw, 13px);
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.75em 1em;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s, -webkit-transform 0.1s, transform 0.1s;
  text-transform: uppercase;
}

.btn-hint:hover:not(:disabled),
.btn-random-inline:hover {
  border-color: var(--dark);
  color: var(--dark);
  background: var(--bg);
}

.btn-hint:active:not(:disabled),
.btn-random-inline:active {
  -webkit-transform: scale(0.97);
  transform: scale(0.97);
}

.btn-hint:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* =========================================================
   Guess Counter
   ========================================================= */
.guess-counter-row {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 14px 0 16px;
  /* gap fallback for Safari < 14.1 */
  gap: 10px;
}

/* flex gap fallback via margin for very old Safari */
@supports not (gap: 1px) {
  .guess-counter-row > * + * { margin-left: 10px; }
}

.guess-counter {
  display: flex;
  align-items: center;
  gap: 6px;
}

@supports not (gap: 1px) {
  .guess-counter > * + * { margin-left: 6px; }
}

.guess-pip {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--border-dark);
  background: transparent;
  transition: background 0.2s, border-color 0.2s;
}

.guess-pip.used {
  background: var(--text-dim);
  border-color: var(--text-dim);
}

.guess-pip.correct {
  background: var(--correct);
  border-color: #5a9900;
}

.guess-pip.wrong-final {
  background: var(--red);
  border-color: var(--red);
}

/* =========================================================
   Win / Loss Panels
   ========================================================= */
.result-panel {
  margin-top: 20px;
  padding: clamp(16px, 3vw, 24px) clamp(14px, 3vw, 22px);
  background: var(--surface);
  border: 2px solid var(--border-dark);
  border-radius: var(--radius-lg);
  text-align: center;
  opacity: 0;
  -webkit-transform: translateY(10px);
  transform: translateY(10px);
  -webkit-animation: fade-up 0.4s ease 0.2s forwards;
  animation: fade-up 0.4s ease 0.2s forwards;
}

.result-panel.win {
  border-color: #5a9900;
  background: rgba(157, 255, 0, 0.06);
}

.result-panel.lose {
  border-color: var(--red);
  background: rgba(255, 33, 33, 0.04);
}

.result-headline {
  font-family: var(--font-display);
  font-size: clamp(28px, 7vw, 44px);
  font-weight: 700;
  font-style: italic;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.result-panel.win  .result-headline { color: #3a6000; }
.result-panel.lose .result-headline { color: var(--red); }

.result-player-name {
  font-family: var(--font-display);
  font-size: clamp(15px, 3vw, 20px);
  font-weight: 700;
  color: var(--dark);
  margin-bottom: 4px;
}

.result-sub {
  font-size: clamp(12px, 1.8vw, 14px);
  color: var(--text-dim);
  letter-spacing: 0.04em;
  margin-bottom: 18px;
}

/* Confetti */
.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 200;
}

.confetti-particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 1px;
  opacity: 0;
  -webkit-animation: confetti-fall 2s ease-in forwards;
  animation: confetti-fall 2s ease-in forwards;
}

@-webkit-keyframes confetti-fall {
  0%   { opacity: 1; -webkit-transform: translateY(-20px) rotate(0deg);   transform: translateY(-20px) rotate(0deg); }
  100% { opacity: 0; -webkit-transform: translateY(100vh) rotate(720deg); transform: translateY(100vh) rotate(720deg); }
}

@keyframes confetti-fall {
  0%   { opacity: 1; transform: translateY(-20px) rotate(0deg); }
  100% { opacity: 0; transform: translateY(100vh) rotate(720deg); }
}

/* =========================================================
   Continue Playing Section
   ========================================================= */
.continue-section {
  margin-top: 36px;
  padding-top: 20px;
  border-top: 2px solid var(--border-dark);
  text-align: center;
}

.section-label {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 12px;
}

.continue-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

@supports not (gap: 1px) {
  .continue-buttons > * { margin: 4px; }
}

.btn-continue {
  font-family: var(--font-display);
  font-size: clamp(13px, 1.8vw, 15px);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.7em 1.75em;
  border-radius: var(--radius);
  border: 2px solid var(--dark);
  cursor: pointer;
  transition: background 0.15s, -webkit-transform 0.1s, transform 0.1s;
  text-decoration: none;
  display: inline-block;
  background: var(--gold);
  color: var(--dark);
}

.btn-continue:hover {
  background: var(--gold-dark);
}

.btn-continue:active {
  -webkit-transform: scale(0.97);
  transform: scale(0.97);
}

/* =========================================================
   Toast
   ========================================================= */
.toast {
  position: fixed;
  top: 22px;
  left: 50%;
  -webkit-transform: translateX(-50%) translateY(-80px);
  transform: translateX(-50%) translateY(-80px);
  background: var(--dark);
  color: #fff;
  border-radius: var(--radius);
  padding: 11px 22px;
  font-family: var(--font-body);
  font-size: clamp(12px, 1.8vw, 14px);
  font-weight: 600;
  letter-spacing: 0.04em;
  z-index: 500;
  transition: -webkit-transform 0.28s cubic-bezier(0.23, 1, 0.32, 1), transform 0.28s cubic-bezier(0.23, 1, 0.32, 1);
  max-width: calc(100vw - 32px);
  text-align: center;
  word-break: break-word;
}

.toast.visible {
  -webkit-transform: translateX(-50%) translateY(0);
  transform: translateX(-50%) translateY(0);
}

/* =========================================================
   Loading
   ========================================================= */
.loading-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

@supports not (gap: 1px) {
  .loading-dots > * + * { margin-left: 5px; }
}

.loading-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  -webkit-animation: dot-pulse 1.2s ease-in-out infinite;
  animation: dot-pulse 1.2s ease-in-out infinite;
}

.loading-dot:nth-child(2) { -webkit-animation-delay: 0.2s; animation-delay: 0.2s; }
.loading-dot:nth-child(3) { -webkit-animation-delay: 0.4s; animation-delay: 0.4s; }

@-webkit-keyframes dot-pulse {
  0%, 80%, 100% { opacity: 0.2; -webkit-transform: scale(0.8); transform: scale(0.8); }
  40%            { opacity: 1;   -webkit-transform: scale(1);   transform: scale(1); }
}

@keyframes dot-pulse {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
  40%            { opacity: 1;   transform: scale(1); }
}

/* Loss flicker */
.flicker {
  -webkit-animation: flicker-out 0.6s ease forwards;
  animation: flicker-out 0.6s ease forwards;
}

@-webkit-keyframes flicker-out {
  0%   { opacity: 1; }
  15%  { opacity: 0.15; }
  25%  { opacity: 0.85; }
  40%  { opacity: 0.05; }
  55%  { opacity: 0.9; }
  100% { opacity: 1; }
}

@keyframes flicker-out {
  0%   { opacity: 1; }
  15%  { opacity: 0.15; }
  25%  { opacity: 0.85; }
  40%  { opacity: 0.05; }
  55%  { opacity: 0.9; }
  100% { opacity: 1; }
}

/* =========================================================
   Keyframe Animations
   ========================================================= */
@-webkit-keyframes letter-flip-in {
  from { opacity: 0; -webkit-transform: rotateX(90deg) scaleY(0.4); transform: rotateX(90deg) scaleY(0.4); }
  to   { opacity: 1; -webkit-transform: rotateX(0deg) scaleY(1);    transform: rotateX(0deg) scaleY(1); }
}

@keyframes letter-flip-in {
  from { opacity: 0; transform: rotateX(90deg) scaleY(0.4); }
  to   { opacity: 1; transform: rotateX(0deg) scaleY(1); }
}

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

@-webkit-keyframes fade-up {
  from { opacity: 0; -webkit-transform: translateY(10px); transform: translateY(10px); }
  to   { opacity: 1; -webkit-transform: translateY(0);    transform: translateY(0); }
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes row-ripple {
  0%   { box-shadow: 0 0 0 0 rgba(157, 255, 0, 0.4); }
  50%  { box-shadow: 0 0 0 8px rgba(157, 255, 0, 0); }
  100% { box-shadow: none; }
}

.guess-row.winning {
  -webkit-animation: row-ripple 0.8s ease 0.5s;
  animation: row-ripple 0.8s ease 0.5s;
}

/* =========================================================
   Responsive — only what clamp() can't handle on its own
   ========================================================= */
@media (max-width: 700px) {
  :root { --cell-gap: 4px; }
}
