:root {
  --bg: #fbf6e9;
  --panel: #f2e9d4;
  --table: #e6d9bb;
  --ink: #2f2a24;
  --muted: #6b6255;
  --pink: #c2185b;
  --teal: #0f7f76;
  --line: #ddd0b3;
  --btn: #ffffff;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
#app { max-width: 760px; margin: 0 auto; padding: 12px 16px 32px; }

header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
h1 { margin: 0; font-size: 24px; letter-spacing: .5px; color: var(--pink); }
.stats { display: flex; gap: 14px; }
.stat { text-align: center; min-width: 44px; }
.lbl { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }
.stat b { font-size: 18px; font-variant-numeric: tabular-nums; }

#controls, #options { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0 0; }
#options { margin-top: 8px; font-size: 14px; color: var(--muted); }
#options label { display: flex; align-items: center; gap: 6px; }
button {
  font: inherit; font-weight: 600; color: var(--ink);
  background: var(--btn); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; cursor: pointer;
}
button:hover { border-color: var(--teal); }
button:disabled { opacity: .45; cursor: default; border-color: var(--line); }
button.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
button.primary.on, button.on { background: var(--pink); border-color: var(--pink); color: #fff; }
.speed { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
select, input[type=number] {
  font: inherit; color: var(--ink); background: var(--btn);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px;
}
.check input { width: 17px; height: 17px; accent-color: var(--teal); }
#msg { min-height: 22px; font-size: 14px; color: var(--muted); margin: 8px 0 6px; }

#boardWrap { position: relative; margin: 0 auto; }
#board {
  position: relative; width: 100%; height: 100%;
  background: var(--table); border: 6px solid var(--table); border-radius: 12px;
  box-shadow: 0 2px 10px rgba(60, 45, 20, .18);
  overflow: hidden; user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
#inner { position: absolute; inset: 0; }
.tile {
  position: absolute; cursor: pointer;
  background-repeat: no-repeat; background-origin: border-box;
  border: 1px solid rgba(255, 252, 240, .85); border-radius: 3px;
  transition: left .16s ease, top .16s ease, border-color .6s ease, border-radius .6s ease;
}
.fast .tile { transition-duration: .07s, .07s, .6s, .6s; }
.noanim .tile { transition: none; }
.tile .num {
  position: absolute; left: 4px; top: 4px; min-width: 1.7em; padding: 1px 5px;
  border-radius: 9px; background: rgba(255, 255, 255, .88); color: var(--ink);
  font-size: 12px; font-weight: 700; text-align: center; line-height: 1.35;
  display: none; pointer-events: none;
}
.numbers .tile .num { display: block; }
.tile.home .num { color: var(--teal); }
.tile.hint { z-index: 2; animation: glow .8s ease infinite; }
@keyframes glow {
  0%, 100% { box-shadow: inset 0 0 0 3px var(--pink), 0 0 0 2px rgba(194, 24, 91, .35); }
  50% { box-shadow: inset 0 0 0 3px #fff, 0 0 0 5px rgba(194, 24, 91, .5); }
}
.tile.last { opacity: 0; transition: opacity .6s ease; pointer-events: none; }
.done .tile { border-color: transparent; border-radius: 0; cursor: default; }
.done .tile.last { opacity: 1; }
.done .tile .num { display: none; }

#peek {
  position: absolute; inset: 0; background-size: 100% 100%; z-index: 5;
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.peeking #peek { opacity: 1; }

#win {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: rgba(255, 253, 246, .96); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 20px; text-align: center; box-shadow: 0 6px 20px rgba(60, 45, 20, .25);
  z-index: 6; min-width: 240px;
}
#win h2 { margin: 0 0 4px; color: var(--pink); }
#win p { margin: 0 0 10px; }
.hidden { display: none !important; }

#credit { font-size: 13px; color: var(--muted); text-align: center; margin: 8px 0 12px; }
#credit a { color: var(--teal); }

#pics { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; }
.pic {
  padding: 0; border: 3px solid transparent; border-radius: 10px; overflow: hidden;
  aspect-ratio: 1; background: var(--panel) center / cover no-repeat;
}
.pic.sel { border-color: var(--pink); }

#more { margin-top: 18px; }
details { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; }
summary { font-weight: 600; cursor: pointer; }
details ul { padding-left: 20px; margin: 8px 0; }
details li { margin: 4px 0; }

@media (max-width: 520px) {
  h1 { font-size: 20px; }
  .stats { gap: 10px; }
  button { padding: 7px 10px; }
  .tile .num { font-size: 10px; left: 2px; top: 2px; }
}
.title .back { font-size: 12px; color: var(--muted); text-decoration: none; }
.title .back:hover { color: var(--ink); }
