/* Ace Valley Tennis 3D - stage + in-game UI. Everything is scoped under #stage so site styles never leak in. */
html.pip-big, html.pip-big body { overflow: hidden; }
:root { --tn-green: #1f8f5f; --tn-deep: #0e2a22; --tn-ink: #eaf7f0; --tn-lime: #d8f23a; --tn-gold: #ffc83d; --tn-red: #ff6b5b; --tn-card: rgba(255,255,255,.08); --tn-line: rgba(255,255,255,.16); }
#stage { position: relative; width: min(100%, calc(78vh * 0.5625)); width: min(100%, calc(78svh * 0.5625)); aspect-ratio: 9 / 16; margin: 0 auto; overflow: hidden;
  border-radius: 14px; background: linear-gradient(#9fd8ff, #4f9d45); color: var(--tn-ink); font-family: "Trebuchet MS", "Segoe UI", Verdana, system-ui, sans-serif;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; line-height: 1.25; font-size: 14px; }
#stage.is-big { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; aspect-ratio: auto; border-radius: 0; z-index: 99999; }
html.pip-immersive #stage, html.pip-native #stage { width: min(100%, calc(100vh * 0.5625)); width: min(100%, calc(100svh * 0.5625)); }
#stage *, #stage *::before, #stage *::after { box-sizing: border-box; }
#stage #app { position: absolute; inset: 0; }
#stage #app canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#stage #ui { position: absolute; inset: 0; pointer-events: none; }
#stage button { font-family: inherit; font-size: inherit; color: inherit; cursor: pointer; touch-action: manipulation; pointer-events: auto; }
#stage button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
#stage #loader { position: absolute; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: linear-gradient(#1f8f5f, #0e2a22); }
#stage #loader[hidden], #stage #ctxlost[hidden], #stage [hidden] { display: none !important; }
#stage .load-in { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #fff; text-align: center; padding: 0 18px; }
#stage .load-in b { font-size: clamp(20px, 6vw, 32px); letter-spacing: 3px; }
#stage .load-in span { font-size: 14px; opacity: .95; }
#stage .spinner { width: 42px; height: 42px; border-radius: 50%; border: 6px solid rgba(255,255,255,.3); border-top-color: var(--tn-lime); animation: tnspin .8s linear infinite; }
@keyframes tnspin { to { transform: rotate(360deg); } }
#stage #ctxlost { position: absolute; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; background: rgba(10,30,24,.88); color: #fff; font-weight: 700; }

/* HUD */
#stage #hud { position: absolute; inset: 0; pointer-events: none; }
#stage #score { position: absolute; left: 8px; top: 8px; min-width: 128px; padding: 6px 10px; border-radius: 12px; background: rgba(8,28,22,.78); border: 1px solid var(--tn-line); }
#stage .sr { display: flex; align-items: center; gap: 6px; font-weight: 800; }
#stage .sr b { flex: 1; font-size: 13px; max-width: 74px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#stage .sr .g { min-width: 18px; text-align: center; font-size: 17px; color: var(--tn-lime); }
#stage .sr .p { min-width: 26px; text-align: right; font-size: 15px; }
#stage .dot { width: 8px; height: 8px; border-radius: 50%; background: transparent; border: 1px solid rgba(255,255,255,.3); }
#stage .dot.on { background: var(--tn-lime); border-color: var(--tn-lime); }
#stage .sets { font-size: 11px; opacity: .8; margin-top: 2px; }
#stage #btn-pause { position: absolute; right: 8px; top: 8px; width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--tn-line); background: rgba(8,28,22,.78); font-weight: 900; letter-spacing: 1px; }
#stage #banner { position: absolute; left: 50%; top: 17%; transform: translateX(-50%); max-width: 92%; padding: 8px 16px; border-radius: 999px; background: rgba(8,28,22,.86); font-weight: 800; font-size: 16px; text-align: center; border: 2px solid var(--tn-line); white-space: nowrap; }
#stage #banner.good { border-color: var(--tn-lime); color: var(--tn-lime); } #stage #banner.bad { border-color: var(--tn-red); color: #ffd2cc; }
#stage #hint { position: absolute; left: 50%; bottom: 17%; transform: translateX(-50%); width: min(92%, 320px); padding: 8px 12px; border-radius: 12px; background: rgba(8,28,22,.82); text-align: center; font-weight: 700; font-size: 14px; border: 1px solid var(--tn-line); }
#stage #stickbase { position: absolute; width: 96px; height: 96px; margin: -48px 0 0 -48px; border-radius: 50%; border: 3px solid rgba(255,255,255,.55); background: rgba(255,255,255,.12); }
#stage #stickknob { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; background: rgba(255,255,255,.75); display: block; }
#stage #spinbar { position: absolute; right: 8px; bottom: 8px; display: flex; flex-direction: column; gap: 6px; }
#stage #spinbar button { width: 56px; height: 44px; border-radius: 12px; border: 1px solid var(--tn-line); background: rgba(8,28,22,.78); font-weight: 800; font-size: 13px; }
#stage #spinbar button.sel { background: var(--tn-lime); color: #10230f; border-color: var(--tn-lime); }
#stage #meter { position: absolute; left: 20%; right: 20%; top: 9.5%; height: 14px; border-radius: 8px; background: rgba(8,28,22,.8); border: 1px solid var(--tn-line); }
#stage #meterzone { position: absolute; left: 40%; width: 20%; top: 0; bottom: 0; background: rgba(216,242,58,.55); border-radius: 6px; display: block; }
#stage #meterdot { position: absolute; top: -3px; width: 12px; height: 20px; margin-left: -6px; border-radius: 6px; background: #fff; display: block; }
#stage #pbar { position: absolute; left: 30%; right: 30%; bottom: 3%; height: 10px; border-radius: 6px; background: rgba(8,28,22,.8); overflow: hidden; }
#stage #pfill { display: block; height: 100%; background: linear-gradient(90deg, var(--tn-lime), var(--tn-red)); }
#stage #lives { position: absolute; left: 8px; top: 8px; padding: 8px 12px; border-radius: 12px; background: rgba(8,28,22,.78); font-weight: 800; font-size: 13px; border: 1px solid var(--tn-line); max-width: calc(100% - 70px); }
#stage #toast { position: absolute; left: 50%; bottom: 12%; transform: translateX(-50%); z-index: 30; max-width: 88%; padding: 10px 16px; border-radius: 14px; background: rgba(8,28,22,.95); border: 1px solid var(--tn-line); font-weight: 700; text-align: center; pointer-events: none; }
#stage #fade { position: absolute; inset: 0; z-index: 25; background: #000; pointer-events: none; animation: tnfade .45s ease-out forwards; }
@keyframes tnfade { from { opacity: .85; } to { opacity: 0; } }

/* screens */
#stage #screens { position: absolute; inset: 0; z-index: 10; pointer-events: none; }
#stage .screen { position: absolute; inset: 0; display: flex; flex-direction: column; background: linear-gradient(rgba(10,32,26,.94), rgba(10,32,26,.97)); pointer-events: auto; }
#stage .screen.menu { background: linear-gradient(rgba(10,32,26,.15) 0%, rgba(10,32,26,.9) 36%, rgba(10,32,26,.97) 100%); overflow-y: auto; touch-action: pan-y; }
#stage .screen.over { align-items: center; justify-content: center; background: rgba(6,20,16,.72); padding: 12px; }
#stage .logo { text-align: center; padding: 18px 12px 4px; text-shadow: 0 3px 0 rgba(0,0,0,.35); }
#stage .logo small { letter-spacing: 3px; font-size: 11px; opacity: .9; }
#stage .logo h1 { font-size: clamp(30px, 10vw, 46px); line-height: 1; color: var(--tn-lime); margin-top: 2px; }
#stage .bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
#stage .bar.sm { justify-content: space-between; padding: 6px 14px 10px; }
#stage .bar h2 { flex: 1; font-size: 20px; }
#stage .coin { font-weight: 800; color: var(--tn-gold); font-size: 14px; }
#stage .back { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--tn-line); background: var(--tn-card); font-size: 26px; line-height: 1; }
#stage .rank { display: flex; align-items: center; gap: 8px; font-size: 13px; }
#stage .xp { display: inline-block; width: 86px; height: 8px; border-radius: 5px; background: rgba(255,255,255,.18); overflow: hidden; }
#stage .xp i { display: block; height: 100%; background: var(--tn-lime); }
#stage .stack { display: flex; flex-direction: column; gap: 8px; padding: 4px 14px 14px; }
#stage .big { min-height: 56px; border-radius: 14px; border: 1px solid var(--tn-line); background: var(--tn-card); font-size: 18px; font-weight: 800; padding: 8px 12px; text-align: left; display: flex; flex-direction: column; justify-content: center; }
#stage .big small { font-size: 12px; font-weight: 600; opacity: .8; }
#stage .big.primary, #stage button.primary { background: var(--tn-green); border-color: #35c58a; color: #fff; }
#stage .big.locked, #stage .opt.locked, #stage .swatch.locked { opacity: .45; }
#stage .row { display: flex; gap: 8px; flex-wrap: wrap; }
#stage .row button { flex: 1; min-height: 46px; min-width: 70px; border-radius: 12px; border: 1px solid var(--tn-line); background: var(--tn-card); font-weight: 800; padding: 6px 8px; }
#stage em { font-style: normal; color: var(--tn-gold); font-weight: 800; }
#stage .scroll { flex: 1; overflow-y: auto; overflow-x: hidden; touch-action: pan-y; -webkit-overflow-scrolling: touch; padding: 0 12px 16px; display: flex; flex-direction: column; gap: 10px; }
#stage .card { background: var(--tn-card); border: 1px solid var(--tn-line); border-radius: 14px; padding: 10px; }
#stage .card.dim { opacity: .55; }
#stage .ct { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
#stage .chip { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; color: #fff; }
#stage .note { font-size: 12px; opacity: .8; margin: 4px 0; }
#stage .rounds { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#stage .round { position: relative; min-height: 76px; border-radius: 12px; border: 1px solid var(--tn-line); background: rgba(255,255,255,.05); padding: 6px 8px; text-align: left; display: flex; flex-direction: column; gap: 1px; }
#stage .round:disabled { opacity: .4; cursor: default; }
#stage .round.now { border-color: var(--tn-lime); background: rgba(216,242,58,.12); }
#stage .round.ok { border-color: #35c58a; }
#stage .round .rn { font-size: 11px; opacity: .8; } #stage .round b { font-size: 14px; } #stage .round .st { font-size: 11px; opacity: .8; }
#stage .round .tick { position: absolute; right: 6px; top: 6px; font-size: 11px; color: #7ff0b4; font-weight: 800; }
#stage .dots { display: inline-flex; gap: 2px; margin-top: 3px; } #stage .dots i { width: 7px; height: 7px; border-radius: 50%; background: rgba(255,255,255,.2); display: block; } #stage .dots i.on { background: var(--tn-lime); }
#stage .pick { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; } #stage .pick.two { grid-template-columns: 1fr 1fr; } #stage .pick.sw { grid-template-columns: repeat(4, 1fr); }
#stage .opt { min-height: 56px; border-radius: 12px; border: 1px solid var(--tn-line); background: rgba(255,255,255,.05); padding: 6px 8px; text-align: left; display: flex; flex-direction: column; gap: 1px; }
#stage .opt b { font-size: 13px; } #stage .opt span { font-size: 11px; opacity: .8; }
#stage .opt.sel, #stage .swatch.sel, #stage .seg button.sel { border-color: var(--tn-lime); background: rgba(216,242,58,.16); }
#stage .swatch { min-height: 64px; border-radius: 12px; border: 1px solid var(--tn-line); background: rgba(255,255,255,.05); padding: 6px 2px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
#stage .swatch i { display: block; width: 26px; height: 26px; border-radius: 50%; background: var(--c); border: 2px solid rgba(255,255,255,.6); } #stage .swatch span { font-size: 10px; }
#stage .stat button, #stage .card > button { min-height: 46px; width: 100%; border-radius: 12px; border: 1px solid var(--tn-line); background: var(--tn-card); font-weight: 800; margin-top: 6px; }
#stage button[aria-disabled="true"], #stage button:disabled { opacity: .5; }
#stage button.danger { background: #b3261e; border-color: #ff8a80; }
#stage .seg { display: flex; gap: 6px; } #stage .seg button { flex: 1; min-height: 46px; border-radius: 12px; border: 1px solid var(--tn-line); background: rgba(255,255,255,.05); font-weight: 800; }
#stage .mis, #stage .ach { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--tn-line); font-size: 13px; }
#stage .mis span, #stage .ach span { flex: 1; } #stage .ach { flex-wrap: wrap; } #stage .ach b { width: 100%; } #stage .ach span { font-size: 12px; opacity: .8; }
#stage .mis.done, #stage .ach.done { opacity: .6; }
#stage .panel { width: min(100%, 340px); max-height: 100%; overflow-y: auto; touch-action: pan-y; background: rgba(10,32,26,.97); border: 1px solid var(--tn-line); border-radius: 18px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
#stage .panel h2 { text-align: center; font-size: 26px; } #stage .panel h2.win { color: var(--tn-lime); } #stage .panel h2.lose { color: #ffb4a8; }
#stage .score { text-align: center; font-size: 18px; font-weight: 800; }
#stage .pay { display: flex; flex-direction: column; gap: 2px; font-size: 13px; } #stage .pay div { display: flex; justify-content: space-between; gap: 8px; } #stage .pay .gold { color: var(--tn-gold); } #stage .pay .tot { border-top: 1px solid var(--tn-line); padding-top: 4px; margin-top: 2px; font-weight: 800; }
#stage .unlock { text-align: center; color: var(--tn-gold); font-weight: 800; font-size: 13px; } #stage .next { text-align: center; font-weight: 800; font-size: 14px; }
@media (prefers-reduced-motion: reduce) { #stage #fade { animation-duration: .01s; } #stage .spinner { animation-duration: 2s; } }

.tn-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: .75rem 0 .25rem; }
.tn-bar .btn { min-height: 44px; min-width: 44px; }
.tn-keys { text-align: center; font-size: .8rem; color: #64748b; margin: .25rem 0 0; }
.tn-guide { max-width: 640px; margin: 1.5rem auto; padding: 0 1rem; line-height: 1.6; }
.tn-guide h2 { font-size: 1.25rem; margin-bottom: .5rem; }
.tn-guide h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
.tn-guide p { margin-bottom: .5rem; font-size: .95rem; }

/* feel layer: rally chip and shot popups */
#stage #feel { position: absolute; inset: 0; pointer-events: none; }
#stage #rallychip { position: absolute; left: 50%; top: calc(8px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); display: flex; align-items: baseline; gap: 6px; padding: 4px 12px; border-radius: 999px; background: rgba(8,28,22,.78); border: 1px solid var(--tn-line); font-weight: 800; transition: opacity .15s; }
#stage #rallychip.off { opacity: 0; }
#stage #rallychip b { font-size: 20px; color: var(--tn-lime); min-width: 18px; text-align: center; }
#stage #rallychip span { font-size: 11px; opacity: .85; text-transform: uppercase; letter-spacing: .5px; }
#stage #rallychip.hot { border-color: var(--tn-lime); animation: tnbeat .5s ease-out; }
#stage #pops { position: absolute; left: 50%; top: 30%; transform: translateX(-50%); width: 80%; display: flex; flex-direction: column; align-items: center; gap: 4px; }
#stage .pop { font-weight: 900; font-size: 20px; letter-spacing: .5px; text-shadow: 0 2px 6px rgba(0,0,0,.6); color: #fff; animation: tnpop .9s ease-out forwards; }
#stage .pop.gold { color: #ffd84a; } #stage .pop.dim { color: #cbd5e1; font-size: 16px; }
#stage .pop.calm { animation: tnfade .9s linear forwards; }
@keyframes tnpop { 0% { opacity: 0; transform: translateY(8px) scale(.8); } 15% { opacity: 1; transform: translateY(0) scale(1.1); } 70% { opacity: 1; } 100% { opacity: 0; transform: translateY(-18px) scale(1); } }
@keyframes tnfade { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }
@keyframes tnbeat { 0% { transform: translateX(-50%) scale(1.25); } 100% { transform: translateX(-50%) scale(1); } }
@media (prefers-reduced-motion: reduce) { #stage #rallychip.hot { animation: none; } }
@media (max-width: 420px) { #stage #rallychip { top: 62px; } }

/* Full screen on phones: the shell stage (.game-wrap) becomes a flex column and the game fills it in portrait and landscape.
   The 3D camera already fits any aspect, and the renderer resizes on the stage ResizeObserver at devicePixelRatio (capped by quality). */
html.pip-immersive .game-wrap, html.pip-native .game-wrap { display: flex; flex-direction: column; min-height: 0; padding: 0; }
html.pip-immersive .tn-bar, html.pip-immersive .tn-keys, html.pip-native .tn-bar, html.pip-native .tn-keys,
html.pip-immersive .game-header, html.pip-immersive .ad-well, html.pip-immersive .tn-guide, html.pip-immersive #similar-games { display: none !important; }
html.pip-immersive #stage, html.pip-native #stage { flex: 1 1 auto; width: 100%; height: auto; min-height: 0; max-width: none; aspect-ratio: auto; border-radius: 0; margin: 0; }
html.pip-immersive #stage #score { top: calc(8px + env(safe-area-inset-top, 0px)); }
html.pip-immersive #stage #btn-pause { top: calc(8px + env(safe-area-inset-top, 0px)); width: 48px; height: 48px; }
