/* ==========================================================================
   Palabras (arrowword-style picture clues) — Styles
   Shares the same visual language as the other dundilgame games.
   ========================================================================== */

:root {
  --bg-base: #140f2b;
  --bg-c1: 16, 185, 129;   /* green */
  --bg-c2: 59, 130, 246;   /* blue */
  --bg-c3: 217, 70, 239;   /* magenta */
  --panel: rgba(255, 255, 255, 0.08);
  --panel-solid: #241f3d;
  --text: #f5f3ff;
  --text-dim: #c4b5fd;
  --accent: #fbbf24;
  --accent-2: #34d399;
  --danger: #f87171;
  --radius: 16px;
  --topbar-h: 72px;
  --statsbar-h: 52px;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-base);
  background-image:
    radial-gradient(circle at 15% 15%, rgba(var(--bg-c1), 0.65) 0%, rgba(var(--bg-c1), 0) 60%),
    radial-gradient(circle at 85% 20%, rgba(var(--bg-c2), 0.65) 0%, rgba(var(--bg-c2), 0) 60%),
    radial-gradient(circle at 50% 100%, rgba(var(--bg-c3), 0.55) 0%, rgba(var(--bg-c3), 0) 65%);
  background-attachment: fixed;
  color: var(--text);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------------------------------------------------------------------- */
/* Top bar (shared chrome)                                                */
/* ---------------------------------------------------------------------- */

.topbar {
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 10px 20px 10px 200px;
  background-color: #0c0c12;
  background-image:
    linear-gradient(rgba(8, 6, 16, 0.6), rgba(8, 6, 16, 0.6)),
    url("../../assets/textures/carbon-fiber.jpg");
  background-repeat: no-repeat, repeat;
  background-size: cover, 180px 135px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand {
  position: fixed;
  top: 12px;
  left: 18px;
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-link {
  display: block;
  line-height: 0;
  transition: opacity 0.15s ease;
}

.brand-link:hover {
  opacity: 0.85;
}

.brand-logo {
  height: 44px;
  width: auto;
  display: block;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.35));
}

.brand-link-mobile {
  display: none;
}

.brand-home-icon {
  display: block;
  font-size: 26px;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}

.controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 12px;
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  padding: 12px 18px;
  min-height: 44px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, filter 0.12s ease;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #f59e0b);
  color: #1a1a1a;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-ghost {
  background: var(--panel);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 18px;
  padding: 10px 14px;
}

/* ---------------------------------------------------------------------- */
/* Stats bar                                                               */
/* ---------------------------------------------------------------------- */

.statsbar {
  min-height: var(--statsbar-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  flex-wrap: wrap;
  padding: 6px 16px;
  background: rgba(0, 0, 0, 0.15);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.statsbar.hidden { display: none !important; }

.stat {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.stat-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}

.stat-value {
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------------- */
/* Main area                                                                */
/* ---------------------------------------------------------------------- */

#mainArea {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---------------------------------------------------------------------- */
/* Theme picker (reused pattern: rows of 4, centered)                     */
/* ---------------------------------------------------------------------- */

.theme-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: 920px;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  padding: 8px;
}

.theme-picker h1 {
  margin: 0;
  font-size: clamp(20px, 3.5vw, 30px);
  text-align: center;
}

.picker-subtitle {
  margin: 0 0 8px;
  color: var(--text-dim);
  font-size: 14px;
  text-align: center;
}

.theme-grid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.theme-row {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.theme-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 130px;
  padding: 8px;
  border-radius: 14px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  background: var(--panel-solid);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.theme-tile:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
}

.theme-tile-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.theme-tile-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
}

.theme-tile-thumb .css-thumb {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
}

.theme-tile-label {
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  line-height: 1.2;
}

/* ---------------------------------------------------------------------- */
/* Game view: crossword grid + clue panel + on-screen keyboard            */
/* ---------------------------------------------------------------------- */

.game-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 100%;
  max-width: 1100px;
}

.puzzle-area {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.grid-wrap {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}

.crossword-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 10), var(--cell, 40px));
  grid-template-rows: repeat(var(--rows, 10), var(--cell, 40px));
  gap: 2px;
  background: rgba(0, 0, 0, 0.35);
  padding: 4px;
  border-radius: 8px;
}

.cw-cell {
  position: relative;
  width: var(--cell, 40px);
  height: var(--cell, 40px);
}

.cw-cell.block {
  background: transparent;
}

.cw-clue-badge {
  position: absolute;
  inset: 2px;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  gap: 1px;
  background: rgba(255, 255, 255, 0.92);
  pointer-events: none;
}

.cw-clue-badge-item {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cw-clue-badge-item.solved::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell, 40px) * 0.5);
  font-weight: 900;
  color: #0a2e22;
  background: rgba(52, 211, 153, 0.85);
}

.cw-clue-badge-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
}

.cw-clue-badge-item .css-clue {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell, 40px) * 0.45);
}

.cw-input {
  width: 100%;
  height: 100%;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.95);
  color: #1a1a2e;
  text-align: center;
  font-size: calc(var(--cell, 40px) * 0.5);
  font-weight: 800;
  text-transform: uppercase;
  padding: 0;
  outline: none;
  caret-color: transparent;
  transition: border-color 0.15s ease, background 0.2s ease;
}

.cw-cell.active-word .cw-input {
  background: rgba(251, 191, 36, 0.35);
}

.cw-cell.active-cell .cw-input {
  background: rgba(251, 191, 36, 0.75);
  border-color: var(--accent);
}

.cw-input:disabled {
  background: rgba(52, 211, 153, 0.85);
  color: #0a2e22;
}

.cw-cell.shake .cw-input {
  border-color: var(--danger);
  animation: shakeCell 0.35s ease;
}

@keyframes shakeCell {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-3px); }
}

/* ---------------------------------------------------------------------- */
/* Solved-words tray (only the completed words get a list)                */
/* ---------------------------------------------------------------------- */

.solved-tray {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  max-height: 76px;
  overflow-y: auto;
  padding: 2px 4px;
}

.solved-tray:empty {
  display: none;
}

.solved-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  background: rgba(52, 211, 153, 0.18);
  border: 1px solid rgba(52, 211, 153, 0.4);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-2);
  animation: winPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.solved-chip-thumb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #ffffff;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.solved-chip-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
}

.solved-chip-thumb .css-clue {
  font-size: 14px;
}

/* ---------------------------------------------------------------------- */
/* Info panel (loading)                                                    */
/* ---------------------------------------------------------------------- */

.info-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  background: var(--panel-solid);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 720px;
  margin: auto;
}

.info-panel h2 {
  margin: 0;
  font-size: 26px;
}

.info-spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------------------------------------------------------------------- */
/* Win overlay                                                             */
/* ---------------------------------------------------------------------- */

.win-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 5, 30, 0.82);
  backdrop-filter: blur(4px);
  cursor: pointer;
  touch-action: manipulation;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.win-content {
  text-align: center;
  padding: 48px 56px;
  border-radius: 24px;
  background: linear-gradient(160deg, #312e81, #581c87);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: winPop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 90vw;
}

@keyframes winPop {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.win-emoji {
  font-size: 72px;
  margin-bottom: 6px;
}

.win-content h1 {
  margin: 0 0 8px;
  font-size: clamp(26px, 4.5vw, 42px);
  color: var(--accent);
}

.win-content p {
  margin: 4px 0;
  font-size: clamp(16px, 2.2vw, 22px);
  color: var(--text);
}

.win-tap {
  margin-top: 18px !important;
  font-weight: 700;
  color: var(--accent-2) !important;
  animation: tapPulse 1.4s ease-in-out infinite;
}

@keyframes tapPulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

/* ---------------------------------------------------------------------- */
/* Small screens                                                           */
/* ---------------------------------------------------------------------- */

@media (max-width: 640px) {
  .topbar { padding: 8px 10px; }

  .brand { position: static; top: auto; left: auto; }
  .brand-link-desktop { display: none; }
  .brand-link-mobile {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--panel);
    border: 1px solid rgba(255, 255, 255, 0.12);
  }

  .btn { padding: 8px 12px; font-size: 13px; min-height: 36px; }
  .btn-label { display: none; }
  #newGameBtn { padding: 8px 14px; }

  .statsbar { gap: 14px; }
  .win-content { padding: 32px 24px; }

  .theme-grid { gap: 8px; }
  .theme-row { gap: 8px; }
  .theme-tile { width: 70px; padding: 6px; }

  .grid-wrap { height: auto; flex: 0 0 auto; }


}

/* ---------------------------------------------------------------------- */
/* On-screen letter keyboard (floating, draggable by its "Mover" handle)  */
/* ---------------------------------------------------------------------- */

.letter-keyboard {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 10px 10px;
  border-radius: 18px;
  background: rgba(20, 15, 45, 0.94);
  border: 2px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.letter-keyboard.dragging {
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.7), 0 0 0 3px var(--accent, #fbbf24);
  opacity: 0.96;
}

.kb-handle {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 6px 18px;
  min-height: 34px;
  background: var(--accent, #fbbf24);
  color: #1a1a1a;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  cursor: grab;
  touch-action: none;
}

.letter-keyboard.dragging .kb-handle { cursor: grabbing; }

.kb-rows { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.kb-row { display: flex; gap: 6px; justify-content: center; }

.kb-key {
  appearance: none;
  width: clamp(28px, 8.2vw, 54px);
  height: clamp(40px, 9vw, 56px);
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, #ffffff, #e6e2f3);
  color: #1a1a2e;
  font: inherit;
  font-size: clamp(17px, 4.4vw, 26px);
  font-weight: 900;
  box-shadow: 0 4px 0 #9d94c0;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.kb-key:active, .kb-key.pressed { animation: keyPress 0.18s ease; }

@keyframes keyPress {
  0% { transform: translateY(0); }
  40% { transform: translateY(3px); box-shadow: 0 1px 0 #9d94c0; background: #fde68a; }
  100% { transform: translateY(0); }
}

.kb-key.kb-back {
  width: clamp(48px, 13vw, 90px);
  background: linear-gradient(180deg, #ffd8d8, #f4a6a6);
  box-shadow: 0 4px 0 #b85b5b;
}
