* { box-sizing: border-box; }
[hidden] { display: none !important; } /* makes the menu's Close actually hide it */

/* ---------- Theme colors ----------
   Each theme sets these variables. Add a new block for each new theme. */
body.theme-classic {
  --header-bg: rgba(0, 0, 0, 0.25);
  --tile-bg: #fbf7ea;
  --tile-border: #b9ae94;
  --tile-side: #a99f84;
  --tile-back: repeating-linear-gradient(45deg, #2e7d5b 0 6px, #286f50 6px 12px);
  --title-font: "Segoe UI", system-ui, sans-serif;
}

body.theme-croquet {
  --header-bg: #2c5424;
  --tile-bg: #fffdf5;
  --tile-border: #c9bfa3;
  --tile-side: #8fa77e;
  --tile-back: repeating-linear-gradient(90deg, #3d7a31 0 8px, #4a8a3c 8px 16px);
  --title-font: Georgia, "Times New Roman", serif;
}

body.theme-birds {
  --header-bg: #2d5566;
  --tile-bg: #fffdf7;
  --tile-border: #c6bda5;
  --tile-side: #8fa9b5;
  --tile-back: repeating-linear-gradient(45deg, #3f7088 0 6px, #36627a 6px 12px);
  --title-font: Georgia, "Times New Roman", serif;
}

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #1f5d3a; /* replaced by the chosen background (game.js) */
  color: #f4f1e6;
  font-family: "Segoe UI", system-ui, sans-serif;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  padding: 10px 16px;
  background: var(--header-bg);
}

h1 { font-size: 24px; margin: 0; font-family: var(--title-font); }

.buttons { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

button {
  font: inherit;
  font-size: 16px;
  padding: 7px 16px;
  border: none;
  border-radius: 6px;
  background: #f4f1e6;
  color: #1f3a2a;
  cursor: pointer;
}
button:hover { background: #fff; }

#status { font-size: 16px; }
#status.win { color: #ffe28a; font-weight: bold; }
#status.stuck { color: #ffb3a7; font-weight: bold; }

#wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}
/* a magnified board sticks out of the window: it scrolls (by mouse or finger), with no scrollbars */
#wrap.magnified { overflow: auto; scrollbar-width: none; }
#wrap.magnified::-webkit-scrollbar { display: none; }
#sizer { position: absolute; width: 1px; height: 1px; }

#board {
  position: absolute;
  transform-origin: top left;
}

/* ---------- Tiles ---------- */
.tile {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--tile-bg);
  border: 1px solid var(--tile-border);
  border-radius: 6px;
  /* first shadow = the tile's thick side, second = soft drop shadow */
  box-shadow: 4px 4px 0 var(--tile-side), 5px 5px 6px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  user-select: none;
  line-height: 1;
}

.tile .big { font-size: 30px; font-weight: bold; font-family: "Microsoft YaHei", "Segoe UI", sans-serif; }
.tile .small { font-size: 11px; margin-top: 4px; white-space: nowrap; max-width: 100%; }
.tile .icon svg { width: 34px; height: 34px; display: block; }
.tile .mini-icon svg { width: 20px; height: 20px; display: block; margin-top: 1px; }
.tile .emoji { font-size: 28px; line-height: 34px; white-space: nowrap; }
.tile .emoji.pair { font-size: 21px; letter-spacing: -3px; }
.tile .pips { display: grid; gap: 1px 2px; margin-top: 8px; }
.tile .pips svg { width: 13px; height: 13px; display: block; }
.tile .pips.few svg { width: 17px; height: 17px; }
.tile .pips.one svg { width: 28px; height: 28px; }
.tile .corner { position: absolute; top: 3px; left: 4px; font-size: 13px; font-weight: bold; line-height: 1; font-family: "Segoe UI", sans-serif; }
.tile .corner.tag { font-size: 8px; font-weight: normal; text-transform: uppercase; letter-spacing: 0.3px; opacity: 0.85; }
.tile .cn { font-size: 26px; margin-top: 8px; }
.tile .wan { font-size: 18px; color: #c0262d; font-family: "Microsoft YaHei", sans-serif; margin-top: 2px; }
.tile .pic { width: 46px; height: 52px; object-fit: cover; border-radius: 3px; display: block; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25); pointer-events: none; }
.tile .pic + .small { margin-top: 3px; }

.tile.blocked.dim { filter: brightness(0.78); cursor: default; }
.tile.facedown { background: var(--tile-back); border-color: rgba(0, 0, 0, 0.3); }
.tile.selected { background: #ffe28a; border-color: #c9a227; outline: 3px solid #e0b020; }
.tile.hint { background: #a8e6a8; border-color: #3c9a3c; outline: 3px solid #3c9a3c; }

/* Classic tile colors */
.c-dot    { color: #1d5fb8; }
.c-bam    { color: #1d8a3c; }
.c-crak   { color: #222; }
.c-wind   { color: #222; }
.c-red    { color: #c0262d; }
.c-green  { color: #1d8a3c; }
.c-white  { color: #1d5fb8; }
.c-flower { color: #c2577e; }
.c-season { color: #b8741a; }

/* Croquet tile colors */
.q-hoop   { color: #2f4a6b; }
.q-mallet { color: #7a4a22; }
.q-flag   { color: #c0262d; }
.q-ball   { color: #333; }
.q-party  { color: #2c5424; }
.q-family { color: #b8476e; }
.q-season { color: #a0661a; }
body.theme-croquet .tile .big,
body.theme-birds .tile .big { font-family: Georgia, serif; }

/* Bird watching tile colors */
.b-egg     { color: #3f6f7a; }
.b-feather { color: #6a4fa0; }
.b-nest    { color: #7a4a22; }
.b-bird    { color: #4a3a22; }
.b-farm    { color: #a0441e; }
.b-baby    { color: #b8861a; }

/* ---------- Menu ---------- */
#menu {
  position: fixed;
  inset: 0;
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.55);
}

.panel {
  width: min(560px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 20px 24px;
  border-radius: 12px;
  background: #fbf7ea;
  color: #1f3a2a;
}

.panel h2 { margin: 0 0 8px; font-family: var(--title-font); }
.panel h3 { margin: 16px 0 6px; font-size: 16px; }
.panel h3 small { font-weight: normal; color: #6b6b5c; }

.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices button { background: #e6e0cc; }
.choices button.chosen { background: #2c5424; color: #fff; }

.choices button small { display: block; font-size: 12px; opacity: 0.8; margin-top: 2px; }

/* on/off switches */
.toggles { display: flex; flex-direction: column; gap: 6px; }
.toggle {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #efe9d6;
  cursor: pointer;
}
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch {
  flex: none;
  position: relative;
  width: 42px;
  height: 24px;
  margin-top: 1px;
  border-radius: 12px;
  background: #bbb3a0;
  transition: background 0.15s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.15s;
}
.toggle input:checked + .switch { background: #2c5424; }
.toggle input:checked + .switch::after { left: 21px; }
.toggle input:focus-visible + .switch { outline: 2px solid #2c5424; outline-offset: 2px; }
.toggle .text b { display: block; font-size: 15px; }
.toggle .text small { display: block; font-size: 13px; color: #55594c; margin-top: 2px; }

.note { margin: 8px 0 0; font-size: 14px; color: #55594c; }

.menu-actions {
  position: sticky;
  bottom: -20px;
  display: flex;
  gap: 10px;
  margin-top: 12px;
  padding: 12px 0 4px;
  background: #fbf7ea;
}
button.primary { background: #2c5424; color: #fff; }
button.primary:hover { background: #3a6d30; }

/* ---------- Menu tabs ---------- */
.panel { display: flex; flex-direction: column; height: min(690px, 100%); }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 2px solid #2c5424; }
.tabs button { border-radius: 6px 6px 0 0; background: #e6e0cc; padding: 7px 12px; }
.tabs button.chosen { background: #2c5424; color: #fff; }
.tab-page { flex: 1; overflow-y: auto; min-height: 0; padding-bottom: 4px; }
.tab-page h3:first-child { margin-top: 12px; }

/* background choices show a little preview */
.choices.backgrounds { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.choices.backgrounds button { padding: 6px; text-align: left; }
.swatch { display: block; height: 42px; margin-bottom: 5px; border-radius: 4px; }
.choices.zooms { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.choices.zooms button { text-align: left; }

/* ---------- Mini map (when the board is magnified) ---------- */
#minimap {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 50000;
  padding: 4px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

/* ---------- Mom is sleeping! ---------- */
#btn-sleep {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 6px;
  background: rgba(0, 0, 0, 0.2);
  color: #f4f1e6;
  font-size: 13px;
}
#btn-sleep:hover { background: rgba(0, 0, 0, 0.35); }
.bulb { width: 24px; height: 24px; display: block; }
.bulb .glass { fill: rgba(255, 255, 255, 0.15); stroke: #f4f1e6; stroke-width: 1.5; }
.bulb .base { fill: none; stroke: #c9c3b0; stroke-width: 1.8; stroke-linecap: round; }

/* lights out: everything black except the bulb, which glows very dimly */
#night { position: fixed; inset: 0; z-index: 200000; background: #000; }
#btn-sleep.on { position: relative; z-index: 200001; background: transparent; border-radius: 50%; }
#btn-sleep.on .sleep-text { visibility: hidden; }
#btn-sleep.on .bulb { filter: drop-shadow(0 0 6px rgba(255, 196, 90, 0.45)) drop-shadow(0 0 18px rgba(255, 180, 70, 0.18)); }
#btn-sleep.on .bulb .glass { fill: #8a6a2a; stroke: #6b5426; }
#btn-sleep.on .bulb .base { stroke: #2a2418; }

/* ---------- Layout cards ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.filters button { padding: 4px 14px; font-size: 14px; border-radius: 14px; background: #e6e0cc; }
.filters button.chosen { background: #6b5426; color: #fff; }
.choices.layouts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.choices.layouts button { padding: 6px 8px; text-align: left; font-size: 15px; }
.choices.layouts button[hidden] { display: none; }
.preview { display: block; width: 120px; height: 62px; margin: 0 auto 4px; }
.stars { color: #c08a12; letter-spacing: 1px; }
.choices button.chosen .stars { color: #ffd76a; }

/* ---------- Winning screen ---------- */
#win {
  position: fixed;
  inset: 0;
  z-index: 150000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.7));
  overflow: hidden;
}
.win-card {
  position: relative;
  width: min(480px, 100%);
  padding: 28px 32px 20px;
  text-align: center;
  color: #3a2e1a;
  background: #fffaf0;
  border-radius: 16px;
  /* a gold frame inside a white edge, like a certificate */
  box-shadow: 0 0 0 6px #fffaf0, 0 0 0 9px #c9a227, 0 18px 50px rgba(0, 0, 0, 0.5);
  animation: win-pop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.win-flourish { color: #c9a227; letter-spacing: 10px; font-size: 18px; }
.win-card h2 {
  margin: 6px 0 10px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 38px;
  line-height: 1.15;
  color: var(--header-bg);
}
.win-stats { margin: 0 0 14px; font-size: 14px; color: #7a6a4a; }
.win-message { margin: 0; font-size: 22px; font-family: Georgia, serif; font-style: italic; }
.win-love { margin: 8px 0 0; font-size: 20px; font-family: "Segoe Script", "Brush Script MT", cursive; color: #a0441e; }
.win-actions { display: flex; justify-content: center; gap: 10px; margin: 20px 0 14px; }
.win-credits {
  line-height: 1.7;
  margin: 0;
  padding-top: 12px;
  border-top: 1px solid #e6dcc0;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #9a8a6a;
}
@keyframes win-pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

#confetti span {
  position: absolute;
  top: -20px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  opacity: 0;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  0%   { transform: translateY(0) rotate(0); opacity: 1; }
  85%  { opacity: 1; }
  100% { transform: translateY(105vh) rotate(var(--spin)); opacity: 0; }
}
