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

:root {
  --bg: #f3ece1;
  --ink: #2f2a24;
  --accent: #6b8e5a;
  --accent-dark: #4e6c41;
  --light-sq: #f0d9b5;
  --dark-sq: #b58863;
  --sel: #f6d55c;
  --good: #58a55c;
  --bad: #d4564f;
  --card: #fff;
}

html, body {
  height: 100%;
  font-family: ui-rounded, "Trebuchet MS", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
}

#app { height: 100%; display: flex; flex-direction: column; }
.screen { display: none; flex: 1; min-height: 0; flex-direction: column; }
.screen.active { display: flex; }
.hidden { display: none !important; }

/* ---------- menus ---------- */

.menu-screen { align-items: center; padding: 20px 16px; overflow-y: auto; }
.logo { font-size: clamp(32px, 8vw, 52px); margin-top: 5vh; text-align: center; }
.tagline { font-size: clamp(14px, 3vw, 18px); margin: 12px 0 28px; text-align: center; line-height: 1.6; }

.menu-buttons { display: flex; flex-direction: column; gap: 14px; width: min(340px, 92vw); }

.big-btn {
  min-height: 54px; border: 0; border-radius: 14px;
  background: var(--accent); color: #fff;
  font-family: inherit; font-size: 18px; font-weight: 700;
  cursor: pointer; padding: 10px 18px;
  box-shadow: 0 4px 0 var(--accent-dark);
}
.big-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-dark); }
.big-btn.ghost { background: #fff; color: var(--ink); box-shadow: 0 4px 0 #d8cdbb; }
.big-btn.danger { background: var(--bad); box-shadow: 0 4px 0 #a53b36; }

.portal-link {
  margin-top: 22px; padding: 12px 20px; min-height: 44px;
  display: inline-flex; align-items: center;
  font-size: 14px; color: var(--ink); text-decoration: none;
  background: #fff; border-radius: 999px; box-shadow: 0 2px 0 #d8cdbb;
}
.build { margin-top: 14px; font-size: 12px; color: #877e70; }

.menu-header {
  display: flex; align-items: center; gap: 12px;
  width: min(760px, 100%); margin-bottom: 10px;
}
.menu-header h2 { font-size: clamp(18px, 4vw, 24px); }
.back-btn, .hud-btn {
  min-width: 44px; min-height: 44px;
  border: 0; border-radius: 12px; background: #fff; color: var(--ink);
  font-size: 18px; cursor: pointer; box-shadow: 0 2px 0 #d8cdbb;
}
.map-progress { width: min(760px, 100%); font-size: 14px; margin-bottom: 12px; color: #6d6355; }

.grid {
  display: grid; gap: 10px; width: min(760px, 100%);
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}
.tile {
  border: 0; border-radius: 14px; background: var(--card);
  font-family: inherit; color: var(--ink); cursor: pointer;
  padding: 12px 8px; min-height: 104px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  box-shadow: 0 3px 0 #d8cdbb; position: relative;
}
.tile:active { transform: translateY(2px); box-shadow: 0 1px 0 #d8cdbb; }
.tile.locked { opacity: 0.5; cursor: default; }
.tile-num {
  position: absolute; top: 6px; left: 8px;
  font-size: 12px; font-weight: 700; color: #9c9284;
}
.tile-icon { font-size: 30px; line-height: 1.2; }
.tile-title { font-size: 13px; font-weight: 700; text-align: center; }
.tile-stars { font-size: 13px; color: #e0a020; }
.dim { color: #ded5c6; }

/* ---------- game ---------- */

#game-header {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; background: rgba(255,255,255,0.8);
  font-weight: 700; font-size: clamp(13px, 2.6vw, 16px);
}
#round-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#task-dots { display: flex; gap: 5px; }
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #ded5c6; display: inline-block;
}
.dot.done { background: var(--good); }
.dot.now { background: var(--accent); transform: scale(1.3); }

.teach {
  padding: 10px 16px; text-align: center;
  font-size: clamp(13px, 2.8vw, 16px); line-height: 1.5;
  background: #fffdf8;
}

.board-wrap {
  flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 8px; touch-action: manipulation;
}
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(92vw, 62vh); height: min(92vw, 62vh);
  border: 4px solid #6b5540; border-radius: 6px; overflow: hidden;
}
.sq {
  border: 0; padding: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: min(7vw, 4.8vh); line-height: 1;
  position: relative; font-family: inherit;
}
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq.wp { color: #fff; text-shadow: 0 0 2px #000, 0 1px 2px rgba(0,0,0,.5); }
.sq.bp { color: #1c1c1c; text-shadow: 0 1px 1px rgba(255,255,255,.25); }

.sq.sel { box-shadow: inset 0 0 0 4px var(--sel); }
/* Move dot uses ::before so it can coexist with the star's ::after — on a
   star square the dot is replaced by a green ring (see .star.move below). */
.sq.move::before {
  content: ""; position: absolute;
  width: 30%; height: 30%; border-radius: 50%;
  background: rgba(60, 120, 60, 0.55);
}
.sq.cap { box-shadow: inset 0 0 0 4px rgba(212, 86, 79, 0.85); }
.sq.check { box-shadow: inset 0 0 0 4px var(--bad); }
.sq.star::after {
  content: "⭐"; position: absolute; font-size: 60%;
  animation: twinkle 1.6s ease-in-out infinite;
}
.sq.star.move::before { display: none; }
.sq.star.move { box-shadow: inset 0 0 0 4px rgba(60, 120, 60, 0.75); }
@keyframes twinkle { 0%,100% { transform: scale(1); } 50% { transform: scale(1.18); } }
.sq.good { animation: flashg 0.6s ease; }
.sq.bad { animation: flashb 0.6s ease; }
@keyframes flashg { 0% { box-shadow: inset 0 0 0 40px rgba(88,165,92,.6); } 100% {} }
@keyframes flashb { 0% { box-shadow: inset 0 0 0 40px rgba(212,86,79,.6); } 100% {} }

.game-footer {
  padding: 8px 14px 14px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.status { font-size: clamp(13px, 2.8vw, 16px); font-weight: 700; }
.moves { font-size: 13px; color: #6d6355; }
.moves.warn { color: var(--bad); font-weight: 700; }
.hint-btn {
  min-height: 44px; padding: 8px 18px;
  border: 0; border-radius: 999px; background: #fff;
  font-family: inherit; font-size: 14px; cursor: pointer;
  box-shadow: 0 2px 0 #d8cdbb;
}
.hint { font-size: 14px; color: #6d6355; max-width: 46ch; line-height: 1.5; }

/* ---------- overlays ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 30; padding: 16px;
  background: rgba(47, 42, 36, 0.55);
  display: flex; align-items: center; justify-content: center;
}
.card {
  background: #fff; border-radius: 18px; padding: 24px;
  width: min(420px, 94vw); max-height: 90vh; overflow-y: auto; text-align: center;
}
.card h2 { font-size: clamp(19px, 4vw, 25px); margin-bottom: 10px; }
.card p { font-size: 15px; line-height: 1.6; margin-bottom: 8px; }
.overlay.fail .card { border-top: 6px solid var(--bad); }
.stars { font-size: 38px; color: #e0a020; margin: 6px 0; }
.card-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
#btn-msg-ok { margin-top: 14px; width: 100%; }

.promo-row { display: flex; gap: 10px; justify-content: center; margin-top: 12px; }
.promo-btn {
  width: 64px; height: 64px; border: 0; border-radius: 12px;
  background: var(--light-sq); font-size: 38px; cursor: pointer;
  box-shadow: 0 3px 0 #c8ab84;
}

.setting-row {
  display: flex; align-items: center; gap: 12px;
  font-size: 16px; font-weight: 700; padding: 12px 6px; cursor: pointer;
}
.setting-row input { width: 22px; height: 22px; }

/* landscape phones: put the board beside the text so it stays big */
@media (orientation: landscape) and (max-height: 560px) {
  .teach { font-size: 12px; padding: 6px 12px; }
  .board { width: min(52vh, 92vw); height: min(52vh, 92vw); }
  .game-footer { padding: 4px 10px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .sq.star::after { animation: none; }
}
