:root {
  --bg1: #1b1446;
  --bg2: #2d1b69;
  --ink: #ffffff;
  --muted: #c9c3ee;
  --accent: #ff3d71;
  --accent2: #ffb020;
  --font: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, "Thonburi", "Sukhumvit Set", "Noto Sans Thai", "Myanmar MN", "Myanmar Sangam MN", "Noto Sans Myanmar", "Myanmar Text", "Padauk", "Pyidaungsu", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 15%, rgba(255, 61, 113, .28), transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(14, 165, 233, .28), transparent 42%),
    radial-gradient(circle at 80% 10%, rgba(139, 92, 246, .35), transparent 38%),
    linear-gradient(160deg, var(--bg1), var(--bg2));
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 1.2vh 2vw 4.5vh;
}

/* ---------- header ---------- */
.top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  height: 9vh;
  min-height: 48px;
}
.top h1 {
  font-size: clamp(1.4rem, 4.2vh, 3.2rem);
  font-weight: 800;
  letter-spacing: .02em;
  text-transform: uppercase;
}
.top h1 #t2 { color: var(--accent2); }
.top h1 { text-align: center; }
.right-tools { justify-self: end; display: flex; align-items: center; gap: .8vw; }
.lang { display: flex; gap: 4px; padding: 4px; border-radius: 16px; background: rgba(255,255,255,.1); border: 2px solid rgba(255,255,255,.25); }
.lang-btn {
  font-family: var(--font); font-weight: 800; letter-spacing: .05em;
  font-size: clamp(.7rem, 1.7vh, 1.1rem);
  padding: .35em .7em; border: none; border-radius: 11px;
  background: transparent; color: #fff; cursor: pointer; transition: background .2s;
}
.flag { display: block; width: 2.1em; height: 1.4em; border-radius: 4px; box-shadow: 0 0 0 1.5px rgba(0,0,0,.25); }
img.flag { object-fit: cover; object-position: left center; }
.lang-btn { display: grid; place-items: center; padding: .3em .45em; }
.lang-btn:hover { background: rgba(255,255,255,.2); }
.lang-btn.active { background: #fff; color: var(--bg1); }
.lang-btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

.icon-btn {
  width: clamp(40px, 5.4vh, 60px);
  height: clamp(40px, 5.4vh, 60px);
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, .25);
  background: rgba(255, 255, 255, .1);
  color: #fff;
  font-size: clamp(1.1rem, 2.8vh, 1.9rem);
  cursor: pointer;
  transition: background .2s, transform .15s;
}
.icon-btn:hover { background: rgba(255, 255, 255, .22); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.off { opacity: .55; }

/* ---------- stage ---------- */
.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
}

.wheel-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.wheel-area {
  flex: 1;
  min-height: 0;
  container-type: size;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wheel-box {
  position: relative;
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
  /* leave room for the pointer sticking out at the top */
  margin-top: 0;
}
@supports not (width: 1cqw) {
  .wheel-box { width: min(66vh, 90vw); height: min(66vh, 90vw); }
}

.wheel {
  position: absolute;
  inset: 5% 0 0 0;
  margin: auto;
  width: 94%;
  height: 94%;
  inset: auto;
  top: 6%;
  left: 3%;
  will-change: transform;
  filter: drop-shadow(0 1.6vh 2.4vh rgba(0, 0, 0, .45));
}
.wheel svg { width: 100%; height: 100%; display: block; overflow: visible; }

/* wheel sections */
.seg { transition: opacity .5s, filter .5s; }
.seg-inner { transition: transform .45s cubic-bezier(.2, 1.4, .4, 1); }
.wheel.done .seg { opacity: .42; filter: saturate(.6); }
.wheel.done .seg.win { opacity: 1; filter: none; }
.wheel.done .seg.win .seg-inner { transform: translate(0, -2.5px) scale(1.045); }
.seg .glow { opacity: 0; transition: opacity .4s; }
.wheel.done .seg.win .glow { opacity: 1; }

.pointer {
  position: absolute;
  top: -1%;
  left: 50%;
  width: 9%;
  margin-left: -4.5%;
  z-index: 3;
  transform-origin: 50% 25%;
  filter: drop-shadow(0 .6vh .9vh rgba(0, 0, 0, .5));
}
.pointer svg { width: 100%; display: block; }

.hub {
  position: absolute;
  left: 50%;
  top: calc(6% + 47%);
  width: 15%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #ddd7ff 70%);
  border: .7vh solid #1b1446;
  box-shadow: 0 .6vh 1.6vh rgba(0, 0, 0, .45), inset 0 -.5vh 1vh rgba(60, 40, 140, .25);
  display: grid;
  place-items: center;
  z-index: 2;
}
.hub i {
  width: 38%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--accent);
}

/* ---------- buttons ---------- */
.spin-row {
  display: flex;
  justify-content: center;
  padding-top: 2.4vh;
  padding-bottom: 1.5vh;
  transition: opacity .3s;
}
.stage.has-result .spin-row { opacity: 0; pointer-events: none; }

.big-btn {
  font-family: var(--font);
  font-weight: 900;
  letter-spacing: .06em;
  font-size: clamp(1.3rem, 4vh, 3rem);
  padding: .55em 1.8em;
  border: none;
  border-radius: 999px;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(135deg, #ff3d71, #ff8a3d);
  box-shadow: 0 .9vh 0 #b3204a, 0 1.8vh 3vh rgba(255, 61, 113, .45);
  transition: transform .12s, box-shadow .12s, filter .2s;
}
.big-btn:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.08); }
.big-btn:active:not(:disabled) { transform: translateY(.6vh); box-shadow: 0 .3vh 0 #b3204a, 0 .8vh 2vh rgba(255, 61, 113, .4); }
.big-btn:disabled {
  cursor: not-allowed;
  filter: grayscale(.7) brightness(.8);
  box-shadow: 0 .9vh 0 #5b4a75;
}
.big-btn:not(:disabled) { animation: pulse 2.2s ease-in-out infinite; }
@keyframes pulse {
  50% { box-shadow: 0 .9vh 0 #b3204a, 0 1.8vh 4.5vh rgba(255, 138, 61, .7); }
}
.big-btn:focus-visible, .icon-btn:focus-visible { outline: 4px solid #fff; outline-offset: 4px; }

/* ---------- result panel ---------- */
.result {
  flex: 0 0 0;
  min-width: 0;
  overflow: hidden;
  opacity: 0;
  display: flex;
  align-items: center;
  transition: flex-basis .7s cubic-bezier(.2, .9, .3, 1), opacity .5s;
}
.stage.has-result .result { flex-basis: 44%; opacity: 1; }

.result-inner {
  width: 40vw;
  min-width: 40vw;
  margin-left: 1.5vw;
  padding: 4vh 2.6vw;
  text-align: center;
  background: rgba(255, 255, 255, .1);
  border: 2px solid rgba(255, 255, 255, .22);
  border-radius: 40px;
  box-shadow: 0 2vh 5vh rgba(0, 0, 0, .35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.r-emoji {
  font-size: clamp(5rem, 22vh, 14rem);
  line-height: 1.05;
}
.stage.has-result .r-emoji { animation: pop .8s cubic-bezier(.2, 1.6, .4, 1) both .25s; }
@keyframes pop { from { transform: scale(0) rotate(-25deg); } to { transform: scale(1) rotate(0); } }

.r-title {
  margin-top: 1.4vh;
  font-size: clamp(1.8rem, 6.4vh, 4.6rem);
  font-weight: 900;
  line-height: 1.05;
  text-transform: uppercase;
  letter-spacing: .01em;
}
.r-quote {
  margin: 2vh 0 3.2vh;
  font-size: clamp(1.3rem, 4.1vh, 3rem);
  font-weight: 600;
  line-height: 1.3;
  color: #fff;
}
.big-btn.again { font-size: clamp(1.1rem, 3.2vh, 2.4rem); }

/* ---------- confetti ---------- */
#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

/* Thai / Burmese-script languages: no letter-spacing, taller lines */
html[lang="th"] .top h1, html[lang="my"] .top h1, html[lang="ksw"] .top h1,
html[lang="th"] .r-title, html[lang="my"] .r-title, html[lang="ksw"] .r-title,
html[lang="th"] .big-btn, html[lang="my"] .big-btn, html[lang="ksw"] .big-btn { letter-spacing: 0; line-height: 1.4; }
html[lang="th"] .r-quote, html[lang="my"] .r-quote, html[lang="ksw"] .r-quote { line-height: 1.6; }
html[lang="th"] .r-title, html[lang="my"] .r-title, html[lang="ksw"] .r-title { line-height: 1.45; }

/* ---------- touch niceties ---------- */
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

/* ---------- portrait / narrow screens (phones, tablets) ---------- */
@media (max-aspect-ratio: 1/1), (max-width: 700px) {
  .app { padding: max(1vh, env(safe-area-inset-top)) 4vw max(3.5vh, env(safe-area-inset-bottom)); }

  /* header: title on its own row, tools below */
  .top {
    height: auto;
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "sound title fs" "lang lang lang";
    row-gap: 1vh;
    padding-bottom: 1vh;
  }
  .top h1 { grid-area: title; font-size: clamp(.95rem, 4.6vw, 2.2rem); }
  .right-tools { display: contents; }
  #soundBtn { grid-area: sound; }
  .lang { grid-area: lang; justify-self: center; }
  #fsBtn { grid-area: fs; }
  .icon-btn { width: clamp(40px, 9vw, 56px); height: clamp(40px, 9vw, 56px); font-size: clamp(1.1rem, 4.5vw, 1.8rem); }
  .lang { flex-wrap: wrap; justify-content: center; }
  .lang-btn { font-size: clamp(.6rem, 2.6vw, 1rem); padding: .3em .4em; }

  .stage { flex-direction: column; }
  .stage.has-result .result { flex-basis: auto; }
  .result { flex: 0 0 auto; max-height: 0; transition: max-height .7s cubic-bezier(.2, .9, .3, 1), opacity .5s; align-items: flex-start; }
  .stage.has-result .result { max-height: 48%; overflow-y: auto; }
  .result-inner {
    width: 100%; min-width: 0; margin: 1vh 0 0; padding: 1.4vh 4vw 1.8vh;
    border-radius: 26px;
  }
  .r-emoji { font-size: clamp(3rem, 9vw, 6rem); }
  .r-title { margin-top: .4vh; font-size: clamp(1.3rem, 6vw, 2.8rem); }
  .r-quote { margin: 1vh 0 1.6vh; font-size: clamp(1rem, 4.4vw, 2rem); }

  .big-btn { font-size: clamp(1.1rem, 5.4vw, 2.2rem); padding: .6em 1.4em; box-shadow: 0 6px 0 #b3204a, 0 12px 24px rgba(255, 61, 113, .4); }
  .big-btn.again { font-size: clamp(1rem, 4.6vw, 1.8rem); }
  .big-btn:disabled { box-shadow: 0 6px 0 #5b4a75; }
  .spin-row { padding-top: 1.2vh; }
}

/* small tablet portrait / big phones: cap button width */
@media (max-width: 700px) {
  .big-btn { width: 100%; max-width: 420px; }
}

/* short landscape screens (phones turned sideways) */
@media (max-height: 520px) and (min-aspect-ratio: 1/1) {
  .top { height: 12vh; min-height: 40px; }
  .top h1 { font-size: clamp(1rem, 5vh, 1.6rem); }
  .icon-btn { width: 36px; height: 36px; font-size: 1rem; }
  .lang-btn { font-size: .75rem; }
  .result-inner { padding: 2vh 2vw; border-radius: 22px; }
  .r-emoji { font-size: clamp(2.6rem, 18vh, 5rem); }
  .r-title { font-size: clamp(1.1rem, 6vh, 2rem); }
  .r-quote { font-size: clamp(.9rem, 4.4vh, 1.5rem); margin: 1vh 0 1.8vh; }
  .big-btn { font-size: clamp(1rem, 5.5vh, 1.6rem); padding: .45em 1.4em; }
  .big-btn.again { font-size: clamp(.9rem, 4.5vh, 1.3rem); }
  .spin-row { padding-top: .6vh; }
}

@media (prefers-reduced-motion: reduce) {
  .big-btn:not(:disabled) { animation: none; }
}
