:root {
  --rows: 12;
  --cell: min(calc((100vw - 48px) / 6), calc((100svh - 300px) / 12), 56px);
}

.bx-layout {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 24px;
  align-items: start;
}
.bx-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.bx-title h1 { margin: 0; font-size: 40px; }
.bx-title p { margin: 4px 0 0; color: var(--muted); }
.bx-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 14px; }
.bx-side-btns .btn { flex: 1 1 auto; }
.bx-toggle { color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; cursor: pointer; }
.bx-toggle input { accent-color: var(--accent); }

.bx-center { display: flex; flex-direction: column; align-items: center; gap: 12px; }

/* current word bar */
.bx-word {
  width: calc(var(--cell) * 6 + 12px); min-height: 52px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px;
  transition: border-color .15s, box-shadow .15s;
}
.bx-word.valid { border-color: var(--good); box-shadow: 0 0 0 3px rgba(94, 224, 122, .15); }
.bx-word.shake { animation: shake .35s; border-color: var(--bad); }
.bx-word-tiles { display: flex; flex-wrap: wrap; gap: 3px; font-family: var(--font-display); font-weight: 700; font-size: 22px; letter-spacing: .04em; }
.bx-word-hint { font-family: var(--font-body); font-weight: 400; font-size: 13px; color: var(--muted); letter-spacing: 0; }
.bx-word-pts { font-family: var(--font-display); font-weight: 700; color: var(--good); white-space: nowrap; }
.bx-word-pts.bad { color: var(--muted); font-weight: 500; font-size: 13px; }
@keyframes shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-6px); } 40%,80% { transform: translateX(6px); } }

/* board */
.bx-board-wrap { position: relative; padding: 6px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.bx-board {
  position: relative; width: calc(var(--cell) * 6); height: calc(var(--cell) * var(--rows));
  background:
    linear-gradient(to right, rgba(255,255,255,.035) 1px, transparent 1px) 0 0 / var(--cell) var(--cell),
    linear-gradient(to bottom, rgba(255,255,255,.035) 1px, transparent 1px) 0 0 / var(--cell) var(--cell),
    #12132a;
  border-radius: 10px; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
}
.bx-danger {
  position: absolute; left: 0; right: 0; top: 0; height: calc(var(--cell) * 2);
  background: linear-gradient(to bottom, rgba(255, 93, 93, .22), transparent);
  border-top: 2px dashed rgba(255, 93, 93, .55); pointer-events: none; opacity: .5; transition: opacity .3s;
}
.bx-board.danger .bx-danger { opacity: 1; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.bx-board.paused .block { filter: blur(6px) grayscale(1); }

.block {
  position: absolute; width: var(--cell); height: var(--cell); padding: 2px;
  left: calc(var(--c) * var(--cell)); bottom: calc(var(--r) * var(--cell));
  transition: bottom .28s cubic-bezier(.3, 1.3, .6, 1), left .2s;
  pointer-events: none;
}
.block .face {
  width: 100%; height: 100%; border-radius: 9px; position: relative;
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: calc(var(--cell) * .5); line-height: 1;
  color: #231a00; background: var(--tile, #ffcc33);
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.22), inset 0 2px 0 rgba(255,255,255,.35);
  transition: transform .12s, background .12s;
}
.block .face.qu { font-size: calc(var(--cell) * .38); }
.block .v { position: absolute; right: 5px; bottom: 4px; font-size: calc(var(--cell) * .2); opacity: .7; }
.block.t1 { --tile: #ffcc33; }
.block.t2 { --tile: #ffb547; }
.block.t3 { --tile: #4fd1c5; }
.block.t4 { --tile: #ff8fa8; }
.block.t5 { --tile: #b79cff; }
.block.sel .face { background: #fff; transform: scale(.92); color: #111; box-shadow: 0 0 0 3px var(--good), inset 0 -4px 0 rgba(0,0,0,.15); }
.block.can .face::after { content: ""; position: absolute; inset: 0; border-radius: 9px; box-shadow: inset 0 0 0 2px rgba(255,255,255,.55); }
.block.blast { transition: none; z-index: 3; }
.block.blast .face { animation: blast .38s ease-out forwards; }
@keyframes blast { 0% { transform: scale(1); background: #fff; } 40% { transform: scale(1.25); background: #fff; } 100% { transform: scale(0); opacity: 0; } }
.block.warn .face { animation: warn .5s infinite alternate; }
.block.dropin .face { animation: dropin .3s ease-out; }
@keyframes dropin { from { transform: translateY(-40%); opacity: .2; } }

.col-warn { position: absolute; top: 0; bottom: 0; width: var(--cell); background: rgba(255, 93, 93, .18); border-left: 2px solid var(--bad); border-right: 2px solid var(--bad); animation: pulse .5s infinite; pointer-events: none; z-index: 2; }
.flood-warn { position: absolute; inset: 0; background: rgba(79, 209, 197, .14); animation: pulse .5s infinite; pointer-events: none; z-index: 2; }

.bx-path { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; }
.bx-path polyline { fill: none; stroke: var(--good); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; opacity: .75; }

.pop { position: absolute; z-index: 6; font-family: var(--font-display); font-weight: 700; font-size: 26px; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.4); pointer-events: none; transform: translate(-50%, -50%); animation: pop 1s ease-out forwards; white-space: nowrap; }
@keyframes pop { to { transform: translate(-50%, -160%); opacity: 0; } }

.bx-next { display: grid; grid-template-columns: repeat(6, var(--cell)); width: calc(var(--cell) * 6); margin-top: 4px; opacity: .35; }
.bx-next span { text-align: center; font-family: var(--font-display); font-weight: 700; font-size: calc(var(--cell) * .32); color: var(--muted); padding: 3px 0; }
.bx-timer { position: relative; height: 18px; margin-top: 6px; border-radius: 999px; background: #0c0d1e; overflow: hidden; }
.bx-timer-fill { position: absolute; inset: 0; width: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transform-origin: left; }
.bx-timer.low .bx-timer-fill { background: linear-gradient(90deg, var(--accent-3), var(--bad)); }
.bx-timer span { position: relative; display: block; text-align: center; font: 700 11px/18px var(--font-display); color: #0b0c1a; }

.bx-alert {
  position: absolute; left: 50%; top: 30%; transform: translate(-50%, -50%) scale(.6); z-index: 8;
  font-family: var(--font-display); font-weight: 700; font-size: 26px; text-align: center; white-space: nowrap;
  padding: 10px 18px; border-radius: 12px; background: var(--bad); color: #fff; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; box-shadow: var(--shadow);
}
.bx-alert.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.bx-alert.info { background: var(--accent-2); color: #062421; }
.bx-alert.gold { background: var(--accent); color: var(--accent-ink); }
.bx-alert small { display: block; font-size: 13px; font-weight: 500; }

.bx-actions { width: calc(var(--cell) * 6 + 12px); }
.bx-actions .btn { flex: 1; padding: 13px 10px; }
.bx-blast { font-size: 16px; flex: 1.6 !important; }

.bx-words h3, .bx-values h3 { margin: 0 0 10px; font-size: 15px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.bx-words ol { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.bx-words li { display: flex; justify-content: space-between; font-family: var(--font-display); font-weight: 600; padding: 5px 8px; border-radius: 6px; background: var(--panel-2); text-transform: uppercase; }
.bx-words li b { color: var(--accent); }
.bx-words li.fresh { animation: fresh .6s; }
@keyframes fresh { from { background: var(--good); color: #062; } }
.bx-empty { color: var(--muted); font-size: 14px; margin: 0; }
.bx-value-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.bx-value-grid div { background: var(--panel-2); border-radius: 6px; text-align: center; padding: 4px 0; font-family: var(--font-display); font-weight: 700; font-size: 14px; }
.bx-value-grid div small { display: block; color: var(--muted); font-size: 10px; font-weight: 500; }

.bx-help { text-align: left; max-width: 480px; }
.bx-help h2 { text-align: center; }
.bx-help ul { padding-left: 18px; line-height: 1.55; color: var(--text); }
.bx-help .btn { display: block; margin: 16px auto 0; }
.bx-final { font-family: var(--font-display); font-size: 56px; font-weight: 700; color: var(--accent) !important; margin: 4px 0; }

@media (max-width: 1000px) {
  .bx-layout { grid-template-columns: 1fr; gap: 8px; }
  .bx-center { order: 1; gap: 8px; }
  .bx-right { order: 2; max-width: 520px; width: 100%; margin: 12px auto 0; }
  .bx-title, .bx-left .bx-toggle { display: none; }
  .bx-left { align-items: center; gap: 8px; }
  .bx-stats { width: calc(var(--cell) * 6 + 12px); padding: 6px 12px; }
  .bx-stats .value { font-size: 17px; }
  .bx-stats .label { font-size: 10px; }
  .bx-side-btns { width: calc(var(--cell) * 6 + 12px); flex-wrap: nowrap; gap: 6px; }
  .bx-side-btns .btn { padding: 8px 6px; font-size: 12px; flex: 1; }
  .bx-word { min-height: 44px; padding: 6px 10px; }
  .bx-word-tiles { font-size: 19px; }
  .bx-next { display: none; }
  .bx-timer { height: 8px; margin-top: 5px; }
  .bx-timer span { display: none; }
  .bx-actions .btn { padding: 12px 8px; }
  :root { --cell: min(calc((100vw - 48px) / 6), calc((100vh - 300px) / 12), calc((100dvh - 300px) / 12), 56px); }
}
.wrap:has(.bx-layout) { padding-top: 0; }
@media (max-width: 640px) { .topbar { padding: 10px 16px; } }
.bx-help .bx-toggle { margin-top: 12px; justify-content: center; }

/* ---- special blocks ---- */
.block.special .face { background: #24275a; box-shadow: inset 0 0 0 2px #4b4f9a, inset 0 -4px 0 rgba(0,0,0,.3); }
.block.special .face svg { width: 78%; height: 78%; }
.block.bomb .face { background: radial-gradient(circle at 50% 45%, #d8363f 0%, #7a1622 60%, #3d0a14 100%); box-shadow: inset 0 0 0 2px rgba(255, 120, 110, .6), 0 0 12px rgba(255, 70, 60, .35), inset 0 -4px 0 rgba(0,0,0,.3); }
.block.star .face { background: radial-gradient(circle at 50% 45%, #5b3fd9 0%, #2c1f7a 55%, #170f45 100%); box-shadow: inset 0 0 0 2px rgba(255, 216, 77, .55), 0 0 12px rgba(255, 200, 60, .35), inset 0 -4px 0 rgba(0,0,0,.3); }
.block.star .face svg { width: 86%; height: 86%; overflow: visible; }
.block.star .glow { filter: drop-shadow(0 0 3px rgba(255, 220, 90, .9)); transform-origin: 20px 21px; animation: starPulse 1.8s ease-in-out infinite; }
.block.star .twinkle { animation: twinkle 1.2s ease-in-out infinite alternate; }
@keyframes starPulse { 50% { transform: scale(1.07) rotate(4deg); } }
@keyframes twinkle { from { opacity: .25; } to { opacity: 1; } }
.block.bomb .face svg { width: 80%; height: 80%; overflow: visible; }
.block.bomb .spark { transform-origin: 36px 5.4px; animation: spark .45s infinite alternate; }
@keyframes spark { to { transform: scale(.55) rotate(30deg); opacity: .7; } }
.block.armed .face { animation: armed .35s infinite alternate; }
@keyframes armed { to { transform: scale(1.08); box-shadow: 0 0 0 3px #ff5d5d, 0 0 18px #ff5d5d; } }
.block.star.armed .face { animation-name: armedStar; }
@keyframes armedStar { to { transform: scale(1.08); box-shadow: 0 0 0 3px #ffd84d, 0 0 22px #ffd84d; } }
.block.doomed .face::before { content: ""; position: absolute; inset: 0; border-radius: 9px; background: rgba(255, 93, 93, .35); box-shadow: inset 0 0 0 2px rgba(255, 93, 93, .8); }
.block.boom { transition: none; z-index: 4; }
.block.boom .face { animation: boom .45s ease-out forwards; }
@keyframes boom { 0% { transform: scale(1); } 30% { transform: scale(1.7); background: #ffd23f; box-shadow: 0 0 40px 16px #ff8a00; } 100% { transform: scale(2.2); opacity: 0; background: #ff5d00; } }
.bx-board-wrap.shake { animation: boardShake .4s; }
@keyframes boardShake { 0%,100% { transform: none; } 20% { transform: translate(-5px, 3px); } 40% { transform: translate(5px, -3px); } 60% { transform: translate(-3px, -2px); } 80% { transform: translate(3px, 2px); } }

.pop.boom-pop { color: #ffd23f; font-size: 30px; text-shadow: 0 0 12px #ff5d00, 0 2px 0 #000; }
.pop.bonus-pop { color: #ffd23f; font-size: 22px; }
.pop.magic-pop { color: #d8ccff; font-size: 22px; text-shadow: 0 0 12px #7b5cff, 0 2px 0 #000; }
.bx-boom-tag { font-style: normal; font-size: 10px; background: #e5383b; color: #fff; padding: 2px 5px; border-radius: 4px; vertical-align: 2px; letter-spacing: .04em; }

.hole-warn { position: absolute; width: var(--cell); background: rgba(255, 93, 93, .22); outline: 2px dashed var(--bad); outline-offset: -3px; border-radius: 8px; animation: pulse .5s infinite; pointer-events: none; z-index: 2; }
.hole-warn.flood { background: rgba(79, 209, 197, .22); outline-color: var(--accent-2); }

.bx-next span svg { width: 1.3em; height: 1.3em; vertical-align: middle; }

.bx-specials h3 { margin: 0 0 10px; font-size: 15px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.bx-special-row { display: flex; gap: 10px; align-items: center; }
.bx-special-row + .bx-special-row { margin-top: 10px; }
.bx-special-row p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.45; }
.bx-special-row p b { color: var(--text); }
.bx-special-icon { flex: none; width: 40px; height: 40px; border-radius: 9px; display: grid; place-items: center; background: #24275a; }
.bx-special-icon.bomb { background: radial-gradient(circle at 50% 45%, #d8363f 0%, #7a1622 60%, #3d0a14 100%); box-shadow: inset 0 0 0 2px rgba(255, 120, 110, .6); }
.bx-special-icon.star { background: radial-gradient(circle at 50% 45%, #5b3fd9 0%, #2c1f7a 55%, #170f45 100%); box-shadow: inset 0 0 0 2px rgba(255, 216, 77, .55); }
.bx-special-icon .glow { filter: drop-shadow(0 0 3px rgba(255, 220, 90, .9)); }
.bx-special-icon svg { width: 30px; height: 30px; }


/* ---- start screen ---- */
.bx-start {
  position: absolute; inset: 6px; z-index: 9; border-radius: 10px;
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 16px; text-align: center; background: rgba(15, 16, 32, .78); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.bx-start.show { display: flex; }
.bx-start h2 { margin: 0; font-size: 34px; color: var(--accent); }
.bx-start p { margin: 0 0 4px; color: var(--muted); font-size: 14px; }
.bx-diff { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 230px; }
.bx-diff button {
  appearance: none; cursor: pointer; text-align: left; color: var(--text);
  background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 9px 14px;
  font-family: var(--font-body); transition: border-color .15s, background .15s, transform .1s;
}
.bx-diff button:hover { border-color: var(--muted); }
.bx-diff button.on { border-color: var(--accent); background: #2f2a3f; }
.bx-diff b { display: block; font: 700 17px var(--font-display); }
.bx-diff small { color: var(--muted); font-size: 12px; }
.bx-diff button.on b { color: var(--accent); }
.bx-start-btn { width: 100%; max-width: 230px; padding: 14px; font-size: 18px; margin-top: 4px; }
.bx-link { appearance: none; background: none; border: 0; color: var(--muted); font: 500 13px var(--font-body); text-decoration: underline; cursor: pointer; }
.bx-board.waiting .block { filter: saturate(.4) brightness(.7); }

.bx-sound { flex: 0 0 auto !important; padding: 8px 12px; display: grid; place-items: center; }
.bx-sound svg { width: 20px; height: 20px; }
.bx-sound .cross { display: none; }
.bx-sound.muted .cross { display: inline; }
.bx-sound.muted .waves { display: none; }
.bx-sound.muted { color: var(--muted); }
.bx-short { display: none; }
.bx-over-btns { justify-content: center; }

@media (max-width: 1000px) {
  .bx-long { display: none; }
  .bx-short { display: inline; }
  .bx-start { gap: 7px; padding: 10px; }
  .bx-start h2 { font-size: 26px; }
  .bx-diff button { padding: 7px 12px; }
  .bx-diff b { font-size: 15px; }
  .bx-start-btn { padding: 11px; font-size: 16px; }
}
#bestLabel { white-space: nowrap; }

/* ---- magic star wish mode ---- */
.bx-board.wishing { box-shadow: inset 0 0 0 2px rgba(255, 216, 77, .6), inset 0 0 40px rgba(123, 92, 255, .35); }
.bx-board.wishing .block:not(.special):not(.wish) .face { filter: saturate(.55) brightness(.85); }
.block.wish .face { background: #fff3b0; transform: scale(.94); box-shadow: 0 0 0 3px #ffd84d, 0 0 16px rgba(255, 216, 77, .8); animation: wishGlow .6s ease-in-out infinite alternate; }
@keyframes wishGlow { to { box-shadow: 0 0 0 3px #ffd84d, 0 0 26px rgba(255, 216, 77, 1); } }
.bx-word.wish-mode { border-color: #ffd84d; }
.bx-word.wish-mode.valid { box-shadow: 0 0 0 3px rgba(255, 216, 77, .2); }
.bx-alert.star { background: linear-gradient(135deg, #5b3fd9, #2c1f7a); color: #fff3b0; }
