/* khmermath.org — «កង់ចាប់ឈ្មោះ» (play/wheel.html, static/js/wheel.js). */
.wh { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 28px; align-items: start; max-width: 1080px; margin: 0 auto; }
.wh-stage { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.wh-wheel-box { position: relative; width: min(100%, 560px); aspect-ratio: 1; }
.wh-wheel-box canvas { display: block; width: 100%; height: 100%; border-radius: 50%; box-shadow: var(--shadow); touch-action: manipulation; }
.wh-pointer {
  position: absolute; top: -10px; left: 50%; z-index: 2; width: 0; height: 0; transform: translateX(-50%);
  border-left: 16px solid transparent; border-right: 16px solid transparent; border-top: 30px solid var(--ink);
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.3));
}
.wh-hub {
  position: absolute; top: 50%; left: 50%; z-index: 2; width: 21%; aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: 50%; border: 4px solid #fff; background: var(--teal); color: #fff; font: inherit; font-weight: 700; font-size: clamp(14px, 3.4vw, 20px);
  cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,.3);
}
.wh-hub:hover { background: var(--teal-strong); }
.wh-hub:disabled { cursor: default; opacity: .75; }
.wh-empty { margin: 0; padding: 14px 18px; border-radius: var(--radius); background: var(--amber-soft); color: var(--ink); text-align: center; line-height: 1.7; }
.wh-result-acts, .wh-tools, .wh-row { display: flex; gap: 8px; }
.wh-result-acts, .wh-tools { flex-wrap: wrap; justify-content: center; }
.wh .btn { min-height: 44px; }
.wh .btn[aria-pressed="false"] { opacity: .75; }

.wh-panel { display: flex; flex-direction: column; gap: 14px; }
.wh-box { padding: 14px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.wh-lbl { font-weight: 700; color: var(--ink); }
.wh-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.wh-hint { margin: 0; font-size: 14px; line-height: 1.6; color: var(--ink-3); }
.wh-row-wrap { flex-wrap: wrap; }
.wh select, .wh input[type="text"], .wh textarea {
  width: 100%; 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;
}
.wh textarea { resize: vertical; line-height: 1.7; }
.wh-chips { display: flex; flex-wrap: wrap; gap: 6px; max-height: 300px; overflow-y: auto; margin: 0; padding: 0; list-style: none; }
.wh-chips li button {
  min-height: 36px; padding: 4px 12px; border-radius: 999px; border: 1.5px solid var(--line-2); background: var(--surface-2);
  color: var(--ink); font: inherit; font-size: 15px; cursor: pointer;
}
.wh-chips li button.off { text-decoration: line-through; opacity: .5; }
.wh-chips li button.done { border-color: var(--teal); background: var(--teal-soft); color: var(--teal-strong); }
.wh-add { display: flex; gap: 8px; }
.wh-add input { flex: 1; min-width: 0; }

/* winner popup + fireworks (both live inside the stage, so they also show in fullscreen) */
.wh-stage { position: relative; }
.wh-fw { position: fixed; inset: 0; z-index: 90; width: 100vw; height: 100vh; pointer-events: none; }
.wh-stage:fullscreen .wh-fw { position: fixed; }
.wh-pop { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 16px; background: rgba(10, 18, 30, .55); animation: wh-fade .2s ease-out; }
.wh-pop-card {
  width: min(92vw, 640px); padding: 26px 22px 22px; text-align: center; border-radius: 24px; background: var(--surface); border: 3px solid var(--teal);
  box-shadow: 0 20px 60px rgba(0,0,0,.4); animation: wh-pop .45s cubic-bezier(.2, 1.4, .4, 1);
}
.wh-pop-card small { display: block; color: var(--ink-3); font-size: 16px; }
.wh-pop-card b { display: block; margin: 6px 0 16px; font-size: clamp(34px, 9vw, 72px); line-height: 1.4; color: var(--teal-strong); overflow-wrap: anywhere; }
@keyframes wh-pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes wh-fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .wh-pop, .wh-pop-card { animation: none; } }

.wh-filter { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.wh-filter select { width: auto; min-width: 150px; }
.wh-seg { display: flex; flex-wrap: wrap; gap: 6px; }
.wh-seg button { min-height: 40px; padding: 4px 14px; border-radius: 999px; border: 1.5px solid var(--line-2); background: var(--surface); color: var(--ink); font: inherit; font-size: 15px; cursor: pointer; }
.wh-seg button[aria-pressed="true"] { background: var(--teal-soft); border-color: var(--teal); color: var(--teal-strong); font-weight: 600; }
.wh-chips li button.g-m { border-left: 5px solid #1c7ed6; }
.wh-chips li button.g-f { border-left: 5px solid #d6336c; }
.wh-check { display: flex; gap: 8px; align-items: flex-start; font-size: 15px; line-height: 1.6; color: var(--ink-2); }
.wh-check input { width: 20px; height: 20px; margin-top: 4px; flex: none; }
.wh-grp input[type="number"] { width: 90px; flex: none; }
.wh-grp select { flex: 1; min-width: 0; }
.wh-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; max-height: 420px; overflow-y: auto; }
.wh-g { padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.wh-g b { display: block; margin-bottom: 4px; color: var(--teal-strong); }
.wh-g ol { margin: 0; padding-left: 22px; font-size: 15px; line-height: 1.7; }

/* fullscreen / projector: the wheel gets the whole screen */
.wh-stage:fullscreen { justify-content: center; background: var(--bg); padding: 12px; }
.wh-stage:fullscreen .wh-wheel-box { width: min(78vh, 92vw); }
.wh-stage:fullscreen .wh-result { width: min(92vw, 720px); }

@media (max-width: 860px) {
  .wh { grid-template-columns: 1fr; gap: 20px; }
}
.wh [hidden] { display: none !important; }

.wh-lbl2 { font-size: 15px; color: var(--ink-2); }
.wh input[type="range"] { width: 100%; min-height: 32px; accent-color: var(--teal); padding: 0; border: 0; background: none; }
.wh kbd { padding: 1px 6px; border-radius: 6px; border: 1px solid var(--line-2); background: var(--surface-2); font: inherit; font-size: 13px; }
.wh-hist { margin: 0; padding-left: 26px; max-height: 260px; overflow-y: auto; font-size: 15px; line-height: 1.8; }
.wh-hist li small { color: var(--ink-3); margin-left: 6px; }
.wh-hist li .cnt { float: right; font-weight: 700; color: var(--teal-strong); }
.wh-hist:empty::after { content: "មិនទាន់មានលទ្ធផលទេ។"; color: var(--ink-3); }
.wh-hist.tally { list-style: none; padding-left: 0; }

/* group-maker popup */
.wh-gcard { width: min(96vw, 980px); max-height: 94vh; display: flex; flex-direction: column; padding: 18px 16px 16px; }
.wh-gcard small { font-size: 18px; font-weight: 700; color: var(--teal-strong); }
.wh-ggrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin: 12px 0 14px; overflow-y: auto; text-align: left; flex: 1; min-height: 0; max-height: 66vh; }
.wh-ggrid .wh-g { background: var(--surface-2); }
.wh-ggrid .wh-g li { font-size: 16px; overflow-wrap: anywhere; }
/* one card at a time: waiting (dim) -> active (drum roll) -> done */
.wh-ggrid .wh-g.wait { opacity: .45; }
.wh-ggrid .wh-g li.ph { color: var(--ink-3); list-style: none; letter-spacing: 2px; }
.wh-ggrid .wh-g.active { border-color: var(--amber); background: var(--amber-soft); box-shadow: 0 0 0 3px rgba(224, 178, 74, .45); animation: wh-shake .12s infinite alternate; }
.wh-ggrid .wh-g.done { animation: wh-card .55s cubic-bezier(.2, 1.3, .4, 1); }
@keyframes wh-shake { from { transform: translateX(-1.5px) rotate(-.3deg); } to { transform: translateX(1.5px) rotate(.3deg); } }
@keyframes wh-card { from { transform: translateY(24px) scale(.8); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .wh-ggrid .wh-g.active, .wh-ggrid .wh-g.done { animation: none; } }
.wh-pop-card.wh-gcard .wh-g b { margin: 0 0 4px; font-size: 17px; line-height: 1.5; color: var(--teal-strong); }
.wh-pop-card.wh-gcard small { margin-bottom: 0; }

/* finished result: poster look */
.wh-gsub { margin-top: 8px; color: var(--ink-2); font-size: 17px; white-space: pre-line; line-height: 1.7; }
.wh-gbrand { margin: 0 0 12px; font-weight: 700; color: var(--teal-strong); letter-spacing: .3px; }
.wh-pop-card.wh-gcard.final small { display: block; padding: 12px 18px; border-radius: 16px; color: #fff; font-size: clamp(24px, 4.2vw, 38px); line-height: 1.5; background: linear-gradient(100deg, #1f6f66, #2d8f7e 60%, #3aa68f); box-shadow: 0 6px 18px rgba(31, 111, 102, .35); }
.wh-gcard.final .wh-ggrid { gap: 14px; margin-top: 16px; }
.wh-ggrid .wh-g.done { padding: 0; overflow: hidden; border: 0; background: #fff; box-shadow: 0 6px 18px rgba(0, 0, 0, .14); }
.wh-pop-card.wh-gcard .wh-g.done b { margin: 0 0 6px; padding: 10px 14px; font-size: 18px; color: #fff; background: var(--gc, var(--teal)); border-radius: 0; }
.wh-ggrid .wh-g.done ol { padding: 2px 14px 12px 38px; }
.wh-ggrid .wh-g.done li::marker { color: var(--gc, var(--teal)); font-weight: 700; }

/* gender panel (opens after a pasted list is saved) */
.wh-gpanel { border: 2px solid var(--teal); }
.wh-glist { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.wh-glist li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 6px; border-radius: 10px; border-bottom: 1px solid var(--line); }
.wh-glist li .nm { flex: 1; min-width: 0; font-size: 16px; overflow-wrap: anywhere; }
.wh-glist li .nm small { color: var(--ink-3); margin-right: 6px; }
.wh-glist .gb { display: flex; gap: 6px; flex: none; }
.wh-glist .gb button { min-width: 64px; min-height: 40px; padding: 2px 12px; border-radius: 999px; border: 1.5px solid var(--line-2); background: var(--surface); color: var(--ink); font: inherit; font-size: 15px; cursor: pointer; }
.wh-glist .gb button[aria-pressed="true"].m { background: #e7f1ff; border-color: #1c7ed6; color: #1864ab; font-weight: 700; }
.wh-glist .gb button[aria-pressed="true"].f { background: #ffe8f1; border-color: #d6336c; color: #a61e4d; font-weight: 700; }
.wh-glist li.todo { background: var(--amber-soft); }

/* fixed columns: 2 for up to 4 groups, 3 for five or more (6 groups = 3 x 2); fewer on small screens */
.wh-gcard { width: min(96vw, 1080px); }
.wh-ggrid.cols-1 { grid-template-columns: 1fr; }
.wh-ggrid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.wh-ggrid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 720px) { .wh-ggrid.cols-3, .wh-ggrid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 440px) { .wh-ggrid.cols-3, .wh-ggrid.cols-2 { grid-template-columns: 1fr; } }

/* final group fireworks sit behind the result card so they never cover a name */
.wh-fw.behind { z-index: 79; }
/* cards keep their full height and the grid scrolls (without this, short screens squash every card to one name) */
.wh-ggrid { grid-auto-rows: max-content; align-content: start; }
.wh-ggrid .wh-g { min-height: min-content; }

/* last picked name, always visible under the wheel (also if the popup cannot be shown) */
.wh-last { margin: 0; width: min(100%, 560px); padding: 10px 16px; border-radius: 14px; background: var(--teal-soft); border: 2px solid var(--teal); text-align: center; font-size: 18px; color: var(--ink-2); }
.wh-last b { display: block; font-size: clamp(26px, 7vw, 40px); line-height: 1.5; color: var(--teal-strong); overflow-wrap: anywhere; }
/* PNG preview (phones: long-press the picture to save, or use the share button) */
.wh-pv { position: fixed; inset: 0; z-index: 120; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 14px 12px; background: rgba(10, 18, 30, .97); overflow-y: auto; }
.wh-pv p { margin: 0; color: #fff; text-align: center; line-height: 1.7; font-size: 15px; }
.wh-pv img { width: min(100%, 900px); height: auto; border-radius: 12px; background: #fff; }
.wh-pv .wh-row { flex-wrap: wrap; justify-content: center; }

/* phones: sizes are relative to the visible area (not 100vh, which runs under Safari's bottom toolbar); a close ✕ is always at the top */
.wh-pop { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.wh-pop-card { position: relative; max-height: 100%; overflow-y: auto; }
.wh-gcard { max-height: 100%; overflow: hidden; }
.wh-ggrid { max-height: none; }
.wh-x { position: absolute; top: 8px; right: 8px; 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; }
.wh-pop-card.wh-gcard.final small, .wh-pop-card.wh-gcard small { padding-right: 56px; }
.wh-pv .wh-row { order: -1; }

/* ✕ on the picture preview: always visible in the top-right corner */
.wh-pv .wh-x-pv { position: fixed; top: max(10px, env(safe-area-inset-top)); right: 10px; z-index: 130; width: 48px; height: 48px; background: #fff; }
.wh-pv p { padding-right: 52px; }
.wh-pv { padding-top: max(66px, calc(env(safe-area-inset-top) + 58px)); }
