/* ใช้ร่วมกันทุกหน้า · ฟอนต์ระบบ (ไม่โหลดฟอนต์นอก — มือถือ 300 เครื่องโหลดเร็วขึ้น) */
:root {
  --bg: #f7f4ee;
  --card: #ffffff;
  --ink: #1d2733;
  --muted: #59636f;
  --line: #e2dbcf;
  --accent: #1f4f8f;
  --accent-soft: #e6eef8;
  --gold: #a87a1c;
  --a: #d9692a; /* ขวดขั้ว A (ส้ม) */
  --b: #2f6fb8; /* ขวดขั้ว B (ฟ้า) — ส้ม/ฟ้า แยกได้แม้ตาบอดสี */
  --ok: #2b7a4b;
  --no: #b3362b;
  --unsure: #6b7280;
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Noto Sans Thai", "Sarabun", "Thonburi", "Leelawadee UI", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.status {
  position: fixed; top: 10px; left: 50%; transform: translateX(-50%);
  background: #3b3b3b; color: #fff; padding: 6px 14px; border-radius: 999px;
  font-size: 14px; z-index: 50; box-shadow: 0 4px 16px rgb(0 0 0 / .2);
}
.toast {
  position: fixed; top: 56px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 12px;
  font-size: 15px; z-index: 50; max-width: calc(100% - 32px); text-align: center;
}

/* ───────── มือถือผู้เข้าร่วม ───────── */
.p-wrap { max-width: 520px; margin: 0 auto; padding: 16px 16px 120px; }
.p-head { font-size: 13px; color: var(--muted); padding: 4px 2px 12px; display: flex; justify-content: space-between; gap: 8px; }
.p-title { font-size: 14px; font-weight: 600; color: var(--accent); margin: 0 0 4px; letter-spacing: .02em; }
.p-prompt { font-size: 22px; font-weight: 700; line-height: 1.45; margin: 0 0 6px; }
.p-hint { font-size: 14px; color: var(--muted); margin: 0 0 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.idle { text-align: center; padding: 48px 20px; }
.idle .big { font-size: 44px; line-height: 1.2; margin-bottom: 12px; }
.idle h2 { margin: 0 0 6px; font-size: 20px; }

.scenario {
  background: var(--card); border-left: 5px solid var(--accent); border-radius: 12px;
  padding: 16px 18px; font-size: 19px; line-height: 1.55; margin: 6px 0 18px;
}
.choices { display: grid; gap: 10px; }
.choices.row { grid-template-columns: repeat(3, 1fr); }
.choice {
  background: var(--card); border: 2px solid var(--line); border-radius: 14px;
  padding: 14px 10px; cursor: pointer; text-align: center; transition: border-color .15s, background .15s;
  min-height: 56px;
}
.choices.row .choice { display: grid; place-items: center; gap: 2px; padding: 16px 6px; }
.choice .emo { font-size: 34px; line-height: 1; }
.choice .lbl { font-weight: 700; font-size: 16px; }
.choices.list .choice { text-align: left; padding: 14px 16px; }
.choice .det { display: block; font-size: 14px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.choice[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.choice:disabled { cursor: default; opacity: .65; }
.choice[aria-pressed="true"]:disabled { opacity: 1; }

.answer-box { margin-top: 16px; background: #fbf5e6; border: 1px solid #ecd9a6; border-radius: 14px; padding: 14px 16px; }
.answer-box .k { font-size: 13px; color: var(--gold); font-weight: 700; }
.answer-box .v { font-size: 18px; font-weight: 700; }
.answer-box .l { margin-top: 4px; }

.note { margin-top: 14px; text-align: center; color: var(--muted); font-size: 15px; }

.word-form { display: flex; gap: 8px; margin-top: 4px; }
.word-form input {
  flex: 1; min-width: 0; font: inherit; font-size: 17px; padding: 12px 14px;
  border: 2px solid var(--line); border-radius: 12px; background: #fff;
}
.word-form input:focus { outline: none; border-color: var(--accent); }
.btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 12px; padding: 12px 18px;
  font-weight: 700; cursor: pointer; font-size: 16px;
}
.btn:disabled { background: #a9b4c2; cursor: default; }
.btn.ghost { background: transparent; color: var(--accent); border: 2px solid var(--accent); }
.btn.wide { width: 100%; padding: 15px; font-size: 17px; }
.mine { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
.mine li { background: var(--accent-soft); border-radius: 999px; padding: 6px 6px 6px 14px; display: flex; align-items: center; gap: 4px; }
.mine button { border: 0; background: transparent; font-size: 18px; line-height: 1; padding: 4px 8px; cursor: pointer; color: var(--muted); }

/* ขวด */
.pairs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pair { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 8px 10px; text-align: center; }
.pair.todo { border-color: #e9c46a; }
.pair h3 { margin: 0 0 8px; font-size: 15px; }
.bottles { display: flex; justify-content: center; gap: 14px; }
.bot { display: flex; flex-direction: column; align-items: center; width: 64px; }
.bottle { position: relative; width: 52px; height: 132px; touch-action: none; cursor: ns-resize; user-select: none; -webkit-user-select: none; }
.bottle .neck {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 20px; height: 16px; border: 3px solid #9aa4b1; border-bottom: 0; border-radius: 5px 5px 0 0; background: #fff;
}
.bottle .body {
  position: absolute; top: 14px; left: 0; right: 0; bottom: 0;
  border: 3px solid #9aa4b1; border-radius: 14px 14px 16px 16px; overflow: hidden; background: #fff;
}
.bottle .water { position: absolute; left: 0; right: 0; bottom: 0; height: 0; }
.bot.a .water { background: linear-gradient(#ef9a5f, var(--a)); }
.bot.b .water { background: linear-gradient(#64a0e3, var(--b)); }
.bottle .pct { position: absolute; inset: auto 0 6px; text-align: center; font-size: 12px; font-weight: 700; color: #1d2733; mix-blend-mode: multiply; }
.bot .lab { font-weight: 700; margin-top: 6px; font-size: 15px; }
.bot.a .lab { color: var(--a); }
.bot.b .lab { color: var(--b); }
.bot .hint { font-size: 11.5px; line-height: 1.35; color: var(--muted); min-height: 32px; }
.sendbar {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
}
.sendbar .btn { max-width: 488px; margin: 0 auto; display: block; }

/* ───────── จอหลัก ───────── */
.s-body { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
.s-top {
  display: flex; align-items: center; justify-content: space-between; gap: 2vw;
  padding: 1.4vh 2.2vw; border-bottom: 1px solid var(--line); background: #fff;
}
.s-top .t { font-weight: 700; font-size: clamp(16px, 1.5vw, 28px); color: var(--accent); }
.s-top .join { display: flex; align-items: center; gap: 1vw; font-size: clamp(14px, 1.3vw, 24px); }
.s-top .join img { height: 7.5vh; width: 7.5vh; image-rendering: pixelated; }
.s-top .join b { font-size: 1.15em; }
.s-main { flex: 1; min-height: 0; padding: 3vh 4vw; display: flex; flex-direction: column; }
.s-kicker { font-size: clamp(16px, 1.5vw, 28px); color: var(--accent); font-weight: 700; margin: 0; }
.s-prompt { font-size: clamp(26px, 3.2vw, 60px); font-weight: 700; line-height: 1.35; margin: .4vh 0 2.4vh; }
.s-prompt.quote { border-left: .6vw solid var(--accent); padding-left: 1.6vw; }
.lobby { flex: 1; display: flex; align-items: center; justify-content: center; gap: 5vw; }
.lobby img { height: 58vh; width: 58vh; image-rendering: pixelated; background: #fff; border-radius: 18px; padding: 1vh; }
.lobby .big { font-size: clamp(28px, 3.6vw, 70px); font-weight: 800; }
.lobby .url { font-size: clamp(22px, 2.6vw, 50px); color: var(--accent); font-weight: 700; word-break: break-all; }
.lobby .n { font-size: clamp(20px, 2vw, 40px); margin-top: 3vh; }

.cloud { flex: 1; display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 1.2vh 2.2vw; overflow: hidden; }
.cloud span { font-weight: 700; line-height: 1.15; }
.foot { font-size: clamp(14px, 1.3vw, 24px); color: var(--muted); }

/* ทุกแถวใช้คอลัมน์ชุดเดียว — ชื่อยาวไม่เท่ากันแท่งก็เริ่มตรงกัน */
.bars { display: grid; grid-template-columns: max-content 1fr 9vw; gap: 2.2vh 1.6vw; align-items: center; margin-top: 1vh; font-size: clamp(18px, 2vw, 38px); }
.bar { display: contents; }
.bar .name { font-weight: 700; max-width: 34vw; }
.bar .name small { display: block; font-size: .55em; font-weight: 400; color: var(--muted); line-height: 1.3; }
.bar .track { height: 6.5vh; background: #ece6db; border-radius: 12px; overflow: hidden; }
.bar .fill { height: 100%; width: 0; background: var(--accent); border-radius: 12px; transition: width .5s ease; }
.bar.correct .fill { background: var(--ok); }
.bar .num { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.bar .num small { font-weight: 400; color: var(--muted); font-size: .6em; display: block; }
.counter { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.counter .n { font-size: clamp(60px, 11vw, 220px); font-weight: 800; color: var(--accent); line-height: 1; font-variant-numeric: tabular-nums; }
.counter .l { font-size: clamp(20px, 2.2vw, 42px); margin-top: 2vh; }
.s-answer { margin-top: 3vh; background: #fbf5e6; border: 2px solid #ecd9a6; border-radius: 18px; padding: 2vh 2vw; font-size: clamp(20px, 2.2vw, 42px); }
.s-answer .k { color: var(--gold); font-weight: 700; font-size: .7em; }
.s-answer b { display: block; }

.panels { flex: 1; min-height: 0; display: grid; gap: 2vh 2vw; }
.panels.all { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 1.2vh 1.2vw; display: flex; flex-direction: column; min-height: 0; }
.panel h3 { margin: 0; font-size: clamp(16px, 1.6vw, 34px); display: flex; justify-content: space-between; gap: 1vw; align-items: baseline; }
.panel h3 .pa { color: var(--a); }
.panel h3 .pb { color: var(--b); }
.panel .cv { flex: 1; min-height: 0; position: relative; margin: .8vh 0; }
.panel canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.panel .sum { display: flex; justify-content: space-between; font-size: clamp(13px, 1.25vw, 28px); font-variant-numeric: tabular-nums; }
.panel .sum .sa { color: var(--a); font-weight: 700; }
.panel .sum .sb { color: var(--b); font-weight: 700; }

/* ───────── ผู้ดำเนินการ ───────── */
.h-wrap { max-width: 760px; margin: 0 auto; padding: 16px 16px 80px; }
.h-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.h-head h1 { font-size: 18px; margin: 0; }
.h-links { display: flex; gap: 8px; flex-wrap: wrap; }
.h-links a { font-size: 14px; color: var(--accent); }
.pill { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 13px; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.acts { display: grid; gap: 8px; }
.act { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.act.cur { border: 2px solid var(--accent); box-shadow: 0 4px 18px rgb(31 79 143 / .12); }
.act .row { display: flex; align-items: center; gap: 10px; }
.act .row .ti { flex: 1; min-width: 0; }
.act .row .ti b { display: block; }
.act .row .ti span { font-size: 13px; color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.act .cnt { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 3em; text-align: right; }
.ctrl { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.ctrl button, .h-btn {
  border: 2px solid var(--line); background: #fff; border-radius: 10px; padding: 7px 12px; cursor: pointer; font-size: 14px; font-weight: 600;
}
.ctrl button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: #fff; }
.ctrl .danger, .h-btn.danger { color: var(--no); border-color: #e7b9b4; }
.h-btn.go { border-color: var(--accent); color: var(--accent); }
.wordlist { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.wordlist button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 10px; font-size: 14px; cursor: pointer; }
.wordlist button.off { text-decoration: line-through; color: var(--muted); background: #f1f1f1; }
.mini { margin-top: 8px; font-size: 14px; color: var(--muted); }
.keyhelp { margin-top: 18px; font-size: 13px; color: var(--muted); }
.login { max-width: 360px; margin: 18vh auto; }
.login input { width: 100%; font: inherit; padding: 12px; border: 2px solid var(--line); border-radius: 12px; margin: 10px 0; }
