/* ═══════════════════════════════════════════
   TENTS & TREES — style.css
   Mobile-first, light theme
═══════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&family=Courier+Prime:wght@400;700&display=swap');

/* ─── CSS VARIABLES ─── */
:root {
  /* Colors */
  --bg:           #f7f4ee;
  --surface:      #ffffff;
  --border:       #e0d9ce;
  --border-dark:  #c8bfb0;
  --ink:          #2c2416;
  --ink-muted:    #8a7d6b;
  --green:        #3a7d44;
  --green-light:  #e8f5eb;
  --green-dark:   #2d6235;
  --amber:        #d4860a;
  --amber-light:  #fff3e0;
  --red:          #c0392b;
  --red-light:    #fdecea;
  --blue:         #2563a8;
  --blue-light:   #e8f0fb;
  --grass-bg:     #f0f4e8;

  /* Typography */
  --font-ui:      'Nunito', sans-serif;
  --font-mono:    'Courier Prime', monospace;

  /* Spacing */
  --gap:          16px;
  --gap-sm:       8px;
  --gap-lg:       24px;
  --gap-xl:       40px;
  --radius:       10px;
  --radius-sm:    6px;
  --radius-lg:    16px;

  /* Shadows */
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:    0 4px 16px rgba(0,0,0,0.10);
  --shadow-lg:    0 8px 32px rgba(0,0,0,0.14);

  /* Game grid — fallback sizes, overridden dynamically by game.js */
  --cell-size:    48px;
  --cell-size-sm: 36px;
  --cell-size-lg: 52px;
}

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

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

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ─── VIEW SYSTEM ─── */
.view {
  display: none;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100vh;
  overflow-y: auto;
  padding: var(--gap);
  animation: fadeIn 0.2s ease;
}

.view.active {
  display: flex;
}

#view-game.active,
#view-daily.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  padding: var(--gap);
  gap: var(--gap);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── BUTTONS ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap-sm);
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 700;
  padding: 12px 28px;
  border-radius: var(--radius);
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}
.btn-primary:hover {
  background: var(--green-dark);
  border-color: var(--green-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: var(--surface);
  color: var(--green);
  border-color: var(--green);
}
.btn-secondary:hover {
  background: var(--green-light);
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
  border-color: var(--border-dark);
}
.btn-ghost:hover {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--ink-muted);
}

.btn-ghost.btn-disabled,
.btn-ghost.btn-disabled:hover {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-full {
  width: 100%;
}

.btn-back {
  background: none;
  border: none;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 4px 0;
  transition: color 0.15s;
}
.btn-back:hover { color: var(--ink); }

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border-dark);
  background: var(--surface);
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink-muted);
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover {
  border-color: var(--green);
  color: var(--green);
}

.btn-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.btn-close:hover { color: var(--ink); }

/* ─── HOME VIEW ─── */
#view-home {
  justify-content: center;
  gap: var(--gap-xl);
  max-width: 400px;
  margin: 0 auto;
}

.home-logo {
  text-align: center;
}

.logo-icon {
  font-size: 4rem;
  display: block;
  margin-bottom: var(--gap-sm);
  animation: sway 3s ease-in-out infinite;
}

@keyframes sway {
  0%, 100% { transform: rotate(-4deg); }
  50%       { transform: rotate(4deg); }
}

.home-logo h1 {
  font-family: var(--font-ui);
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.home-logo h1 span {
  color: var(--green);
}

.home-tagline {
  font-size: 1rem;
  color: var(--ink-muted);
  margin-top: var(--gap-sm);
}

.home-actions {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  width: 100%;
}

.home-actions .btn {
  width: 100%;
  padding: 16px;
  font-size: 1.1rem;
}

.home-howto {
  text-align: center;
}

/* ─── SELECTOR VIEW ─── */
#view-selector {
  max-width: 400px;
  margin: 0 auto;
  gap: var(--gap-lg);
  padding-top: var(--gap-lg);
}

.selector-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--gap);
}

.selector-header h2 {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--ink);
}

.selector-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
}

.selector-label {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.toggle-group {
  display: flex;
  gap: var(--gap-sm);
  width: 100%;
}

.toggle-btn {
  flex: 1;
  padding: 10px;
  border: 2px solid var(--border-dark);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.toggle-btn:hover {
  border-color: var(--green);
  color: var(--green);
}

.toggle-btn.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

/* ─── GAME TOPBAR ─── */
.game-topbar {
  width: 100%;
  max-width: 860px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: var(--gap);
  border-bottom: 1px solid var(--border);
  gap: var(--gap-sm);
  flex-shrink: 0;
}

.game-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.85rem;
  color: var(--ink-muted);
  font-weight: 600;
  gap: 2px;
}

.game-topbar-right {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
}

.timer {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
  min-width: 52px;
  text-align: center;
}

/* ─── GAME VIEW LAYOUT ─── */

.game-controls {
  flex-shrink: 0;
  width: 100%;
  max-width: 480px;
}

.game-status {
  flex-shrink: 0;
  width: 100%;
  max-width: 860px;
  text-align: center;
}

.board-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow: auto;
  padding: var(--gap-sm);
}

/* ─── PUZZLE BOARD ─── */
/* FIX #6: Cells use --dynamic-cell when set by game.js, falling back to --cell-size */
#board, #daily-board {
  display: inline-flex;
  flex-direction: column;
  gap: 0;
  margin: auto;
}

.board-col-clues {
  display: flex;
  padding-left: var(--dynamic-cell, var(--cell-size));
}

.board-row {
  display: flex;
  align-items: center;
}

.clue {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: var(--dynamic-clue-font, 0.9rem);
  font-weight: 700;
  color: var(--green);
  transition: color 0.2s;
  flex-shrink: 0;
}

.clue.col {
  width: var(--dynamic-cell, var(--cell-size));
  height: var(--dynamic-cell-sm, var(--cell-size-sm));
}

.clue.row {
  width: var(--dynamic-cell, var(--cell-size));
  height: var(--dynamic-cell, var(--cell-size));
}

.clue.satisfied { color: var(--green-dark); font-weight: 800; }
.clue.violated  { color: var(--red); }
.clue.zero      { color: var(--border-dark); }

/* ─── CELLS ─── */
.cell {
  width: var(--dynamic-cell, var(--cell-size));
  height: var(--dynamic-cell, var(--cell-size));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--dynamic-font, 1.5rem);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: background 0.1s, box-shadow 0.15s;
  user-select: none;
  flex-shrink: 0;
  position: relative;
}

.cell:hover:not(.tree) {
  background: var(--green-light);
}

.cell:focus-visible:not(.tree) {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
  z-index: 1;
}

.cell.tree {
  background: #edf7ef;
  cursor: default;
}

.cell.tent {
  background: var(--amber-light);
}

/* FIX #5: Grass cell styling */
.cell.grass {
  background: var(--grass-bg);
  color: var(--border-dark);
  font-size: calc(var(--dynamic-font, 1.5rem) * 1.6);
  font-weight: 700;
  line-height: 1;
}

.cell.correct {
  background: var(--green-light);
  box-shadow: inset 0 0 0 2px var(--green);
}

.cell.wrong {
  background: var(--red-light);
  box-shadow: inset 0 0 0 2px var(--red);
}

/* ─── GAME CONTROLS ─── */
.game-controls {
  display: flex;
  gap: var(--gap-sm);
  width: 100%;
  max-width: 400px;
  flex-shrink: 0;
}

.game-controls .btn {
  flex: 1;
  padding: 10px;
  font-size: 0.9rem;
}

/* ─── TAP LEGEND ─── */
.tap-legend {
  flex-shrink: 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--ink-muted);
  padding: 2px 0;
}

/* ─── GAME STATUS ─── */
.game-status {
  min-height: 24px;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  color: var(--ink-muted);
}

.game-status.error { color: var(--red); }
.game-status.win   { color: var(--green-dark); }
.game-status.hint  { color: var(--blue); }

/* ─── OVERLAYS ─── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(44, 36, 22, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gap);
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

.overlay.hidden {
  display: none;
}

.overlay-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--gap-lg);
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.overlay-header h2 {
  font-size: 1.2rem;
  font-weight: 800;
}

/* ─── WIN OVERLAY ─── */
.win-trophy {
  font-size: 3rem;
  text-align: center;
  animation: pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes pop {
  from { transform: scale(0.5); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

#win-title {
  font-size: 1.5rem;
  font-weight: 800;
  text-align: center;
  color: var(--green-dark);
}

#win-message {
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.95rem;
}

.win-stats {
  display: flex;
  gap: var(--gap);
  background: var(--bg);
  border-radius: var(--radius);
  padding: var(--gap);
}

.win-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.win-stat-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.win-stat-value {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--ink);
}

.win-actions {
  display: flex;
  gap: var(--gap-sm);
}

.win-actions .btn {
  flex: 1;
}

/* ─── HOW TO PLAY OVERLAY ─── */
.howtoplay-rules {
  padding-left: var(--gap-lg);
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
}

.howtoplay-rules li {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--ink);
}

.howtoplay-tip {
  font-size: 0.85rem;
  color: var(--ink-muted);
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: var(--gap-sm) var(--gap);
  line-height: 1.5;
}

/* ─── DESKTOP BREAKPOINT ─── */
@media (min-width: 640px) {
  :root {
    --cell-size:    64px;
    --cell-size-sm: 44px;
  }

  #view-home {
    gap: var(--gap-xl);
  }

  .home-logo h1 {
    font-size: 3rem;
  }

  .home-actions {
    flex-direction: row;
  }

  .game-controls {
    max-width: 480px;
  }
}

/* ─── SMALL SCREENS ─── */
@media (max-width: 480px) {
  :root {
    --cell-size:    32px;
    --cell-size-sm: 24px;
  }

  .clue {
    font-size: 0.75rem;
  }

  .cell {
    font-size: 1.1rem;
  }
}
