/* ==========================================================================
   CROZZ — style kawaii B (aplat + contour d'encre + reflet statique, cf
   standard fleet konekt/gomz). Zéro backdrop-filter, zéro glow multi-couche :
   surfaces opaques, contour épais, ombre plate décalée. Thème piloté par le
   hub (html[data-theme], voir /_kit/theme.js) plutôt que l'OS seul.
   ========================================================================== */

:root {
  --acc: #6b8cff;
  --acc-light: #3a57c0;
  --err: #ff8a8a;
  --ok: #5fe08a;
  --bg-dark: #0b1226;
  --bg-glow: #182253;
  --bg-surface: #161c33;
  --bg-surface-2: #1c2440;
  --text-primary: #eaf1ff;
  --text-secondary: #dbe4f7;
  --text-muted: #9fb0d0;
  --border: rgba(255, 255, 255, 0.12);
  --scrim: rgba(6, 9, 22, 0.72);
  /* Kawaii B : contour or accent sur fond sombre (encre foncée = invisible
     sur panneau sombre), reflet statique, ombre plate (jamais de flou). */
  --toon-outline: #f0c04d;
  --toon-outline-w: 2px;
  --kawaii-sheen: radial-gradient(circle at 30% 24%, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 46%);
}

html[data-theme="light"] {
  --bg-dark: #f7f8fe;
  --bg-glow: #eef0ff;
  --bg-surface: #ffffff;
  --bg-surface-2: #eef0ff;
  --text-primary: #1a2340;
  --text-secondary: #384566;
  --text-muted: #5b6890;
  --border: rgba(26, 35, 64, 0.14);
  --scrim: rgba(26, 35, 64, 0.45);
  /* Encre foncée sur fond clair = fort contraste (leçon FACETA : un contour
     sombre sur panneau sombre est invisible, l'inverse est vrai en clair). */
  --toon-outline: #1a2340;
  --kawaii-sheen: radial-gradient(circle at 30% 24%, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0) 46%);
}

* {
  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%, var(--bg-glow), 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: var(--bg-surface);
  border-bottom: var(--toon-outline-w) solid var(--toon-outline);
}

.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: 12px;
  border: 1.5px solid var(--border);
  background: var(--bg-surface-2);
  color: var(--text-primary);
  cursor: pointer;
  font-weight: 700;
  font-size: 0.9rem;
  transition: transform 0.12s ease, border-color 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 {
    border-color: var(--toon-outline);
  }
}

/* ========== 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-color: var(--bg-surface-2);
  background-image: var(--kawaii-sheen);
  color: var(--text-primary);
  border: var(--toon-outline-w) solid var(--toon-outline);
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 800;
  font-size: 0.85rem;
  box-shadow: 0 2px 0 var(--toon-outline);
}

.wchip .ic {
  display: inline-block;
}

.wchip[hidden] {
  display: none;
}

.wchip.lives.low {
  animation: livesLowPulse 1s ease-in-out infinite;
}

@keyframes livesLowPulse {
  0%, 100% { transform: scale(1); border-color: var(--toon-outline); }
  50% { transform: scale(1.06); border-color: var(--err); }
}

/* ========== 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 {
  display: flex;
  justify-content: center;
  gap: 10px;
  font-size: 2rem;
  margin: 8px 0;
  opacity: 0.8;
  color: var(--acc);
}

.sub {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin: 8px 0 0;
}

.menu-card {
  width: 100%;
  max-width: 320px;
  padding: 20px;
  background-color: var(--bg-surface);
  background-image: var(--kawaii-sheen);
  border: var(--toon-outline-w) solid var(--toon-outline);
  border-radius: 22px;
  text-align: center;
  box-shadow: 0 4px 0 var(--toon-outline);
}

.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-color: var(--acc);
  background-image: var(--kawaii-sheen);
  border: var(--toon-outline-w) solid var(--toon-outline);
  border-radius: 14px;
  color: #fff;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.15s ease;
  box-shadow: 0 4px 0 var(--toon-outline);
}

.big-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--toon-outline);
}

.big-btn.alt {
  background-color: #ff8a5e;
}

@media (hover: hover) and (pointer: fine) {
  .big-btn:hover {
    filter: brightness(1.06);
  }
}

/* ========== Progression : objectif + thèmes + difficulté ========== */
.goal-bar {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-top: 6px;
}

.goal-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--acc), var(--acc-light));
  border-radius: 999px;
  transition: width 0.3s ease;
}

.themes-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.theme-swatch {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  border: var(--toon-outline-w) solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.theme-swatch.active {
  border-color: var(--toon-outline);
  transform: scale(1.08);
  box-shadow: 0 2px 0 var(--toon-outline);
}

.theme-swatch:active {
  transform: scale(0.94);
}

.theme-swatch.locked {
  background: var(--bg-surface-2) !important;
  cursor: default;
}

.theme-swatch .i-svg {
  color: var(--text-primary);
  opacity: 0.85;
}

.diffs {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.diff-chip {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--bg-surface-2);
  color: var(--text-primary);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.12s ease, border-color 0.12s ease;
}

.diff-chip.on {
  background-color: var(--acc);
  background-image: var(--kawaii-sheen);
  border-color: var(--toon-outline);
  color: #fff;
}

.diff-chip.locked {
  opacity: 0.55;
}

.diff-chip:active {
  transform: scale(0.96);
}

#diff-lock-hint {
  min-height: 1.2em;
}

/* ========== Game HUD ========== */
.hud {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 500px;
  justify-content: center;
  flex-wrap: wrap;
}

.box {
  background: var(--bg-surface-2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  text-align: center;
  min-width: 90px;
}

.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);
}

.puzzle-label {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ========== Grid & Game Container ========== */
.game-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 500px;
  align-items: center;
}

.current-clue {
  min-height: 1.4em;
  width: 100%;
  max-width: 100%;
  text-align: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
  background: var(--bg-surface-2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 8px 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#grid-container {
  width: 100%;
  max-width: 100%;
  display: flex;
  justify-content: center;
}

.gboard {
  display: grid;
  gap: 2px;
  padding: 10px;
  background: var(--bg-surface);
  border: var(--toon-outline-w) solid var(--toon-outline);
  border-radius: 16px;
  box-shadow: 0 6px 0 var(--toon-outline);
  width: min(94vw, 460px);
  aspect-ratio: auto;
}

.gcell {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: clamp(0.85rem, 3.4vw, 1.15rem);
  font-weight: 800;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
  will-change: transform;
}

.gcell.black {
  background: #05070f;
  border-color: #05070f;
  cursor: default;
}

.gcell.active {
  background: color-mix(in srgb, var(--acc) 24%, var(--bg-surface-2));
  border-color: color-mix(in srgb, var(--acc) 55%, transparent);
}

.gcell.selected {
  background: color-mix(in srgb, var(--acc) 48%, var(--bg-surface-2));
  border-color: var(--acc);
  box-shadow: 0 0 0 2px var(--acc);
  z-index: 1;
}

.gcell.wrong {
  background: color-mix(in srgb, var(--err) 30%, var(--bg-surface-2));
  border-color: color-mix(in srgb, var(--err) 60%, transparent);
  color: var(--err);
}

.gcell.hint .glet {
  color: var(--ok);
}

.gnum {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: 0.55em;
  font-weight: 700;
  color: var(--text-muted);
  line-height: 1;
  pointer-events: none;
}

.gcell.selected .gnum,
.gcell.active .gnum {
  color: var(--text-primary);
}

.glet {
  pointer-events: none;
}

.gcell.pop .glet {
  animation: cellPop 0.18s var(--cb-easing-bounce, cubic-bezier(0.34, 1.56, 0.64, 1));
}

@keyframes cellPop {
  0% { transform: scale(0.6); }
  60% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.gcell.shake {
  animation: cellShake 0.32s ease;
}

@keyframes cellShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* ========== Clavier virtuel (toutes langues, indispensable kana/han) ========== */
.keypad {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
  width: 100%;
  max-width: 500px;
  padding: 4px 0;
}

.kkey {
  min-width: 30px;
  height: 38px;
  padding: 0 8px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg-surface-2);
  color: var(--text-primary);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.1s ease, border-color 0.1s ease, transform 0.08s ease;
}

.kkey:active {
  transform: scale(0.92);
  border-color: var(--toon-outline);
}

.kkey.kback {
  background: color-mix(in srgb, #ff8a5e 18%, var(--bg-surface-2));
  border-color: color-mix(in srgb, #ff8a5e 45%, var(--border));
}

@media (hover: hover) and (pointer: fine) {
  .kkey:hover {
    border-color: var(--toon-outline);
  }
}

#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: 4px;
}

.clue-item {
  color: var(--text-secondary);
  line-height: 1.3;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.clue-item strong {
  color: var(--text-primary);
  font-weight: 700;
}

@media (hover: hover) and (pointer: fine) {
  .clue-item:hover {
    background: var(--bg-surface-2);
  }
}

.clue-item.active {
  background: color-mix(in srgb, var(--acc) 22%, var(--bg-surface-2));
  color: var(--text-primary);
}

.clue-item.solved {
  color: var(--ok);
  text-decoration: line-through;
  opacity: 0.75;
}

.clue-item.solved strong {
  color: var(--ok);
}

/* ========== 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-color: var(--acc);
  background-image: var(--kawaii-sheen);
  border: var(--toon-outline-w) solid var(--toon-outline);
  border-radius: 14px;
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.15s ease;
  box-shadow: 0 3px 0 var(--toon-outline);
}

.controls button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--toon-outline);
}

.controls button.ghost {
  background-color: var(--bg-surface-2);
  background-image: none;
  color: var(--text-primary);
  border-color: var(--border);
  box-shadow: none;
}

.controls button.alt {
  background-color: #ff8a5e;
}

@media (hover: hover) and (pointer: fine) {
  .controls button:hover {
    filter: brightness(1.06);
  }
  .controls button.ghost:hover {
    border-color: var(--toon-outline);
  }
}

/* ========== Overlay ========== */
.ov {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: var(--scrim);
  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-color: var(--bg-surface);
  background-image: var(--kawaii-sheen);
  color: var(--text-primary);
  border: var(--toon-outline-w) solid var(--toon-outline);
  border-radius: 26px;
  padding: 20px;
  box-shadow: 0 8px 0 var(--toon-outline);
  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-color: var(--acc);
  background-image: var(--kawaii-sheen);
  border: var(--toon-outline-w) solid var(--toon-outline);
  border-radius: 14px;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.9rem;
  margin-top: 10px;
  box-shadow: 0 3px 0 var(--toon-outline);
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.15s ease;
}

.dialog .btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--toon-outline);
}

.dialog .btn.ghost {
  background-color: var(--bg-surface-2);
  background-image: none;
  color: var(--text-primary);
  border-color: var(--border);
  box-shadow: none;
}

.dialog .btn.alt {
  background-color: #ff8a5e;
}

.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: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  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-icon {
  display: flex;
  justify-content: center;
  margin: 0 0 10px;
  color: var(--acc);
}

.over-icon .i-svg svg {
  width: 3rem;
  height: 3rem;
}

#ov-complete .over-icon {
  animation: completeBounce 0.6s var(--cb-easing-bounce, cubic-bezier(0.34, 1.56, 0.64, 1));
}

@keyframes completeBounce {
  0% { transform: scale(0.4) rotate(-8deg); opacity: 0; }
  60% { transform: scale(1.15) rotate(4deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}

/* ========== Toast ========== */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translate(-50%, 6px);
  background: var(--bg-surface-2);
  color: var(--text-primary);
  padding: 10px 18px;
  border-radius: 14px;
  font-weight: 700;
  z-index: 40;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  border: var(--toon-outline-w) solid var(--toon-outline);
  pointer-events: none;
  max-width: 88vw;
  text-align: center;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ========== Icônes SVG trait fin (zéro emoji) ========== */
.i-svg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.i-svg svg {
  width: 1em;
  height: 1em;
}

/* ========== Accessibility ========== */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
