/* Daily Calendar Puzzle */

:root {
  --page: #eef1f5;
  --board: #243447;
  --cell-bg: #f7f9fb;
  --cell-line: #c5ced9;
  --text: #243447;
  --today: #2f6fed;
  --pad-ratio: 0.55;
}

* { box-sizing: border-box; }

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

body {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .6rem;
  padding: max(.75rem, env(safe-area-inset-top)) 1rem max(.75rem, env(safe-area-inset-bottom));
  color: var(--text);
  font-family: "Segoe UI", "Avenir Next", system-ui, sans-serif;
  background: var(--page);
  overflow: hidden;
}

.top { text-align: center; flex: none; }
.top h1 { margin: 0; line-height: 0; }
.logo { height: 6.5rem; width: auto; }
.today-label { margin: .15rem 0 0; font-size: .9rem; opacity: .75; }
/* Short screens: shrink the logo so the board keeps its room. */
@media (max-height: 700px) { .logo { height: 4rem; } }
@media (max-height: 480px) { .logo { height: 2.75rem; } }

/* The stage fills the space between header and toolbar; game.js sizes .play to fit. */
.stage {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --cell is set in px by game.js; everything below scales from it. */
.play { --cell: 40px; position: relative; flex: none; }

.board {
  position: absolute;
  display: grid;
  grid-template-columns: repeat(7, var(--cell));
  grid-template-rows: repeat(7, var(--cell));
  padding: calc(var(--cell) * var(--pad-ratio));
  width: calc(var(--cell) * (7 + 2 * var(--pad-ratio)));
  height: calc(var(--cell) * (7 + 2 * var(--pad-ratio)));
  border-radius: calc(var(--cell) * 0.4);
  background: var(--board);
  box-shadow: 0 8px 24px rgba(36, 52, 71, .25);
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cell-bg);
  box-shadow: inset 0 0 0 1px var(--cell-line);
  color: var(--text);
  font-size: calc(var(--cell) * 0.36);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.cell.month { font-size: calc(var(--cell) * 0.28); }

/* Marks today's two cells so the target is easy to find. */
.cell.today {
  box-shadow: inset 0 0 0 3px var(--today);
  color: var(--today);
  font-weight: 700;
}

/* Pieces ------------------------------------------------------------- */

.piece {
  position: absolute;
  pointer-events: none;            /* only the filled cells grab, not the notches */
  touch-action: none;
  transform-origin: center;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .35));
  user-select: none;
  -webkit-user-select: none;
}
.piece .pc {
  position: absolute;
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .22);
}
.piece.animate { transition: scale .12s ease-out; }
.piece.settle { transition: left .18s ease-out, top .18s ease-out, scale .18s ease-out; }
.piece.selected {
  filter: drop-shadow(0 0 1.5px var(--text)) drop-shadow(0 0 1.5px var(--text))
          drop-shadow(0 3px 6px rgba(0, 0, 0, .3));
}
.piece.dragging { filter: drop-shadow(0 10px 14px rgba(0, 0, 0, .35)); }
.piece.dragging .pc { cursor: grabbing; }

/* Toolbar ------------------------------------------------------------ */

.toolbar { flex: none; display: flex; gap: .5rem; width: 100%; max-width: 30rem; }
.toolbar button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 0 .6rem;
  border: 0;
  border-radius: 999px;
  background: var(--board);
  color: #fff;
  font: inherit;
  font-size: .95rem;
  cursor: pointer;
}
.toolbar button:disabled { opacity: .35; cursor: default; }
.toolbar button:focus-visible { outline: 3px solid var(--today); outline-offset: 2px; }

/* Covered-date warning: sits above every piece */
.warn {
  position: absolute;
  z-index: 100000;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: rgba(220, 38, 38, .82);
  box-shadow: inset 0 0 0 3px #b91c1c;
  color: #fff;
  font-weight: 700;
  line-height: 1;
}
.warn.on { display: flex; }

/* Win dialog --------------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 200000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(36, 52, 71, .55);
}
.overlay[hidden] { display: none; }
.dialog {
  width: min(22rem, 100%);
  padding: 1.5rem;
  border-radius: 1rem;
  background: #fff;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .35);
  animation: pop .38s ease-out;
}
.dialog h2 { margin: 0 0 1rem; font-size: 1.6rem; line-height: 1.2; }
.dialog p { margin: 0 0 .5rem; line-height: 1.45; }
.win-stats {
  margin: .75rem 0 .9rem;
  padding: .6rem .75rem;
  border-radius: .6rem;
  background: #eef1f5;
  font-size: .92rem;
}
.win-stats[hidden] { display: none; }
.dialog .win-stats p { margin: 0; }
.dialog .win-stats p + p { margin-top: .35rem; }
.win-stats .first { color: var(--today); font-weight: 700; }
.dialog .win-note { margin: 0 0 1.4rem; font-size: .9rem; opacity: .7; }

/* The two uncovered squares, drawn like the board's own date cells. */
.win-date { display: flex; justify-content: center; gap: .5rem; margin: 0 0 1rem; }
.win-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 4.25rem;
  height: 4.25rem;
  padding: 0 .5rem;
  border-radius: .5rem;
  background: var(--cell-bg);
  box-shadow: inset 0 0 0 3px var(--today);
  color: var(--today);
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1;
}

.dialog-actions { display: flex; gap: .5rem; }
.dialog-actions button {
  flex: 1 1 0;
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  background: var(--board);
  color: #fff;
  font: inherit;
  cursor: pointer;
}
.dialog-actions button.secondary { background: #e3e8ee; color: var(--text); }
.dialog-actions button:focus-visible { outline: 3px solid var(--today); outline-offset: 2px; }

/* How to play --------------------------------------------------------- */

.help-btn {
  position: fixed;
  top: max(.75rem, env(safe-area-inset-top));
  right: max(.75rem, env(safe-area-inset-right));
  z-index: 150000;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--board);
  color: #fff;
  font: inherit;
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(36, 52, 71, .3);
}
.help-btn:focus-visible { outline: 3px solid var(--today); outline-offset: 2px; }

.dialog.help {
  width: min(26rem, 100%);
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
}
.dialog.help h2 { margin-bottom: .75rem; }
.dialog .help-goal { margin: 0 0 1rem; }
.help-list {
  margin: 0 0 1.4rem;
  padding-left: 1.2rem;
  text-align: left;
  line-height: 1.45;
}
.help-list li + li { margin-top: .4rem; }
.help-red { color: #dc2626; font-weight: 700; }

/* Confetti sits above the dialog but never blocks taps. */
.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 300000;
  pointer-events: none;
}
.confetti[hidden] { display: none; }

@keyframes pop {
  0%   { transform: scale(.88); opacity: 0; }
  60%  { transform: scale(1.03); opacity: 1; }
  100% { transform: none; opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
