:root {
  --page: #eff4fb;
  --ink: #1b2430;
  --blue: #336699;
  --blue2: #aac2da;
  --card: #ffffff;
  --line: #253858;
  --given: #8b1d16;
  --wrong: #d41414;
  --mark: #222;
  --soft: #eef1f6;
  --tile: #ffffff;
  --tile-alt: #e1e1d2;
  --select: #ffd95a;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, rgba(255,255,255,.9), transparent 34rem),
    linear-gradient(180deg, #ffffff 0%, var(--page) 100%);
}
.site-header {
  background: #336699;
  color: #fff;
  border-bottom: 4px solid #aac2da;
}
.brand {
  width: min(1000px, calc(100% - 24px));
  margin: 0 auto;
  padding: 14px 0;
  display: flex;
  align-items: center;
  gap: 14px;
}
.logo {
  width:106px;
  height:80px;
  display:grid;
  place-items:center;
  padding:0;
  overflow:hidden;
}
.logo img {
  display:block;
  width:106px;
  height:80px;
  object-fit:contain;
}
h1 { margin: 0; font-size: clamp(1.8rem, 4vw, 2.7rem); }
.site-header p { margin: 2px 0 0; color: #e8f1fb; }
.layout {
  width: min(1000px, calc(100% - 24px));
  margin: 18px auto 36px;
  display: grid;
  gap: 18px;
}
.game-card, .instructions {
  background: var(--card);
  border: 2px solid #c8d6e7;
  border-radius: 14px;
  box-shadow: 0 12px 30px rgba(30,55,90,.12);
}
.game-card {
  padding: 14px;
  background-image: url("pics/back4.gif");
}
.game-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.status {
  flex: 1;
  min-height: 32px;
  border: 1px solid #c5d0df;
  border-radius: 999px;
  background: rgba(255,255,255,.92);
  padding: 7px 14px;
  font-size: 1rem;
  text-align: center;
}
.timer {
  min-width: 74px;
  text-align: center;
  font-weight: 800;
  padding: 7px 10px;
  border-radius: 999px;
  color: #fff;
  background: var(--blue);
}
.start-panel {
  max-width: 620px;
  min-height: 260px;
  margin: 28px auto;
  padding: 28px;
  text-align: center;
  background: rgba(255,255,255,.93);
  border: 2px solid #333;
  border-radius: 12px;
}
.start-panel h2 { margin-top: 0; font-size: 2rem; }
.field { display: grid; gap: 8px; font-weight: 700; margin: 22px auto; max-width: 470px; }
input[type=range] { width: 100%; }
.difficulty-row { display: flex; justify-content: space-between; font-weight: 400; font-size: .92rem; }
.difficulty-row strong { font-weight: 800; }
button {
  border: 1px solid #91a8c2;
  border-radius: 8px;
  background: linear-gradient(#fff, #e7edf5);
  color: #142033;
  font-weight: 700;
  min-height: 34px;
  padding: 7px 12px;
  cursor: pointer;
}
button:hover { filter: brightness(.98); transform: translateY(-1px); }
button:active { transform: translateY(0); }
.primary {
  color: #fff;
  background: linear-gradient(#477bb2, #285887);
  border-color: #1d456d;
  padding-inline: 22px;
}
.hidden { display: none !important; }
.game-area {
  display: grid;
  justify-items: center;
  gap: 12px;
  min-height: calc(100vh - 190px);
  align-content: center;
}
.board-shell {
  position: relative;
  width: min(760px, calc(100vw - 56px), calc(100vh - 285px));
  min-width: min(100%, 300px);
  aspect-ratio: 1 / 1;
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #fff;
  border: 3px solid var(--line);
  box-shadow: 0 2px 12px rgba(0,0,0,.12);
  touch-action: none;
}
.number-pad {
  display: grid;
  grid-template-columns: repeat(9, minmax(34px, 1fr));
  width: min(560px, 100%);
  gap: 5px;
}
.number-pad button {
  min-height: 40px;
  font-size: 1.25rem;
  position: relative;
  overflow: visible;
}
.number-pad button.number-complete {
  background: linear-gradient(#eef1f5, #d7dde6);
  border-color: #b6c0cc;
  color: #77808d;
  cursor: default;
  opacity: .62;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.06);
}
.number-pad button.number-complete:hover {
  filter: grayscale(.35);
  transform: none;
}
.number-burst {
  position: absolute;
  left: 50%;
  top: 48%;
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 4;
}
.number-burst i {
  position: absolute;
  left: -3px;
  top: -3px;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #ffcf33;
  box-shadow: 0 0 0 2px rgba(255,255,255,.9), 0 0 10px rgba(255,145,0,.75);
  opacity: 0;
  transform: translate(0, 0) scale(.4);
  animation: numberFirework .78s ease-out var(--delay, 0ms) forwards;
}
.number-burst i:nth-child(3n+1) { background: #5fcd78; }
.number-burst i:nth-child(3n+2) { background: #ff7b54; }
@keyframes numberFirework {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(.25);
  }
  16% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(1);
  }
}
@media (prefers-reduced-motion: reduce) {
  .number-burst { display: none; }
}
.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 10px;
  align-items: center;
}
.check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(255,255,255,.92);
  border: 1px solid #c5d0df;
  border-radius: 999px;
  padding: 7px 10px;
  min-height: 34px;
}
.instructions {
  padding: 18px 22px;
  line-height: 1.5;
}
.instructions h2 { margin-top: 0; color: #244d76; }
.win-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.96);
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 3px solid #111;
}
.win-overlay img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}
.fortune-card {
  position: absolute;
  left: 49%;
  right: 8%;
  top: calc(51% + 25px);
  transform: translateY(-6%);
  font-size: clamp(.68rem, 1.95vw, 1rem);
  text-align: center;
  color: #111;
  font-weight: 700;
  line-height: 1.2;
}
#winTime {
  color: #111;
  text-shadow: 1px 1px #eef1cc, -1px -1px #d94816;
  font-size: clamp(.9rem, 2.5vw, 1.18rem);
  margin-bottom: 12px;
}
#fortuneText {
  margin: 0 auto 12px;
  max-width: 17em;
}
#luckyNumbers {
  color: #f421ac;
  margin: 0 auto;
  max-width: 17em;
}
@media (max-width: 640px) {
  .layout { width: min(100% - 12px, 1000px); margin-top: 8px; }
  .brand { width: min(100% - 12px, 1000px); }
  .game-card { padding: 8px; border-radius: 10px; }
  .game-top { margin-bottom: 8px; }
  .status { font-size: .88rem; padding: 6px 10px; }
  .timer { min-width: 66px; padding: 6px 8px; }
  .number-pad { gap: 4px; grid-template-columns: repeat(9, 1fr); }
  .number-pad button { min-width: 0; padding-inline: 0; min-height: 36px; }
  .controls { gap: 6px; }
  .controls button, .check { font-size: .86rem; }
  .start-panel { margin: 10px auto; padding: 18px 14px; }
  .instructions { padding: 14px; }
}


/* v2 responsive board scaling */
@media (min-width: 900px) {
  .game-card {
    min-height: calc(100vh - 120px);
  }
}
@media (max-height: 760px) and (min-width: 700px) {
  .board-shell {
    width: min(66vh, 680px, calc(100vw - 40px));
  }
  .game-area {
    align-content: start;
    min-height: auto;
  }
}
@media (max-width: 640px) {
  .board-shell {
    width: min(calc(100vw - 28px), 82vh);
  }
  .game-area {
    min-height: auto;
    align-content: start;
  }
  .fortune-card {
    left: 48%;
    right: 7%;
    top: calc(51% + 20px);
    font-size: clamp(.58rem, 2.5vw, .82rem);
  }
  #winTime {
    font-size: clamp(.7rem, 3vw, .95rem);
    margin-bottom: 6px;
  }
  #fortuneText,
  #luckyNumbers {
    max-width: 15em;
  }
}


/* v3: ensure the actual puzzle canvas grows, not just the surrounding game area */
.board-shell {
  max-width: 100%;
}
.game-area {
  justify-content: center;
}
@media (min-width: 900px) {
  .board-shell {
    width: min(760px, calc(100vw - 56px), calc(100vh - 285px));
  }
}
@media (max-height: 760px) and (min-width: 700px) {
  .board-shell {
    width: min(640px, calc(100vw - 56px), calc(100vh - 250px));
  }
}
@media (max-width: 640px) {
  .board-shell {
    width: min(calc(100vw - 28px), calc(100vh - 250px));
  }
}


/* v5 JGames page shell additions */
.jgames-home-badge{
  position:fixed;
  top:12px;
  right:12px;
  z-index:10000;
  width:44px;
  height:44px;
  display:grid;
  place-items:center;
  border-radius:14px;
  background:#fff;
  border:1px solid rgba(11,46,131,.18);
  box-shadow:0 8px 22px rgba(11,46,131,.18);
  transition:transform .12s ease, box-shadow .12s ease;
}
.jgames-home-badge img{
  width:32px;
  height:32px;
  display:block;
}
.jgames-home-badge:hover{
  transform:translateY(-1px);
  box-shadow:0 12px 28px rgba(11,46,131,.22);
}
.footer{
  margin:34px auto 0;
  padding:22px 14px 28px;
  max-width:1000px;
  color:#58607a;
  text-align:center;
  font:14px/1.45 system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Arial,sans-serif;
  border-top:1px solid rgba(11,46,131,.16);
}
.footer nav{
  display:flex;
  flex-wrap:wrap;
  justify-content:center;
  gap:8px 14px;
  margin-bottom:12px;
  font-weight:700;
}
.footer a{
  color:#0B2E83;
  text-decoration:none;
}
.footer a:hover{
  color:#D80D16;
  text-decoration:underline;
}
.footer p{
  margin:6px 0 0;
}
@media (max-width:720px){
  .jgames-home-badge{
    width:40px;
    height:40px;
    border-radius:13px;
  }
  .jgames-home-badge img{
    width:29px;
    height:29px;
  }
  .site-header{
    padding-right:56px;
  }
  .logo,
  .logo img{
    width:82px;
    height:62px;
  }
}
