/* หน้าเมนูนักเรียน — โครงหน้า (หน้าตาจริงมาจากชีตตกแต่ง) */
html, body { margin: 0; height: 100%; background: #000; overflow: hidden; font-family: "Sarabun", sans-serif; -webkit-tap-highlight-color: transparent; }
#stage { position: fixed; inset: 0; overflow: hidden; }
#stage.long { overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; }
#sizer { position: absolute; left: 0; top: 0; width: 1px; pointer-events: none; }
#backdrop { position: absolute; inset: -60px; background: #000 center / cover no-repeat; filter: blur(22px) brightness(.4) saturate(.9); }
#canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; background: center / cover no-repeat; overflow: hidden; }

#boot { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; color: #d9b878; font: 600 20px "Sarabun", sans-serif; letter-spacing: .05em; background: #0d0905; z-index: 50; transition: opacity .4s; }
#boot.gone { opacity: 0; pointer-events: none; }

.el { position: absolute; box-sizing: border-box; user-select: none; -webkit-user-select: none; }
.el > .fx { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; line-height: 1.15; box-sizing: border-box; padding: 0 .35em; }
.el img.pic { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; pointer-events: none; -webkit-user-drag: none; }
.el .over { position: absolute; left: 6%; right: 6%; transform: translateY(-50%); text-align: center; pointer-events: none; }
.el .txt { white-space: pre-line; overflow-wrap: anywhere; }
.el .txt.one { white-space: nowrap; overflow-wrap: normal; }
.el.clickable { cursor: pointer; }
.el.clickable:active > .fx { filter: brightness(1.15); }
.el.clickable:active { transform: translateY(2px); }
.el .set-badge { position: absolute; object-fit: contain; pointer-events: none; z-index: 2; }
.el .set-champ { position: absolute; top: 0; height: 100%; display: flex; align-items: center; white-space: nowrap; pointer-events: none; text-shadow: 0 2px 0 rgba(0,0,0,.6), 0 0 12px rgba(0,0,0,.75); letter-spacing: .02em; }
.el .chain { position: absolute; left: -5%; width: 110%; top: 50%; transform: translateY(-50%); pointer-events: none; }
.el.locked > .fx { filter: saturate(.55) brightness(.8); }
.el input.idbox { width: 100%; height: 100%; border: 0; outline: 0; text-align: center; font: inherit; color: inherit; background: transparent; letter-spacing: .08em; padding: 0; }
.el input.idbox::placeholder { color: inherit; opacity: .4; letter-spacing: 0; font-size: .7em; }

/* เอฟเฟกต์ (ช่อง เอฟเฟกต์ ในชีต) */
.fx-float  { animation: fxFloat 3.2s ease-in-out infinite; }
.fx-glow   { animation: fxGlow 2.2s ease-in-out infinite alternate; }
.fx-flicker{ animation: fxFlicker 4s steps(1) infinite; }
.fx-spin   { animation: fxSpin 14s linear infinite; }
.fx-sway   { animation: fxSway 3.6s ease-in-out infinite; transform-origin: 50% 0; }
.fx-pulse  { animation: fxPulse 1.8s ease-in-out infinite; }
.fx-shake  { animation: fxShake .6s ease-in-out 1; }
.fx-fadein { animation: fxFade .7s ease-out 1 both; }
.fx-bob    { animation: fxBob 1.7s ease-in-out infinite; }
/* บินผ่าน: ไปขวา (หันขวา) → พ้นจอ → กลับตัว → บินซ้าย → พ้นจอ · เวลาตั้งที่ ตกแต่ง รอบละ= */
.el.fly { animation: fxFly 26s linear infinite; will-change: transform; }
body.edit .el.fly { animation: none; }
body.edit .fx-fadein { animation: none; }  /* โหมดจัดวางหยุดแอนิเมชัน — เข้าทีละน้อยค้างที่จาง 0 จนมองไม่เห็น */
@keyframes fxFloat  { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-9px) } }
@keyframes fxGlow   { from { filter: drop-shadow(0 0 0 rgba(255,200,90,0)) } to { filter: drop-shadow(0 0 16px rgba(255,200,90,.85)) } }
@keyframes fxFlicker{ 0%,100% { opacity: 1 } 42% { opacity: .78 } 44% { opacity: 1 } 71% { opacity: .86 } 73% { opacity: 1 } }
@keyframes fxSpin   { to { transform: rotate(360deg) } }
@keyframes fxSway   { 0%,100% { transform: rotate(-1.6deg) } 50% { transform: rotate(1.6deg) } }
@keyframes fxPulse  { 0%,100% { transform: scale(1) } 50% { transform: scale(1.05) } }
@keyframes fxShake  { 0%,100% { transform: translateX(0) } 20% { transform: translateX(-10px) } 40% { transform: translateX(9px) } 60% { transform: translateX(-6px) } 80% { transform: translateX(4px) } }
@keyframes fxBob { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-22px) } }
@keyframes fxFly {
  0%   { transform: translateX(var(--fly-from)) scaleX(1); }
  44%  { transform: translateX(var(--fly-to)) scaleX(1); }
  50%  { transform: translateX(var(--fly-to)) scaleX(-1); }
  94%  { transform: translateX(var(--fly-from)) scaleX(-1); }
  100% { transform: translateX(var(--fly-from)) scaleX(1); }
}
@keyframes fxFade   { from { opacity: 0; transform: translateY(10px) } to { opacity: 1; transform: none } }
/* ไม่ปิดตาม "ลดภาพเคลื่อนไหว" ของมือถือ — เจ้าของต้องการให้ทุกเครื่องเห็นเหมือนกัน (15 พ.ย. 69 · เดิมทำให้ผีเสื้อบินอยู่กับที่) */

#toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: rgba(28,18,9,.94); color: #f3dfae; border: 1px solid #8a6330; border-radius: 10px; padding: 10px 18px; font: 600 16px "Sarabun", sans-serif; opacity: 0; transition: .25s; pointer-events: none; z-index: 60; max-width: 86vw; text-align: center; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
#rotate-hint { position: fixed; left: 50%; top: 10px; transform: translateX(-50%); background: rgba(0,0,0,.65); color: #e8d4a8; padding: 6px 12px; border-radius: 8px; font: 14px "Sarabun", sans-serif; display: none; z-index: 40; pointer-events: none; }

/* ───────── โหมดจัดวาง (?edit=1) ───────── */
body.edit #stage { top: 52px; }
body.edit.panel-right #stage { right: 340px; }
body.edit.panel-bottom #stage { bottom: 46vh; }
body.edit .el { outline: 1px dashed rgba(255,214,120,.55); cursor: move; }
body.edit .el.sel { outline: 2px solid #ffcf5a; z-index: 9999 !important; }
body.edit .el.ghost { opacity: .35; }
body.edit .el .fx { animation-play-state: paused; }
.handle { position: absolute; right: 0; bottom: 0; transform: translate(50%, 50%); background: #ffcf5a; border: 2px solid #3a2410; border-radius: 4px; cursor: nwse-resize; touch-action: none; }
#toolbar { position: fixed; top: 0; left: 0; right: 0; height: 52px; display: flex; align-items: center; gap: 6px; padding: 0 8px; background: #1b120a; border-bottom: 1px solid #5a3e1e; z-index: 70; overflow-x: auto; color: #f0dcb0; font: 14px "Sarabun", sans-serif; }
#toolbar b { color: #ffcf5a; white-space: nowrap; }
#toolbar select, #toolbar button, #panel button, #panel select, #panel input, #panel textarea { font: 14px "Sarabun", sans-serif; background: #2c1f12; color: #f6e6c0; border: 1px solid #6b4a24; border-radius: 6px; padding: 5px 8px; }
#toolbar button, #panel button { cursor: pointer; white-space: nowrap; }
#toolbar button.on { background: #8a6330; color: #fff; }
#toolbar .dirty { color: #ff9b6a; white-space: nowrap; }
#panel { position: fixed; z-index: 70; background: #150e07; color: #f0dcb0; font: 14px "Sarabun", sans-serif; overflow-y: auto; padding: 12px; box-sizing: border-box; }
body.panel-right #panel { top: 52px; right: 0; bottom: 0; width: 340px; border-left: 1px solid #5a3e1e; }
body.panel-bottom #panel { left: 0; right: 0; bottom: 0; height: 46vh; border-top: 1px solid #5a3e1e; }
#panel h3 { margin: 4px 0 8px; color: #ffcf5a; font-size: 16px; }
#panel .f { margin-bottom: 9px; }
#panel .f label { display: block; font-size: 12px; color: #c9ad7a; margin-bottom: 2px; }
#panel .f input, #panel .f select, #panel .f textarea { width: 100%; box-sizing: border-box; }
#panel .f textarea { min-height: 52px; resize: vertical; }
#panel .hint { font-size: 12px; color: #a28a62; margin-top: 2px; }
#panel .row4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
#panel .row4 input { padding: 5px 4px; }
#panel .btns { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
#panel .item { padding: 6px 8px; border: 1px solid #3e2a14; border-radius: 6px; margin-bottom: 5px; cursor: pointer; display: flex; justify-content: space-between; gap: 6px; }
#panel .item:hover { background: #24180c; }
#panel .item small { color: #a28a62; }
#panel .warn { color: #ff9b6a; }
#panel .ok { color: #9fd38a; }
#panel .link { font-size: 12px; word-break: break-all; color: #d8c296; background: #0d0905; border-radius: 5px; padding: 4px 6px; margin-top: 3px; }
#copybox { position: fixed; inset: 10% 8%; z-index: 90; background: #150e07; border: 1px solid #8a6330; border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; color: #f0dcb0; font: 14px "Sarabun", sans-serif; }
#copybox textarea { flex: 1; background: #0d0905; color: #f0dcb0; border: 1px solid #5a3e1e; font: 12px monospace; }

/* ── หน้าโซ่ (ชิ้นชนิด ตารางโซ่) — หน้าตาตามตาราง Red&Blue ใน Looker ── */
.el .chain-box { position: absolute; inset: 0; display: flex; flex-direction: column; background: #fff; border: 2px solid #c8892e; color: #1a1a1a; font-family: "Sarabun", sans-serif; text-align: center; }
.chain-box .chain-title { font-size: 15px; padding: 6px 10px; text-align: left; color: #333; border-bottom: 1px solid #ddd; }
.chain-box .chain-scroll { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.chain-box .chain-msg { margin: auto; font-size: 24px; color: #555; }
.chain-tbl { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 20px; }
.chain-tbl th { position: sticky; top: 0; z-index: 1; background: #dff3fb; font-weight: 400; font-size: 15px; height: 64px; border: 1px solid #c9d6dc; padding: 2px 4px; line-height: 1.2; }
.chain-tbl th.c-s { background: #8fd3f2; font-size: 17px; }
.chain-tbl th small { display: block; font-size: 11px; color: #355; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chain-tbl td { height: 44px; border: 1px solid #d5d5d5; padding: 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chain-tbl .c-n { width: 60px; } .chain-tbl .c-nick { width: 150px; } .chain-tbl .c-chain { width: 80px; }
.chain-tbl th.c-chain { background: #000; color: #e11; font-size: 24px; }
.chain-tbl td.c-chain { background: #000; color: #e11; font-size: 30px; font-weight: 700; }
.chain-tbl .c-best { width: 92px; } .chain-tbl th.c-best { background: #fff4d6; font-size: 14px; }
.chain-tbl td.c-best { font-size: 26px; font-weight: 700; } .chain-tbl td.c-best.red { color: #c0262d; } .chain-tbl td.c-best.blue { color: #1a56c4; }
.chain-tbl td.c-s img { height: 36px; width: 36px; object-fit: contain; vertical-align: middle; }
.chain-tbl td.none { font-size: 14px; color: #777; }
.chain-tbl tr.me td { background: #fff3c4; } .chain-tbl tr.me td.c-chain { background: #2a1d00; }
.chain-tbl tr.me td.c-nick { font-weight: 700; }
.chain-box .chain-tabs { display: flex; gap: 2px; overflow-x: auto; background: #eef1f3; border-top: 1px solid #ccc; padding: 3px; }
.chain-tabs button { flex: 1 0 auto; font: 13px "Sarabun", sans-serif; border: 0; background: transparent; padding: 6px 8px; border-radius: 4px; cursor: pointer; color: #444; white-space: nowrap; }
.chain-tabs button.on { background: #fff; font-weight: 700; color: #1a56c4; box-shadow: 0 0 0 1px #c3d3ee; }
.chain-tabs button.red.on { color: #b51e1e; box-shadow: 0 0 0 1px #efc2c2; }
.chain-box .chain-note { padding: 8px; font-size: 16px; color: #8a5a00; background: #fff8e0; border-bottom: 1px solid #f0dca0; }

/* ประวัติรายสัปดาห์ (20 พ.ย. 69) */
.el .gw-box { position: absolute; inset: 0; display: flex; flex-direction: column; background: #fffaf0; border: 2px solid #c8892e; border-radius: 10px; color: #222; font-family: "Sarabun", sans-serif; text-align: left; overflow: hidden; }
.gw-box .gw-title { font-size: 20px; font-weight: 700; padding: 8px 14px; background: #c8892e; color: #fff; }
.gw-box .gw-scroll { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 6px 12px 12px; }
.gw-box .gw-msg { margin: auto; font-size: 22px; color: #555; padding: 20px; text-align: center; }
.gw-sec { margin-top: 10px; }
.gw-h { font-size: 18px; font-weight: 700; color: #7a4a10; border-bottom: 1px solid #e6cfa5; padding-bottom: 2px; margin-bottom: 6px; }
.gw-h small { font-weight: 400; font-size: 14px; color: #666; }
.gw-big { display: flex; gap: 8px; }
.gw-stat { flex: 1; background: #fff; border: 1px solid #e6cfa5; border-radius: 8px; text-align: center; padding: 6px 4px; }
.gw-stat b { display: block; font-size: 30px; color: #2e7d32; line-height: 1.1; }
.gw-stat span { font-size: 14px; color: #555; }
.gw-stat.gw-red b, .gw-tbl td.v.gw-red { color: #c62828; }
.gw-stat.gw-blue b, .gw-tbl td.v.gw-blue { color: #1565c0; }
.gw-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.gw-chips.sm { margin-top: 2px; }
.gw-chip { background: #e8f5e9; border: 1px solid #a5d6a7; border-radius: 12px; padding: 1px 8px; font-size: 14px; white-space: nowrap; }
.gw-chips.sm .gw-chip { font-size: 12px; }
.gw-chip.neg { background: #ffebee; border-color: #ef9a9a; }
.gw-note { font-size: 15px; color: #666; margin-top: 6px; }
.gw-tbl { width: 100%; border-collapse: collapse; font-size: 16px; }
.gw-tbl td, .gw-tbl th { border-bottom: 1px solid #eee; padding: 4px 6px; vertical-align: top; }
.gw-tbl th { font-weight: 600; font-size: 14px; color: #555; text-align: left; }
.gw-tbl td.v { text-align: right; font-weight: 700; white-space: nowrap; color: #2e7d32; }
.gw-tbl td.w { font-size: 14px; color: #555; }
