/* ================================================================
   WORD WHEEL – style.css
   Mobile-first responsive design
   Breakpoints: xs(<360) | sm(360+) | md(600+) | lg(900+) | xl(1200+)
   ================================================================ */

/* ── CSS VARIABLES ────────────────────────────────────────────── */
:root {
  /* Colors */
  --navy:      #0d1b2a;
  --navy2:     #162236;
  --navy3:     #1e2f44;
  --teal:      #00d4aa;
  --teal2:     #00b894;
  --gold:      #ffd166;
  --coral:     #ff6b6b;
  --purple:    #a29bfe;
  --pink:      #fd79a8;
  --white:     #f0f4f8;
  --grey:      #8599b0;
  --card-bg:   #1a2d42;

  /* Misc */
  --radius:    16px;
  --shadow:    0 8px 32px rgba(0,0,0,0.45);
  --font-d:    'Righteous', cursive;
  --font-ui:   'Nunito', sans-serif;

  /* Layout tokens – mobile defaults (< 360px) */
  --topbar-h:    52px;
  --bottombar-h: 62px;
  --wordbar-h:   38px;
  --wheel-size:  min(290px, 8vw);

  /* Letter box tokens */
  --box-size:    clamp(25px, 7vw, 30px);
  --box-font:    clamp(0.72rem, 3vw, 1.1rem);
  --box-gap:     5px;
  --box-radius:  7px;
}

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

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  height: 100%;
  overflow: hidden;
  background: var(--navy);
  color: var(--white);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.hidden { display: none !important; }

/* ================================================================
   PRELOADER
   ================================================================ */
#preloader {
  position: fixed; inset: 0;
  background: var(--navy);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  transition: opacity 0.6s ease, visibility 0.6s;
}
#preloader.fade-out { opacity: 0; visibility: hidden; pointer-events: none; }

.preloader-inner {
  text-align: center;
  padding: 0 24px;
  width: 100%;
  max-width: 300px;
}

.preloader-logo {
  font-family: var(--font-d);
  font-size: clamp(1.9rem, 9vw, 3.2rem);
  line-height: 1;
  margin-bottom: 24px;
  animation: logoPulse 1.8s ease-in-out infinite;
}
.logo-w, .logo-w2    { color: var(--teal); }
.logo-rest, .logo-rest2 { color: var(--white); }
.logo-w2, .logo-rest2  { display: block; font-size: 78%; }

@keyframes logoPulse {
  0%,100% { transform: scale(1); }
  50%      { transform: scale(1.05); }
}

.preloader-spinner {
  display: flex; justify-content: center; gap: 10px;
  margin-bottom: 18px;
}
.spinner-ring {
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--teal);
  animation: bounce 0.9s ease-in-out infinite;
}
.spinner-ring:nth-child(2) { background: var(--gold);  animation-delay: 0.15s; }
.spinner-ring:nth-child(3) { background: var(--coral); animation-delay: 0.30s; }

@keyframes bounce {
  0%,80%,100% { transform: scale(0.6); opacity: 0.5; }
  40%          { transform: scale(1.2); opacity: 1;   }
}

.preloader-tip { color: var(--grey); font-size: 0.8rem; margin-bottom: 12px; }

.preloader-bar-wrap {
  width: 170px; height: 5px;
  background: var(--navy3);
  border-radius: 99px;
  overflow: hidden;
  margin: 0 auto;
}
.preloader-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  border-radius: 99px;
  width: 0%;
  transition: width 0.3s ease;
}

/* ================================================================
   GAME WRAPPER  – full-screen flex column
   ================================================================ */
#gameWrapper {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: var(--navy);
  overflow: hidden;
  /* Safe areas for notched/punched-hole phones */
  padding-top:    env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left:   env(safe-area-inset-left);
  padding-right:  env(safe-area-inset-right);
}

/* ── TOP BAR ──────────────────────────────────────────────────── */
#topBar {
  flex-shrink: 0;
  display: flex; align-items: center;
  height: var(--topbar-h);
  padding: 0 10px;
  gap: 7px;
  background: var(--navy2);
  border-bottom: 1px solid rgba(255,255,255,0.07);
  z-index: 10;
}

.topbar-left  { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.topbar-center { flex: 1; min-width: 0; padding: 0 5px; }
.topbar-right { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }

.icon-btn {
  flex-shrink: 0;
  width: 32px; height: 32px;
  border-radius: 8px; border: none;
  background: var(--navy3);
  color: var(--white);
  font-size: 0.9rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.1s, filter 0.12s;
  -webkit-appearance: none;
}
.icon-btn:active { transform: scale(0.88); }
.icon-btn:hover  { filter: brightness(1.35); }

#btnHelp {
  color: var(--teal);
  font-family: var(--font-d);
  font-size: 0.95rem;
  border: 1px solid rgba(0,212,170,0.3);
}

.level-badge {
  font-family: var(--font-d);
  font-size: 0.88rem;
  color: var(--teal);
  white-space: nowrap;
}

.progress-wrap {
  height: 6px;
  background: var(--navy3);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  border-radius: 99px;
  width: 0%;
  transition: width 0.5s cubic-bezier(.22,1,.36,1);
}

.hint-badge {
  display: flex; align-items: center; gap: 3px;
  background: var(--navy3);
  border-radius: 8px;
  padding: 3px 8px;
  font-weight: 800;
  font-size: 0.82rem;
  color: var(--gold);
  white-space: nowrap;
}
.hint-icon { font-size: 0.88rem; }

/* ── WORD GRID SECTION ────────────────────────────────────────── */
#wordGridSection {
  flex: 1;
  min-height: 0;          /* CRITICAL for flex shrink */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 8px 4px;
  overflow-y: auto;
  overflow-x: hidden;
}

#wordGrid {
  display: flex;
  flex-direction: column;
  gap: var(--box-gap);
  align-items: center;
  width: 100%;
  max-width: 440px;
  padding: 2px 0;
}

.word-row {
  display: flex;
  gap: var(--box-gap);
  justify-content: center;
  flex-wrap: nowrap;
}

.letter-box {
  flex-shrink: 0;
  width: var(--box-size);
  height: var(--box-size);
  border-radius: var(--box-radius);
  background: var(--card-bg);
  border: 2px solid rgba(255,255,255,0.09);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-d);
  font-size: var(--box-font);
  color: transparent;
  transition: background 0.22s, color 0.22s, border-color 0.22s;
}

.letter-box.revealed {
  background: linear-gradient(135deg, var(--teal2), var(--teal));
  border-color: var(--teal);
  color: var(--navy);
  font-weight: 700;
  animation: popIn 0.38s cubic-bezier(.34,1.56,.64,1);
}

.letter-box.hint-revealed {
  background: linear-gradient(135deg, var(--gold), #c8a000);
  border-color: var(--gold);
  color: var(--navy);
}

@keyframes popIn {
  0%   { transform: scale(0.3) rotateY(90deg); opacity: 0; }
  60%  { transform: scale(1.1) rotateY(-5deg); }
  100% { transform: scale(1)   rotateY(0);     opacity: 1; }
}

.word-row.flash { animation: rowFlash 0.45s ease; }
@keyframes rowFlash {
  0%,100% { filter: brightness(1); }
  50%      { filter: brightness(1.7); }
}

/* ── CURRENT WORD DISPLAY ─────────────────────────────────────── */
#currentWordDisplay {
  flex-shrink: 0;
  min-height: var(--wordbar-h);
  height: var(--wordbar-h);
  display: flex;
  align-items: center;
  justify-content: center;
  /* Subtle separator lines so the area is always visible */
  border-top: 1px solid rgba(255,255,255,0.05);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  background: rgba(255,255,255,0.02);
  padding: 0 12px;
  /* Never collapse */
  overflow: visible;
}

#currentWord {
  font-family: var(--font-d);
  font-size: clamp(1.1rem, 5vw, 1.6rem);
  /* Explicit white — never inherit transparent from letter-box */
  color: var(--white) !important;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  display: block;
  min-width: 2ch;
  min-height: 1.4em;
  line-height: 1.4;
  text-align: center;
  transition: color 0.15s, transform 0.15s;
  /* Show placeholder dots so the area looks active even when empty */
  position: relative;
}

/* When empty, show subtle dots so player knows it's a typing area */
#currentWord:empty::before {
  content: '• • •';
  color: rgba(255,255,255,0.15);
  font-size: 0.55em;
  letter-spacing: 0.4em;
  font-family: var(--font-ui);
}

#currentWord.error {
  color: var(--coral) !important;
  animation: shake 0.3s ease;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}

#currentWord.success {
  color: var(--teal) !important;
  animation: successPop 0.32s ease;
}
@keyframes successPop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* ── WHEEL SECTION ────────────────────────────────────────────── */
#wheelSection {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  padding: clamp(2px, 1.2vh, 10px) 0;
}

#wheelCanvas {
  display: block;
  width: var(--wheel-size);
  height: var(--wheel-size);
  touch-action: none;
  cursor: pointer;
}

/* ── BOTTOM BAR ───────────────────────────────────────────────── */
#bottomBar {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  gap: 7px;
  height: var(--bottombar-h);
  padding: 0 10px;
  background: var(--navy2);
  border-top: 1px solid rgba(255,255,255,0.07);
}

.ctrl-btn {
  flex: 1;
  max-width: 120px;
  height: 40px;
  display: flex; align-items: center; justify-content: center;
  gap: 5px;
  border-radius: 11px; border: none;
  font-family: var(--font-ui);
  font-size: clamp(0.72rem, 2.4vw, 0.86rem);
  font-weight: 800;
  cursor: pointer;
  background: var(--navy3);
  color: var(--white);
  white-space: nowrap;
  transition: transform 0.1s, filter 0.12s;
  -webkit-appearance: none;
}
.ctrl-btn span  { font-size: 1.05em; }
.ctrl-btn:active { transform: scale(0.90); }
.ctrl-btn:hover  { filter: brightness(1.3); }

#btnShuffle { background: linear-gradient(135deg, #2d3d52, #1e2f44); }
#btnHint    { background: linear-gradient(135deg, #3d3300, #554700); color: var(--gold); }
.bonus-btn  { background: linear-gradient(135deg, #3a0060, #5c0090); color: var(--purple); }

.bonus-count {
  background: var(--purple);
  color: var(--navy);
  border-radius: 99px;
  padding: 1px 6px;
  font-size: 0.7rem;
  font-weight: 900;
}

/* ================================================================
   OVERLAYS
   ================================================================ */
.overlay {
  position: fixed; inset: 0;
  background: rgba(8,16,26,0.88);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 14px;
  animation: overlayIn 0.2s ease;
}
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }

.overlay-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px 18px;
  width: 100%;
  max-width: 340px;
  max-height: 88vh;
  overflow-y: auto;
  text-align: center;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.08);
  position: relative;
  animation: cardIn 0.3s cubic-bezier(.34,1.56,.64,1);
}
@keyframes cardIn {
  from { transform: scale(0.82) translateY(14px); opacity: 0; }
  to   { transform: scale(1)    translateY(0);    opacity: 1; }
}

.overlay-title {
  font-family: var(--font-d);
  font-size: clamp(1.3rem, 5vw, 1.75rem);
  color: var(--white);
  margin-bottom: 5px;
}
.overlay-sub { color: var(--grey); font-size: 0.85rem; margin-bottom: 16px; }

.menu-btn {
  display: block; width: 100%;
  padding: 11px;
  margin: 8px 0 0;
  border-radius: 10px; border: none;
  font-family: var(--font-ui);
  font-size: 0.92rem; font-weight: 800;
  cursor: pointer;
  background: var(--navy3); color: var(--white);
  transition: filter 0.12s, transform 0.1s;
  -webkit-appearance: none;
}
.menu-btn:hover  { filter: brightness(1.35); }
.menu-btn:active { transform: scale(0.96); }
.menu-btn.primary {
  background: linear-gradient(135deg, var(--teal2), var(--teal));
  color: var(--navy);
}

.celebrate { overflow: visible; }

#lcStats {
  display: flex; justify-content: center; flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0 16px;
}
.stat-pill {
  background: var(--navy3);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 0.8rem; color: var(--grey);
  min-width: 64px;
}
.stat-pill strong { display: block; font-size: 1.1rem; color: var(--white); }

.bonus-list {
  display: flex; flex-wrap: wrap; gap: 6px;
  justify-content: center;
  max-height: 200px; overflow-y: auto;
  margin-bottom: 14px; padding: 3px;
}
.bonus-chip {
  background: var(--navy3);
  border-radius: 99px;
  padding: 4px 12px;
  font-size: 0.76rem; color: var(--purple);
  font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em;
  animation: chipIn 0.26s cubic-bezier(.34,1.56,.64,1);
}
@keyframes chipIn {
  from { transform: scale(0.5); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
.bonus-empty { color: var(--grey); font-size: 0.85rem; padding: 12px; line-height: 1.5; }

/* HOW TO PLAY */
.htp-scroll { max-height: 58vh; overflow-y: auto; margin: 0 -3px; padding: 0 3px; }
.htp-steps { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 16px; text-align: left; }
.htp-step {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--navy3);
  border-radius: 10px; padding: 10px 12px;
}
.htp-icon { font-size: 1.25rem; flex-shrink: 0; line-height: 1; margin-top: 1px; }
.htp-text strong { display: block; font-size: 0.85rem; color: var(--white); margin-bottom: 2px; }
.htp-text span   { font-size: 0.74rem; color: var(--grey); line-height: 1.4; }

/* ================================================================
   TOAST
   ================================================================ */
#toast {
  position: fixed;
  bottom: 76px; left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--card-bg);
  color: var(--white);
  padding: 8px 18px;
  border-radius: 99px;
  font-size: 0.82rem; font-weight: 700;
  pointer-events: none; opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 800;
  border: 1px solid rgba(255,255,255,0.1);
  white-space: nowrap;
  max-width: 88vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ================================================================
   CONFETTI
   ================================================================ */
#confettiCanvas {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 600;
  width: 100%; height: 100%;
}

/* ================================================================
   SCROLLBAR
   ================================================================ */
::-webkit-scrollbar       { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--navy3); border-radius: 99px; }

/* ================================================================
   RESPONSIVE BREAKPOINTS  (mobile-first, progressively enhanced)
   ================================================================ */

/* Small phones 360px+ */
@media (min-width: 360px) {
  :root {
    --wheel-size:  min(300px, 83vw);
    --box-size:    clamp(27px, 7.2vw, 42px);
    --box-gap:     5px;
  }
  .icon-btn   { width: 33px; height: 33px; }
  .ctrl-btn   { height: 41px; }
}

/* Larger phones 480px+ */
@media (min-width: 480px) {
  :root {
    --topbar-h:    54px;
    --bottombar-h: 64px;
    --wordbar-h:   42px;
    --wheel-size:  min(315px, 76vw);
    --box-size:    clamp(30px, 6.5vw, 44px);
    --box-font:    clamp(0.82rem, 2.8vw, 1.2rem);
    --box-gap:     6px;
  }
  #topBar    { padding: 0 12px; gap: 8px; }
  #bottomBar { padding: 0 12px; gap: 9px; }
  .icon-btn  { width: 35px; height: 35px; font-size: 0.95rem; }
  .ctrl-btn  { max-width: 130px; height: 43px; font-size: 0.84rem; border-radius: 12px; }
  .hint-badge { font-size: 0.85rem; padding: 4px 9px; }
  .level-badge { font-size: 0.9rem; }
  #wordGridSection { padding: 10px 10px 4px; }
  #wordGrid { gap: 6px; }
}

/* Tablets 600px+ */
@media (min-width: 600px) {
  :root {
    --topbar-h:    58px;
    --bottombar-h: 68px;
    --wordbar-h:   46px;
    --wheel-size:  320px;
    --box-size:    42px;
    --box-font:    1.15rem;
    --box-gap:     8px;
    --box-radius:  9px;
  }
  #gameWrapper {
    max-width: 560px;
    margin: 0 auto;
    border-left:  1px solid rgba(255,255,255,0.05);
    border-right: 1px solid rgba(255,255,255,0.05);
  }
  #topBar    { padding: 0 16px; gap: 10px; }
  #bottomBar { padding: 0 16px; gap: 12px; }
  #wordGridSection { padding: 14px 16px 6px; }
  #wordGrid  { gap: 8px; }
  .icon-btn  { width: 37px; height: 37px; border-radius: 10px; }
  .ctrl-btn  { max-width: 148px; height: 46px; font-size: 0.87rem; border-radius: 13px; }
  .hint-badge { font-size: 0.88rem; padding: 4px 10px; }
  .level-badge { font-size: 0.93rem; }
  .progress-wrap { height: 7px; }
  .overlay-card { padding: 28px 24px; max-width: 360px; }
  .overlay-title { font-size: 1.7rem; }
  .menu-btn { padding: 12px; font-size: 0.95rem; }
}

/* Large tablets / laptops 768px+ */
@media (min-width: 768px) {
  :root {
    --topbar-h:    60px;
    --bottombar-h: 70px;
    --wordbar-h:   48px;
    --wheel-size:  340px;
    --box-size:    44px;
    --box-font:    1.2rem;
    --box-gap:     9px;
  }
  #gameWrapper { max-width: 580px; }
  #wordGrid { gap: 9px; }
  .ctrl-btn { max-width: 155px; }
}

/* Desktop 900px+ */
@media (min-width: 900px) {
  :root {
    --topbar-h:    64px;
    --bottombar-h: 74px;
    --wordbar-h:   50px;
    --wheel-size:  360px;
    --box-size:    46px;
    --box-font:    1.25rem;
    --box-gap:     10px;
  }
  #gameWrapper {
    max-width: 600px;
    box-shadow: 0 0 80px rgba(0,0,0,0.5);
  }
  #topBar    { padding: 0 20px; gap: 12px; }
  #bottomBar { padding: 0 20px; gap: 14px; }
  #wordGridSection { padding: 16px 20px 8px; }
  #wordGrid { gap: 10px; }
  .icon-btn { width: 40px; height: 40px; font-size: 1rem; border-radius: 11px; }
  .ctrl-btn { max-width: 165px; height: 50px; font-size: 0.9rem; border-radius: 14px; }
  .hint-badge { font-size: 0.9rem; padding: 5px 11px; }
  .level-badge { font-size: 0.97rem; }
  .progress-wrap { height: 8px; }
  /* Enable hover states (only meaningful on desktop) */
  .letter-box:hover { border-color: rgba(255,255,255,0.22); }
}

/* Wide desktop 1200px+ */
@media (min-width: 1200px) {
  :root {
    --wheel-size: 380px;
    --box-size:   48px;
  }
  #gameWrapper { max-width: 620px; }
}

/* ================================================================
   HEIGHT-BASED BREAKPOINTS
   ================================================================ */

/* Tall phones (lots of vertical space) */
@media (min-height: 700px) {
  :root { --wordbar-h: 44px; }
  #wordGridSection { padding-top: 14px; }
  #wheelSection    { padding: clamp(4px, 1.8vh, 14px) 0; }
}

@media (min-height: 800px) {
  :root {
    --topbar-h:    60px;
    --bottombar-h: 70px;
    --wordbar-h:   48px;
  }
  #wordGridSection { padding-top: 16px; }
}

@media (min-height: 900px) {
  :root { --wheel-size: min(380px, 80vw); }
}

/* Short phones (landscape or compact portrait) */
@media (max-height: 600px) {
  :root {
    --topbar-h:    44px;
    --bottombar-h: 54px;
    --wordbar-h:   32px;
    --wheel-size:  min(220px, 52vw);
    --box-size:    clamp(21px, 5.2vw, 30px);
    --box-font:    clamp(0.62rem, 2.3vw, 0.84rem);
    --box-gap:     4px;
  }
  #wordGridSection { padding: 5px 7px 2px; }
  #wordGrid { gap: 4px; }
  .ctrl-btn { height: 36px; font-size: 0.73rem; padding: 0 8px; border-radius: 9px; }
  .icon-btn { width: 29px; height: 29px; font-size: 0.8rem; border-radius: 7px; }
  .hint-badge { padding: 3px 6px; font-size: 0.74rem; }
  .level-badge { font-size: 0.78rem; }
  #currentWord { font-size: clamp(0.88rem, 3.5vw, 1.1rem); }
  .preloader-logo { font-size: clamp(1.5rem, 7vw, 2.4rem); }
}

/* Very short screens (e.g. landscape on tiny phones) */
@media (max-height: 420px) {
  :root {
    --topbar-h:    38px;
    --bottombar-h: 46px;
    --wordbar-h:   26px;
    --wheel-size:  min(190px, 46vw);
    --box-size:    clamp(18px, 4.2vw, 26px);
    --box-font:    clamp(0.55rem, 1.9vw, 0.75rem);
    --box-gap:     3px;
  }
  .progress-wrap { height: 5px; }
}

/* ================================================================
   LANDSCAPE + SHORT  – hide non-essential chrome
   ================================================================ */
@media (orientation: landscape) and (max-height: 500px) {
  /* Collapse progress bar label */
  .level-badge { font-size: 0.75rem; }
  /* Compress overlay cards */
  .overlay-card { padding: 16px 14px; }
  .htp-scroll { max-height: 50vh; }
  .menu-btn { padding: 9px; margin-top: 6px; }
}

/* ================================================================
   PRINT
   ================================================================ */
@media print {
  #preloader, #confettiCanvas, #toast,
  .overlay, #bottomBar { display: none !important; }
  #gameWrapper { position: static; overflow: visible; }
}
