:root{--ink:#2a2437;--cloth:#efe6d2;--cloth2:#e2d6bb;--brass:#b88a2e;--red:#b3261e;--vermilion:#d8452e}
*{box-sizing:border-box}
body{margin:0;background:var(--ink);color:var(--cloth);font:16px/1.4 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;padding-left:env(safe-area-inset-left);padding-right:env(safe-area-inset-right);padding-bottom:env(safe-area-inset-bottom)}
a{color:#f3c969}
.game-header{display:flex;justify-content:space-between;gap:.5rem;padding:.75rem 1rem;background:#1c1829;font-size:.9rem}
.game-header a{min-height:44px;display:inline-flex;align-items:center}
.game-tag{color:#b7aec9;align-self:center}
.game-title h1{margin:.2rem 0 .5rem;font-size:1.5rem;letter-spacing:.02em}
footer{padding:1rem;text-align:center;color:#b7aec9;font-size:.85rem}
.tw{user-select:none;-webkit-user-select:none;-webkit-touch-callout:none}
.tw button{font:inherit;touch-action:manipulation;-webkit-tap-highlight-color:transparent;cursor:pointer}
.tw-hud{display:flex;align-items:center;gap:.4rem;flex-wrap:wrap}
.tw-chip{background:var(--cloth);color:var(--ink);border-radius:999px;padding:.3rem .7rem;font-weight:700;font-size:.85rem}
.tw-lives{display:inline-flex;gap:5px}
.tw-lives i{width:14px;height:14px;border-radius:50%;background:var(--vermilion);border:2px solid var(--cloth);display:block}
.tw-lives i.off{background:transparent;opacity:.5}
.tw-ico{margin-left:auto;min-height:44px;min-width:44px;padding:0 .7rem;border-radius:10px;border:2px solid var(--brass);background:transparent;color:var(--cloth);font-size:.8rem}
.tw-coach{min-height:2.7em;margin:.4rem 0;font-size:.9rem;color:#f3e7c6}
.tw-stage{position:relative;border-radius:10px;overflow:hidden;background:var(--cloth);width:100%}
#tw-canvas{display:block;touch-action:none;margin:0 auto;outline:none;max-width:100%}
#tw-canvas:focus-visible{outline:3px solid #f3c969;outline-offset:-3px}
.tw-screen{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(42,36,55,.78);padding:.75rem;overflow:auto}
.tw-screen[hidden]{display:none}
.tw-card{background:var(--cloth);color:var(--ink);border:2px dashed var(--brass);border-radius:12px;padding:1rem;width:100%;max-width:320px;display:flex;flex-direction:column;gap:.5rem;text-align:center;animation:twin .28s ease-out}
.tw-card h2{margin:0;font-size:1.5rem}
.tw-sub{margin:0;font-size:.9rem}
.tw-stats{margin:0;font-size:.8rem;color:#5b5368}
.tw-btn{min-height:44px;min-width:44px;padding:.4rem .9rem;border-radius:10px;border:2px solid var(--ink);background:var(--cloth2);color:var(--ink);font-weight:700}
.tw-btn:disabled{opacity:.45;cursor:default}
.tw-btn:focus-visible,.tw-ico:focus-visible,.tw-chipbtn:focus-visible{outline:3px solid #f3c969;outline-offset:2px}
.tw-primary{background:var(--vermilion);color:#fff;border-color:var(--ink)}
.tw-step{display:flex;align-items:center;justify-content:center;gap:1rem;font-weight:700}
.tw-stars{display:flex;justify-content:center;gap:8px;min-height:34px}
.tw-stars b{width:32px;height:32px;background:#c9bda0;clip-path:polygon(50% 0,62% 36%,100% 38%,70% 60%,80% 100%,50% 76%,20% 100%,30% 60%,0 38%,38% 36%)}
.tw-stars b.on{background:var(--vermilion)}
.tw-legend{display:flex;flex-wrap:wrap;gap:.4rem;margin:.6rem 0}
.tw-chipbtn{min-height:44px;display:inline-flex;align-items:center;gap:.4rem;padding:0 .7rem;border-radius:10px;border:2px solid var(--cloth);background:transparent;color:var(--cloth);font-size:.8rem;font-weight:700}
.tw-chipbtn.sel{background:var(--cloth);color:var(--ink)}
.tw-chipbtn i{width:14px;height:14px;border-radius:50%;display:block;border:2px solid var(--ink)}
.tw-bar{display:grid;grid-template-columns:1fr 1fr 1fr 1.6fr;gap:.4rem}
.tw-bar .tw-btn{padding:.4rem .3rem}
.tw-keys{font-size:.75rem;color:#9d94b0;margin:.6rem 0 0}
@keyframes twin{from{transform:translateY(10px) scale(.96);opacity:0}to{transform:none;opacity:1}}
@media (prefers-reduced-motion:reduce){.tw-card{animation:none}*{transition:none!important}}
@media (hover:none){.tw-keys{display:none}}
.tw-stage{background:var(--cloth) repeating-linear-gradient(45deg,rgba(184,138,46,.07) 0 2px,transparent 2px 9px)}
.tw-card{box-shadow:0 6px 0 rgba(42,36,55,.25)}
.tw-path{display:flex;justify-content:center;gap:6px;flex-wrap:nowrap;overflow-x:auto;padding:2px 0}
.tw-node{flex:0 0 auto;min-width:44px;min-height:52px;padding:2px 4px;border-radius:10px;border:2px solid var(--ink);background:var(--cloth2);color:var(--ink);font-weight:800;display:flex;flex-direction:column;align-items:center;justify-content:center;line-height:1.1}
.tw-node.sel{background:var(--ink);color:var(--cloth)}
.tw-node.new{border-style:dashed;border-color:var(--vermilion)}
.tw-dots{font-size:.6rem;letter-spacing:1px;color:var(--vermilion)}
.tw-node.sel .tw-dots{color:#f3c969}
.tw-goals{list-style:none;margin:0;padding:0;text-align:left;font-size:.85rem}
.tw-goals li{padding:.15rem 0 .15rem 1.2rem;position:relative}
.tw-goals li::before{position:absolute;left:0;font-weight:800}
.tw-goals li.ok::before{content:"+";color:#2f7a3a}
.tw-goals li.no::before{content:"-";color:var(--red)}
.tw-btn:active{transform:translateY(1px)}
.tw-stars b.on{background:#e0a526;filter:drop-shadow(0 1px 0 var(--ink))}
@media (prefers-reduced-motion:reduce){.tw-btn:active{transform:none}}

/* full screen (shell adds html.pip-immersive in both native and immersive modes) */
html.pip-immersive .game-wrap.pip-stage{padding-left:8px;padding-right:8px;padding-bottom:8px;display:flex;flex-direction:column}
html.pip-immersive .game-wrap.pip-stage>.tw{flex:1;min-height:0;display:flex;flex-direction:column;gap:6px}
html.pip-immersive .tw-keys,html.pip-immersive .tw-coach:empty{display:none}
html.pip-immersive .tw-coach{min-height:0;margin:0;font-size:.85rem}
html.pip-immersive .tw-stage{flex:1;min-height:0;width:100%}
html.pip-immersive #tw-canvas{position:absolute;left:0;top:0;max-width:none}
html.pip-immersive .tw-legend{margin:0;flex-wrap:nowrap;overflow-x:auto}
html.pip-immersive .tw-chipbtn{flex:0 0 auto}
html.pip-immersive .tw-screen{padding:.4rem}
@media (orientation:landscape) and (max-height:560px){
  html.pip-immersive .game-wrap.pip-stage>.tw{display:grid;grid-template-columns:minmax(0,1fr) 230px;grid-template-rows:auto auto auto 1fr auto;grid-template-areas:"stage hud" "stage coach" "stage legend" "stage ." "stage bar";column-gap:8px;row-gap:6px}
  html.pip-immersive .tw-stage{grid-area:stage}
  html.pip-immersive .tw-hud{grid-area:hud}
  html.pip-immersive .tw-coach{grid-area:coach}
  html.pip-immersive .tw-legend{grid-area:legend;flex-wrap:wrap;overflow:visible}
  html.pip-immersive .tw-bar{grid-area:bar;grid-template-columns:1fr 1fr}
  html.pip-immersive .tw-card{gap:.3rem;padding:.6rem}
  html.pip-immersive .tw-card .tw-sub,html.pip-immersive .tw-stats{display:none}
}
