
:root{
  --bg:#0b1020;
  --card:#0f1733;
  --card2:#101b3d;
  --stroke:rgba(255,255,255,.10);
  --text:rgba(255,255,255,.92);
  --muted:rgba(255,255,255,.68);
  --muted2:rgba(255,255,255,.50);
  --good:#2dd4bf;
  --warn:#fbbf24;
  --bad:#fb7185;
  --accent:#60a5fa;
  --shadow: 0 18px 50px rgba(0,0,0,.35);
  --radius: 18px;
  --radius2: 22px;
}

*{box-sizing:border-box}
html,body{min-height:100%}

/*
  Background fix (scroll-safe):
  - Some browsers scroll the <html> element when body has height:100%.
  - That can cause the lower part of the page to show a different background.
  We render the gradients on a fixed layer so the background is consistent
  even when the page can scroll.
*/
html, body{height:100%;}
html{background: var(--bg);}
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: var(--text);
  background: transparent;
  position: relative;
  isolation: isolate; /* keep ::before behind content without escaping */
}
body::before{
  content:"";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: radial-gradient(1200px 800px at 15% 10%, rgba(96,165,250,.20), transparent 55%),
              radial-gradient(900px 600px at 90% 15%, rgba(45,212,191,.18), transparent 60%),
              radial-gradient(900px 700px at 40% 100%, rgba(251,113,133,.12), transparent 55%),
              var(--bg);
}

.app{
  min-height:100vh;
  display:flex;
  flex-direction:column;
}

.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: calc(18px + env(safe-area-inset-top)) 18px 0;
  gap:12px;
}

.topbarRight{display:flex; align-items:center; gap:10px; position:relative}

.pillBtn{
  cursor:pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select:none;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
.pillBtn:hover{background: rgba(255,255,255,.10)}
.pillBtn:active{transform: translateY(1px)}
.brand{display:flex; align-items:center; gap:12px;}
.logo{
  width:44px;height:44px;border-radius:14px;
  display:flex;align-items:center;justify-content:center;
  background: linear-gradient(135deg, rgba(96,165,250,.35), rgba(45,212,191,.20));
  border:1px solid var(--stroke);
  box-shadow: var(--shadow);
  font-size:20px;
}
.title{font-weight:800; letter-spacing:.2px}
.subtitle{font-size:13px; color: var(--muted); margin-top:2px}

.pill{
  padding:10px 12px;
  border-radius:999px;
  border:1px solid var(--stroke);
  background: rgba(255,255,255,.06);
  color: var(--muted);
  font-size:13px;
  white-space:nowrap;
}

.badge{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: rgba(96,165,250,.16);
  color: var(--text);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .2px;
  white-space: nowrap;
}
.badge.good{background: rgba(45,212,191,.14); border-color: rgba(45,212,191,.35)}
.badge.warn{background: rgba(251,191,36,.14); border-color: rgba(251,191,36,.35)}

.main{
  /* Wider layout on desktop so the bingo board can be bigger */
  width:min(1680px, 96vw);
  margin: 14px auto 0;
  padding: 14px 0 26px;
  position:relative;
  flex:1;
}

.card{
  background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.03));
  border:1px solid var(--stroke);
  border-radius: var(--radius2);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  padding: 18px;
}

.h1{font-size:22px; margin:0 0 10px}
.muted{color:var(--muted)}
.small{font-size:13px}

.joinForm{display:grid; gap:12px; margin-top:12px; max-width:520px}
.label{display:grid; gap:6px}
.label span{font-size:13px; color:var(--muted)}
.input, .textarea{
  width:100%;
  padding:12px 12px;
  border-radius: 14px;
  border:1px solid var(--stroke);
  background: rgba(0,0,0,.22);
  color:var(--text);
  outline:none;
}
.input:focus, .textarea:focus{border-color:rgba(96,165,250,.55); box-shadow:0 0 0 3px rgba(96,165,250,.18)}
.textarea{resize:vertical; min-height:140px; line-height:1.35}

.btn{
  border:1px solid var(--stroke);
  background: rgba(255,255,255,.08);
  color:var(--text);
  padding: 11px 14px;
  border-radius: 14px;
  cursor:pointer;
  font-weight:700;
  letter-spacing:.2px;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
.btn:hover{background: rgba(255,255,255,.12)}
.btn:active{transform: translateY(1px)}
.btn.primary{background: rgba(96,165,250,.22); border-color: rgba(96,165,250,.35)}
.btn.primary:hover{background: rgba(96,165,250,.28)}
.btn.success{background: rgba(45,212,191,.18); border-color: rgba(45,212,191,.35)}
.btn.success:hover{background: rgba(45,212,191,.24)}
.btn.danger{background: rgba(251,113,133,.26); border-color: rgba(251,113,133,.5); box-shadow: 0 10px 22px rgba(251,113,133,.18)}
.btn.danger:hover{background: rgba(251,113,133,.32)}
.btn.ghost{background: transparent}

.footer{
  padding: 12px 18px calc(18px + env(safe-area-inset-bottom));
  color: var(--muted2);
  font-size:12px;
}

.tips{display:grid; gap:12px; margin-top:14px}
.tip{display:flex; gap:12px; padding:12px; border-radius: 16px; border:1px solid var(--stroke); background: rgba(0,0,0,.18)}
.tipIcon{width:34px; height:34px; border-radius: 12px; display:flex; align-items:center; justify-content:center;
  background: rgba(255,255,255,.07); border:1px solid var(--stroke)}
.tipTitle{font-weight:800; font-size:14px}
.tipBody{color:var(--muted); font-size:13px; margin-top:2px; line-height:1.35}

.game{
  display:grid;
  gap:14px;
  /* Student play area (desktop): make the board larger.
     v5 was a bit too small on wide screens; upscale ~1.5x. */
  /* Bigger on PC screens */
  max-width: 1680px;
  width: 100%;
  margin: 0 auto;
}
.gameHeader{display:flex; align-items:flex-end; justify-content:space-between; gap:12px}
.meName{font-weight:900; font-size:20px}
.meMeta{color:var(--muted); font-size:13px; margin-top:2px}
.actions{display:flex; gap:10px; flex-wrap:wrap}

.boardWrap{
  background: linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.02));
  border:1px solid var(--stroke);
  border-radius: var(--radius2);
  box-shadow: var(--shadow);
  padding: 14px;
  /* Desktop: enlarge board (~1.5x vs v5) */
  /* Bigger board on desktop */
  max-width: 1600px;
  margin: 0 auto;
}

.board{
  display:grid;
  /* Use minmax(0,1fr) so long words won't force the column wider */
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}

.tile{
  border:1px solid var(--stroke);
  /* IMPORTANT: tiles are <button>, some browsers don't inherit text color.
     Explicitly set color + improve contrast for học sinh. */
  color: var(--text);
  background: linear-gradient(180deg, rgba(255,255,255,.075), rgba(0,0,0,.26));
  border-radius: 18px;
  /* Square tiles: keep board 5×5 neat */
  aspect-ratio: 1 / 1;
  /* Bigger + more "premium" spacing so words don't feel cramped */
  padding: 12px 10px;
  /* Bigger typography (especially on desktop) */
  font-size: clamp(16px, 1.45vw, 38px);
  /* Better Chinese font fallback */
  font-family: ui-sans-serif, system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  display:flex;
  align-items:center;
  justify-content:center;
  text-align:center;
  line-height:1.15;
  font-weight:900;
  letter-spacing:.15px;
  text-shadow: 0 1px 0 rgba(0,0,0,.45);
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select:none;
  cursor:pointer;
  position:relative;
  /* Create a stacking context so the selected ✓ badge can sit BEHIND text
     (fix: badge never covers the word even on small tiles). */
  z-index: 0;
  overflow:hidden;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.10), 0 10px 22px rgba(0,0,0,.22);
  transition: transform .08s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.tile::before{
  content:"";
  position:absolute;
  inset:0;
  pointer-events:none;
  /* subtle gloss */
  background: radial-gradient(520px 260px at 20% 15%, rgba(255,255,255,.11), transparent 58%);
  opacity: .75;
  z-index: -2;
}
.tile:hover{
  background: linear-gradient(180deg, rgba(255,255,255,.09), rgba(0,0,0,.24));
  border-color: rgba(255,255,255,.18);
}
.tile:active{transform: translateY(1px)}
.tile:focus-visible{
  outline: 3px solid rgba(96,165,250,.55);
  outline-offset: 2px;
}
.tile.on{
  border-color: rgba(45,212,191,.65);
  background: linear-gradient(180deg, rgba(45,212,191,.26), rgba(0,0,0,.22));
  box-shadow: 0 0 0 3px rgba(45,212,191,.14), inset 0 1px 0 rgba(255,255,255,.10), 0 14px 28px rgba(0,0,0,.20);
}
.tile.on::after{
  content:"✓";
  position:absolute;
  top:10px;
  right:10px;
  width:28px;
  height:28px;
  display:flex;
  align-items:center;
  justify-content:center;
  border-radius:999px;
  background: rgba(45,212,191,.16);
  border: 1px solid rgba(45,212,191,.55);
  font-size:16px;
  line-height:1;
  color: rgba(45,212,191,.95);
  pointer-events:none;
  /* Fix: never cover text */
  z-index:-1;
}

.legend{display:flex; gap:16px; align-items:center; flex-wrap:wrap; font-size:13px; color:var(--muted)}
.legendItem{display:flex; align-items:center; gap:8px}
.dot{width:10px;height:10px;border-radius:999px; border:1px solid var(--stroke)}
.dotOn{background: rgba(45,212,191,.6); border-color: rgba(45,212,191,.8)}
.dotOff{background: rgba(255,255,255,.08)}

.overlay{
  position:fixed; inset:0;
  display:flex; align-items:center; justify-content:center;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(7px);
  z-index:50;
  padding:18px;
}
.overlayCard{
  width:min(560px, 92vw);
  background: linear-gradient(180deg, rgba(255,255,255,.09), rgba(255,255,255,.04));
  border:1px solid var(--stroke);
  border-radius: var(--radius2);
  box-shadow: var(--shadow);
  padding: 18px;
}
.overlayTitle{font-weight:950; font-size:20px}
.overlayBody{margin-top:10px; font-size:16px; font-weight:850}
.overlayBody{white-space: pre-line;}
.overlayHint{margin-top:8px; font-size:13px}
.overlayCard .btn{margin-top:14px}

.toast{
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  right: calc(14px + env(safe-area-inset-right));
  left: auto;
  bottom: auto;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--stroke);
  /* More opaque for readability */
  background: rgba(15,23,51,.92);
  color: var(--text);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  z-index: 80;
  width: min(420px, 92vw);
  opacity: 0;
  transform: translate(12px,-12px);
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}

/* Allow multi-line status text in lobby */
#waitText{white-space: pre-line;}
.toast.is-show{
  opacity: 1;
  transform: translate(0,0);
  pointer-events: auto;
}
.toast.is-hide{
  opacity: 0;
  transform: translate(12px,-12px);
}

@media (prefers-reduced-motion: reduce){
  .toast{transition:none}
}


.rowBetween{display:flex; align-items:center; justify-content:space-between; gap:12px}
.rowGap{display:flex; gap:10px; flex-wrap:wrap; align-items:center}

.segmented{
  display:inline-flex;
  flex-wrap:wrap;
  gap:6px;
  padding: 6px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: rgba(0,0,0,.16);
}
.segBtn{
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 900;
  font-size: 13px;
  letter-spacing: .2px;
  transition: background .15s ease, border-color .15s ease, transform .08s ease;
}
.segBtn:hover{background: rgba(255,255,255,.10)}
.segBtn:active{transform: translateY(1px)}
.segBtn.active{
  background: rgba(96,165,250,.22);
  border-color: rgba(96,165,250,.35);
  color: var(--text);
}
.segBtn:disabled{opacity:.55; cursor:not-allowed}

.divider{height:1px; background: rgba(255,255,255,.10); margin: 12px 0}

.grid2{
  display:grid;
  grid-template-columns: 1.2fr 1fr;
  gap:12px;
  margin-top:12px;
}
.panel{
  border:1px solid var(--stroke);
  background: rgba(0,0,0,.16);
  border-radius: var(--radius2);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  padding: 14px;
}
.panel + .panel{margin-top:12px}
.panelTitle{font-weight:900; margin-bottom:10px}
.bigLabel{font-weight:900}
.toggleRow{display:flex; align-items:center; justify-content:space-between; gap:12px}
.list{display:grid; gap:8px; max-height: 320px; overflow:auto; padding-right:4px}
.listItem{
  border:1px solid var(--stroke);
  background: rgba(255,255,255,.06);
  border-radius: 14px;
  padding: 10px 12px;
}
.listItem.compact{padding: 8px 10px}
.listItemTitle{font-weight:900}
.listItemMeta{color:var(--muted); font-size:12px; margin-top:3px}

/* Compact list item (admin participants) */
.listItemRow{display:flex; align-items:center; justify-content:space-between; gap:12px}
.listItemRow .name{
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.listItemRow .time{color:var(--muted); font-size:12px; white-space:nowrap}
code{color: rgba(96,165,250,.95)}

.winnerBox{
  border:1px dashed rgba(45,212,191,.5);
  background: rgba(45,212,191,.08);
  border-radius: var(--radius2);
  padding: 14px;
}
.winnerName{font-weight:950; font-size:18px}
.winnerMeta{color:var(--muted); font-size:13px; margin-top:4px}

.switch{position:relative; display:inline-block; width:52px; height:30px; flex: 0 0 auto}
.switch input{display:none}
.slider{
  position:absolute; cursor:pointer;
  inset:0;
  background: rgba(255,255,255,.10);
  border:1px solid var(--stroke);
  border-radius:999px;
  transition: .15s;
}
.slider:before{
  position:absolute; content:"";
  height:22px; width:22px;
  left:4px; top:3px;
  background: rgba(255,255,255,.9);
  border-radius:999px;
  transition: .15s;
}
.switch input:checked + .slider{
  background: rgba(45,212,191,.22);
  border-color: rgba(45,212,191,.45);
}
.switch input:checked + .slider:before{transform: translateX(22px); background: rgba(45,212,191,.95)}

@media (max-width: 900px){
  .grid2{grid-template-columns: 1fr}
}
@media (max-width: 560px){
  .topbar{flex-direction:column; align-items:flex-start}
  .boardWrap{padding: 10px}
  .board{grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px}
  .tile{
    padding: 10px 8px;
    font-size: clamp(14px, 3.6vw, 20px);
    border-radius: 16px;
  }
  .tile.on::after{
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    font-size: 14px;
  }
}



/* -----------------------------
   Sound settings popover
   ----------------------------- */
.soundPopover{
  position:absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(360px, 92vw);
  padding: 14px;
  border-radius: 18px;
  border: 1px solid var(--stroke);
  background: rgba(15,23,51,.94);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  z-index: 90;
}
.soundPopoverTitle{
  font-weight: 950;
  letter-spacing: .2px;
}
.soundRow{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-top:10px;
}
.soundLabel{
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}
.range{
  width: 180px;
}
.select{
  width: 180px;
  padding: 10px 10px;
  border-radius: 14px;
  border:1px solid var(--stroke);
  background: rgba(0,0,0,.22);
  color: var(--text);
  outline:none;
}
.select:focus{
  border-color:rgba(96,165,250,.55);
  box-shadow:0 0 0 3px rgba(96,165,250,.18);
}
.soundHint{
  margin-top: 10px;
}

/* Small screens: popover should not go off-screen */
@media (max-width: 560px){
  .soundPopover{
    left: 0;
    right: auto;
    width: min(420px, 96vw);
  }
}

/* Fix: ensure HTML [hidden] works even when components define display */
[hidden]{display:none !important;}
