:root { --p1: #ff7a2f; --p2: #2f86ff; --ink: #17324d; --gold: #ffc531; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1f6fb2; color: var(--ink);
  font-family: "Leelawadee UI", "Sukhumvit Set", "Noto Sans Thai", Tahoma, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: none; }
canvas { position: fixed; inset: 0; display: block; }
.hidden { display: none !important; }

.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 12px; z-index: 5; }
.screen.dim { background: rgba(8, 35, 60, .55); }
.box { background: #fff; border-radius: 20px; padding: 18px 22px; width: min(460px, 100%); max-height: 100%; overflow: auto;
  text-align: center; box-shadow: 0 12px 40px rgba(0,0,0,.35); }
.box h2 { margin: 2px 0 6px; font-size: 26px; }
.box p { margin: 6px 0; }

button { font: inherit; font-weight: bold; border: 0; border-radius: 14px; padding: 10px 18px; margin: 5px; cursor: pointer;
  background: #e6eef6; color: var(--ink); touch-action: manipulation; }
button.big { background: #1fa45a; color: #fff; font-size: 22px; padding: 12px 34px; box-shadow: 0 4px 0 #157a42; }
button.ghost { background: transparent; color: #5a6f84; }
button:active { transform: translateY(2px); }

/* หน้าเลือกด่าน */
#menu { background: linear-gradient(180deg, rgba(20,90,150,.82), rgba(10,50,90,.9)); overflow: auto; touch-action: pan-y; align-items: flex-start; }
.menuIn { margin: auto; text-align: center; color: #fff; max-width: 760px; padding: 4px 0 10px; }
.logo { width: 76px; height: 76px; }
h1 { margin: 2px 0; font-size: 34px; letter-spacing: 1px; text-shadow: 0 3px 10px rgba(0,0,0,.35); }
.sub { margin: 2px 0 12px; opacity: .9; }
.tip { margin: 6px 0 0; font-size: 14px; opacity: .8; }
#levels { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.card { width: 200px; background: #fff; color: var(--ink); border-radius: 16px; padding: 12px; margin: 0; text-align: left;
  box-shadow: 0 6px 0 #0d3d66; }
.card .n { font-size: 13px; color: #6a7f93; }
.card .nm { font-size: 19px; margin: 2px 0; }
.card .st { font-size: 22px; color: #d5dce3; letter-spacing: 2px; }
.card .st i { font-style: normal; color: var(--gold); }
.card.locked { background: #b9c7d4; box-shadow: 0 6px 0 #6f8599; cursor: default; }
.card.locked .st { font-size: 14px; color: #4a5e72; letter-spacing: 0; }

/* หน้าแนะนำด่าน */
.lv { color: #6a7f93; font-size: 14px; }
.how { display: flex; gap: 10px; margin: 10px 0 6px; }
.side { flex: 1; border-radius: 14px; padding: 10px 6px; color: #fff; font-size: 15px; line-height: 1.4; }
.side b { display: block; font-size: 19px; }
.side.l { background: var(--p1); }
.side.r { background: var(--p2); }
.rule { font-size: 15px; color: #33506b; }

/* ผลด่าน */
#stars { font-size: 50px; letter-spacing: 6px; color: #d5dce3; line-height: 1.1; }
#stars i { font-style: normal; color: var(--gold); text-shadow: 0 2px 6px rgba(200,140,0,.4); }
#resRows { margin: 6px 0 10px; font-size: 16px; text-align: left; display: inline-block; }
#resRows div { margin: 3px 0; }
#resRows .ok { color: #1a8f4c; }
#resRows .no { color: #9aa7b4; }
.box.wide { width: min(640px, 100%); }
.resGrid { display: flex; flex-wrap: wrap; gap: 6px 22px; justify-content: center; align-items: center; }
.resCol { flex: 1 1 240px; }
.score { background: #f2f7fc; border-radius: 14px; padding: 8px 12px; }
.score .lbl { font-size: 13px; color: #6a7f93; }
#scoreTotal { font-size: 44px; font-weight: 900; color: #1f6fb2; line-height: 1.05; }
#scoreBest { font-size: 14px; color: #6a7f93; margin-bottom: 4px; }
#scoreBest.rec { color: #e0700e; font-weight: bold; }
#scoreRows { width: 100%; font-size: 14px; border-collapse: collapse; }
#scoreRows td { padding: 1px 2px; text-align: left; }
#scoreRows td.q { color: #6a7f93; text-align: center; }
#scoreRows td:last-child { text-align: right; font-weight: bold; color: #1a8f4c; }
#scoreRows td.neg { color: #d0452a !important; }
.card .bs { font-size: 13px; color: #1f6fb2; font-weight: bold; margin-top: 2px; }

.corner { position: fixed; top: max(8px, env(safe-area-inset-top)); z-index: 6; width: 46px; height: 46px; padding: 0; margin: 0;
  border-radius: 50%; background: rgba(255,255,255,.85); font-size: 18px; }
#btnPause { right: max(10px, env(safe-area-inset-right)); }
#btnSound { left: max(10px, env(safe-area-inset-left)); }
body.playing #btnSound { display: none; }

@media (max-height: 430px) {
  .box { padding: 10px 16px; }
  .box h2 { font-size: 22px; }
  .how { margin: 6px 0 2px; }
  .side { padding: 6px; font-size: 13px; }
  .side b { font-size: 16px; }
  .rule { font-size: 13px; }
  button.big { font-size: 19px; padding: 9px 28px; }
  #stars { font-size: 40px; }
  .logo { width: 54px; height: 54px; }
  h1 { font-size: 28px; }
  .sub { margin-bottom: 8px; }
  .card { width: 180px; padding: 9px 12px; }
}
