:root {
  color-scheme: light;
  font-family: Outfit, "Noto Sans Thai", system-ui, sans-serif;
  color: #241741; background: #f7f5ff;
  --purple: #6036e7; --muted: #6e6387; --line: #e9e1f8;
}
* { box-sizing: border-box }
[hidden] { display: none !important }
body { margin: 0; min-width: 0; background: radial-gradient(ellipse at 50% 11rem,#eee5ff 0%,transparent 51%) }
button, input, select, textarea { font: inherit }
button { cursor: pointer; border: 0; min-height: 44px; touch-action: manipulation }
button:disabled { cursor: default; opacity: .58 }
button:focus-visible, a:focus-visible { outline: 3px solid #aa83ff; outline-offset: 3px }
.wrap { width: min(100% - 28px, 1120px); margin-inline: auto }
.top { background: #fff; border-bottom: 1px solid var(--line) }
.bar { min-height: 65px; display: flex; align-items: center; justify-content: space-between; gap: .75rem }
.bar .brand { margin-right: auto }
#music[aria-pressed="false"] { color: var(--muted); background: #f7f5ff }
.decision { display: grid; grid-template-columns: 1fr 1fr; gap: .55rem; align-items: stretch; margin-bottom: .2rem }
@media (max-width: 380px) { .bar { gap: .3rem } .bar .quiet { padding-inline: .4rem } }
.brand { display: flex; align-items: center; color: #261848; font-weight: 800; font-size: 1.55rem; letter-spacing: -.05em; text-decoration: none }
.brand > span:last-child { color: #744ae6 }
.mark { background: #6b41ed; color: white; border-radius: 13px; width: 38px; height: 38px; display: grid; place-items: center; margin-right: 9px; font-size: 1.3rem; box-shadow: 0 3px 0 #4b21bd }
.quiet { background: #fff; color: #5839a4; border: 1px solid var(--line); border-radius: 12px; padding: .48rem .75rem; font-weight: 700; font-size: .9rem }
.quiet:hover { background: #f7f2ff }
.intro { text-align: center; padding: clamp(1.4rem,5vw,3.1rem) 0 1.45rem }
.overline { display: inline-block; color: #603bbe; background: #eadeff; border-radius: 999px; padding: .26rem .85rem; font-size: .76rem; letter-spacing: .13em; font-weight: 800 }
h1 { font-size: clamp(1.7rem, 6.7vw, 3.5rem); line-height: 1.23; margin: .55rem 0 .4rem; letter-spacing: -.035em; font-weight: 800 }
h1 span { color: #6b42de }
.intro p { margin: 0; color: var(--muted); font-size: clamp(.875rem, 2.5vw, 1rem) }
.profiles { display: flex; gap: .55rem; padding: .45rem; background: #fff; border: 1px solid var(--line); border-radius: 16px; margin-bottom: .8rem }
.tabs { flex: 1; min-width: 0; display: flex; gap: .4rem; overflow-x: auto; scrollbar-width: thin }
.tab { flex: 0 0 auto; max-width: 18rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: .55rem .85rem; background: #f8f5ff; color: #5e5278; border-radius: 10px; font-weight: 700; font-size: .86rem }
.tab.active { background: #eadeff; color: #5025b9 }
.add { flex-shrink: 0 }
.layout { display: grid; gap: .8rem }
.play, .history { min-width: 0; background: #fff; border: 1px solid var(--line); border-radius: 23px; box-shadow: 0 8px 28px #4426790a }
.play { padding: .5rem }
.stage { position: relative; isolation: isolate; overflow: hidden; border-radius: 17px; padding: .72rem .72rem .85rem; text-align: center; color: white; background: radial-gradient(ellipse at 50% 52%,#8955f5 6%,#5c32cc 47%,#361a84 100%) }
.stage::before { content: ''; position: absolute; z-index: -1; inset: 0; background: repeating-radial-gradient(circle at 50% 51%,transparent 0 47px,#eae0ff15 48px 49px); pointer-events: none }
.stage-top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .25rem }
.pill { padding: .25rem .55rem; background: #2811576b; border: 1px solid #e4d8ff44; color: #fff; border-radius: 99px; font-weight: 600; font-size: .78rem }
.counter { background: #f2eaff; color: #4c289f; margin-left: auto }
.art { display: grid; place-items: center; height: clamp(160px,45vw,245px); position: relative; }
.art img { display: block; width: min(93%, 455px); height: 100%; min-height: 0; position: absolute; inset: 0; margin: auto; object-fit: contain; filter: drop-shadow(0 11px 17px #1b075f60); animation: float 4s ease-in-out infinite }
.spark { position: absolute; z-index: -1; color: #fde382; animation: twinkle 3s ease-in-out infinite; font-size: 1.5rem }
.one { top: 29%; left: 9% }.two { top: 20%; right: 12%; animation-delay: -.7s }.three { top: 64%; left: 16%; animation-delay: -1.6s }.four { top: 60%; right: 9%; animation-delay: -2.2s }
.stage-center { position: relative }
.result-kicker { color: #fff1a1; letter-spacing: .07em; font-weight: 700; font-size: .8rem }
.result { font-size: clamp(1.6rem, 6vw, 2.65rem); font-weight: 800; line-height: 1.27; margin: .2rem 0; overflow-wrap: anywhere }
#hint { color: #efe5ff; margin: .25rem 0 0; font-size: .87rem; overflow-wrap: anywhere }
.controls { padding: .75rem .45rem .2rem; display: grid; gap: .45rem }
.primary { border-radius: 13px; background: #6b40ea; color: #fff; box-shadow: 0 4px 0 #4a26b7; font-weight: 800; padding: .6rem 1rem; transition: background .15s, transform .15s }
.primary:not(:disabled):hover { background: #784df0 }
.primary:not(:disabled):active { transform: translateY(2px); box-shadow: 0 2px 0 #4a26b7 }
.draw { background: linear-gradient(110deg,#5937da,#7c49f5); min-height: 54px; font-size: 1.12rem; width: 100% }
.utilities { display: flex; justify-content: space-between; gap: .25rem; margin-top: .3rem }
.link { color: #5b438e; background: transparent; border-radius: 9px; font-weight: 600; font-size: .87rem; padding: .2rem .4rem }
.link:hover { background: #f4edff }
.history { padding: 1rem; display: flex; flex-direction: column }
.history-header { display: flex; align-items: center; gap: .7rem; padding-bottom: .85rem; border-bottom: 1px solid var(--line) }
.history-icon { border-radius: 13px; background: #eee5ff; width: 43px; height: 43px; display: grid; place-items: center; color: #713ee8; font-size: 1.45rem; font-weight: 800 }
h2 { font-size: 1.12rem; margin: 0; line-height: 1.5 }
.history-header p { color: var(--muted); margin: 0; font-size: .87rem }
.empty { text-align: center; padding: 1.1rem 0; color: var(--muted); margin: auto }
.ticket { margin: auto; background: #f5efff; width: 58px; height: 58px; border-radius: 18px; display: grid; place-items: center; font-size: 1.6rem }
.empty p { margin: .65rem 0 .15rem; font-weight: 700; color: #544369 }
.history-list { margin: .65rem 0 0; list-style: none; padding: 0; max-height: 395px; overflow: auto }
.history-list li { background: #f8f5ff; display: flex; align-items: center; gap: .55rem; border-radius: 11px; padding: .55rem; margin-bottom: .42rem; overflow-wrap: anywhere }
.rank { display: grid; place-items: center; flex: 0 0 auto; min-width: 2rem; min-height: 2rem; padding: .12rem .3rem; border-radius: 8px; background: #e9dfff; color: #592eb9; font-weight: 800 }
.history-list small { display: block; color: var(--muted) }
footer { color: var(--muted); font-size: .85rem; text-align: center; padding: 1.15rem }
dialog { border: 1px solid var(--line); border-radius: 21px; padding: 1.15rem; max-width: min(31rem, calc(100% - 1.5rem)); width: 100%; max-height: 93dvh; color: inherit; box-shadow: 0 24px 80px #20104355 }
dialog::backdrop { background: #24134799; backdrop-filter: blur(3px) }
.dialog-head, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: .65rem }
.dialog-actions { justify-content: flex-end; margin: 1rem 0 .2rem }
#profile-form { display: grid; gap: .7rem }
label { display: grid; gap: .3rem; font-size: .92rem; font-weight: 700 }
label small, .form-note { color: var(--muted); font-weight: 400; font-size: .85rem; margin: 0 }
input:not([type=checkbox]), textarea, select { border: 1px solid #dcd1ef; border-radius: 10px; background: #fbf9ff; min-width: 0; width: 100%; padding: .55rem .65rem; color: inherit; font-size: 1rem }
select { appearance: none; padding-right: 2rem; background-image: linear-gradient(45deg,transparent 50%,#6a4aa4 50%),linear-gradient(135deg,#6a4aa4 50%,transparent 50%); background-position: calc(100% - 14px) center,calc(100% - 9px) center; background-size: 5px 5px; background-repeat: no-repeat }
textarea { resize: vertical }
.check { display: flex; align-items: center; min-height: 44px; gap: .5rem }
.check input { width: 19px; height: 19px; flex-shrink: 0; accent-color: var(--purple) }
.check small { display: block }
.error, .storage-note { background: #fff0f3; color: #92183c; border-radius: 10px; padding: .55rem .7rem; font-size: .88rem }
.storage-note { position: fixed; inset: auto 12px 12px; z-index: 5; text-align: center }
#confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 2 }
.piece { position: absolute; top: -12px; width: 8px; height: 13px; border-radius: 2px; animation: rain 1.35s var(--delay) ease-in both }
.stage.rolling img { animation: shake .29s ease-in-out infinite }
.stage.reveal .result { animation: pop .45s ease-out }
.stage.bounce img { animation: bounce .55s ease-out, float 4s .55s ease-in-out infinite }
.stage.flip img { animation: flip .52s ease-out, float 4s .52s ease-in-out infinite }
.stage.zoom img { animation: pop .52s ease-out, float 4s .52s ease-in-out infinite }
@keyframes twinkle { 50% { opacity: .32; transform: scale(.72) } }
@keyframes float { 50% { transform: translateY(-6px) } }
@keyframes shake { 25% { transform: rotate(-6deg) scale(.96) } 75% { transform: rotate(6deg) scale(1.02) } }
@keyframes pop { 0% { opacity: .35; transform: scale(.65) } 65% { transform: scale(1.12) } }
@keyframes bounce { 0% { transform: translateY(30px) scale(.84) } 55% { transform: translateY(-14px) scale(1.04) } }
@keyframes flip { 0% { opacity: .35; transform: rotateY(85deg) scale(.86) } }
@keyframes rain { to { transform: translate(var(--drift),430px) rotate(530deg); opacity: 0 } }
@media (min-width: 740px) {
  .wrap { width: min(100% - 52px,1120px) }
  .layout { grid-template-columns: minmax(0, 2.12fr) minmax(0, 1fr); gap: 1rem }
  .profiles { margin-bottom: 1rem }
  .play { padding: .7rem }
  .stage { padding: 1rem 1.1rem 1.25rem }
  .history { padding: 1.15rem }
  .controls { padding-inline: .72rem }
  .pill { font-size: .85rem }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important } #confetti { display: none } }
