:root {
  --ink: #1f2a1e; --jade: #2f5d3a; --jade2: #2f7d46; --coral: #c8452c; --coral2: #c8452c; --cream: #fbf6e8;
  --blue: #2f5d3a; --gold: #e2b34a; --wood: #6b4226; --wood2: #4a2c18;
  --light: #f8f3e6; --dark: #6f9a5d; --bs: 360px; --sw: 300px; --pad: 10px; --gap: 10px; --top: 0px;
  --fs: clamp(11px, min(2.2vh, 1.7vw) + 4px, 19px);
  font-size: var(--fs);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif; color: var(--ink);
  background: #cfe3c4 url(img/bg.webp) center / cover no-repeat; touch-action: none; user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.hidden { display: none !important; }

#main { position: fixed; inset: 0; padding: calc(var(--pad) + var(--top)) var(--pad) var(--pad); display: flex; flex-direction: row-reverse; gap: var(--gap); justify-content: center; align-items: center; }
#boardCol { width: var(--bs); height: var(--bs); flex: none; margin: var(--ring, 0px); }
#boardWrap { position: relative; width: 100%; height: 100%; border-radius: 6px; padding: 0; box-shadow: 0 0 0 calc(var(--bs) * .008) #f3dcae, 0 0 0 calc(var(--bs) * .034) var(--wood), 0 0 0 calc(var(--bs) * .037) var(--wood2), 0 12px 28px rgba(20, 40, 20, .45); }
#board { position: relative; width: 100%; height: 100%; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); border-radius: 3px; overflow: hidden; touch-action: none; }
.sq { position: relative; }
.sq.l { background: var(--light); }
.sq.d { background: var(--dark); background-image: linear-gradient(135deg, rgba(255,255,255,.06), rgba(0,0,0,.05)); }
.sq.last::before { content: ""; position: absolute; inset: 0; background: rgba(240, 214, 90, .5); }
.sq.sel::before { content: ""; position: absolute; inset: 0; background: rgba(226, 179, 74, .7); }
.sq.hint::before { content: ""; position: absolute; inset: 0; background: rgba(80, 170, 255, .5); animation: hintp 1s ease-in-out infinite alternate; }
@keyframes hintp { from { opacity: .45; } to { opacity: 1; } }
.sq.mv::after { content: ""; position: absolute; left: 35%; top: 35%; width: 30%; height: 30%; border-radius: 50%; background: rgba(31, 60, 30, .45); z-index: 3; pointer-events: none; }
.sq.cap::after { content: ""; position: absolute; inset: 4%; border-radius: 22%; border: calc(var(--bs) * .009) solid rgba(200, 69, 44, .9); z-index: 3; pointer-events: none; }
.sq.chk { background: radial-gradient(circle, #ff5a4a 0%, rgba(255, 90, 74, .55) 45%, transparent 75%) !important; }
.sq.hov { box-shadow: inset 0 0 0 calc(var(--bs) * .008) #fff; }
.sq.cur { box-shadow: inset 0 0 0 calc(var(--bs) * .01) var(--coral2); }
.coord { position: absolute; font-size: calc(var(--bs) * .028); font-weight: 700; opacity: .75; pointer-events: none; }
.coord.f { right: 4%; bottom: 2%; } .coord.r { left: 4%; top: 2%; }
.sq.l .coord { color: #4f7a43; } .sq.d .coord { color: #f6efd9; }
#pieces { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.piece { position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%; transition: transform .2s cubic-bezier(.3, .8, .3, 1); will-change: transform; }
.piece.drag { transition: none; z-index: 10; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, .3)); }
.piece.drag svg { transform: scale(1.15); }
.piece.lift svg { transform: translateY(-6%) scale(1.06); }
.piece.pop svg { animation: pop .3s ease-out; }
.piece.gone { animation: gone .3s ease-in forwards; }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes gone { to { transform: var(--t) scale(.2); opacity: 0; } }
.pc { width: 100%; height: 100%; display: block; transition: transform .12s; overflow: visible; }
.pc .o { stroke-width: 3.6; stroke-linejoin: round; }
.pc .in, .pc .cut, .pc .hl { fill: none; stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; }
.pw .o { fill: #f0d6a2; stroke: #4a2c18; } .pw .in { stroke: #2f7d46; } .pw .cut { stroke: #a77b4c; } .pw .hl { stroke: #fffaf0; } .pw .f { fill: #4a2c18; }
.pb .o { fill: #3a2216; stroke: #140a05; } .pb .in { stroke: #e2a05a; } .pb .cut { stroke: #7a4d2e; } .pb .hl { stroke: #6e4a33; } .pb .f { fill: #e2b34a; }
.pc { filter: drop-shadow(0 2px 1.5px rgba(0, 0, 0, .3)); }

/* side panel */
#side { width: var(--sw); height: calc(var(--bs) + 2 * var(--ring, 0px)); flex: none; display: flex; flex-direction: column; gap: .45rem; min-height: 0; }
.pstrip { display: flex; align-items: center; gap: .4rem; background: rgba(251, 246, 232, .94); border-radius: 6px; border-left: 5px solid var(--jade) !important; padding: .3rem .55rem; min-height: 2.1rem; box-shadow: 0 2px 6px rgba(0, 0, 0, .12); border: 2px solid transparent; flex: none; }
.pstrip.turn { border-color: var(--coral); box-shadow: 0 0 0 3px rgba(255, 122, 89, .25); }
#stripTop { margin-right: 5.6rem; }
body:not(.port) #snd { right: auto; left: var(--pad); }
body:not(.port) #stripTop { margin-right: 0; margin-left: 5.6rem; }
.dot { width: .9rem; height: .9rem; border-radius: 50%; flex: none; border: 2px solid var(--ink); }
.dot.w { background: #f0d6a2; } .dot.b { background: #3a2216; }
.pname { font-weight: 800; white-space: nowrap; font-size: .92rem; }
.pname .you { background: var(--coral); color: #fff; border-radius: 6px; padding: 0 .35rem; margin-right: .2rem; font-size: .8rem; }
.caps { display: flex; flex-wrap: nowrap; align-items: center; overflow: hidden; margin-left: auto; }
.caps svg { width: 1.15rem; height: 1.15rem; margin-left: -.3rem; }
.adv { font-size: .8rem; font-weight: 800; margin-left: .25rem; color: var(--jade); }
#igelBox { display: flex; align-items: center; gap: .4rem; flex: none; }
#igel { width: 4.4rem; height: 4.4rem; object-fit: contain; flex: none; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .2)); }
#igel.bounce { animation: bounce .45s ease-out; }
@keyframes bounce { 30% { transform: translateY(-10%) scale(1.06); } 60% { transform: translateY(2%); } }
#bubble { position: relative; flex: 1; background: #fff; border-radius: 14px; border: 2px solid #cfe0c3; padding: .45rem .6rem; font-size: .9rem; font-weight: 600; line-height: 1.35; box-shadow: 0 2px 8px rgba(0, 0, 0, .15); min-height: 2.6rem; display: flex; align-items: center; }
#bubble::before { content: ""; position: absolute; left: -.45rem; top: 50%; margin-top: -.45rem; border: .45rem solid transparent; border-right-color: #fff; border-left: 0; }
#bubble.pulse { animation: bpulse .3s ease-out; }
@keyframes bpulse { 40% { transform: scale(1.03); } }
#tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: .35rem; flex: none; }
.tool { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem; background: var(--cream); color: var(--jade); border-radius: 8px; padding: .3rem .1rem; font-weight: 800; font-size: .8rem; box-shadow: 0 3px 0 #b9c7a8; min-height: 2.6rem; }
.tool svg { width: 1.2rem; height: 1.2rem; }
.tool.primary { background: var(--jade2); color: #fff; box-shadow: 0 3px 0 #1d4a2a; }
.tool:active { transform: translateY(2px); box-shadow: none; }
.tool:disabled { opacity: .45; }
#movesBox { flex: 1 1 auto; min-height: 2.6rem; background: rgba(251, 246, 232, .94); border-radius: 6px; padding: .3rem .5rem; display: flex; flex-direction: column; box-shadow: 0 2px 6px rgba(0, 0, 0, .12); }
.mhead { display: flex; align-items: center; justify-content: space-between; }
.mhead h3 { margin: 0; font-size: .85rem; color: var(--jade); }
.mini { background: var(--jade); color: #fff; border-radius: 8px; padding: .12rem .5rem; font-size: .75rem; font-weight: 700; }
#moves { list-style: none; margin: .2rem 0 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; display: grid; grid-template-columns: 1fr 1fr; align-content: start; column-gap: .5rem; touch-action: pan-y; }
#moves li { display: grid; grid-template-columns: 1.9rem 1fr 1fr; }
#moves .n { color: #7c8f6e; } #moves .m.cur { background: var(--gold); border-radius: 4px; padding: 0 .15rem; }
#keysLine { margin: 0; font-size: .72rem; color: var(--ink); background: rgba(255, 255, 255, .7); border-radius: 8px; padding: .15rem .4rem; text-align: center; flex: none; }

/* sound buttons */
#snd { position: fixed; top: calc(var(--pad) + 2px); right: var(--pad); display: flex; gap: .35rem; z-index: 60; }
#snd button { width: 2.4rem; height: 2.4rem; border-radius: 50%; background: var(--cream); box-shadow: 0 2px 0 #b9c7a8, 0 2px 6px rgba(0, 0, 0, .15); display: grid; place-items: center; color: var(--jade); }
#snd svg { width: 1.3rem; height: 1.3rem; }
#hdr { display: none; }

/* overlays */
.ovl { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: .6rem; background: rgba(20, 40, 24, .45); }
#boardWrap .ovl { position: absolute; z-index: 20; border-radius: 8px; }
.card { background: var(--cream); border-radius: 10px; padding: 1rem 1.2rem; box-shadow: 0 0 0 4px var(--wood), 0 12px 40px rgba(0, 0, 0, .3); max-height: 92vh; overflow: auto; text-align: center; border: 2px solid #f3dcae; }
.card h2 { margin: .1rem 0 .5rem; font-size: 1.25rem; color: var(--jade); }
.card p { margin: .3rem 0; }
.btn { background: var(--jade2); color: #fff; font-weight: 900; border-radius: 10px; padding: .55rem 1.2rem; box-shadow: 0 4px 0 #1d4a2a; font-size: 1rem; }
.btn.ghost { background: #fff; color: var(--jade); box-shadow: 0 4px 0 #b9c7a8; }
.btn.small { padding: .35rem .8rem; font-size: .88rem; }
.btn.big { font-size: 1.35rem; padding: .65rem 1.4rem; width: 100%; margin-top: .4rem; }
.btn:active { transform: translateY(3px); box-shadow: none; }
.row2 { display: flex; gap: .5rem; justify-content: center; margin-top: .55rem; flex-wrap: wrap; }
#promoBtns { display: flex; gap: .4rem; justify-content: center; margin-bottom: .5rem; }
#promoBtns button { width: calc(var(--bs) * .16); height: calc(var(--bs) * .16); background: var(--light); border-radius: 10px; box-shadow: 0 3px 0 #b9c7a8; }
#promo .card { padding: .6rem .8rem; }
#promo h2 { font-size: 1rem; }

.startCard { display: flex; gap: 1.2rem; text-align: left; width: min(48rem, 96vw); align-items: center; }
.sLeft { flex: 1.1; text-align: center; }
.sRight { flex: 1; display: flex; flex-direction: column; gap: .3rem; }
.sIgel { width: 7.5rem; height: 7.5rem; object-fit: contain; }
.startCard h1 { margin: 0; font-size: 2.4rem; color: var(--jade); letter-spacing: .01em; line-height: 1.05; font-family: Georgia, "Times New Roman", serif; }
.startCard h1 small { display: block; font-size: .95rem; letter-spacing: .3em; color: var(--coral); text-transform: uppercase; }
.intro { font-size: .92rem; line-height: 1.5; margin: .4rem 0 .5rem !important; }
.keys { display: flex; flex-direction: column; gap: .25rem; font-size: .8rem; align-items: center; }
kbd { display: inline-block; min-width: 1.4rem; padding: 0 .25rem; border-radius: 5px; background: #fff; border: 1px solid #b9c7a8; border-bottom-width: 3px; font-family: inherit; font-size: .75rem; text-align: center; }
.lbl { font-weight: 800; font-size: .8rem; color: var(--jade); }
.seg { display: flex; background: #fff; border-radius: 10px; padding: .2rem; gap: .2rem; box-shadow: inset 0 0 0 2px #d8e3cc; }
.seg.lv button { padding-left: 0; padding-right: 0; min-width: 0; }
.seg button { flex: 1; padding: .38rem .2rem; border-radius: 9px; font-weight: 800; font-size: .88rem; white-space: nowrap; }
.seg button.on { background: var(--jade); color: #fff; }
#levelStats { font-size: .78rem; color: #56664c; min-height: 1em; margin: .1rem 0 !important; }
.sRight .row2 { margin-top: .3rem; } .sRight .row2 .btn { flex: 1; padding: .45rem .5rem; font-size: .92rem; }

.endCard { display: flex; align-items: center; gap: 1rem; max-width: min(34rem, 94vw); }
.endCard img { width: 7rem; height: 7rem; object-fit: contain; flex: none; }
#endMenu { margin-top: .6rem; }
#endReason { font-weight: 700; } #endStats { font-size: .85rem; color: #56664c; }

.tutCard { display: flex; gap: 1rem; width: min(52rem, 96vw); text-align: left; align-items: stretch; }
.tutBoardBox { flex: none; width: min(62vh, 44vw); }
#tutBoard { width: 100%; aspect-ratio: 1; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); border-radius: 8px; overflow: hidden; box-shadow: 0 0 0 4px var(--jade); }
#tutBoard .sq { cursor: pointer; }
#tutBoard .lab { position: absolute; left: 0; right: 0; bottom: 0; text-align: center; font-size: .55rem; font-weight: 800; color: var(--coral2); pointer-events: none; z-index: 4; }
#tutBoard .tp { position: absolute; inset: 0; pointer-events: none; }
.tutText { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.tutStep { font-size: .78rem; font-weight: 800; color: var(--coral2); }
#tutBody { flex: 1; overflow-y: auto; font-size: .9rem; line-height: 1.55; touch-action: pan-y; }
#tutBody p { margin: .25rem 0; } #tutBody b { color: var(--jade); }
.tutNav { display: flex; gap: .4rem; margin-top: .5rem; flex-wrap: wrap; }

#toast { position: fixed; left: 50%; bottom: 8%; transform: translateX(-50%); background: var(--ink); color: #fff; border-radius: 10px; padding: .4rem .9rem; z-index: 80; font-weight: 700; }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 70; }

/* portrait: board on top, info below */
body.port #main { flex-direction: column; justify-content: flex-start; }
body.port #side { width: calc(var(--bs) + 2 * var(--ring, 0px)); height: auto; flex: 1 1 auto; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: auto auto auto 1fr; }
body.port #stripTop { margin-right: 0; grid-row: 1; grid-column: 1; }
body.port #stripBot { grid-row: 1; grid-column: 2; }
body.port #igelBox { grid-row: 2; grid-column: 1 / 3; }
body.port #tools { grid-row: 3; grid-column: 1 / 3; }
body.port #movesBox { grid-row: 4; grid-column: 1 / 3; }
body.port #keysLine { display: none; }
body.port #hdr { display: block; position: fixed; top: calc(var(--pad) + .2rem); left: var(--pad); font-size: 1.5rem; font-weight: 900; color: var(--jade); letter-spacing: .01em; text-shadow: 0 2px 0 #fff; font-family: Georgia, "Times New Roman", serif; }
body.port #igel { width: 3.4rem; height: 3.4rem; }

/* short windows */
@media (max-height: 560px) {
  .startCard { width: min(46rem, 97vw); padding: .7rem .9rem; gap: .9rem; }
  .sIgel { width: 4.6rem; height: 4.6rem; }
  .startCard h1 { font-size: 1.9rem; }
  .intro { font-size: .82rem; }
  #igel { width: 3.3rem; height: 3.3rem; }
  #side { gap: .32rem; }
  .card { padding: .7rem .9rem; }
  .tutCard { padding: .6rem; }
}
@media (max-height: 420px) {
  .sIgel { display: none; }
  .keys { display: none; }
  .startCard h1 { font-size: 1.6rem; }
  .seg button { padding: .3rem .15rem; font-size: .8rem; }
  .btn.big { font-size: 1.1rem; padding: .45rem 1rem; }
  #igel { width: 2.7rem; height: 2.7rem; }
  #bubble { font-size: .8rem; padding: .3rem .45rem; min-height: 2.2rem; }
  .tool { min-height: 2.2rem; padding: .2rem .1rem; }
  .tool span { font-size: .72rem; }
  #keysLine { display: none; }
  .endCard img { width: 4.5rem; height: 4.5rem; }
}
@media (max-width: 600px) {
  .startCard { flex-direction: column; gap: .4rem; text-align: center; }
  .sRight { width: 100%; text-align: left; }
  .sIgel { width: 5rem; height: 5rem; }
  .startCard h1 { font-size: 2rem; }
  .tutCard { flex-direction: column; }
  .tutBoardBox { width: min(100%, 46vh); align-self: center; }
  .endCard { flex-direction: column; text-align: center; }
}

/* puzzles */
.puzPick { display: flex; align-items: center; gap: .3rem; background: #fff; border-radius: 10px; padding: .2rem; box-shadow: inset 0 0 0 2px #d8e3cc; }
.puzPick .arrow { width: 2.2rem; height: 2rem; border-radius: 9px; background: var(--jade2); color: #fff; font-size: 1.4rem; font-weight: 900; line-height: 1; flex: none; }
#puzName { flex: 1; text-align: center; font-weight: 800; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#puzName .today { background: var(--gold); color: var(--ink); border-radius: 6px; padding: 0 .3rem; font-size: .75rem; }
#puzName .ok { color: #2e8b3a; }
.seg button { padding-left: .1rem; padding-right: .1rem; }
