/* ==========================================================================
   CROZZ — Premium CSS (mobile-first, glassmorphism, premium animations)
   ========================================================================== */

:root {
  --acc: #6b8cff;
  --acc-light: #3a57c0;
  --err: #ff8a8a;
  --ok: #5fe08a;
  --bg-dark: #0b1226;
  --bg-surface: #161c33;
  --text-primary: #eaf1ff;
  --text-secondary: #dbe4f7;
  --text-muted: #9fb0d0;
  --border: rgba(255, 255, 255, 0.12);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: radial-gradient(900px 500px at 50% -10%, #182253, var(--bg-dark) 60%);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ========== Topbar ========== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 12px calc(12px + env(safe-area-inset-left));
  gap: 8px;
  background: linear-gradient(180deg, rgba(22, 28, 51, 0.6), transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.brand {
  flex: 1;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: 0.16em;
  font-weight: 800;
  background: linear-gradient(90deg, var(--acc), var(--acc-light));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tag {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: -2px;
}

.icon-btn {
  padding: 8px 14px;
  border-radius: 10px;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  cursor: pointer;
  font-weight: 700;
  font-size: 0.9rem;
  transition: background 0.12s ease, transform 0.12s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.icon-btn:active {
  transform: scale(0.96);
}

@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover {
    background: rgba(255, 255, 255, 0.14);
  }
}

/* ========== Wallet HUD ========== */
.wallet-hud {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
  display: flex;
  gap: 6px;
  z-index: 20;
  flex-wrap: wrap;
  justify-content: flex-end;
}

[dir=rtl] .wallet-hud {
  right: auto;
  left: calc(8px + env(safe-area-inset-left));
  justify-content: flex-start;
}

.wchip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(14, 20, 48, 0.8);
  color: white;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 800;
  font-size: 0.85rem;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.wchip .ic {
  display: inline-block;
}

/* ========== Screens ========== */
#screen-menu, #screen-game {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  gap: 16px;
  max-width: 100%;
  width: 100%;
}

#screen-game {
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

/* ========== Hero & Menu ========== */
.hero {
  text-align: center;
  margin: 16px 0;
}

.logo {
  font-size: 3.2rem;
  font-weight: 900;
  letter-spacing: 0.2em;
  background: linear-gradient(90deg, var(--acc), var(--acc-light));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: 0;
}

.glyphs {
  font-size: 2rem;
  margin: 8px 0;
  opacity: 0.8;
}

.sub {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin: 8px 0 0;
}

.menu-card {
  width: 100%;
  max-width: 320px;
  padding: 20px;
  background: linear-gradient(180deg, var(--bg-surface), #0e1226);
  border: 1px solid var(--border);
  border-radius: 16px;
  text-align: center;
}

.menu-card h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
  color: var(--text-primary);
}

.hint {
  margin: 8px 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.4;
}

.big-btn {
  width: 100%;
  padding: 12px 20px;
  background: linear-gradient(rgba(9, 13, 30, 0.55), rgba(9, 13, 30, 0.55)), linear-gradient(135deg, var(--acc), var(--acc-light));
  border: none;
  border-radius: 10px;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.32);
}

.big-btn:active {
  transform: scale(0.96);
}

.big-btn.alt {
  background: linear-gradient(rgba(9, 13, 30, 0.55), rgba(9, 13, 30, 0.55)), linear-gradient(135deg, #ff8a5e, #ff5a3a);
}

@media (hover: hover) and (pointer: fine) {
  .big-btn:hover {
    filter: brightness(1.08);
  }
}

/* ========== Game HUD ========== */
.hud {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 500px;
  justify-content: center;
  flex-wrap: wrap;
}

.box {
  background: rgba(22, 28, 51, 0.6);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  text-align: center;
  min-width: 90px;
  backdrop-filter: blur(6px);
}

.box .k {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 4px;
}

.box .v {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--acc);
}

/* ========== Grid & Game Container ========== */
.game-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 500px;
  align-items: center;
}

#grid-container {
  width: 100%;
  max-width: 100%;
  display: flex;
  justify-content: center;
}

#clues-container {
  width: 100%;
  display: flex;
  gap: 16px;
  font-size: 0.9rem;
  max-height: 300px;
  overflow-y: auto;
}

#across-clues, #down-clues {
  flex: 1;
  min-width: 0;
}

#across-clues h3, #down-clues h3 {
  margin: 0 0 8px;
  font-size: 0.9rem;
  color: var(--acc);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

#across-list, #down-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#across-list div, #down-list div {
  color: var(--text-secondary);
  line-height: 1.3;
}

#across-list strong, #down-list strong {
  color: var(--text-primary);
  font-weight: 700;
}

/* ========== Controls ========== */
.controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  padding: 0 calc(env(safe-area-inset-left) + 8px) calc(8px + env(safe-area-inset-bottom)) calc(env(safe-area-inset-right) + 8px);
}

.controls button {
  padding: 10px 16px;
  background: linear-gradient(rgba(9, 13, 30, 0.55), rgba(9, 13, 30, 0.55)), linear-gradient(135deg, var(--acc), var(--acc-light));
  border: none;
  border-radius: 10px;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.32);
}

.controls button:active {
  transform: scale(0.96);
}

.controls button.ghost {
  background: rgba(255, 255, 255, 0.08);
  box-shadow: none;
}

.controls button.alt {
  background: linear-gradient(rgba(9, 13, 30, 0.55), rgba(9, 13, 30, 0.55)), linear-gradient(135deg, #ff8a5e, #ff5a3a);
}

@media (hover: hover) and (pointer: fine) {
  .controls button:hover {
    filter: brightness(1.08);
  }
  .controls button.ghost:hover {
    background: rgba(255, 255, 255, 0.14);
  }
}

/* ========== Overlay ========== */
.ov {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(6, 9, 22, 0.8);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.ov.show {
  display: flex;
}

.dialog {
  width: min(94vw, 420px);
  max-height: 88vh;
  overflow: auto;
  background: linear-gradient(180deg, var(--bg-surface), #0e1226);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
  animation: dialogIn 0.22s cubic-bezier(0.2, 1, 0.4, 1);
}

@keyframes dialogIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.dialog h2 {
  margin: 0 0 4px;
  font-size: 1.35rem;
}

.dialog p {
  line-height: 1.5;
  color: var(--text-secondary);
  margin: 0.4em 0;
}

.dialog .btn {
  display: block;
  width: 100%;
  padding: 10px 20px;
  background: linear-gradient(rgba(9, 13, 30, 0.55), rgba(9, 13, 30, 0.55)), linear-gradient(135deg, var(--acc), var(--acc-light));
  border: none;
  border-radius: 10px;
  color: var(--text-primary);
  font-weight: 700;
  cursor: pointer;
  font-size: 0.9rem;
  margin-top: 10px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.32);
  transition: transform 0.12s ease, filter 0.15s ease;
}

.dialog .btn:active {
  transform: scale(0.96);
}

.dialog .btn.ghost {
  background: rgba(255, 255, 255, 0.08);
  box-shadow: none;
}

.dialog .btn.alt {
  background: linear-gradient(rgba(9, 13, 30, 0.55), rgba(9, 13, 30, 0.55)), linear-gradient(135deg, #ff8a5e, #ff5a3a);
}

.dialog .wide {
  margin-top: 12px;
}

.dialog .stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.dialog .s {
  padding: 10px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  text-align: center;
}

.dialog .s.big {
  grid-column: 1 / -1;
}

.dialog .s .k {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  margin: 0 0 4px;
}

.dialog .s .v {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--acc);
}

.over-emoji {
  font-size: 3rem;
  text-align: center;
  margin: 0 0 10px;
}

/* ========== Toast ========== */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translate(-50%, 6px);
  background: rgba(14, 20, 48, 0.94);
  color: white;
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 700;
  z-index: 40;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  border: 1px solid var(--border);
  pointer-events: none;
  max-width: 88vw;
  text-align: center;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ========== Accessibility ========== */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* ========== Dark/Light ========== */
@media (prefers-color-scheme: light) {
  body {
    background: radial-gradient(900px 500px at 50% -10%, #f0f2ff, #f7f8fe 60%);
    color: #1a2340;
  }

  .tag {
    color: #506080;
  }

  .topbar {
    background: linear-gradient(180deg, rgba(247, 248, 254, 0.8), transparent);
    border-bottom-color: rgba(0, 0, 0, 0.08);
  }

  .icon-btn {
    background: rgba(0, 0, 0, 0.06);
    color: #1a2340;
  }

  .wchip {
    background: rgba(247, 248, 254, 0.9);
    color: #1a2340;
    border-color: rgba(0, 0, 0, 0.1);
  }

  .box {
    background: rgba(247, 248, 254, 0.7);
    border-color: rgba(0, 0, 0, 0.08);
    color: #1a2340;
  }

  .box .k {
    color: #506080;
  }

  .menu-card {
    background: linear-gradient(180deg, #f7f8fe, #eff0ff);
    border-color: rgba(0, 0, 0, 0.08);
    color: #1a2340;
  }

  .menu-card h2 {
    color: #1a2340;
  }

  .hint {
    color: #506080;
  }

  .dialog {
    background: linear-gradient(180deg, #f7f8fe, #eff0ff);
    border-color: rgba(0, 0, 0, 0.08);
    color: #1a2340;
  }

  .dialog p {
    color: #506080;
  }

  #clues-container {
    color: #1a2340;
  }

  #across-list div, #down-list div {
    color: #506080;
  }

  #across-list strong, #down-list strong {
    color: #1a2340;
  }

  .wchip {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }
}
