:root {
  --plum: #3b1d4a; --plum2: #5a2a6e; --pink: #ff3e8a; --pink2: #ff7ab0; --teal: #16b8ad; --teal2: #7be3da;
  --gold: #ffc531; --cream: #fff7e8; --ink: #2b1436; --red: #e8445a; --green: #2fbf71;
  font-size: clamp(11px, calc(min(2.15vh, 1.45vw) + 5px), 27px);
  --f: "Noto Sans Thai", "Leelawadee UI", "Thonburi", "Sukhumvit Set", "Loma", Tahoma, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; background: #2b1436; }
body { font-family: var(--f); color: var(--ink); touch-action: manipulation; user-select: none; -webkit-user-select: none; }
button { font-family: inherit; color: inherit; border: 0; cursor: pointer; background: none; touch-action: manipulation; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column;
  background: linear-gradient(180deg, rgba(43,20,54,.72), rgba(43,20,54,.9)), url(img/street.webp) center 70% / cover no-repeat, #2b1436; }
#app::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 1.6rem; pointer-events: none; opacity: .9;
  background: radial-gradient(circle at 1rem .9rem, #ffd76a 0 .22rem, transparent .26rem) 0 0 / 2rem 1.6rem repeat-x; }

/* header */
#top { position: relative; z-index: 3; display: flex; align-items: center; gap: .5rem; padding: .45rem .7rem .3rem; padding-top: max(.45rem, env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: .4rem; color: var(--cream); font-weight: 800; font-size: 1.05rem; text-shadow: 0 2px 0 rgba(0,0,0,.35); white-space: nowrap; }
.brand img { height: 1.9rem; }
.sp { flex: 1; }
.hbtn { width: 2.5rem; height: 2.5rem; border-radius: .8rem; background: var(--cream); color: var(--plum); display: grid; place-items: center;
  box-shadow: 0 .22rem 0 #c9a77a; border: 2px solid var(--plum); flex: none; }
.hbtn svg { width: 1.4rem; height: 1.4rem; }
.hbtn.txt { width: auto; padding: 0 .55rem; font-weight: 800; font-size: .95rem; }
.hbtn.on { background: var(--gold); }
.hbtn:active { transform: translateY(2px); box-shadow: 0 .1rem 0 #c9a77a; }
body.inStart #bHome { visibility: hidden; }

/* screens */
.screen { display: none; position: relative; flex: 1; min-height: 0; padding: .3rem .7rem .7rem; }
.screen.on { display: flex; flex-direction: column; }
.card { background: var(--cream); border: 3px solid var(--plum); border-radius: 1.2rem; box-shadow: 0 .35rem 0 rgba(0,0,0,.35); }

/* start */
.startGrid { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; align-items: center; max-width: 64rem; width: 100%; margin: 0 auto; }
.hero { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 1rem 1.1rem 1.1rem; gap: .5rem;
  background: linear-gradient(180deg, #fff3cf, var(--cream)); }
.heroTuk { width: min(13rem, 60%); animation: bob 1.6s ease-in-out infinite; }
h1 { font-size: 2.3rem; line-height: 1.15; color: var(--pink); text-shadow: 0 2px 0 var(--plum); -webkit-text-stroke: 1px var(--plum); }
h1 span { display: block; font-size: 1.05rem; color: var(--plum); -webkit-text-stroke: 0; text-shadow: none; margin-top: .2rem; }
.intro { font-size: .92rem; line-height: 1.5; color: #4e3358; }
.pickCard { padding: .9rem 1rem 1rem; display: flex; flex-direction: column; gap: .6rem; }
.pickHead { font-weight: 800; font-size: 1.05rem; color: var(--plum); }
.pickHead small { font-weight: 600; font-size: .8rem; color: #7a5a84; margin-left: .3rem; }
.grades { display: grid; grid-template-columns: repeat(6, 1fr); gap: .35rem; }
.grade { border-radius: .8rem; background: #fff; border: 2px solid #d9c3e0; padding: .35rem 0 .25rem; display: flex; flex-direction: column; align-items: center; font-weight: 800; font-size: 1.05rem; color: var(--plum); }
.grade i { font-style: normal; font-size: .62rem; color: #c9b2cf; letter-spacing: -.05em; }
.grade i b { color: var(--gold); -webkit-text-stroke: .5px #a8730b; }
.grade.sel { background: var(--teal); border-color: var(--plum); color: #fff; box-shadow: 0 .2rem 0 var(--plum); }
.grade.sel i { color: rgba(255,255,255,.5); }
.big { display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: 1rem; background: var(--pink); color: #fff; border: 3px solid var(--plum);
  box-shadow: 0 .3rem 0 var(--plum); padding: .55rem 1rem; font-weight: 800; font-size: 1.35rem; min-height: 3.4rem; }
.big b { font-size: 1.45rem; line-height: 1.2; }
.big small { font-size: .82rem; font-weight: 600; opacity: .92; }
.big:active, .mode:active, .mid:active { transform: translateY(3px); box-shadow: 0 .1rem 0 var(--plum); }
.play { animation: pulse 1.8s ease-in-out infinite; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: .45rem; }
.mode { border-radius: .9rem; background: var(--gold); border: 3px solid var(--plum); box-shadow: 0 .25rem 0 var(--plum); padding: .4rem .3rem; display: flex; flex-direction: column; align-items: center; }
.mode b { font-size: 1.02rem; color: var(--plum); }
.mode small { font-size: .74rem; color: #6a4a12; }
#bDuo { background: var(--teal2); }
.keys { display: flex; flex-wrap: wrap; gap: .3rem .8rem; font-size: .74rem; color: #6d5576; justify-content: center; }
.k { display: inline-block; font-style: normal; min-width: 1.4rem; padding: 0 .3rem; margin-right: .15rem; border: 1.5px solid #b9a3c0; border-bottom-width: 3px; border-radius: .35rem; background: #fff; text-align: center; font-weight: 700; color: var(--plum); font-size: .7rem; line-height: 1.2rem; }

/* play */
.hud { display: flex; gap: .4rem; align-items: center; justify-content: center; margin-bottom: .4rem; flex-wrap: nowrap; }
.pill { background: var(--cream); border: 2px solid var(--plum); border-radius: 2rem; padding: .15rem .7rem; font-weight: 800; font-size: .95rem; color: var(--plum); white-space: nowrap; }
.pill.time { background: var(--gold); min-width: 4.2rem; text-align: center; }
.pill.time.warn { background: var(--red); color: #fff; animation: pulse .5s infinite; }
.pill.score { background: var(--pink); color: #fff; }
.pill:empty { display: none; }
.playGrid { flex: 1; min-height: 0; display: grid; grid-template-columns: 1.25fr 1fr; gap: .7rem; max-width: 70rem; width: 100%; margin: 0 auto; }
.left { display: flex; flex-direction: column; gap: .6rem; min-height: 0; }
.raceBox { position: relative; flex: 1 1 40%; min-height: 5rem; border: 3px solid var(--plum); border-radius: 1.1rem; overflow: hidden; background: #f4a45a; box-shadow: 0 .3rem 0 rgba(0,0,0,.35); }
.raceBox canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.tip { position: absolute; left: .5rem; bottom: .4rem; background: rgba(43,20,54,.78); color: #fff; font-size: .78rem; font-weight: 700; padding: .12rem .55rem; border-radius: 1rem; pointer-events: none; }
.qcard { flex: 1 1 45%; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: .5rem; gap: .35rem; position: relative; }
.qnum { position: absolute; left: .7rem; top: .4rem; font-size: .75rem; font-weight: 700; color: #8a6c92; }
.qline { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: .15em .35em; font-size: 2.6rem; font-weight: 800; color: var(--plum); line-height: 1.1; }
.qline .w { font-size: .55em; font-weight: 700; color: #6d4b78; }
.qline .op { color: var(--pink); }
.qline .bx { display: inline-block; width: 1.3em; height: 1.1em; border: 3px dashed var(--teal); border-radius: .3em; background: #e7fbf8; }
.fr { display: inline-flex; flex-direction: column; align-items: center; font-size: .72em; line-height: 1.05; vertical-align: middle; }
.fr i { font-style: normal; padding: 0 .12em; }
.fr i:first-child { border-bottom: .09em solid currentColor; }
.ansBox { min-width: 7rem; min-height: 2.9rem; padding: .1rem .9rem; border-radius: .8rem; border: 3px solid var(--teal); background: #fff; font-size: 2.1rem; font-weight: 800; color: var(--ink); text-align: center; line-height: 2.5rem; }
.ansBox.empty::after { content: "?"; color: #cbb8d0; }
.ansBox.ok, .choice.ok { background: var(--green); border-color: #157a44; color: #fff; }
.ansBox.bad, .choice.bad { background: var(--red); border-color: #8f1d2d; color: #fff; }
.ansBox.hidden { display: none; }
.right { display: flex; flex-direction: column; min-height: 0; }
.pad { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(5, 1fr); gap: .4rem; }
.pad button { background: #fff; border: 3px solid var(--plum); border-radius: .9rem; font-size: 1.6rem; font-weight: 800; color: var(--plum); box-shadow: 0 .22rem 0 var(--plum); min-height: 0; }
.pad button:active, .pad button.hit { transform: translateY(2px); box-shadow: 0 .06rem 0 var(--plum); background: #ffe9f2; }
.pad .del { background: #ffe1d0; }
.pad .go { grid-column: span 3; background: var(--green); color: #fff; font-size: 1.35rem; }
.choices { flex: 1; min-height: 0; display: none; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: .5rem; }
.choiceMode .pad { display: none; }
.choiceMode .choices { display: grid; }
.choiceMode .ansBox { display: none; }
.choice { position: relative; background: #fff; border: 3px solid var(--plum); border-radius: 1rem; font-size: 2rem; font-weight: 800; color: var(--plum); box-shadow: 0 .25rem 0 var(--plum); display: flex; align-items: center; justify-content: center; min-height: 0; }
.choice .fr { font-size: .95em; }
.choice .kn { position: absolute; left: .45rem; top: .3rem; font-size: .7rem; color: #a58cae; font-weight: 700; }
.choice:active { transform: translateY(2px); }
.shake { animation: shake .35s; }

/* duo */
#duo { gap: .5rem; }
.duoRace { flex: 0 0 34%; }
.duoGrid { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.side { display: flex; flex-direction: column; padding: .45rem; gap: .35rem; min-height: 0; }
.side.p1 { border-color: var(--pink); box-shadow: 0 .3rem 0 #a3164f; }
.side.p2 { border-color: var(--teal); box-shadow: 0 .3rem 0 #0b6c66; }
.sideHead { display: flex; justify-content: space-between; align-items: center; font-weight: 800; font-size: .95rem; }
.p1 .sideHead { color: #c81e63; } .p2 .sideHead { color: #0b7d75; }
.sideHead small { font-size: .7rem; color: #8a6c92; font-weight: 700; }
.side .qline { font-size: 1.9rem; flex: 0 0 auto; min-height: 2.6rem; }
.side .choices { display: grid; }
.side .choice { font-size: 1.5rem; }
.side.locked .choices { opacity: .45; }
.side.win { background: #fff3b0; }

/* end */
#end { align-items: center; justify-content: center; }
.endcard { width: min(40rem, 100%); max-height: 100%; display: flex; flex-direction: column; padding: .8rem 1rem; gap: .5rem; min-height: 0; }
.endTop { display: flex; gap: .9rem; align-items: center; }
.endPic { height: 7.5rem; flex: none; }
.endInfo { flex: 1; min-width: 0; }
.endInfo h2 { font-size: 1.7rem; color: var(--pink); -webkit-text-stroke: .7px var(--plum); }
.endInfo p { font-size: .92rem; line-height: 1.45; color: #4e3358; }
.stars3 { display: flex; gap: .2rem; margin: .1rem 0 .25rem; }
.stars3 svg { width: 2.2rem; height: 2.2rem; }
.stars3 .s { animation: pop .45s backwards; }
.review { flex: 1 1 auto; min-height: 0; overflow-y: auto; font-size: .88rem; border-top: 2px dashed #d9c3e0; padding-top: .35rem; }
.review:empty { display: none; }
.review h3 { font-size: .9rem; color: var(--plum); margin-bottom: .2rem; }
.rv { display: flex; gap: .5rem; align-items: center; padding: .18rem 0; border-bottom: 1px solid #f0e3f2; flex-wrap: wrap; }
.rv .q { font-weight: 800; color: var(--plum); display: inline-flex; align-items: center; gap: .25em; }
.rv .q .w { font-size: .85em; color: #6d4b78; }
.rv .y { color: var(--red); text-decoration: line-through; }
.rv .c { color: #157a44; font-weight: 800; }
.rv .fr { font-size: .8em; }
.endBtns { display: flex; gap: .5rem; flex: none; }
.endBtns .big { flex: 2; min-height: 3rem; }
.mid { flex: 1; border-radius: 1rem; border: 3px solid var(--plum); background: var(--gold); font-weight: 800; font-size: 1.1rem; color: var(--plum); box-shadow: 0 .25rem 0 var(--plum); }
.mid.ghost { background: var(--cream); }
.endBtns button:disabled { opacity: .55; }

/* fx */
#fx { position: absolute; inset: 0; pointer-events: none; z-index: 9; overflow: hidden; }
.float { position: absolute; font-weight: 800; font-size: 1.6rem; color: var(--gold); -webkit-text-stroke: 1px var(--plum); animation: rise .9s ease-out forwards; }
.banner { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); background: var(--pink); color: #fff; border: 3px solid var(--plum); border-radius: 1rem; padding: .4rem 1.2rem; font-size: 1.8rem; font-weight: 800; animation: pop .4s backwards; white-space: nowrap; }

@keyframes bob { 50% { transform: translateY(-.35rem) rotate(-1deg); } }
@keyframes pulse { 50% { transform: scale(1.03); } }
@keyframes pop { from { transform: scale(.3); opacity: 0; } }
@keyframes rise { to { transform: translateY(-3rem); opacity: 0; } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.banner { animation: popc .4s backwards; }
@keyframes popc { from { transform: translate(-50%, -50%) scale(.3); opacity: 0; } }

/* ---------- short / small windows ---------- */
@media (max-height: 560px) {
  #top { padding-top: .25rem; padding-bottom: .15rem; }
  .hbtn { width: 2.1rem; height: 2.1rem; }
  .brand img { height: 1.5rem; }
  .hero { flex-direction: column; padding: .6rem .8rem; gap: .3rem; }
  .heroTuk { width: min(9rem, 45%); }
  h1 { font-size: 1.9rem; }
  .pickCard { padding: .6rem .8rem; gap: .45rem; }
  .big { min-height: 2.9rem; padding: .35rem .8rem; }
  .big b { font-size: 1.25rem; }
  .qline { font-size: 2.2rem; }
  .ansBox { font-size: 1.8rem; line-height: 2.1rem; min-height: 2.5rem; }
  .pad { gap: .3rem; } .pad button { font-size: 1.35rem; border-radius: .7rem; }
  .endPic { height: 5.5rem; }
}
@media (max-height: 420px) {
  .intro { display: none; }
  .heroTuk { width: min(7rem, 40%); }
  h1 { font-size: 1.7rem; }
  .keys { display: none; }
  .tip { display: none; }
  .screen { padding-bottom: .45rem; }
  .endPic { height: 4.2rem; }
  .endInfo h2 { font-size: 1.35rem; }
  .stars3 svg { width: 1.7rem; height: 1.7rem; }
}

/* ---------- portrait (phones) ---------- */
@media (max-aspect-ratio: 1/1) {
  .startGrid { grid-template-columns: 1fr; align-content: center; gap: .6rem; }
  .hero { padding: .7rem .8rem; }
  .heroTuk { width: min(11rem, 48%); }
  .playGrid { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .left { gap: .45rem; }
  .raceBox { flex: none; height: 24vh; min-height: 7rem; }
  .qcard { flex: none; min-height: 7.5rem; }
  .pad, .choices { gap: .45rem; }
  .duoRace { flex: 0 0 22%; }
  .duoGrid { grid-template-columns: 1fr; }
  .brand span { display: none; }
  .endTop { flex-direction: column; text-align: center; gap: .3rem; }
  .stars3 { justify-content: center; }
  .endPic { height: 8rem; }
}
@media (max-aspect-ratio: 1/1) and (max-height: 700px) {
  .intro { font-size: .85rem; }
  .raceBox { height: 20vh; min-height: 5.5rem; }
}
