.rw { --g: #2ec27e; --y: #e5b43c; --x: #2b3448; --ytext: #1a1200; max-width: 560px; margin: 0 auto; padding: 10px 8px 18px; user-select: none; color: #dfe9ff; }
.rw.cb { --g: #f5793a; --y: #85c0f9; --ytext: #0b1328; }
.rw [hidden] { display: none !important; }
.rw-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 0 0 10px; }
.rw-modes { display: inline-flex; padding: 3px; gap: 2px; background: #0b1328; border: 1px solid #1c2b4a; border-radius: 999px; }
.rw-mode { background: transparent; color: #8aa3c4; border: 0; border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: 13px; cursor: pointer; transition: background-color .2s, color .2s; }
.rw-mode:hover { color: #dfe9ff; }
.rw-mode.is-on { background: #55d6ff; color: #04111f; }
.rw-mode:focus-visible { outline: 2px solid #dfe9ff; outline-offset: -2px; }
.rw-tools { display: flex; gap: 6px; }
.rw-ibtn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: #0b1328; color: #dfe9ff; border: 1px solid #1c2b4a; border-radius: 10px; padding: 0 12px; height: 36px; font-weight: 700; font-size: 13px; cursor: pointer; min-width: 36px; transition: border-color .15s, background-color .15s, opacity .15s; }
.rw-ibtn svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.rw-icon { padding: 0; width: 36px; color: #b8c9e2; }
.rw-ibtn:hover:not(:disabled) { border-color: #55d6ff; color: #fff; }
.rw-ibtn:active:not(:disabled) { background: #13203d; }
.rw-ibtn:disabled { opacity: 0.4; cursor: default; }
.rw-subbar { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; min-height: 36px; }
.rw-hintbtn { margin-left: auto; color: #ffd166; }
.rw-hintleft { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: rgba(255,209,102,0.16); font-size: 11px; line-height: 18px; text-align: center; }
.rw-hintleft:empty { display: none; }
.rw-sub { font-size: 13px; color: #8aa3c4; display: flex; gap: 8px 12px; flex-wrap: wrap; align-items: center; min-width: 0; }
.rw-sub b { color: #ffd166; }
.rw-sub .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.rw-sub select { appearance: none; -webkit-appearance: none; background: #0b1328 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238aa3c4' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 9px center / 10px 6px; color: #dfe9ff; border: 1px solid #1c2b4a; border-radius: 8px; padding: 0 26px 0 10px; height: 32px; font-size: 13px; font-weight: 600; cursor: pointer; }
.rw-sub select:hover { border-color: #55d6ff; }
.rw-link { background: none; border: 0; padding: 4px 2px; color: #55d6ff; font-weight: 700; font-size: 13px; cursor: pointer; }
.rw-link:hover { text-decoration: underline; }
.rw-pill { font-size: 10.5px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: #ffd166; border: 1px solid rgba(255,209,102,0.4); border-radius: 999px; padding: 2px 8px; }
.rw-clock { font-variant-numeric: tabular-nums; color: #dfe9ff; font-weight: 600; }
.rw-clock::before { content: '⏱ '; }
.rw-main { position: relative; display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: stretch; margin: 0 0 10px; }
.rw-main .rw-board { grid-column: 2; }
.rw-pad { grid-column: 1; justify-self: end; width: 64px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; position: relative; }
.rw-rocket { width: 54px; height: auto; transition: transform .3s; }
.rw-fuelcell { fill: #1c2b4a; }
.rw-fuelcell.on { fill: #ffd166; }
.rw-flame { opacity: 0; transform-origin: 30px 96px; }
.rw-pad.lit .rw-flame { opacity: 1; animation: rw-flicker .18s infinite alternate; }
.rw-pad.launch .rw-rocket { animation: rw-launch 1.6s ease-in forwards; }
.rw-pad.launch .rw-flame { opacity: 1; animation: rw-flicker .1s infinite alternate; }
.rw-pad.scrub .rw-rocket { transform: rotate(8deg) translateY(4px); filter: grayscale(0.6); }
.rw-padbase { width: 56px; height: 6px; background: #3d5a7a; border-radius: 3px; box-shadow: 0 0 10px rgba(85,214,255,0.3); }
.rw-count { font-size: 11px; font-weight: 800; letter-spacing: 0.1em; color: #7f9bc0; margin-top: 6px; }
.rw-board { display: grid; grid-template-rows: repeat(6, 1fr); gap: 6px; width: min(100%, 330px); }
.rw-board.len6 { width: min(100%, 372px); }
.rw-row { display: grid; grid-template-columns: repeat(var(--cols, 5), 1fr); gap: 6px; position: relative; }
.rw-row.shake { animation: rw-shake .45s; }
.rw-row.win .rw-tile { animation: rw-bounce .5s ease; }
.rw-tile { aspect-ratio: 1; transition: border-color .1s; display: flex; align-items: center; justify-content: center; font-size: clamp(20px, 6.5vw, 30px); font-weight: 800; text-transform: uppercase; color: #fff; border: 2px solid #1c2b4a; border-radius: 6px; background: #060b18; position: relative; }
.rw-tile.filled { border-color: #3d5a7a; animation: rw-pop .1s; }
.rw-tile.hintfill { border-color: #ffd166; color: #ffd166; }
.rw-tile.flip { animation: rw-flip .42s ease forwards; }
.rw-tile.g { background: var(--g); border-color: var(--g); }
.rw-tile.y { background: var(--y); border-color: var(--y); color: var(--ytext); }
.rw-tile.x { background: var(--x); border-color: var(--x); color: #9aa7b8; }
.rw-toastwrap { position: absolute; left: 0; right: 0; top: 10px; z-index: 5; display: flex; justify-content: center; pointer-events: none; }
.rw-toast { padding: 7px 14px; border-radius: 999px; background: #dfe9ff; color: #04111f; font-weight: 700; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,0.35); opacity: 0; transform: translateY(4px) scale(0.96); transition: opacity .18s, transform .18s; pointer-events: none; }
.rw-toast.on { opacity: 1; transform: none; }
.rw-known { min-height: 18px; text-align: center; font-size: 12.5px; color: #8aa3c4; margin: 0 0 8px; display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 14px; }
.rw-known b { color: #dfe9ff; }
.rw-keys { display: grid; gap: 6px; }
.rw-keyrow { display: flex; justify-content: center; gap: 5px; }
.rw-key { flex: 1 1 0; min-width: 0; padding: 0; max-width: 44px; height: 54px; border: 0; border-radius: 7px; background: #223253; color: #fff; font-weight: 800; font-size: 15px; text-transform: uppercase; cursor: pointer; touch-action: manipulation; position: relative; display: flex; align-items: center; justify-content: center; transition: background-color .2s, color .2s, transform .06s; -webkit-tap-highlight-color: transparent; }
.rw-key:hover { filter: brightness(1.12); }
.rw-key:active { transform: scale(0.94); filter: brightness(1.25); }
.rw-key svg { width: 22px; height: 22px; }
.rw-key.wide { flex: 1.8 1 0; max-width: 78px; font-size: 12px; letter-spacing: 0.04em; }
.rw-key.launch { background: #3d5a7a; }
.rw-key.wide:not(.launch) { background: #2b3d63; }
.rw-key.g { background: var(--g); } .rw-key.y { background: var(--y); color: var(--ytext); } .rw-key.x { background: #141c2e; color: #5f6b80; }
.rw-key .n { position: absolute; top: 2px; right: 4px; font-size: 9px; background: rgba(0,0,0,0.45); border-radius: 6px; padding: 0 4px; }
.rw-overlay { position: fixed; inset: 0; background: rgba(2,5,14,0.72); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 16px; animation: rw-fade .18s ease; }
.rw-dialog { position: relative; background: #0b1328; border: 1px solid #244b6b; border-radius: 16px; padding: 22px 22px 20px; width: min(100%, 420px); max-height: min(90vh, 90dvh); overflow: auto; overscroll-behavior: contain; color: #dfe9ff; font-size: 14px; box-shadow: 0 24px 60px rgba(0,0,0,0.5); animation: rw-rise .22s cubic-bezier(.2,.9,.3,1.2); }
.rw-dialog:focus { outline: none; }
.rw-dialog h3 { margin: 0 36px 12px 0; color: #fff; font-size: 21px; }
.rw-dialog h4 { margin: 14px 0 6px; color: #9fd9ff; font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; }
.rw-dialog p { margin: 0 0 10px; line-height: 1.5; }
.rw-x { position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; background: #13203d; border: 0; border-radius: 50%; color: #8aa3c4; cursor: pointer; transition: background-color .15s, color .15s; }
.rw-x svg { width: 14px; height: 14px; }
.rw-x:hover { background: #1c2b4a; color: #fff; }
.rw-statrow { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; text-align: center; margin: 0 0 16px; gap: 4px; }
.rw-statrow b { display: block; font-size: 24px; color: #fff; font-variant-numeric: tabular-nums; }
.rw-statrow span { display: block; font-size: 11px; line-height: 1.25; color: #8aa3c4; }
.rw-dist { display: grid; gap: 4px; margin: 0 0 14px; }
.rw-dist div { display: grid; grid-template-columns: 14px 1fr; gap: 8px; align-items: center; font-size: 12px; }
.rw-dist i { display: block; background: #2b3448; color: #fff; font-style: normal; font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 4px; text-align: right; font-variant-numeric: tabular-nums; transform-origin: left; animation: rw-grow .5s ease both; }
.rw-dist i.hit { background: var(--g); }
.rw-answer { margin: 0 0 12px; font-size: 15px; color: #ffd166; font-weight: 700; }
.rw-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.rw-btn { background: #0b1328; color: #dfe9ff; border: 1px solid #244b6b; border-radius: 10px; padding: 0 16px; height: 40px; font-weight: 700; font-size: 14px; cursor: pointer; transition: border-color .15s, background-color .15s, transform .06s; }
.rw-btn:hover { border-color: #55d6ff; }
.rw-btn:active { transform: scale(0.97); }
.rw-btn:disabled { cursor: default; }
.rw-btn-primary { background: #ffd166; color: #1a1200; border-color: #ffd166; }
.rw-btn-primary:hover { background: #ffe08a; border-color: #ffe08a; }
.rw-shield { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: #9fd9ff; margin: 0 0 10px; }
.rw-shield .bar { width: 70px; height: 6px; background: #1c2b4a; border-radius: 3px; overflow: hidden; }
.rw-shield .bar i { display: block; height: 100%; background: #55d6ff; }
.rw-setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid #1c2b4a; }
.rw-setting small { display: block; color: #7f9bc0; font-size: 12px; }
.rw-switch { width: 42px; height: 24px; border-radius: 12px; background: #2b3448; border: 0; position: relative; cursor: pointer; flex: none; }
.rw-switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .15s; }
.rw-switch { transition: background-color .15s; }
.rw-switch.on { background: #2ec27e; } .rw-switch.on::after { left: 21px; }
.rw-example { display: inline-grid; grid-template-columns: repeat(5, 28px); gap: 3px; margin: 2px 0 6px; }
.rw-example span { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; font-weight: 800; border-radius: 4px; font-size: 13px; background: #060b18; border: 2px solid #1c2b4a; }
.rw-example span.g { background: var(--g); border-color: var(--g); } .rw-example span.y { background: var(--y); border-color: var(--y); color: var(--ytext); } .rw-example span.x { background: var(--x); border-color: var(--x); }
.rw-archive { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 6px; max-height: 300px; overflow: auto; }
.rw-archive button { background: #060b18; border: 1px solid #1c2b4a; color: #dfe9ff; border-radius: 8px; height: 36px; font-size: 13px; font-weight: 600; cursor: pointer; font-variant-numeric: tabular-nums; }
.rw-archive button:hover { border-color: #55d6ff; }
.rw-archive button.won { border-color: #2ec27e; color: #7ee2b0; } .rw-archive button.lost { border-color: #ff6b81; color: #ff9aaa; }
.rw-archive button.cur { background: #13203d; }
.rw-stars { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.rw-star { position: absolute; width: 6px; height: 6px; border-radius: 50%; background: #ffd166; animation: rw-star 1.2s ease-out forwards; }
textarea.rw-code { display: block; width: 100%; height: 70px; resize: none; padding: 8px 10px; background: #060b18; color: #9fd9ff; border: 1px solid #1c2b4a; border-radius: 8px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; user-select: text; transition: border-color .15s; }
textarea.rw-code:focus { outline: none; border-color: #55d6ff; }
textarea.rw-code.bad { border-color: #ff6b81; animation: rw-shake .45s; }
@keyframes rw-pop { 50% { transform: scale(1.1); } }
@keyframes rw-flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes rw-shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); } 30%, 50%, 70% { transform: translateX(-6px); } 40%, 60% { transform: translateX(6px); } }
@keyframes rw-bounce { 30% { transform: translateY(-10px); } 60% { transform: translateY(3px); } }
@keyframes rw-flicker { from { transform: scaleY(0.8); } to { transform: scaleY(1.15); } }
@keyframes rw-launch { 0% { transform: translateY(0); } 20% { transform: translateY(2px) translateX(-1px); } 80% { opacity: 1; } 100% { transform: translateY(-420px); opacity: 0; } }
@keyframes rw-fade { from { opacity: 0; } }
@keyframes rw-rise { from { opacity: 0; transform: translateY(12px) scale(0.98); } }
@keyframes rw-grow { from { transform: scaleX(0.2); opacity: 0; } }
@keyframes rw-star { to { transform: translate(var(--dx), var(--dy)); opacity: 0; } }
@media (max-width: 480px) {
  .rw-pad { display: none; } .rw-main { grid-template-columns: 1fr; } .rw-main .rw-board { grid-column: 1; justify-self: center; }
  .rw-key { height: 52px; font-size: 14px; } .rw-key.wide { font-size: 10.5px; } .rw { padding: 8px 0 14px; } .rw-keyrow { gap: 4px; }
  .rw-mode { padding: 6px 11px; } .rw-tools { gap: 4px; } .rw-icon { width: 34px; height: 34px; }
  .rw-hintbtn { padding: 0 10px; }
}

/* full-screen (shared stage.js): board fills the space between the toolbar and a keyboard pinned to the bottom */
.stage.is-immersive .rw { display: flex; flex-direction: column; width: 100%; max-width: 600px; margin: 0 auto; padding: 10px 10px max(10px, env(safe-area-inset-bottom, 0px)); }
.stage.is-immersive .rw-main { flex: 1 1 auto; min-height: 0; margin: 0 0 8px; align-items: center; container: rwmain / size; }
.stage.is-immersive .rw-board { --bw: min(100cqw, 400px, calc((100cqh - 30px) * 5 / 6 + 24px)); width: var(--bw); }
.stage.is-immersive .rw-board.len6 { --bw: min(100cqw, 440px, 100cqh); }
.stage.is-immersive .rw-tile { font-size: calc(var(--bw) / var(--cols, 5) * 0.5); }
.stage.is-immersive .rw-pad { align-self: end; }
@container rwmain (max-height: 330px) { .rw-pad { display: none; } }
.stage.is-immersive .rw-keys { flex: none; }
.stage.is-immersive .rw-key { height: clamp(42px, 7.2vh, 58px); }
@media (max-height: 700px) { .stage.is-immersive .rw-subbar { margin-bottom: 8px; } .stage.is-immersive .rw-top { margin-bottom: 8px; } }
/* phone landscape: board on the left, keyboard on the right */
@media (orientation: landscape) and (max-height: 540px) {
  .stage.is-immersive .rw { max-width: none; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); grid-template-rows: auto auto minmax(0, 1fr) auto; grid-template-areas: "top top" "main sub" "main known" "main keys"; column-gap: 20px; padding-top: 8px; }
  .stage.is-immersive .rw-top { grid-area: top; }
  .stage.is-immersive .rw-subbar { grid-area: sub; margin: 0; }
  .stage.is-immersive .rw-main { grid-area: main; margin: 0; height: 100%; }
  .stage.is-immersive .rw-known { grid-area: known; align-self: end; }
  .stage.is-immersive .rw-keys { grid-area: keys; }
  .stage.is-immersive .rw-key { height: clamp(36px, 12vh, 50px); }
}

@media (max-width: 360px) { .rw-mode { padding: 6px 8px; font-size: 12px; } .rw-hintbtn > span:not(.rw-hintleft) { display: none; } }
@media (prefers-reduced-motion: reduce) {
  .rw *, .rw *::before, .rw *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
