/* khmermath.org — «ហ្គេមក្រុម» (play/teamgame.html, static/js/teamgame.js) */
.tg { max-width: 1180px; margin: 0 auto; }
.tg [hidden] { display: none !important; }
.tg-setup { display: flex; flex-direction: column; gap: 16px; }
.tg-box { padding: 16px 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.tg-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px 14px; }
.tg-head b { font-size: 19px; color: var(--teal-strong); }
.tg-row { display: flex; align-items: center; gap: 8px; }
.tg-row-wrap { flex-wrap: wrap; }
.tg-hint { margin: 0; font-size: 14px; line-height: 1.7; color: var(--ink-3); }
.tg-hint code { padding: 1px 6px; border-radius: 6px; background: var(--surface-2); font-size: 13px; }
.tg-count { font-size: 15px; color: var(--ink-3); }
.tg input[type="text"], .tg input[type="number"], .tg select, .tg textarea {
  min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1.5px solid var(--line-2); background: var(--bg); color: var(--ink); font: inherit; font-size: 16px;
}
.tg input[type="number"] { width: 90px; }
.tg textarea { width: 100%; line-height: 1.7; resize: vertical; }
.tg .btn { min-height: 44px; }
.tg-teams { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.tg-team { display: grid; grid-template-columns: 22px 1fr; gap: 4px 8px; align-items: center; }
.tg-team .dot, .tg-turn .dot { width: 18px; height: 18px; border-radius: 50%; display: inline-block; }
.tg-team input { width: 100%; }
.tg-team .mem { grid-column: 2; color: var(--ink-3); font-size: 13px; line-height: 1.5; }
.tg-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.tg-opts label { display: flex; flex-direction: column; gap: 4px; font-size: 15px; color: var(--ink-2); }
.tg-opts label.tg-check { flex-direction: row; align-items: center; gap: 8px; }
.tg-opts input[type="checkbox"] { width: 20px; height: 20px; }
.tg-go { display: flex; gap: 10px; flex-wrap: wrap; }
.tg-go .btn-primary { font-size: 18px; padding: 10px 26px; }

/* play */
.tg-bar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.tg-turn { display: flex; align-items: center; gap: 8px; font-size: 20px; }
.tg-turn small { color: var(--ink-3); font-size: 15px; }
.tg-stage { position: relative; display: flex; flex-direction: column; gap: 16px; }
.tg-stage:fullscreen { background: var(--bg); padding: 14px; overflow-y: auto; justify-content: flex-start; }
.tg-score { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.tg-score.n2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tg-score.n3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tg-tc { position: relative; padding: 0 0 10px; border-radius: 16px; background: var(--surface); border: 2px solid var(--line); overflow: hidden; text-align: center; transition: transform .2s, box-shadow .2s, border-color .2s; }
.tg-tc.turn { border-color: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 30%, transparent), var(--shadow); transform: translateY(-3px); }
.tg-tn { padding: 8px 10px; background: var(--c); color: #fff; font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }
.tg-tm { padding: 4px 8px 0; font-size: 12.5px; color: var(--ink-3); line-height: 1.5; max-height: 3.2em; overflow: hidden; }
.tg-ts { font-size: clamp(36px, 7vw, 58px); font-weight: 800; line-height: 1.3; color: var(--c); }
.tg-tctl { display: flex; justify-content: center; gap: 10px; }
.tg-tctl button { width: 44px; height: 38px; border-radius: 10px; border: 1.5px solid var(--line-2); background: var(--surface-2); color: var(--ink); font-size: 22px; line-height: 1; cursor: pointer; }
.tg-tctl button:hover { background: var(--c); color: #fff; border-color: var(--c); }
.tg-board { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; }
.tg-tile {
  aspect-ratio: 1.15; border-radius: 16px; border: 0; background: var(--tc, var(--teal)); color: #fff; font: inherit; font-size: clamp(26px, 5vw, 38px); font-weight: 800; cursor: pointer;
  box-shadow: 0 6px 0 rgba(0, 0, 0, .22), 0 8px 16px rgba(0, 0, 0, .12); transition: transform .12s, box-shadow .12s, filter .12s;
}
.tg-tile:hover:not(:disabled) { transform: translateY(-3px); filter: brightness(1.08); }
.tg-tile:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, .22); }
.tg-tile.done { opacity: .55; box-shadow: none; cursor: default; font-size: clamp(22px, 4vw, 30px); }

/* popup */
.tg-fw { position: fixed; inset: 0; z-index: 90; width: 100vw; height: 100vh; pointer-events: none; }
.tg-pop { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 14px 14px max(14px, env(safe-area-inset-bottom)); background: rgba(10, 18, 30, .6); animation: tg-fade .2s ease-out; }
.tg-card {
  position: relative; width: min(100%, 860px); max-height: 100%; overflow-y: auto; padding: 22px 22px 20px; border-radius: 24px; background: var(--surface); text-align: center;
  border-top: 12px solid var(--c, var(--teal)); box-shadow: 0 24px 70px rgba(0, 0, 0, .45); animation: tg-flip .5s cubic-bezier(.2, 1.3, .4, 1);
}
.tg-x { position: absolute; top: 12px; right: 10px; z-index: 3; width: 44px; height: 44px; padding: 0; border-radius: 50%; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); font-size: 20px; line-height: 1; cursor: pointer; }
.tg-chead { display: flex; justify-content: center; align-items: center; gap: 10px; flex-wrap: wrap; padding: 0 52px; }
.tg-cn { padding: 3px 14px; border-radius: 999px; background: var(--surface-2); font-weight: 700; color: var(--ink-2); }
.tg-cteam { padding: 3px 14px; border-radius: 999px; background: var(--c); color: #fff; font-weight: 700; }
.tg-q { margin: 18px 0 10px; font-size: clamp(26px, 5.2vw, 44px); line-height: 1.6; font-weight: 700; overflow-wrap: anywhere; color: var(--ink); }
.tg-a { margin: 8px 0 4px; padding: 12px 16px; border-radius: 14px; background: var(--teal-soft); border: 2px dashed var(--teal); font-size: clamp(22px, 4.4vw, 36px); font-weight: 700; color: var(--teal-strong); overflow-wrap: anywhere; }
.tg-timer { margin: 8px auto; width: 84px; height: 84px; display: grid; place-items: center; border-radius: 50%; border: 6px solid var(--teal); font-size: 34px; font-weight: 800; color: var(--teal-strong); }
.tg-timer.hot { border-color: #f08c00; color: #d9480f; animation: tg-pulse .5s infinite alternate; }
.tg-timer.over { border-color: #e03131; color: #e03131; }
.tg-acts { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.tg-acts .btn { min-height: 46px; padding: 6px 18px; font-size: 16px; }
.tg-pick { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; margin-top: 14px; }
.tg-pick small { width: 100%; color: var(--ink-3); font-size: 15px; }
.tg-pickbtn { min-height: 46px; padding: 6px 18px; border-radius: 999px; border: 0; background: var(--c); color: #fff; font: inherit; font-weight: 700; font-size: 16px; cursor: pointer; }
.tg-card.special { background: linear-gradient(160deg, var(--surface), var(--amber-soft)); }
.tg-sicon { margin-top: 10px; font-size: clamp(70px, 18vw, 130px); line-height: 1.2; }
.tg-sname { font-size: clamp(30px, 7vw, 52px); font-weight: 800; color: var(--ink); line-height: 1.5; }
.tg-sdesc { margin: 4px 0 6px; font-size: clamp(17px, 3.4vw, 24px); color: var(--ink-2); line-height: 1.7; }
.tg-title { margin: 6px 0 4px; padding: 10px 16px; border-radius: 16px; color: #fff; font-size: clamp(26px, 6vw, 44px); font-weight: 800; background: linear-gradient(100deg, #1f6f66, #2d8f7e 60%, #3aa68f); }
.tg-winner { margin: 10px 0; font-size: clamp(22px, 4.6vw, 34px); font-weight: 800; color: var(--teal-strong); }
.tg-rank { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; text-align: left; }
.tg-rank li { display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 14px; background: var(--surface-2); border-left: 10px solid var(--c); font-size: 20px; }
.tg-rank .m { font-size: 28px; text-align: center; }
.tg-rank .n { font-weight: 700; overflow-wrap: anywhere; }
.tg-rank .s { font-size: 30px; color: var(--c); }
.tg-pv { position: fixed; inset: 0; z-index: 120; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: max(66px, calc(env(safe-area-inset-top) + 58px)) 12px 14px; background: rgba(10, 18, 30, .97); overflow-y: auto; }
.tg-pv p { margin: 0; color: #fff; text-align: center; line-height: 1.7; font-size: 15px; }
.tg-pv img { width: min(100%, 900px); height: auto; border-radius: 12px; background: #fff; }
.tg-xpv { position: fixed; top: max(10px, env(safe-area-inset-top)); right: 10px; width: 48px; height: 48px; z-index: 130; }

@keyframes tg-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes tg-flip { from { transform: perspective(900px) rotateY(80deg) scale(.7); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes tg-pulse { from { transform: scale(1); } to { transform: scale(1.12); } }
@media (prefers-reduced-motion: reduce) { .tg-card, .tg-pop, .tg-timer.hot { animation: none; } .tg-tc.turn { transform: none; } }
@media (max-width: 760px) {
  .tg-score, .tg-score.n3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tg-board { grid-template-columns: repeat(auto-fill, minmax(66px, 1fr)); gap: 8px; }
  .tg-card { padding: 18px 14px 16px; }
}

/* ===== yellow team bar + a grid of picture cards ===== */
.tg-score { gap: 6px; padding: 8px 12px 10px; border-radius: 16px; background: #ffc864; box-shadow: inset 0 -4px 0 rgba(0,0,0,.08); }
.tg-tc { background: transparent; border: 0; border-radius: 12px; padding: 4px 6px 2px; overflow: visible; transform: none !important; }
.tg-tc.turn { box-shadow: none; }
.tg-tc.turn .tg-tn { background: var(--c); color: #fff; box-shadow: 0 3px 10px rgba(0,0,0,.25); }
.tg-tn { display: inline-block; max-width: 100%; padding: 2px 14px; border-radius: 8px; background: transparent; color: #3a2a00; font-size: clamp(18px, 3.4vw, 30px); font-weight: 800; }
.tg-ts { color: #3a2a00; font-size: clamp(30px, 6vw, 48px); line-height: 1.2; }
.tg-tctl { gap: 6px; }
.tg-tctl button { width: 34px; height: 28px; font-size: 18px; border-radius: 8px; background: rgba(255,255,255,.55); border-color: rgba(0,0,0,.12); }
.tg-board { gap: 12px; }
.tg-board.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tg-board.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tg-board.c5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.tg-tile {
  position: relative; aspect-ratio: 1.35; display: grid; place-items: center; overflow: hidden; padding: 6px; border-radius: 16px; border: 2px solid rgba(255,255,255,.55);
  background: linear-gradient(170deg, var(--f1), var(--f2)); box-shadow: 0 4px 0 rgba(0,0,0,.18), 0 8px 18px rgba(0,0,0,.12); cursor: pointer; transition: transform .15s, filter .15s;
}
.tg-tile:hover:not(:disabled) { transform: translateY(-4px) scale(1.02); filter: brightness(1.06); }
.tg-tile.done { opacity: .6; box-shadow: none; filter: grayscale(.25); }
.tg-tile .tg-mark { font-size: clamp(30px, 6vw, 54px); font-weight: 800; line-height: 1; }
.tg-doneName { position: absolute; left: 6px; right: 6px; bottom: 5px; font-size: clamp(11px, 1.7vw, 15px); font-weight: 700; line-height: 1.3; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.4); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-pic { display: inline-flex; align-items: center; justify-content: center; max-width: 100%; max-height: 100%; font-size: clamp(40px, 9vw, 92px); line-height: 1.1; color: #fff; text-shadow: 0 3px 8px rgba(0,0,0,.28); font-weight: 800; }
.tg-pic img { max-width: 100%; max-height: 100%; width: auto; height: clamp(60px, 14vw, 140px); object-fit: contain; border-radius: 10px; filter: drop-shadow(0 4px 8px rgba(0,0,0,.25)); }
.tg-pic.long { font-size: clamp(24px, 5vw, 48px); text-align: center; }
.tg-pic.num { font-size: clamp(34px, 8vw, 70px); }
.tg-pic.sm { font-size: 30px; }
.tg-pic.sm img { height: 44px; border-radius: 6px; }
.tg-pic.big { font-size: clamp(80px, 20vw, 160px); }
.tg-pic.big img { height: clamp(120px, 30vw, 230px); }
/* the picked card, popped up */
.tg-card { border-top: 0; padding: 0 0 20px; overflow-y: auto; }
.tg-card > .tg-chead { padding: 14px 56px 0; }
.tg-cface { margin: 12px 18px 0; padding: 18px 10px; border-radius: 20px; display: grid; place-items: center; background: linear-gradient(170deg, var(--f1, #4dabf7), var(--f2, #1c7ed6)); box-shadow: inset 0 -5px 0 rgba(0,0,0,.12); }
.tg-name { margin: 14px 18px 4px; font-size: clamp(34px, 7.5vw, 64px); font-weight: 800; line-height: 1.5; color: var(--ink); overflow-wrap: anywhere; }
.tg-card .tg-q { margin: 6px 18px; font-size: clamp(20px, 4.2vw, 32px); font-weight: 600; color: var(--ink-2); }
.tg-card .tg-a { margin: 8px 18px 0; }
.tg-card .tg-acts, .tg-card .tg-pick, .tg-card .tg-timer { margin-left: 18px; margin-right: 18px; }
.tg-card.special, .tg-card.final { padding: 22px 18px 20px; border-top: 12px solid var(--c, var(--teal)); }
.tg-card.special .tg-chead, .tg-card.final .tg-chead { padding-top: 0; }

/* setup: card editor */
.tg-cards { display: flex; flex-direction: column; gap: 10px; max-height: 560px; overflow-y: auto; padding-right: 4px; }
.tg-crow { display: grid; grid-template-columns: 64px minmax(120px, 1fr) minmax(150px, 1fr) minmax(220px, 1.8fr) 40px; gap: 10px; align-items: start; padding: 10px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line); }
.tg-cthumb { width: 64px; height: 56px; border-radius: 12px; display: grid; place-items: center; overflow: hidden; box-shadow: inset 0 -3px 0 rgba(0,0,0,.14); }
.tg-cf { display: flex; flex-direction: column; gap: 6px; }
.tg-cf label { display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; color: var(--ink-3); }
.tg-cf input { min-height: 38px; font-size: 15px; width: 100%; }
.tg-cf-wide { display: grid; grid-template-columns: 1fr 1fr 90px; gap: 6px; align-items: end; }
.tg-cf-wide label input[type="number"] { width: 100%; }
.tg-cdel { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; font-size: 16px; color: var(--ink-2); }
.tg-cdel:hover { background: #ffe3e3; color: #c92a2a; }
.tg-pastebox { display: flex; flex-direction: column; gap: 8px; }
@media (max-width: 860px) {
  .tg-crow { grid-template-columns: 64px 1fr 40px; }
  .tg-crow .tg-cf:nth-of-type(2), .tg-crow .tg-cf:nth-of-type(3) { grid-column: 1 / -1; }
  .tg-cf-wide { grid-template-columns: 1fr 1fr; }
  .tg-cf-wide label:last-child { grid-column: 1 / -1; }
  .tg-board.c4, .tg-board.c5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tg-score, .tg-score.n3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 460px) { .tg-board { gap: 8px; } .tg-board.c3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
