* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #05070f; color: #fff;
  font-family: 'Trebuchet MS', 'Segoe UI', Roboto, sans-serif; touch-action: none; user-select: none; -webkit-user-select: none; }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: 0; color: #fff; }
input, select { font-family: inherit; user-select: text; -webkit-user-select: text; }

.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 50;
  background: radial-gradient(ellipse at 50% 30%, #4a22b8 0%, #1e0f5c 55%, #0b0624 100%); }
#dead.screen { background: rgba(60, 0, 0, .55); }
.card { background: linear-gradient(170deg, #ffffff 0%, #f1ebff 100%); color: #2a1a5e; border-radius: 18px; padding: 26px 28px; width: min(92vw, 420px); text-align: center;
  box-shadow: 0 8px 0 #5a2fc2, 0 20px 50px rgba(0,0,0,.6); }
.logo { display: flex; justify-content: center; gap: 3px; flex-wrap: wrap; }
.logo span { display: inline-block; width: 30px; height: 36px; line-height: 36px; font-weight: 900; font-size: 22px; color: #fff; border-radius: 5px;
  background: #ff7a2f; box-shadow: inset 0 -4px 0 rgba(0,0,0,.25); position: relative; }
.logo span:nth-child(4n+2) { background: #e8439a; } .logo span:nth-child(4n+3) { background: #7b3cff; } .logo span:nth-child(4n) { background: #1fa8e0; }
.logo span::before { content: ''; position: absolute; top: -5px; left: 8px; width: 14px; height: 6px; border-radius: 4px 4px 0 0; background: inherit; }
.logo2 { font-weight: 900; font-size: 30px; letter-spacing: 6px; margin: 8px 0 4px; color: #4b1fb8; }
.sub { margin: 4px 0 14px; font-size: 15px; }
.hint { font-size: 12px; opacity: .75; margin: 10px 0 0; }
.card input { width: 100%; padding: 12px; font-size: 17px; border-radius: 10px; border: 3px solid #6a3be0; margin: 5px 0; background: #fff; color: #2a1a5e; }
.card input:focus { outline: none; border-color: #1fa8e0; }
button.big { width: 100%; padding: 14px; font-size: 20px; font-weight: 800; border-radius: 12px; background: linear-gradient(90deg, #7b3cff, #3d6bff);
  box-shadow: 0 5px 0 #2c1a8a; margin-top: 8px; }
button.big:active { transform: translateY(3px); box-shadow: 0 2px 0 #2c1a8a; }
.card img.dev { display: block; height: 34px; margin: 12px auto 0; }
#splash { position: fixed; inset: 0; z-index: 200; background: #fdfbf9; display: flex; align-items: center; justify-content: center; transition: opacity .5s; }
#splash video { width: min(92vw, 608px); height: auto; }
#splash.out { opacity: 0; pointer-events: none; }
#lerr { color: #c91a09; font-weight: 700; min-height: 20px; margin-top: 6px; }
.spin { font-size: 60px; animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.big-emoji { font-size: 50px; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud button, #hud input, #hud select, #chatlog, #buildbar, #joy { pointer-events: auto; }
#tl { position: absolute; left: max(10px, env(safe-area-inset-left)); top: 10px; background: rgba(10,14,36,.62); padding: 8px 10px;
  border-radius: 12px; font-size: 14px; min-width: 170px; border: 2px solid rgba(255,255,255,.12); }
#plname { font-weight: 800; font-size: 16px; color: #f2cd37; margin-bottom: 4px; }
.row { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.bar { flex: 1; height: 10px; background: rgba(255,255,255,.15); border-radius: 6px; overflow: hidden; min-width: 100px; }
.bar i { display: block; height: 100%; width: 0; background: #36aebf; transition: width .2s; }
.bar.hp i { background: #e0302a; } .bar.jet i { background: #fe8a18; }
#money { font-weight: 700; color: #ffd21f; margin-top: 3px; }
#tr { position: absolute; right: max(10px, env(safe-area-inset-right)); top: 10px; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; max-width: 60vw; }
#tr button { width: 44px; height: 44px; border-radius: 10px; font-size: 21px; background: rgba(10,14,36,.7); border: 2px solid rgba(255,255,255,.15); }
#tr button.on { background: #237841; } #tr button.live { background: #c91a09; animation: pulse 1s infinite; }
@keyframes pulse { 50% { filter: brightness(1.5); } }
#mtrack { position: absolute; right: max(10px, env(safe-area-inset-right)); top: 62px; width: 240px; font-size: 12px; text-align: right; text-shadow: 0 1px 2px #000; }
#mtrack div { background: rgba(10,14,36,.55); padding: 4px 8px; border-radius: 8px; margin-top: 4px; display: inline-block; }
#cross { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font-size: 26px; color: #fff; text-shadow: 0 0 3px #000; opacity: .85; }
#hint { position: absolute; left: 50%; top: 58%; transform: translateX(-50%); background: rgba(10,14,36,.7); padding: 6px 12px; border-radius: 10px;
  font-size: 14px; white-space: nowrap; }
#hint:empty, #target:empty { display: none; }
#target { position: absolute; left: 50%; top: 38%; transform: translateX(-50%); font-size: 13px; background: rgba(10,14,36,.6); padding: 4px 10px; border-radius: 8px; }
#toasts { position: absolute; left: 50%; top: 14%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; width: 90vw; }
.toast { background: rgba(242,205,55,.95); color: #1b2a34; font-weight: 700; padding: 8px 16px; border-radius: 12px; box-shadow: 0 4px 0 #b8941a;
  animation: tin .25s ease-out; max-width: 90vw; text-align: center; }
.toast.big { font-size: 22px; background: #237841; color: #fff; box-shadow: 0 4px 0 #124a26; }
@keyframes tin { from { transform: scale(.6); opacity: 0; } }
#shiphud { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); background: rgba(10,14,36,.7); padding: 6px 14px; border-radius: 12px;
  font-size: 14px; text-align: center; white-space: nowrap; }
#tools { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); display: flex; gap: 6px; }
#tools button { width: 54px; height: 54px; border-radius: 12px; font-size: 24px; background: rgba(10,14,36,.7); border: 3px solid rgba(255,255,255,.15); position: relative; }
#tools button.on { border-color: #f2cd37; background: rgba(242,205,55,.3); }
#tools small { position: absolute; right: 4px; bottom: 1px; font-size: 10px; opacity: .7; }
#buildbar { position: absolute; left: 50%; bottom: 72px; transform: translateX(-50%); background: rgba(10,14,36,.8); padding: 6px; border-radius: 12px;
  max-width: 96vw; }
#blocks, #colors { display: flex; gap: 4px; overflow-x: auto; max-width: 92vw; }
#blocks button { min-width: 50px; height: 50px; border-radius: 8px; background: rgba(255,255,255,.1); font-size: 20px; line-height: 1; padding: 2px; position: relative; }
#blocks button small { display: block; font-size: 9px; }
#blocks button.on { background: #0055bf; outline: 2px solid #f2cd37; }
#blocks button.lock { opacity: .35; }
#colors { margin-top: 5px; }
#colors button { width: 26px; height: 26px; border-radius: 6px; flex: none; border: 2px solid rgba(0,0,0,.4); }
#colors button.on { outline: 3px solid #fff; }
.bbtn { display: flex; gap: 6px; margin-top: 5px; justify-content: center; }
.bbtn button { padding: 6px 12px; border-radius: 8px; background: #0055bf; font-size: 14px; }
.bbtn button.on { background: #c91a09; }
#chat { position: absolute; left: max(10px, env(safe-area-inset-left)); bottom: 80px; width: min(380px, 70vw); }
#chatlog { max-height: 170px; overflow-y: auto; font-size: 13px; text-shadow: 0 1px 2px #000; display: flex; flex-direction: column; justify-content: flex-end; }
#chatlog div { background: rgba(10,14,36,.45); padding: 2px 6px; border-radius: 6px; margin-top: 2px; word-break: break-word; }
#chatlog .sys { color: #f2cd37; } #chatlog .near b { color: #7fe07f; } #chatlog b { color: #8fd3ff; }
#chatin { display: flex; gap: 4px; margin-top: 4px; }
#chatin input { flex: 1; padding: 8px; border-radius: 8px; border: 0; font-size: 15px; }
#chatin select { border-radius: 8px; border: 0; padding: 4px; }
#voices { position: absolute; left: max(10px, env(safe-area-inset-left)); top: 175px; font-size: 13px; }
#voices div { background: rgba(10,14,36,.55); padding: 2px 8px; border-radius: 8px; margin-top: 3px; }
#voices div.talk { background: #237841; }

#panel { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; pointer-events: auto; }
.pcard { background: #1b2a34; border: 4px solid #f2cd37; border-radius: 16px; width: min(96vw, 640px); max-height: 88vh; overflow-y: auto;
  padding: 16px; position: relative; touch-action: pan-y; }
.pcard h2 { margin: 0 0 10px; color: #f2cd37; font-size: 20px; }
.pcard h3 { margin: 14px 0 6px; font-size: 16px; color: #8fd3ff; }
.close { position: absolute; right: 10px; top: 10px; width: 36px; height: 36px; border-radius: 8px; background: #c91a09; font-size: 18px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs button { padding: 8px 12px; border-radius: 8px; background: #0a3463; font-size: 14px; }
.tabs button.on { background: #0055bf; outline: 2px solid #f2cd37; }
.item { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.07); padding: 8px 10px; border-radius: 10px; margin: 5px 0; }
.item .grow { flex: 1; } .item small { opacity: .7; display: block; }
.item button, .pbtn { padding: 7px 12px; border-radius: 8px; background: #237841; font-size: 14px; font-weight: 700; white-space: nowrap; }
.item button:disabled, .pbtn:disabled { background: #555; opacity: .6; cursor: default; }
.item button.red { background: #c91a09; } .item button.blue { background: #0055bf; }
.dot { width: 18px; height: 18px; border-radius: 5px; flex: none; }
.pl { width: 34px; height: 34px; border-radius: 50%; flex: none; box-shadow: inset -6px -6px 0 rgba(0,0,0,.3); }
.muted { opacity: .65; font-size: 13px; }
.keys { columns: 2; font-size: 13px; } .keys div { break-inside: avoid; margin: 2px 0; }
kbd { background: #f4f4f4; color: #1b2a34; border-radius: 4px; padding: 0 5px; font-weight: 700; font-size: 12px; }

.touch { display: none; }
body.mobile .touch { display: block; }
body.mobile #tools small, body.mobile .pc { display: none; }
#bChat { position: absolute; left: max(10px, env(safe-area-inset-left)); bottom: 260px; width: 44px; height: 44px; border-radius: 10px; font-size: 20px; background: rgba(10,14,36,.7); }
#joy { position: absolute; left: 30px; bottom: 30px; width: 140px; height: 140px; border-radius: 50%; background: rgba(255,255,255,.1); border: 3px solid rgba(255,255,255,.25); }
#joyk { position: absolute; left: 45px; top: 45px; width: 50px; height: 50px; border-radius: 50%; background: rgba(242,205,55,.75); }
#tbtns { position: absolute; right: 20px; bottom: 30px; width: 190px; height: 190px; pointer-events: none; }
#tbtns button { position: absolute; border-radius: 50%; background: rgba(10,14,36,.65); border: 3px solid rgba(255,255,255,.3); font-size: 26px; font-weight: 800; pointer-events: auto; }
#tAct { right: 0; bottom: 0; width: 86px; height: 86px; background: rgba(201,26,9,.6) !important; }
#tJump { right: 100px; bottom: 0; width: 66px; height: 66px; }
#tDown { right: 100px; bottom: 76px; width: 56px; height: 56px; }
#tUse { right: 10px; bottom: 100px; width: 60px; height: 60px; background: rgba(35,120,65,.75) !important; }
body.mobile #chat { bottom: 190px; width: min(300px, 55vw); }
body.mobile #chatlog { max-height: 110px; font-size: 12px; }
body.mobile #tools { bottom: 8px; } body.mobile #tools button { width: 46px; height: 46px; font-size: 20px; }
body.mobile #buildbar { bottom: 62px; }
body.mobile #tl { font-size: 12px; min-width: 140px; padding: 6px 8px; }
body.mobile #shiphud { bottom: 200px; }
@media (max-height: 500px) {
  #tl { transform: scale(.85); transform-origin: top left; }
  body.mobile #chat { bottom: 150px; } #mtrack { display: none; }
  #joy { bottom: 15px; left: 20px; } #tbtns { bottom: 10px; }
}
/* телефон вертикально: панель инструментов и чат над джойстиком и кнопками */
@media (orientation: portrait) {
  body.mobile #tools { bottom: 200px; }
  body.mobile #buildbar { bottom: 254px; }
  body.mobile #chat { bottom: 320px; }
  body.mobile #bChat { bottom: 200px; }
}
