/* Badminton - shared look for the game and the sandbox. System fonts only. */
:root {
  --sat: env(safe-area-inset-top, 0px); --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px);
  --you: #2ee6ff; --opp: #ff4d9e; --warn: #ffd23f; --good: #5dffa0; --bad: #ff6b6b;
  --bg: #04050d; --ink: #eaf6ff; --dim: #9db4d6; --panel: rgba(9, 13, 38, 0.9); --edge: rgba(120, 200, 255, 0.28);
  --s: 64px; --d: 66px; /* shot button size and diamond spacing */
}
* { box-sizing: border-box; }
html, body {
  margin: 0; width: 100%; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
[hidden] { display: none !important; }
input, textarea { -webkit-user-select: text; user-select: text; touch-action: manipulation; }
button, a, input, select, textarea { font: inherit; color: inherit; }
button { touch-action: manipulation; cursor: pointer; }
:focus { outline: none; }
:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
kbd { font: 700 11px/1 ui-monospace, Menlo, Consolas, monospace; padding: 3px 5px; border: 1px solid rgba(255, 255, 255, 0.45); border-radius: 4px; background: rgba(0, 0, 0, 0.35); }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ------------------------------------------------------------------ HUD */
.hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
.safe { position: absolute; top: var(--sat); right: var(--sar); bottom: var(--sab); left: var(--sal); }
.safe > * { position: absolute; }
.stick-zone { display: none; left: calc(-1 * var(--sal)); top: 56px; bottom: calc(-1 * var(--sab)); width: 50vw; pointer-events: auto; touch-action: none; }
body.touch .stick-zone { display: block; }

.tl, .tr { top: 6px; display: flex; gap: 6px; align-items: center; pointer-events: auto; }
.tl { left: 6px; } .tr { right: 6px; }
.ibtn {
  width: 44px; height: 44px; padding: 0; border-radius: 12px; border: 1px solid var(--edge); background: rgba(8, 12, 34, 0.72);
  display: grid; place-items: center; color: var(--ink);
}
.ibtn svg { width: 22px; height: 22px; fill: currentColor; }
.ibtn:active { background: rgba(46, 230, 255, 0.25); }
#btn-mute .cross { display: none; }
#btn-mute[aria-pressed="true"] .wave { display: none; }
#btn-mute[aria-pressed="true"] .cross { display: inline; }
#btn-mute[aria-pressed="true"] { color: var(--dim); }
.ping { font: 600 12px/1 ui-monospace, Menlo, Consolas, monospace; color: var(--dim); padding: 6px 8px; border-radius: 8px; background: rgba(8, 12, 34, 0.6); min-width: 52px; text-align: right; }
.ping.bad { color: var(--warn); }

.scoreboard {
  top: 6px; left: 50%; transform: translateX(-50%); padding: 4px 12px 5px; border-radius: 12px; white-space: nowrap;
  background: rgba(8, 12, 34, 0.78); border: 1px solid var(--edge); text-align: center;
}
.sb-row { display: flex; align-items: center; justify-content: center; gap: 7px; height: 28px; }
.sb-name { font-weight: 700; font-size: 13px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.sb-name.you, .sb-pts.you { color: var(--you); } .sb-name.opp, .sb-pts.opp { color: var(--opp); }
.sb-name.you { text-align: right; } .sb-name.opp { text-align: left; }
.sb-pts { font: 800 27px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-variant-numeric: tabular-nums; min-width: 34px; text-shadow: 0 0 12px currentColor; }
.sb-pts.you { text-align: right; } .sb-pts.opp { text-align: left; }
.sb-dash { font-weight: 800; font-size: 20px; color: var(--dim); }
.sb-serve { width: 9px; height: 9px; border-radius: 50%; background: transparent; flex: none; }
.sb-serve.on { background: var(--warn); box-shadow: 0 0 9px var(--warn); }
.sb-games { display: flex; gap: 3px; }
.sb-games i { width: 7px; height: 12px; border-radius: 2px; border: 1px solid currentColor; opacity: 0.55; }
.sb-games i.won { background: currentColor; opacity: 1; box-shadow: 0 0 7px currentColor; }
#sb-g0 { color: var(--you); } #sb-g1 { color: var(--opp); }
.sb-sub { font-size: 10.5px; line-height: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); }

.mid { left: 0; right: 0; top: 0; bottom: 0; }
.mid > * { position: absolute; left: 50%; transform: translateX(-50%); }
.banner {
  top: 62px; display: flex; align-items: baseline; gap: 10px; padding: 6px 18px; border-radius: 12px; white-space: nowrap;
  background: rgba(6, 8, 26, 0.82); border: 2px solid var(--c, var(--you)); color: var(--c, var(--you));
  box-shadow: 0 0 22px -4px var(--c, var(--you)); visibility: hidden; opacity: 0;
}
.banner b { font-size: 26px; line-height: 30px; letter-spacing: 0.06em; font-weight: 900; text-shadow: 0 0 14px currentColor; }
.banner span { font-size: 13px; color: var(--ink); font-weight: 600; }
.banner.on { visibility: visible; opacity: 1; animation: pop 0.22s ease-out; }
.banner.pin, .feedback.pin { animation: none !important; }
.feedback {
  top: 114px; font: 900 20px/26px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; letter-spacing: 0.1em; white-space: nowrap;
  color: var(--c, #fff); text-shadow: 0 0 12px var(--c, #fff), 0 2px 0 rgba(0, 0, 0, 0.6); visibility: hidden; opacity: 0;
}
.feedback.on { visibility: visible; opacity: 1; animation: rise 0.7s ease-out forwards; }
.feedback.pin { opacity: 1; }
@keyframes pop { from { transform: translateX(-50%) scale(0.6); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }
@keyframes rise { 0% { transform: translateX(-50%) scale(1.5); opacity: 0; } 15% { transform: translateX(-50%) scale(1); opacity: 1; } 75% { opacity: 1; } 100% { transform: translateX(-50%) translateY(-6px); opacity: 0; } }

.serve-prompt {
  bottom: 8px; padding: 7px 14px 8px; border-radius: 12px; text-align: center; white-space: nowrap; min-width: 200px;
  background: rgba(6, 8, 26, 0.82); border: 1px solid var(--edge); visibility: hidden;
}
.serve-prompt.on { visibility: visible; }
.serve-prompt.mine { border-color: var(--warn); box-shadow: 0 0 18px -6px var(--warn); }
.sp-line { display: flex; gap: 10px; justify-content: center; align-items: baseline; font-size: 15px; }
.sp-line b { letter-spacing: 0.08em; text-transform: uppercase; }
.serve-prompt.mine .sp-line b { color: var(--warn); }
.sp-count { font: 800 17px/1 ui-monospace, Menlo, Consolas, monospace; min-width: 1.3em; }
.sp-hint { font-size: 11.5px; color: var(--dim); }
.sp-bar { height: 3px; margin-top: 5px; border-radius: 2px; background: rgba(255, 255, 255, 0.14); overflow: hidden; }
.sp-bar i { display: block; height: 100%; width: 100%; background: var(--warn); transform-origin: left center; }
.serve-prompt:not(.mine) .sp-bar, .serve-prompt:not(.mine) .sp-hint:empty { display: none; }

.keys-hint { left: 10px; bottom: 10px; font-size: 12px; color: var(--dim); padding: 7px 10px; border-radius: 10px; background: rgba(6, 8, 26, 0.6); white-space: nowrap; }
.keys-hint kbd { margin: 0 1px; }
.stick-hint { display: none; left: 12px; bottom: 12px; width: 100px; height: 100px; border-radius: 50%; border: 2px dashed rgba(160, 220, 255, 0.4); place-items: center; color: rgba(190, 230, 255, 0.65); font-size: 11px; letter-spacing: 0.14em; font-weight: 700; }
.stick-hint i { position: absolute; width: 40px; height: 40px; border-radius: 50%; background: rgba(160, 220, 255, 0.14); }
.stick-hint span { position: relative; }
.stick-hint.off { visibility: hidden; }
body.touch .stick-hint { display: grid; }
body.touch .keys-hint { display: none; }
.stick { position: fixed; width: 116px; height: 116px; margin: -58px 0 0 -58px; border-radius: 50%; border: 2px solid rgba(46, 230, 255, 0.65); background: rgba(46, 230, 255, 0.08); display: none; pointer-events: none; box-shadow: 0 0 18px -4px var(--you); }
.stick.on { display: block; }
.stick i { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(46, 230, 255, 0.5); border: 2px solid #fff; }

/* shot buttons: a row with key caps for mouse + keyboard, a thumb diamond for touch */
.shots { right: 10px; bottom: 10px; display: flex; gap: 10px; pointer-events: auto; }
.shot {
  width: 78px; height: 64px; border-radius: 14px; padding: 0; border: 2px solid var(--c); background: rgba(6, 8, 26, 0.78); color: var(--c);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; touch-action: none;
  box-shadow: 0 0 16px -5px var(--c), inset 0 0 14px -8px var(--c);
}
.shot b { font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; font-weight: 800; }
.shot kbd { color: var(--ink); }
.shot.pressed { background: var(--c); color: #04050d; transform: scale(0.94); }
.shot.pressed kbd { color: #04050d; border-color: #04050d; background: transparent; }
.s-clear { --c: #49c5ff; } .s-drop { --c: #5dffa0; } .s-smash { --c: #ff7a45; } .s-net { --c: #c59bff; }
body.touch .shots { display: block; right: 8px; bottom: 8px; width: calc(var(--d) * 2 + var(--s)); height: calc(var(--d) * 2 + var(--s)); pointer-events: none; }
body.touch .shot { position: absolute; width: var(--s); height: var(--s); border-radius: 50%; pointer-events: auto; background: rgba(6, 8, 26, 0.62); }
body.touch .shot kbd { display: none; }
body.touch .shot b { font-size: 11.5px; }
body.touch .s-clear { left: var(--d); top: 0; }
body.touch .s-drop { left: 0; top: var(--d); }
body.touch .s-smash { left: calc(var(--d) * 2); top: var(--d); }
body.touch .s-net { left: var(--d); top: calc(var(--d) * 2); }
body.touch .mid { left: 124px; right: calc(var(--d) * 2 + var(--s) + 18px); }
body.touch .sb-name { max-width: 76px; font-size: 12px; }
body.touch .banner { top: 60px; padding: 4px 14px; }
body.touch .banner b { font-size: 22px; line-height: 26px; }
body.touch .feedback { top: 104px; font-size: 17px; line-height: 22px; }
body.touch .serve-prompt { bottom: 6px; padding: 5px 12px 6px; min-width: 0; }
body.touch .sp-line { font-size: 13px; }
body.touch .sp-hint { font-size: 10.5px; }
@media (max-height: 350px) { :root { --s: 58px; --d: 60px; } }
@media (max-width: 1040px) { body:not(.touch) .serve-prompt { bottom: 88px; } }
@media (max-width: 720px) { body:not(.touch) .shot { width: 62px; } body:not(.touch) .keys-hint { bottom: 86px; } body:not(.touch) .serve-prompt { bottom: 128px; } }

/* ------------------------------------------------------------------ screens */
.screen {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; overflow-y: auto; touch-action: pan-y;
  padding: max(10px, var(--sat)) max(10px, var(--sar)) max(10px, var(--sab)) max(10px, var(--sal));
  background: radial-gradient(ellipse at center, rgba(4, 5, 13, 0.55), rgba(4, 5, 13, 0.9));
}
.screen.soft { background: radial-gradient(ellipse at center, rgba(4, 5, 13, 0.35), rgba(4, 5, 13, 0.75)); }
.panel {
  width: min(100%, 520px); padding: 20px 22px; border-radius: 18px; background: var(--panel); border: 1px solid var(--edge);
  box-shadow: 0 0 46px -12px var(--you), 0 0 80px -30px var(--opp);
}
.panel.center { text-align: center; }
.panel.main { width: min(100%, 760px); display: grid; grid-template-columns: 1fr 1.25fr; gap: 22px; align-items: center; }
h1 {
  margin: 0; font: 900 40px/1.05 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; letter-spacing: 0.1em;
  background: linear-gradient(90deg, var(--you), #fff 48%, var(--opp)); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 12px rgba(46, 230, 255, 0.45));
}
h2 { margin: 0 0 12px; font-size: 22px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--you); text-shadow: 0 0 14px rgba(46, 230, 255, 0.5); }
h3 { margin: 0 0 8px; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); }
.tag { margin: 6px 0 16px; color: var(--dim); letter-spacing: 0.06em; }
.note { color: var(--dim); font-size: 13px; margin: 10px 0 0; }
.field { display: block; }
.field span { display: block; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); margin-bottom: 4px; }
input[type="text"], input[type="number"] {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--edge); background: rgba(0, 0, 0, 0.4); color: var(--ink); font-size: 16px;
}
input[type="text"]:focus-visible { outline: 2px solid var(--you); outline-offset: 0; }
.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.btn {
  min-height: 48px; padding: 7px 14px; border-radius: 12px; border: 1px solid var(--edge); background: rgba(30, 44, 110, 0.55); color: var(--ink);
  font-weight: 700; letter-spacing: 0.03em; text-decoration: none; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
}
.btn small { font-weight: 500; font-size: 11px; color: var(--dim); letter-spacing: 0.04em; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(180deg, rgba(46, 230, 255, 0.95), rgba(30, 160, 230, 0.95)); color: #03121c; border-color: #bff6ff; box-shadow: 0 0 20px -6px var(--you); }
.btn.primary small { color: #0b3a4d; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; cursor: default; }
@media (hover: hover) { .btn:hover { border-color: #bff6ff; } .ibtn:hover { border-color: #bff6ff; } .shot:hover { background: rgba(30, 40, 90, 0.8); } }
.row { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }
.row .btn { min-width: 120px; }
.row.wrap { flex-wrap: wrap; }
.opt { display: flex; align-items: center; gap: 12px; margin: 10px 0; }
.opt > span { width: 64px; font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); }
.seg { display: flex; flex: 1; border: 1px solid var(--edge); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; min-height: 44px; border: 0; background: transparent; font-weight: 700; color: var(--dim); }
.seg button + button { border-left: 1px solid var(--edge); }
.seg button[aria-checked="true"] { background: rgba(46, 230, 255, 0.22); color: #fff; box-shadow: inset 0 -3px 0 var(--you); }
.seg button:focus-visible { outline-offset: -3px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.col { display: flex; flex-direction: column; gap: 9px; }
.code-in { text-transform: uppercase; text-align: center; letter-spacing: 0.4em; font-weight: 800; font-size: 20px !important; }
.code { font: 900 54px/1.1 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 0.22em; padding-left: 0.22em; color: var(--warn); text-shadow: 0 0 22px rgba(255, 210, 63, 0.55); -webkit-user-select: text; user-select: text; }
.linkrow { display: flex; gap: 8px; margin: 10px 0 4px; }
.linkrow input { flex: 1; font-size: 13px; min-width: 0; }
.wait { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 14px 0 0; }
.spin { width: 18px; height: 18px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.2); border-top-color: var(--you); animation: spin 0.9s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.endscore { font: 800 30px/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; margin: 4px 0; font-variant-numeric: tabular-nums; }
.endscore small { display: block; font-size: 13px; font-weight: 600; color: var(--dim); }
.win { color: var(--good) !important; text-shadow: 0 0 16px rgba(93, 255, 160, 0.5) !important; }
.lose { color: var(--opp) !important; text-shadow: 0 0 16px rgba(255, 77, 158, 0.5) !important; }
.board { max-height: min(52vh, 380px); overflow-y: auto; touch-action: pan-y; border: 1px solid var(--edge); border-radius: 12px; }
.board table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.board th, .board td { padding: 7px 10px; text-align: right; font-size: 14px; }
.board th { position: sticky; top: 0; background: #0b1030; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); }
.board td:nth-child(2), .board th:nth-child(2) { text-align: left; }
.board tr.me td { color: var(--warn); font-weight: 700; }
.board tbody tr:nth-child(odd) td { background: rgba(255, 255, 255, 0.035); }
.board p { padding: 14px; margin: 0; }

.rotate { display: none; position: fixed; inset: 0; z-index: 40; background: rgba(4, 5, 13, 0.96); place-items: center; text-align: center; padding: 24px; }
.rotate i { display: block; width: 46px; height: 78px; margin: 0 auto 18px; border: 3px solid var(--you); border-radius: 9px; box-shadow: 0 0 18px -4px var(--you); animation: tip 2.2s ease-in-out infinite; }
.rotate p { margin: 0; font-weight: 700; letter-spacing: 0.06em; }
@keyframes tip { 0%, 25% { transform: rotate(0); } 60%, 100% { transform: rotate(90deg); } }
@media (orientation: portrait) and (max-width: 620px) { body.touch.ingame .rotate { display: grid; } }

.toast { position: fixed; left: 50%; bottom: calc(var(--sab) + 18px); transform: translateX(-50%); z-index: 50; padding: 9px 16px; border-radius: 10px; background: rgba(10, 16, 44, 0.95); border: 1px solid var(--edge); font-weight: 600; opacity: 0; pointer-events: none; transition: opacity 0.2s; white-space: nowrap; }
.toast.on { opacity: 1; }

/* short landscape phones */
@media (max-height: 430px) {
  .panel { padding: 12px 16px; }
  h1 { font-size: 30px; } h2 { font-size: 18px; margin-bottom: 8px; }
  .tag { margin: 4px 0 10px; font-size: 13px; }
  .btn { min-height: 46px; padding: 4px 12px; }
  .row { margin-top: 10px; }
  .code { font-size: 40px; }
  .opt { margin: 7px 0; }
  .board { max-height: 46vh; }
  .wait { margin-top: 8px; } .note { margin-top: 6px; }
}
@media (max-width: 600px) and (orientation: portrait) {
  .panel.main { grid-template-columns: 1fr; }
  .cols { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .banner.on, .feedback.on { animation: none; }
  .feedback.on { opacity: 1; }
  .rotate i { animation: none; transform: rotate(90deg); }
}
