/* Ensure [hidden] always wins over authored display rules */
[hidden] { display: none !important; }

/* ── Reset & Base ─────────────────────────────────────────────────────────── */

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

html, body {
  height: 100%;
}

body {
  background: #1a3d1a;
  color: #e8f5e8;
  font-family: 'Segoe UI', system-ui, sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100%;
  padding: 12px 8px 24px;
}

/* ── Page wrapper (game column + optional sidebar) ───────────────────────── */

#page {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 440px;
}

/* ── App Container ────────────────────────────────────────────────────────── */

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 440px;
}

/* ── Header ───────────────────────────────────────────────────────────────── */

header {
  text-align: center;
  width: 100%;
}

h1 {
  font-size: clamp(1.6rem, 7vw, 2.2rem);
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #f5e642;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
  line-height: 1.1;
}

#round-counter {
  margin-top: 4px;
  font-size: clamp(0.85rem, 3.5vw, 1rem);
  color: #a8d8a8;
  letter-spacing: 0.04em;
}

/* ── Difficulty toggle ────────────────────────────────────────────────────── */

#difficulty {
  display: inline-flex;
  margin-top: 0;   /* spacing handled by #header-controls gap */
  border: 1px solid #3a6e3a;
  border-radius: 999px;
  overflow: hidden;
  background: #112b11;
}

.diff-btn {
  background: transparent;
  color: #7aaa7a;
  border: none;
  padding: 0.35em 1.1em;
  font-size: clamp(0.75rem, 3vw, 0.85rem);
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.4;
}

.diff-btn:first-child { border-right: 1px solid #3a6e3a; }

.diff-btn.active {
  background: #2e7d32;
  color: #fff;
}

.diff-btn:not(.active):hover {
  background: #1f4a1f;
  color: #c5e8c5;
}

.diff-btn:focus-visible {
  outline: 2px solid #f5e642;
  outline-offset: -2px;
}

/* ── Main layout ──────────────────────────────────────────────────────────── */

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
}

/* ── SVG Grid ─────────────────────────────────────────────────────────────── */

#grid {
  width: 100%;
  max-width: 400px;
  /* viewBox="0 0 500 500" → always square */
  aspect-ratio: 1;
  display: block;
  border-radius: 12px;
  background: #163216;
  box-shadow: 0 4px 18px rgba(0,0,0,0.45);
}

/* Grid cells */
.cell rect {
  transition: fill 0.18s ease;
}

.cell.empty rect {
  fill: #5a9e30;
  stroke: #3d7020;
  stroke-width: 1.5;
}

.cell.flower rect {
  fill: #246e24;
  stroke: #1a4f1a;
  stroke-width: 1.5;
}

.cell.seed rect {
  fill: #9fcc6a;
  stroke: #7aaa3a;
  stroke-width: 1.5;
}

/* Hover / focus — only on non-flower cells */
.cell:not(.flower):hover rect,
.cell:not(.flower):focus rect {
  fill: #7dbe40;
  stroke: #f5e642;
  stroke-width: 2.5;
  outline: none;
}

.cell:focus-visible rect {
  stroke: #f5e642;
  stroke-width: 3;
}

/* Cell symbols */
.cell-symbol {
  pointer-events: none;
  user-select: none;
}

.cell.flower .cell-symbol {
  font-size: 46px;
  fill: #f5e642;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.55));
}

.cell.seed .cell-symbol {
  font-size: 30px;
  fill: #4a2c00;
}

/* ── Compass Wrap ─────────────────────────────────────────────────────────── */

#compass-wrap {
  width: 100%;
  max-width: 220px;
  aspect-ratio: 1;
  background: #112b11;
  border-radius: 50%;
  box-shadow: 0 3px 14px rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}

#compass {
  width: 100%;
  height: 100%;
  display: block;
}

/* Compass structural elements */
.compass-ring {
  fill: none;
  stroke: rgba(255,255,255,0.08);
  stroke-width: 1;
}

.compass-center {
  fill: #a8d8a8;
}

/* Direction spokes */
.dir-spoke {
  stroke: rgba(168, 216, 168, 0.25);
  stroke-width: 1;
  stroke-linecap: round;
}

/* Direction bg circle (highlighted ring) */
.dir-bg {
  fill: transparent;
  stroke: transparent;
  stroke-width: 2;
  transition: fill 0.2s, stroke 0.2s;
}

/* Direction text */
.dir-text {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.03em;
  fill: #c5e8c5;
  transition: fill 0.2s, opacity 0.2s;
  pointer-events: none;
  user-select: none;
}

/* Used direction — dimmed */
.dir-group.used .dir-bg {
  fill: transparent;
}

.dir-group.used .dir-text {
  fill: #4a6a4a;
  opacity: 0.45;
}

.dir-group.used .dir-spoke {
  stroke: rgba(74, 106, 74, 0.2);
}

/* Last-used direction — most recent gust, still recognisable */
.dir-group.last-used .dir-bg {
  fill: rgba(245, 230, 66, 0.07);
  stroke: rgba(245, 230, 66, 0.45);
  stroke-width: 1.5;
  transition: fill 0.3s, stroke 0.3s;
}

.dir-group.last-used .dir-text {
  fill: #c8cb60;
  opacity: 0.70;
}

.dir-group.last-used .dir-spoke {
  stroke: rgba(200, 203, 96, 0.35);
}

/* Active (just blown) direction — pulse highlight */
.dir-group.active .dir-bg {
  fill: rgba(245, 230, 66, 0.22);
  stroke: #f5e642;
  stroke-width: 2;
  transform-box: fill-box;
  transform-origin: center;
  animation: pulse-ring 1s ease-out forwards;
}

.dir-group.active .dir-text {
  fill: #f5e642;
  font-size: 14px;
}

.dir-group.active .dir-spoke {
  stroke: rgba(245, 230, 66, 0.6);
}

@keyframes pulse-ring {
  0%   { transform: scale(1);    fill-opacity: 0.35; stroke-opacity: 1;   }
  50%  { transform: scale(1.25); fill-opacity: 0.18; stroke-opacity: 0.9; }
  100% { transform: scale(1.1);  fill-opacity: 0.12; stroke-opacity: 0.6; }
}

/* ── Status Message ───────────────────────────────────────────────────────── */

#status {
  font-size: clamp(0.9rem, 3.8vw, 1.05rem);
  color: #d4edda;
  text-align: center;
  min-height: 1.5em;
  letter-spacing: 0.02em;
  padding: 0 8px;
  transition: color 0.3s;
}

#app.win #status {
  color: #f5e642;
  font-weight: 600;
  font-size: clamp(1rem, 4.2vw, 1.15rem);
}

#app.lose #status {
  color: #ef9a9a;
  font-weight: 600;
  font-size: clamp(1rem, 4.2vw, 1.15rem);
}

/* ── Footer / Reset Button ────────────────────────────────────────────────── */

footer {
  width: 100%;
  display: flex;
  justify-content: center;
}

#reset-btn {
  background: #2e7d32;
  color: #fff;
  border: 2px solid #4caf50;
  border-radius: 999px;
  padding: 0.55em 2.2em;
  font-size: clamp(0.9rem, 3.8vw, 1rem);
  font-weight: 600;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background 0.18s, transform 0.1s, box-shadow 0.18s;
  box-shadow: 0 3px 10px rgba(0,0,0,0.35);
  -webkit-tap-highlight-color: transparent;
}

#reset-btn:hover {
  background: #388e3c;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}

#reset-btn:active {
  background: #1b5e20;
  transform: scale(0.96);
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

#reset-btn:focus-visible {
  outline: 3px solid #f5e642;
  outline-offset: 3px;
}

/* ── How to Play — collapsible panel (mobile) ────────────────────────────── */

#how-to-play {
  width: 100%;
  max-width: 440px;
}

#htp-toggle {
  width: 100%;
  background: #163216;
  color: #a8d8a8;
  border: 1px solid #2e5f2e;
  border-radius: 8px;
  padding: 0.55em 1.1em;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  text-align: left;
  transition: background 0.18s, color 0.18s;
  -webkit-tap-highlight-color: transparent;
}

#htp-toggle:hover {
  background: #1f4a1f;
  color: #c5e8c5;
}

#htp-toggle:focus-visible {
  outline: 2px solid #f5e642;
  outline-offset: 2px;
}

#htp-toggle[aria-expanded="true"] {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom-color: transparent;
}

.htp-collapsed {
  display: none;
}

#htp-body {
  background: #163216;
  border: 1px solid #2e5f2e;
  border-top: none;
  border-radius: 0 0 8px 8px;
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#htp-body h2 {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #f5e642;
  margin-bottom: 2px;
}

#htp-body p,
#htp-body li {
  font-size: 0.82rem;
  line-height: 1.55;
  color: #c5e8c5;
}

#htp-body strong {
  color: #d8f0d8;
  font-weight: 600;
}

#htp-body ol {
  padding-left: 1.4em;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.htp-attribution {
  font-size: 0.74rem !important;
  font-style: italic;
  color: #7aaa7a !important;
  border-top: 1px solid #2e5f2e;
  padding-top: 8px;
  margin-top: 2px;
}

/* ── Wider screens: a touch of extra breathing room ──────────────────────── */

@media (min-width: 480px) {
  #app {
    gap: 18px;
  }

  body {
    padding: 24px 16px 40px;
    align-items: center;
  }
}

/* ── Wide screens: sidebar layout ────────────────────────────────────────── */

@media (min-width: 740px) {
  body {
    align-items: flex-start;
  }

  #page {
    flex-direction: row;
    align-items: flex-start;
    max-width: 780px;
    gap: 24px;
    /* keep centred in body */
    margin: 0 auto;
  }

  #app {
    flex: 0 0 auto;
  }

  #how-to-play {
    flex: 1 1 260px;
    max-width: 320px;
    /* give it the same top offset as the game header */
    padding-top: 0;
  }

  /* Hide the toggle button — rules always visible on wide screens */
  #htp-toggle {
    display: none;
  }

  /* Always show the body, collapsed class has no effect here */
  #htp-body,
  #htp-body.htp-collapsed {
    display: flex;
    border: 1px solid #2e5f2e;
    border-radius: 8px;    /* full rounding — toggle is gone */
    padding: 16px 18px 18px;
  }

  #htp-body h2 {
    font-size: 0.78rem;
  }

  #htp-body p,
  #htp-body li {
    font-size: 0.84rem;
  }
}

/* ── Header controls row (difficulty + tutorial button) ──────────────────── */

#header-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

/* Tutorial button */
#tutorial-btn {
  background: transparent;
  color: #a8d8a8;
  border: 1px solid #3a6e3a;
  border-radius: 999px;
  padding: 0.35em 1.1em;
  font-size: clamp(0.75rem, 3vw, 0.85rem);
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.4;
}

#tutorial-btn:hover {
  background: #1f4a1f;
  color: #c5e8c5;
}

#tutorial-btn:focus-visible {
  outline: 2px solid #f5e642;
  outline-offset: 2px;
}

/* ── Grid wrapper (needed for tutorial overlay positioning) ──────────────── */

.grid-wrap {
  position: relative;
  width: 100%;
  max-width: 400px;
}

/* Re-attach sizing rules that were on #grid directly */
#grid {
  display: block;
  width: 100%;
  aspect-ratio: 1;
}

/* ── Tutorial overlay ────────────────────────────────────────────────────── */

#tut-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 25, 10, 0.55);
  border-radius: 12px;
  pointer-events: none;   /* cells remain tappable */
}

/* Highlighted cell: pulsing gold border — pointer-events re-enabled */
.tut-highlight {
  pointer-events: all;
  cursor: pointer;
}

.tut-highlight rect {
  stroke: #f5e642 !important;
  stroke-width: 3.5 !important;
  animation: tut-pulse 0.9s ease-in-out infinite alternate;
  filter: drop-shadow(0 0 6px rgba(245,230,66,0.8));
}

@keyframes tut-pulse {
  from { stroke-opacity: 1;   fill: #7dbe40; }
  to   { stroke-opacity: 0.5; fill: #a8db60; }
}

/* Tutorial instruction panel */
#tut-panel {
  width: 100%;
  max-width: 400px;
  background: #163216;
  border: 1px solid #4caf50;
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#tut-msg {
  font-size: clamp(0.82rem, 3.4vw, 0.95rem);
  line-height: 1.55;
  color: #d4edda;
}

#tut-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tut-btn {
  background: #2e7d32;
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.4em 1.2em;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.tut-btn:hover  { background: #388e3c; }
.tut-btn:active { background: #1b5e20; }
.tut-btn:disabled { opacity: 0.5; cursor: default; }

.tut-btn.tut-skip {
  background: transparent;
  color: #7aaa7a;
  border: 1px solid #3a6e3a;
}

.tut-btn.tut-skip:hover { background: #1f4a1f; color: #c5e8c5; }

/* ── Flower pop animation ────────────────────────────────────────────────── */

@keyframes flower-pop {
  0%   { opacity: 0;   }
  45%  { opacity: 1;   }
  70%  { opacity: 0.6; }
  100% { opacity: 1;   }
}

.flower-pop {
  animation: flower-pop 0.24s ease-out both;
}

/* ── Seed stagger animation ──────────────────────────────────────────────── */

@keyframes seed-appear {
  from { opacity: 0; transform: scale(0.2); }
  to   { opacity: 1; transform: scale(1);   }
}

.seed-appear {
  animation: seed-appear 0.2s ease-out both;
}

/* ── Cell wave (win) ─────────────────────────────────────────────────────── */

@keyframes cell-wave {
  0%   { transform: translateY(0);    fill-opacity: 1;    }
  30%  { transform: translateY(-6px); fill-opacity: 0.85; }
  60%  { transform: translateY(2px);  fill-opacity: 1;    }
  100% { transform: translateY(0);    fill-opacity: 1;    }
}

.cell-wave {
  transform-box: fill-box;
  transform-origin: center;
  animation: cell-wave 0.5s ease-in-out both;
}

/* ── Flower wilt (loss) ──────────────────────────────────────────────────── */

@keyframes flower-wilt {
  0%   { opacity: 1;   }
  40%  { opacity: 0.7; }
  100% { opacity: 0.35; }
}

.flower-wilt {
  animation: flower-wilt 0.7s ease-in-out forwards;
}

/* ── Confetti ────────────────────────────────────────────────────────────── */

#confetti {
  position: fixed;
  bottom: 35%;
  left: 50%;
  transform: translateX(-50%);
  width: min(400px, 95vw);
  height: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 100;
}

@keyframes confetti-fly {
  0%   { transform: translateY(0)    rotate(0deg);   opacity: 1; }
  80%  { opacity: 1; }
  100% { transform: translateY(-280px) rotate(360deg); opacity: 0; }
}

.confetti-dot {
  position: absolute;
  bottom: 0;
  animation: confetti-fly linear forwards;
}

/* ── Cell drop shadow ────────────────────────────────────────────────────── */

.cell rect {
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.30));
  transition: fill 0.18s ease, filter 0.18s ease;
}

.cell:not(.flower):hover rect,
.cell:not(.flower):focus rect {
  filter: drop-shadow(0 3px 7px rgba(0,0,0,0.45)) drop-shadow(0 0 3px rgba(245,230,66,0.4));
}

/* ── Attribution footer line ─────────────────────────────────────────────── */

footer {
  flex-direction: column;
  gap: 8px;
}

#game-attribution {
  font-size: 0.72rem;
  color: #5a8a5a;
  text-align: center;
  line-height: 1.45;
  padding: 0 12px;
}

#game-attribution a {
  color: #7aaa7a;
  text-decoration: underline;
  text-underline-offset: 2px;
}

#game-attribution a:hover { color: #a8d8a8; }


