/**
 * ui/styles.css
 * Global styles for the puzzle platform.
 * Fuentes: Google Fonts (Playfair Display, DM Mono).
 * Para PWA offline: descarga los .woff2 y ponlos en /fonts/ (ver fonts/README.md).
 */

@import url('https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400&family=Playfair+Display:wght@400;700&display=swap');
* { margin: 0; padding: 0; box-sizing: border-box; }

html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

html, body {
  overscroll-behavior: none;
  width: 100%;
  max-width: 100vw;
}

:root {
  --bg:       #0f0e0c;
  --gold:     #c9a84c;
  --gold-dim: #7a5f28;
  --text:     #e8e0d0;
  --text-dim: #7a7060;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Mono', monospace;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  padding: 8px;
  padding-top: 4px;
  padding-left: max(8px, env(safe-area-inset-left));
  padding-right: max(8px, env(safe-area-inset-right));
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  overflow-x: hidden;
}

/* En juego queremos el tablero más arriba y con más alto útil */
body[data-view="game"] {
  justify-content: flex-start;
  gap: 0;
  padding: max(2px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

body[data-view="game"] h1,
body[data-view="game"] #subtitle {
  display: none;
}

h1 {
  font-family: 'Playfair Display', serif;
  font-size: 1.6rem;
  color: var(--gold);
  letter-spacing: 0.05em;
  font-weight: 400;
  margin-bottom: 8px;
}

#subtitle {
  font-size: 0.65rem;
  color: var(--text-dim);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-top: -18px;
  text-align: center;
}

.hidden { display: none !important; }

/* ── Grilla de niveles (mobile first) ── */
.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 100%;
  max-height: 70vh;
  max-height: 70dvh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px;
  -webkit-overflow-scrolling: touch;
}

.level-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(26, 24, 20, 0.9);
  border: 1px solid var(--gold-dim);
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 0.7rem;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
  position: relative;
}

.level-card.revealed img {
  opacity: 1;
}

.level-card:not(.revealed) img {
  opacity: 0;
}

.level-card:not(.revealed)::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--gold-dim) 0%, var(--bg) 100%);
  border: 1px solid var(--gold);
  border-radius: 2px;
}

.level-card:not(.revealed)::after {
  content: attr(data-level-num);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.5rem;
  color: var(--gold);
  font-family: 'Playfair Display', serif;
  font-weight: bold;
  opacity: 0.9;
}

.level-card:hover {
  border-color: var(--gold);
  box-shadow: 0 0 20px rgba(201, 168, 76, 0.2);
}

.level-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  transition: opacity 0.3s ease;
}

.level-card .level-num {
  padding: 4px 0 0;
  color: var(--gold-dim);
  font-size: 0.65rem;
}

.level-card .level-title {
  padding: 2px 6px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.level-card .level-diff {
  color: var(--gold);
  font-size: 0.6rem;
  padding-bottom: 6px;
}

/* ── Área de juego (mobile first) ── */
.game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 0;
  width: 100%;
  max-width: 100%;
  flex: 0 0 auto;
  overflow-x: hidden;
}

#board-container {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  width: 100%;
  max-width: 100%;
  flex: 0 0 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.back-btn {
  align-self: flex-start;
  background: transparent;
  border: 1px solid var(--gold-dim);
  color: var(--text-dim);
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  padding: 6px 12px;
  margin: 0 0 4px 0;
  cursor: pointer;
  transition: all 0.2s;
}

.back-btn:hover { border-color: var(--gold); color: var(--gold); }

/* ── Board (touch-action solo aquí para no bloquear scroll/gestos del resto) ── */
#board-wrap {
  position: relative;
  flex-shrink: 0;
  touch-action: none;
  transform-origin: top left;
}

#grid-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#hover-overlay {
  display: none;
  position: absolute;
  pointer-events: none;
  z-index: 11;
}

/* ── Ghost ── */
#ghost {
  position: fixed;
  pointer-events: none;
  z-index: 999;
  opacity: 1;
  border: 1.5px solid var(--gold);
  box-shadow: 0 8px 40px rgba(0,0,0,0.7), 0 0 24px rgba(201,168,76,0.35);
  display: none;
}
body[data-hide-board-borders="true"] #ghost {
  border: none;
  box-shadow: 0 8px 40px rgba(0,0,0,0.7);
}

/* ── HUD ── */
#status {
  font-size: 0.65rem;
  color: var(--text-dim);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  height: 16px;
  text-align: center;
}

#shuffle-btn {
  background: transparent;
  border: 1px solid var(--gold-dim);
  color: var(--text-dim);
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  padding: 8px 20px;
  cursor: pointer;
  transition: all 0.2s;
}
#shuffle-btn:hover { border-color: var(--gold); color: var(--gold); }

/* ── Win overlay ── */
#win-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,14,12,0.93);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  z-index: 100;
  pointer-events: none;
}
#win-overlay.show {
  display: flex;
  pointer-events: auto;
}

#win-overlay h2 {
  font-family: 'Playfair Display', serif;
  font-size: clamp(1.5rem, 8vw, 2.5rem);
  color: var(--gold);
  animation: glow 2s ease-in-out infinite alternate;
  text-align: center;
}

@keyframes glow {
  from { text-shadow: 0 0 20px rgba(201,168,76,0.5); }
  to   { text-shadow: 0 0 60px rgba(201,168,76,1), 0 0 100px rgba(201,168,76,0.4); }
}

#win-overlay button {
  background: transparent;
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  font-family: 'DM Mono', monospace;
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  padding: 10px 24px;
  cursor: pointer;
  transition: all 0.2s;
}
#win-overlay button:hover { background: var(--gold); color: var(--bg); }

#win-overlay .win-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* ── Tablet/desktop: más espacio y columnas ── */
@media (min-width: 480px) {
  body { 
    padding: 16px; 
    padding-top: 8px;
    gap: 20px; 
  }
  .level-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    max-width: 720px;
    padding: 8px;
  }
}
