/* -----------------------------
   THEME VARIABLES
----------------------------- */
:root {
  --bg: #f4f4f4;
  --cell-fill: #e8e8e8;
  --grid-bg: #fafafa;
  --grid-line: #333;
  --text: #111;
  --tray-bg: #00000014;
  --tray-border: #0000001F;
}

body.dark {
  --bg: #1e1e1e;
  --cell-fill: #4a4a4a;
  --grid-bg: #3a3a3a;
  --grid-line: #d6d6d6;
  --text: #eee;
  --tray-bg: #FFFFFF29;
  --tray-border: #FFFFFF2E;
}

/* -----------------------------
   BASE
----------------------------- */
body {
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--bg);
  color: var(--text);
  font-family: sans-serif;
  padding-bottom: 400px;
}

html, body {
  height: auto;
  min-height: 100%;
}

canvas {
  display: block;
  touch-action: auto;
}

/* -----------------------------
   UI (TOP RIGHT)
----------------------------- */
#ui {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 10px;
  align-items: center;
  z-index: 20;
}

#ui button {
  width: 36px;
  height: 36px;
  font-size: 18px;
  cursor: pointer;
}

#labelsBtn.inactive {
  opacity: 0.6;
}

/* 🔥 Streak */
#streakDisplay {
  display: flex;
  align-items: center;
  font-size: 18px;
  font-weight: bold;
  padding: 0 6px;
}

/* -----------------------------
   CALENDAR PANEL
----------------------------- */
#calendar {
  position: absolute;
  top: 60px;
  right: 10px;
  background: var(--bg);
  padding: 10px;
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  z-index: 15;
}

#calendar > * {
  background: var(--bg);
  padding: 10px;
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);

  transform: scale(0.95);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.hidden {
  display: none;
}

#calendar:not(.hidden) > * {
  transform: scale(1);
  opacity: 1;
}

/* Header */
#calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

#calendar-header button {
  cursor: pointer;
}

/* Grid */
#calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 32px);
  gap: 4px;
}

/* Weekday labels */
.calendar-weekday {
  font-size: 10px;
  text-align: center;
  opacity: 0.7;
}

/* Days */
.calendar-day {
  width: 32px;
  height: 32px;
  line-height: 32px;
  text-align: center;
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
}

.calendar-day.completed {
  background: green;
  color: white;
}

.calendar-day.today {
  border: 2px solid gold;
  background: rgba(255, 215, 0, 0.2);
  font-weight: bold;
}

.calendar-day.selected {
  background: #444;
  color: white;
}

.calendar-day.disabled {
  opacity: 0.3;
  cursor: default;
}

/* -----------------------------
   WIN OVERLAY (FIXED)
----------------------------- */
/* Overlay container */
#winOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;

  display: none;

  align-items: center;
  justify-content: center;

  z-index: 30;

  pointer-events: none; /* 🔥 allow clicks through */
}

/* Active state */
#winOverlay.active {
  display: flex;
  background: rgba(0,0,0,0.5);
}

/* Win box */
#winBox {
  background: #fbf7ef;
  color: var(--text);
  position: relative;
  pointer-events: auto;
  background: var(--bg);
  color: var(--text);
  padding: 34px 48px 24px 24px;
  border-radius: 12px;
  text-align: center;
  min-width: 280px;
  max-width: 360px;
  font-family: Georgia, "Times New Roman", serif;
}

body.dark #winBox {
  background: #2b2f36;
  color: var(--text);
}

#winBox h2 {
  margin: 0 0 16px;
  font-size: 30px;
  line-height: 1.2;
}

#winCloseBtn {
  position: absolute;
  top: 12px;
  right: 12px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 6px;
}

#winCloseBtn:hover {
  opacity: 0.7;
}

/* Win content */
#winMoves {
  font-size: 18px;
}

#winStreak {
  font-size: 28px;
  font-weight: bold;
  margin: 10px 0;
}

#winNext {
  margin-top: 14px;
  font-size: 14px;
  opacity: 0.75;
}

#winSharePreview {
  font-size: 15px;
  margin-top: 8px;
  margin-bottom: 14px;
  line-height: 1.5;
  opacity: 0.92;
}

.winDate {
  font-weight: 700;
  font-size: 18px;
  margin-bottom: 10px;
}

.winMovesPreview {
  margin-bottom: 10px;
  font-size: 16px;
}

.winStreakPreview {
  margin-bottom: 14px;
  font-size: 20px;
  font-weight: 700;
}

.winGridPreview {
  line-height: 1.3;
}

/* Button */
#winBox button {
  margin-top: 15px;
  padding: 8px 12px;
  cursor: pointer;
}

/* Copy feedback */
#copyMsg {
  margin-top: 8px;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.3s;
}

#copyMsg.show {
  opacity: 1;
}

/* Support UI */
#supportUi {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 20;
}

#supportBtn {
  height: 36px;
  padding: 0 12px;
  font-size: 14px;
  cursor: pointer;
}

#supportOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
  background: rgba(0,0,0,0.5);
}

#supportOverlay.active {
  display: flex;
}

#supportBox {
  position: relative;
  background: var(--bg);
  color: var(--text);
  padding: 28px 24px 24px;
  border-radius: 12px;
  text-align: center;
  min-width: 280px;
  max-width: 360px;
}

#supportCloseBtn {
  position: absolute;
  top: 12px;
  right: 12px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 6px;
}

#supportBox h2 {
  margin: 0 0 10px;
}

#supportBox p {
  margin: 0 0 18px;
}

#supportLink {
  display: inline-block;
  padding: 10px 14px;
  border-radius: 8px;
  text-decoration: none;
  color: white;
  background: #29abe0;
}

#beginOverlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 35;
  background: rgba(0,0,0,0.35);
  pointer-events: none;
}

#beginOverlay.active {
  display: flex;
  pointer-events: auto;
}

#beginBox {
  background: var(--bg);
  color: var(--text);
  border-radius: 12px;
  padding: 22px 20px;
  min-width: 220px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}

#beginDate {
  font: 700 22px Georgia, "Times New Roman", serif;
  margin-bottom: 14px;
}

#beginBtn {
  padding: 10px 16px;
  font-size: 16px;
  cursor: pointer;
}

#redoPuzzleBtn {
  display: block;
  margin: 16px auto 24px auto;
  padding: 10px 16px;
  font-size: 16px;
  border-radius: 10px;
  cursor: pointer;
}

@media (min-width: 769px) {
  #beginOverlay {
    display: none !important;
  }
}