:root {
  --ink: #3a1f0b; --cream: #fff4dc; --accent: #e8553a; --accent2: #2c86c9; --pill: rgba(255, 244, 220, .94);
  --pillInk: #7a3f12; --line: #5b2f12;
  font-size: clamp(11px, calc(min(2.1vh, 1.5vw) + 5px), 20px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #d58a32; }
body {
  font-family: "Sukhumvit Set", "Thonburi", "Leelawadee UI", "Leelawadee", "Noto Sans Thai", "Noto Sans Thai UI", "Sarabun", Tahoma, system-ui, sans-serif;
  color: var(--ink); user-select: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none;
}
body.th-wood #app { background: #d58a32 url(img/wood.webp) center / cover no-repeat; }
body.th-pastel { background: #e9f7ea; }
body.th-pastel #app { background: #e9f7ea url(img/pastel.webp) center / cover no-repeat; }
body.th-pastel { --pill: rgba(255, 255, 255, .92); --pillInk: #2f7d5b; --line: #4fa77f; --accent: #f06f92; --accent2: #5fb8d9; --ink: #284a3c; --cream: #fffdf6; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; overflow: hidden; }

/* HUD */
#hud { display: flex; align-items: center; gap: .45rem; padding: .45rem .6rem; flex: none; z-index: 3; }
.pill { background: var(--pill); border: 2px solid var(--line); border-radius: 1.4rem .5rem 1.4rem .5rem; padding: .15rem .7rem .2rem; min-width: 4.6rem;
  display: flex; flex-direction: column; align-items: center; line-height: 1.05; box-shadow: 0 .15rem 0 rgba(0,0,0,.18); position: relative; overflow: hidden; }
.pill small { font-size: .68rem; color: var(--pillInk); font-weight: 700; }
.pill b { font-size: 1.2rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.pill.goal i { position: absolute; left: 0; bottom: 0; height: .22rem; background: #5a9a35; width: 0; transition: width .3s; }
.pill.combo b { color: var(--accent); }
.pill.combo.hot { animation: hot .5s ease; }
@keyframes hot { 30% { transform: scale(1.18); } }
.pips { display: flex; gap: .18rem; margin-top: .08rem; }
.pips i { width: .42rem; height: .42rem; border-radius: 50%; background: #d8c2a5; }
.pips i.on { background: var(--accent); }
.btn.icon.txt span { min-width: .6em; }
#bHint:not(:disabled) svg { stroke: #c98a00; }
.sp { flex: 1; }
.btn { font: inherit; border: 2px solid var(--line); background: var(--pill); color: var(--ink); border-radius: .9rem; cursor: pointer;
  box-shadow: 0 .18rem 0 rgba(0,0,0,.22); font-weight: 800; touch-action: manipulation; }
.btn:active { transform: translateY(2px); box-shadow: 0 .05rem 0 rgba(0,0,0,.22); }
.btn.icon { width: 2.6rem; height: 2.6rem; padding: .45rem; display: flex; align-items: center; justify-content: center; gap: .1rem; }
.btn.icon.txt { width: auto; padding: .45rem .6rem; }
.btn.icon.txt span { font-size: .95rem; }
.btn svg { width: 1.4rem; height: 1.4rem; fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.btn:disabled { opacity: .4; }
#bSound .x { display: none; } #bSound.off .x { display: inline; } #bSound.off .w { display: none; }
#bMusic.off { opacity: .45; }
#bMusic.off svg { stroke-dasharray: 2 2; }

#stage { position: relative; flex: 1; min-height: 0; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#tip { flex: none; text-align: center; font-size: .72rem; font-weight: 700; color: var(--ink); padding: .1rem .5rem .35rem; opacity: .85;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.th-wood #tip { color: #fff8ea; text-shadow: 0 1px 2px rgba(0,0,0,.55); }

#mame { position: absolute; pointer-events: none; display: none; z-index: 2; }
#mame img { width: 100%; height: auto; display: block; filter: drop-shadow(0 4px 4px rgba(0,0,0,.25)); }
#mame.show { display: block; }
#mame.hop img { animation: hop .55s ease; }
@keyframes hop { 30% { transform: translateY(-14%) scale(1.05, .95); } 60% { transform: translateY(0) scale(.97, 1.04); } }
#mame .bub { position: absolute; left: 50%; top: -.3rem; transform: translate(-50%, -100%); background: #fffbe8; color: #3a1f0b; border: 2px solid #5b2f12;
  border-radius: .8rem; padding: .25rem .6rem; font-weight: 800; font-size: .9rem; white-space: nowrap; opacity: 0; transition: opacity .2s; }
#mame .bub.on { opacity: 1; }
#mame .you { position: absolute; }
#toast { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%) scale(.6); font-size: 2.2rem; font-weight: 900; color: #fff;
  -webkit-text-stroke: 2px #6a2c10; text-shadow: 0 .2rem 0 #6a2c10; pointer-events: none; opacity: 0; white-space: nowrap; z-index: 4; }
#toast.on { animation: toast 1.3s ease forwards; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%,-50%) scale(.5); } 15% { opacity: 1; transform: translate(-50%,-50%) scale(1.12); }
  25% { transform: translate(-50%,-50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%,-70%) scale(1); } }

/* overlays */
.ov { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; z-index: 10; background: rgba(50, 22, 5, .42); padding: .6rem; }
body.th-pastel .ov { background: rgba(40, 110, 80, .25); }
.ov.show { display: flex; }
.ov.arming button { pointer-events: none; }
.panel, .card { background: var(--cream); border: 3px solid var(--line); border-radius: 1.6rem .7rem 1.6rem .7rem; box-shadow: 0 .5rem 0 rgba(0,0,0,.22), inset 0 0 0 .3rem rgba(255,255,255,.5); max-height: 96%; overflow: auto; }
.panel { display: flex; gap: 1.2rem; padding: 1rem 1.2rem; width: min(52rem, 100%); }
.pcol { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .55rem; }
.head { display: flex; align-items: center; gap: .7rem; }
.head img { width: 4.6rem; height: auto; }
h1 { margin: 0; font-size: 2.1rem; color: var(--accent); line-height: 1.25; text-shadow: 0 .12rem 0 rgba(0,0,0,.15); }
h2 { margin: .1rem 0 0; font-size: 1rem; color: var(--ink); }
.intro { margin: 0; font-size: .92rem; line-height: 1.5; }
.keys { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; font-size: .8rem; }
.k { border: 2px solid var(--line); border-bottom-width: 4px; border-radius: .45rem; padding: .05rem .45rem; background: #fff; font-weight: 800; }
.or { font-size: .8rem; }
.row { display: flex; align-items: center; gap: .6rem; }
.lbl { font-weight: 800; font-size: .85rem; min-width: 3.2rem; }
.seg { display: flex; flex: 1; border: 2px solid var(--line); border-radius: .8rem; overflow: hidden; }
.seg button { flex: 1; font: inherit; font-weight: 800; font-size: .92rem; border: 0; padding: .45rem .3rem; background: #fff; color: var(--ink); cursor: pointer; }
.seg button + button { border-left: 2px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }
.stepper { display: flex; align-items: center; gap: .5rem; flex: 1; justify-content: space-between; }
.stepper button { font: inherit; border: 2px solid var(--line); background: #fff; border-radius: .6rem; width: 2.4rem; height: 2.1rem; cursor: pointer; color: var(--ink); }
.stepper b { font-size: 1rem; }
.stamps { display: flex; gap: .3rem; justify-content: space-between; margin-top: .45rem; }
.stamp { flex: 1; text-align: center; font-size: .66rem; font-weight: 700; border-radius: .5rem; padding: .15rem 0; background: rgba(0,0,0,.05); border: 2px solid transparent; }
.stamp i { display: block; font-style: normal; font-size: 1rem; line-height: 1.2; color: #c9b7a0; }
.stamp.ok i { color: #e0a800; }
.stamp.sel { border-color: var(--accent); background: #fff; }
.dnote, .mdesc { margin: .3rem 0 0; font-size: .82rem; line-height: 1.45; }
.bestline { font-weight: 800; font-size: .95rem; text-align: center; min-height: 1.2em; }
.btn.big { font-size: 1.35rem; padding: .6rem 1rem; background: var(--accent); color: #fff; border-color: rgba(0,0,0,.35); }
#bPlay { width: 100%; margin-top: auto; }
.card { padding: 1rem 1.4rem; text-align: center; width: min(26rem, 100%); display: flex; flex-direction: column; align-items: center; gap: .5rem; }
.card img { width: 3.4rem; height: auto; }
.card h3 { margin: 0; font-size: 1.6rem; color: var(--accent); }
.card p { margin: 0; font-size: .9rem; line-height: 1.45; }
.nums { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; width: 100%; }
.nums div { background: #fff; border-radius: .7rem; border: 2px solid var(--line); padding: .2rem; display: flex; flex-direction: column; }
.nums small { font-size: .68rem; font-weight: 700; } .nums b { font-size: 1.25rem; }
.rec { font-weight: 900; color: #fff; background: #3fae5a; border-radius: 1rem; padding: .15rem .8rem; display: none; }
.rec.on { display: block; }
.two { display: flex; gap: .5rem; width: 100%; }
.two .btn { flex: 1; padding: .55rem .6rem; font-size: 1rem; }
.two .btn.big { flex: 1.4; font-size: 1.2rem; }

/* short windows (store frame 794x447, 640x360, phone landscape) */
@media (max-height: 560px) {
  #hud { padding: .3rem .5rem; gap: .35rem; }
  .pill { min-width: 3.9rem; padding: .1rem .5rem; }
  .pill b { font-size: 1.05rem; }
  .btn.icon { width: 2.25rem; height: 2.25rem; padding: .35rem; }
  .panel { padding: .7rem .9rem; gap: .9rem; }
  .head img { width: 3.4rem; }
  h1 { font-size: 1.7rem; }
  .intro { font-size: .82rem; line-height: 1.4; }
  .pcol { gap: .4rem; }
  .card { padding: .7rem 1rem; gap: .35rem; }
  .card img { display: none; }
}
@media (max-height: 400px) {
  #tip { display: none; }
  .intro { font-size: .76rem; }
  .keys { display: none; }
  .btn.big { font-size: 1.15rem; padding: .45rem .8rem; }
  .card h3 { font-size: 1.3rem; }
}
/* narrow portrait: stack the start panel */
@media (max-aspect-ratio: 1/1) {
  .panel { flex-direction: column; gap: .6rem; max-width: 30rem; }
  :root { font-size: clamp(11px, calc(1.6vh + 4px), 18px); }
  #tip { white-space: normal; font-size: .7rem; }
  .pill { min-width: 3.4rem; padding: .1rem .4rem; }
  #hud { gap: .3rem; padding: .35rem .4rem; }
  .btn.icon { width: 2.3rem; height: 2.3rem; }
  .btn.icon.txt { padding: .35rem .45rem; }
}
@media (max-aspect-ratio: 1/1) and (max-width: 420px) {
  :root { font-size: clamp(11px, 3.4vw, 16px); }
  .pill small { font-size: .6rem; }
  .pill { min-width: 3rem; }
}
.pill[hidden] { display: none; }
@media (pointer: coarse) { .keys { display: none; } }
@media (max-aspect-ratio: 1/1) { .pB #bPlay { order: -1; margin: .2rem 0 .3rem; } .pB { display: flex; flex-direction: column; } }
