:root {
  --pink: #ff4f9a;
  --pink-d: #c22a6c;
  --blue: #2fb7ff;
  --blue-d: #1669a8;
  --ink: #1f2a44;
  --snow: #f6fbff;
  --panel: rgba(255, 255, 255, 0.92);
  --shadow: 0 6px 0 rgba(31, 42, 68, 0.18), 0 12px 30px rgba(31, 42, 68, 0.18);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #cfe6ff; color: var(--ink); }
body { font-family: 'M PLUS Rounded 1c', system-ui, sans-serif; font-weight: 500; user-select: none; }
button, input, select { font: inherit; }

#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* ---------------------------------------------------------- 画面 */
.screen {
  position: fixed; inset: 0; display: none;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.screen > * { margin: auto; }
.screen.show { display: flex; }
#scr-pause, #scr-settings, #scr-friend, #scr-lobby, #scr-result { background: rgba(160, 200, 240, 0.35); backdrop-filter: blur(3px); }

.title-wrap { width: min(560px, 100%); text-align: center; }
.logo {
  font-family: 'Dela Gothic One', sans-serif; font-weight: 400;
  font-size: clamp(48px, 11vw, 96px); margin: 0; line-height: 1;
  color: #fff; letter-spacing: 0.02em;
  text-shadow: 0 5px 0 var(--blue-d), 0 10px 18px rgba(0, 40, 90, 0.35);
  transform: rotate(-3deg);
}
.logo span { color: var(--pink); text-shadow: 0 5px 0 var(--pink-d), 0 10px 18px rgba(90, 0, 40, 0.3); }
.tagline { margin: 10px 0 18px; font-weight: 800; font-size: 18px; color: #fff; text-shadow: 0 2px 4px rgba(0, 40, 90, 0.5); }

.panel {
  background: var(--panel); border-radius: 22px; padding: 18px 20px;
  box-shadow: var(--shadow); width: 100%;
}
.panel.center { width: min(440px, 100%); text-align: center; display: flex; flex-direction: column; gap: 12px; }
.panel.wide { width: min(860px, 100%); }
.panel h2 { font-family: 'Dela Gothic One', sans-serif; font-weight: 400; margin: 0 0 10px; font-size: 26px; }

.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 800; margin: 6px 0; text-align: left; }
.field input[type=text], .field input:not([type]), #in-code {
  flex: 1; padding: 10px 14px; border-radius: 12px; border: 3px solid #d5e4f5; background: #fff; outline: none;
}
.field input:focus, #in-code:focus { border-color: var(--blue); }
.field input[type=range] { flex: 1; }
.field input[type=range] { min-width: 0; accent-color: var(--pink); }
.field select { padding: 6px 10px; border-radius: 10px; border: 3px solid #d5e4f5; }

.weapon-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.weapon-pick button {
  border: 3px solid #d5e4f5; background: #fff; border-radius: 14px; padding: 8px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-weight: 800; font-size: 14px; color: var(--ink);
  transition: transform 0.1s;
}
.weapon-pick button:hover { transform: translateY(-2px); }
.weapon-pick button.on { border-color: var(--pink); background: #fff0f6; }
.weapon-pick .wicon { font-size: 26px; line-height: 1; }
.weapon-pick .wdesc { font-size: 10px; font-weight: 500; color: #5b6784; line-height: 1.3; }
.weapon-pick.mini { display: inline-grid; grid-template-columns: repeat(4, auto); }
.weapon-pick.mini button { padding: 4px 10px; flex-direction: row; font-size: 13px; }
.weapon-pick.mini .wdesc { display: none; }
.weapon-pick.mini .wicon { font-size: 18px; }

.menu { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.menu.small { margin-top: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 999px; padding: 10px 18px; cursor: pointer; text-decoration: none;
  background: #fff; color: var(--ink); font-weight: 800; box-shadow: 0 4px 0 rgba(31, 42, 68, 0.2);
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(31, 42, 68, 0.2); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.big { font-family: 'Dela Gothic One', sans-serif; font-weight: 400; font-size: 20px; padding: 14px 26px; }
.btn.big small { font-family: 'M PLUS Rounded 1c', sans-serif; font-size: 12px; font-weight: 800; opacity: 0.85; }
.btn.pink { background: var(--pink); color: #fff; box-shadow: 0 5px 0 var(--pink-d); }
.btn.blue { background: var(--blue); color: #fff; box-shadow: 0 5px 0 var(--blue-d); }
.btn.tiny { padding: 4px 10px; font-size: 12px; vertical-align: middle; }
.note { color: #fff; font-size: 13px; text-shadow: 0 1px 3px rgba(0, 40, 90, 0.6); margin-top: 14px; }
.muted { color: #5b6784; font-size: 14px; margin: 0; }
.small-text { font-size: 12px; margin-top: 10px; text-align: center; }
.msg { min-height: 1.4em; margin: 6px 0 0; font-weight: 800; color: var(--pink-d); text-align: center; }

.join-row { display: flex; gap: 8px; }
#in-code { text-transform: uppercase; letter-spacing: 0.2em; font-weight: 800; font-size: 20px; text-align: center; min-width: 0; }

/* ---------------------------------------------------------- ロビー */
.code-label { font-family: 'M PLUS Rounded 1c', sans-serif; font-size: 13px; color: #5b6784; margin-left: 10px; }
.code { letter-spacing: 0.18em; color: var(--blue-d); }
.lobby-teams { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.lobby-team { border-radius: 16px; padding: 10px; }
.lobby-team.t0 { background: #ffe6f1; }
.lobby-team.t1 { background: #e0f4ff; }
.lobby-team h3 { margin: 0 0 6px; font-family: 'Dela Gothic One', sans-serif; font-weight: 400; }
.lobby-team.t0 h3 { color: var(--pink-d); }
.lobby-team.t1 h3 { color: var(--blue-d); }
.lobby-team ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.lobby-team li {
  background: #fff; border-radius: 12px; padding: 8px 12px; display: flex; justify-content: space-between; align-items: center;
  font-weight: 800; min-height: 42px; gap: 8px;
}
.lobby-team li.empty { background: rgba(255, 255, 255, 0.5); color: #8d98b3; border: 2px dashed #b9c6dc; }
.lobby-team li.clickable { cursor: pointer; }
.lobby-team li.me { outline: 3px solid var(--ink); }
.lobby-team li .tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #eef2f8; color: #5b6784; }
.lobby-team li .remove-cpu {
  flex: 0 0 auto; min-width: 44px; min-height: 44px; padding: 6px 10px; border: 0; border-radius: 10px;
  background: #fff0f6; color: var(--pink-d); font: inherit; font-size: 12px; font-weight: 800; cursor: pointer;
}
.lobby-team li .remove-cpu:hover { background: #ffd6e8; }
.lobby-team li .remove-cpu:active { transform: scale(0.96); }
.lobby-me { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; font-weight: 800; }

/* ---------------------------------------------------------- HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
#scorebar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
}
#scorebar .score b {
  display: inline-block; min-width: 64px; text-align: center; padding: 4px 12px; border-radius: 14px;
  font-family: 'Dela Gothic One', sans-serif; font-weight: 400; font-size: 32px; color: #fff;
}
#scorebar .s0 b { background: var(--pink); box-shadow: 0 4px 0 var(--pink-d); }
#scorebar .s1 b { background: var(--blue); box-shadow: 0 4px 0 var(--blue-d); }
#scorebar .target { color: #fff; font-weight: 800; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5); }
.team-icons { display: flex; gap: 4px; }
.team-icons span {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 16px;
  background: #fff; border: 3px solid; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
}
.team-icons.t0 span { border-color: var(--pink); }
.team-icons.t1 span { border-color: var(--blue); }
.team-icons span.dead { background: #5b6784; filter: grayscale(1); opacity: 0.7; }
.team-icons span.me { box-shadow: 0 0 0 3px #fff, 0 2px 4px rgba(0, 0, 0, 0.3); }

#killfeed { position: absolute; top: 70px; right: 14px; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
#killfeed div {
  background: rgba(20, 30, 50, 0.7); color: #fff; padding: 4px 12px; border-radius: 10px; font-weight: 800; font-size: 14px;
  animation: feedIn 0.2s ease-out;
}
#killfeed .n0 { color: #ff8cbf; } #killfeed .n1 { color: #7fd3ff; }
#killfeed .me-row { outline: 2px solid #fff; }
@keyframes feedIn { from { transform: translateX(30px); opacity: 0; } }

#crosshair { position: absolute; left: 50%; top: 50%; width: 60px; height: 60px; transform: translate(-50%, -50%); }
#crosshair .ring {
  position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; transform: translate(-50%, -50%);
  border: 3px solid rgba(255, 255, 255, 0.95); border-radius: 50%; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}
#crosshair .ring::after { content: ''; position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px; border-radius: 50%; background: #fff; }
#charge-ring { position: absolute; inset: 0; transform: rotate(-90deg); }
#charge-ring circle { fill: none; stroke: #fff; stroke-width: 5; stroke-dasharray: 163.4; stroke-dashoffset: 163.4; stroke-linecap: round; filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.6)); }
#charge-ring.full circle { stroke: #ffe14d; }
#hitmarker {
  position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; transform: translate(-50%, -50%) rotate(45deg); opacity: 0;
  background:
    linear-gradient(#fff, #fff) center top / 4px 12px no-repeat,
    linear-gradient(#fff, #fff) center bottom / 4px 12px no-repeat,
    linear-gradient(#fff, #fff) left center / 12px 4px no-repeat,
    linear-gradient(#fff, #fff) right center / 12px 4px no-repeat;
}
#hitmarker.show { animation: hitmark 0.25s ease-out; }
#hitmarker.kill { filter: drop-shadow(0 0 3px var(--pink)); }
@keyframes hitmark { 0% { opacity: 1; transform: translate(-50%, -50%) rotate(45deg) scale(1.3); } 100% { opacity: 0; transform: translate(-50%, -50%) rotate(45deg) scale(1); } }

#scope {
  position: absolute; inset: 0; display: none;
  background: radial-gradient(circle at center, transparent 0, transparent 34vmin, rgba(8, 20, 40, 0.92) 34.5vmin);
}
#scope::before, #scope::after { content: ''; position: absolute; background: rgba(8, 20, 40, 0.75); }
#scope::before { left: 50%; top: calc(50% - 34vmin); width: 2px; height: 68vmin; margin-left: -1px; }
#scope::after { top: 50%; left: calc(50% - 34vmin); height: 2px; width: 68vmin; margin-top: -1px; }
#scope.show { display: block; }

#lowsnow { position: absolute; inset: 0; opacity: 0; transition: opacity 0.3s; background: radial-gradient(circle at center, transparent 50%, rgba(80, 150, 255, 0.55) 100%); }
#lowsnow.hurt { animation: hurt 0.35s ease-out; }
@keyframes hurt { 0% { box-shadow: inset 0 0 120px rgba(255, 60, 120, 0.8); } 100% { box-shadow: inset 0 0 0 rgba(255, 60, 120, 0); } }

#gauge { position: absolute; left: 20px; bottom: 20px; display: flex; align-items: center; gap: 10px; }
.gauge-icon {
  width: 74px; height: 74px; border-radius: 50%; background: #fff; display: grid; place-items: center; grid-auto-flow: column;
  font-family: 'Dela Gothic One', sans-serif; font-size: 26px; box-shadow: var(--shadow); border: 4px solid var(--team, var(--pink));
}
.gauge-icon small { font-size: 12px; }
.gauge-bar { position: relative; width: 240px; height: 22px; background: rgba(20, 30, 50, 0.55); border-radius: 999px; overflow: hidden; border: 3px solid #fff; }
#gauge-fill { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(#fff, #d8ecff); transition: width 0.1s; }
#gauge-debt {
  position: absolute; top: 0; bottom: 0; background: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.55) 0 6px, rgba(255, 255, 255, 0.2) 6px 12px);
}
#gauge-hint { position: absolute; left: 84px; top: -22px; color: #fff; font-size: 12px; font-weight: 800; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7); opacity: 0; transition: opacity 0.3s; white-space: nowrap; }
#gauge-hint.show { opacity: 1; }

#weapon-box { position: absolute; right: 20px; bottom: 20px; text-align: right; color: #fff; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6); }
#weapon-box b { display: block; font-family: 'Dela Gothic One', sans-serif; font-weight: 400; font-size: 24px; }
#weapon-box span { font-size: 12px; font-weight: 800; }

#center-msg {
  position: absolute; left: 50%; top: 64%; transform: translateX(-50%); text-align: center; color: #fff;
  font-weight: 800; font-size: 20px; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7); white-space: pre-line;
}
#center-msg .big { font-family: 'Dela Gothic One', sans-serif; font-weight: 400; font-size: 34px; }
#toast {
  position: absolute; left: 50%; top: 24%; transform: translateX(-50%); color: #fff; font-family: 'Dela Gothic One', sans-serif;
  font-size: 26px; text-shadow: 0 3px 0 var(--pink-d), 0 4px 10px rgba(0, 0, 0, 0.4); opacity: 0; white-space: nowrap;
}
#toast.show { animation: toast 1.4s ease-out; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, 10px) scale(0.8); } 12% { opacity: 1; transform: translate(-50%, 0) scale(1.08); } 80% { opacity: 1; } 100% { opacity: 0; } }

#intro { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; padding: 7vh 16px 5vh; }
#intro-title {
  align-self: center; font-family: 'Dela Gothic One', sans-serif; font-size: clamp(30px, 6vw, 56px); color: #fff;
  padding: 6px 30px; border-radius: 18px; animation: slideIn 0.4s ease-out;
}
#intro-title.t0 { background: var(--pink); box-shadow: 0 6px 0 var(--pink-d); }
#intro-title.t1 { background: var(--blue); box-shadow: 0 6px 0 var(--blue-d); }
#intro-cards { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
#intro-cards div {
  background: rgba(255, 255, 255, 0.95); border-radius: 14px; padding: 8px 16px; min-width: 130px; text-align: center; font-weight: 800;
  box-shadow: var(--shadow); animation: slideIn 0.4s ease-out backwards;
}
#intro-cards small { display: block; color: #5b6784; font-size: 12px; }
@keyframes slideIn { from { transform: translateY(30px); opacity: 0; } }

#countdown {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%);
  font-family: 'Dela Gothic One', sans-serif; font-size: 140px; color: #fff; text-shadow: 0 8px 0 var(--blue-d), 0 12px 24px rgba(0, 0, 0, 0.3);
}
#countdown.pop { animation: pop 0.5s ease-out; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(1.6); opacity: 0; } }

#scoreboard {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(620px, 94vw);
  background: rgba(20, 30, 50, 0.82); color: #fff; border-radius: 18px; padding: 14px;
}
#netinfo { position: absolute; left: 8px; top: 8px; color: #fff; font-size: 11px; opacity: 0.7; text-shadow: 0 1px 2px #000; }
#click-to-play {
  position: absolute; left: 50%; top: 30%; transform: translateX(-50%); background: rgba(20, 30, 50, 0.8); color: #fff;
  padding: 10px 20px; border-radius: 999px; font-weight: 800;
}

/* ---------------------------------------------------------- リザルト */
.result-panel { width: min(1060px, 100%) !important; }
.result-score { text-align: center; font-family: 'Dela Gothic One', sans-serif; font-size: 34px; margin-bottom: 8px; }
.result-score .s0 { color: var(--pink); } .result-score .s1 { color: var(--blue); }
#result-title { text-align: center; font-size: 34px; }
#result-title.t0 { color: var(--pink); } #result-title.t1 { color: var(--blue); }
.result-gallery { position: relative; display: grid; gap: 10px; }
.result-team { border-radius: 16px; padding: 8px 10px 10px; min-width: 0; }
.result-team.t0 { background: rgba(255, 79, 154, 0.12); }
.result-team.t1 { background: rgba(47, 183, 255, 0.15); }
.result-team-label { font-family: 'Dela Gothic One', sans-serif; font-size: 16px; line-height: 1.4; }
.result-team.t0 .result-team-label { color: var(--pink-d); }
.result-team.t1 .result-team-label { color: var(--blue-d); }
.result-team-label span { font-family: 'M PLUS Rounded 1c', sans-serif; font-size: 12px; }
.result-players { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.result-player { min-width: 0; border-radius: 13px; background: rgba(255, 255, 255, 0.83); text-align: center; padding: 0 6px 6px; }
.result-player.me { outline: 3px solid #f3c734; background: #fff9d5; }
.result-player.empty { opacity: 0.55; }
.result-player.empty .result-stats { display: block; font-size: 12px; color: #586680; }
.result-model-slot { height: clamp(92px, 15vh, 150px); }
.result-player-name { font-weight: 800; font-size: clamp(11px, 1.2vw, 15px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-player-name small { font-size: 10px; color: #66718b; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 4px; border-top: 1px solid #d9e4ee; }
.result-stats span { display: flex; align-items: center; flex-direction: column; line-height: 1.15; padding-top: 3px; }
.result-stats small { font-size: 10px; color: #586680; font-weight: 800; }
.result-stats b { font-family: 'Dela Gothic One', sans-serif; font-size: 17px; font-weight: 400; }
.result-gallery canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.sb-table { width: 100%; border-collapse: separate; border-spacing: 0 4px; }
.sb-table td { padding: 6px 10px; font-weight: 800; }
.sb-table th { font-size: 12px; font-weight: 800; opacity: 0.7; text-align: center; }
.sb-table td.num { text-align: center; width: 70px; font-family: 'Dela Gothic One', sans-serif; font-weight: 400; font-size: 18px; }
.sb-table tr.t0 td:first-child { border-left: 5px solid var(--pink); }
.sb-table tr.t1 td:first-child { border-left: 5px solid var(--blue); }
.sb-table tr.me td { color: #ffe14d; }

@media (max-width: 640px) {
  .weapon-pick { grid-template-columns: repeat(2, 1fr); }
  .lobby-teams { grid-template-columns: 1fr; }
  .lobby-team li { padding: 6px 8px; }
  .lobby-team li .remove-cpu { min-width: 52px; }
  .result-panel { padding: 10px 8px; }
  #result-title { font-size: clamp(19px, 5vw, 30px); }
  .result-score { font-size: 27px; }
  .result-team { padding: 6px 4px; }
  .result-players { gap: 3px; }
  .result-player { padding: 0 2px 4px; }
  .result-model-slot { height: clamp(48px, 14vw, 62px); }
  .result-player-name { font-size: 9px; }
  .result-player-name small { display: none; }
  .result-stats small { font-size: 8px; }
  .result-stats b { font-size: 13px; }
}

/* ---------------------------------------------------------- タッチ操作とスマホ画面 */
.touch-controls { display: none; }
.touch-controls.hidden { display: none !important; }

body.touch-mode #touch-controls:not(.hidden) {
    display: block; position: absolute; inset: 0; z-index: 20; pointer-events: none;
    -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
body.touch-mode #view { touch-action: none; }
body.touch-mode .touch-controls button { font: inherit; color: #fff; cursor: pointer; touch-action: none; }
body.touch-mode .touch-look-zone {
    position: absolute; z-index: 0; inset: calc(48px + env(safe-area-inset-top)) 0 0 40%;
    pointer-events: none; touch-action: none;
}
body.touch-mode .touch-look-label {
    position: absolute; top: 18%; left: 50%; transform: translateX(-50%); padding: 6px 10px; border-radius: 999px;
    color: #fff; background: rgba(20, 30, 50, 0.38); font-size: 11px; font-weight: 800; white-space: nowrap;
    pointer-events: none; opacity: 0.72;
}
body.touch-mode .touch-stick {
    position: absolute; z-index: 2; left: calc(14px + env(safe-area-inset-left)); bottom: calc(14px + env(safe-area-inset-bottom));
    width: clamp(112px, 31vw, 142px); aspect-ratio: 1; border: 2px solid rgba(255,255,255,.82); border-radius: 50%;
    background: rgba(20, 40, 70, 0.3); box-shadow: inset 0 0 0 5px rgba(20, 40, 70, 0.16), 0 3px 14px rgba(0,0,0,.24);
    padding: 0; pointer-events: auto; touch-action: none;
}
body.touch-mode .touch-stick-knob {
    position: absolute; left: 50%; top: 50%; width: 44%; aspect-ratio: 1; transform: translate(-50%, -50%);
    border-radius: 50%; border: 2px solid #fff; background: rgba(47, 183, 255, 0.88); box-shadow: 0 3px 8px rgba(0,0,0,.25);
}
body.touch-mode .touch-stick-label { position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%); color: #fff; font-size: 10px; font-weight: 800; text-shadow: 0 1px 3px #17253d; }
body.touch-mode .touch-action {
    position: absolute; z-index: 3; display: grid; place-items: center; min-width: 52px; min-height: 52px; padding: 6px;
    border: 2px solid rgba(255,255,255,.9); border-radius: 50%; background: rgba(31, 42, 68, 0.66);
    box-shadow: 0 3px 10px rgba(0,0,0,.32); font-size: 12px; font-weight: 800; pointer-events: auto;
}
body.touch-mode .touch-action:active, body.touch-mode .touch-action.is-pressed { transform: scale(.94); background: rgba(31, 42, 68, 0.92); }
body.touch-mode #touch-fire {
    right: calc(14px + env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom));
    width: 76px; height: 76px; background: rgba(255, 79, 154, 0.9); border-radius: 50%; font-size: 14px;
}
body.touch-mode #touch-scope {
    right: calc(22px + env(safe-area-inset-right)); bottom: calc(104px + env(safe-area-inset-bottom));
}
body.touch-mode #touch-jump {
    right: calc(100px + env(safe-area-inset-right)); bottom: calc(22px + env(safe-area-inset-bottom));
}
body.touch-mode #touch-pause, body.touch-mode #touch-board { top: calc(8px + env(safe-area-inset-top)); border-radius: 14px; min-width: 44px; min-height: 44px; }
body.touch-mode #touch-pause { right: calc(8px + env(safe-area-inset-right)); }
body.touch-mode #touch-board { left: calc(8px + env(safe-area-inset-left)); }

@media (max-width: 640px) {
  .screen {
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }
  .panel { padding: 14px 12px; border-radius: 18px; }
  .panel.center { gap: 9px; }
  .panel h2 { font-size: 23px; }
  .btn { min-height: 44px; padding: 10px 14px; }
  .btn.big { min-height: 48px; padding: 10px 16px; font-size: 18px; }
  .btn.tiny { min-width: 44px; min-height: 44px; }
  .field { gap: 8px; }
  .field input[type=range] { min-height: 34px; }
  .field select { min-height: 44px; }
  .title-wrap { width: 100%; }
  #scr-title label.field { display: block; }
  #scr-title #in-name { display: block; width: 100%; margin-top: 6px; }
  .logo { font-size: clamp(34px, 10vw, 48px); white-space: nowrap; letter-spacing: -0.02em; }
  .tagline { margin: 5px 0 10px; font-size: 16px; }
  #scr-title .panel { padding: 12px; }
  #scr-title .menu:not(.small) { margin-top: 10px; gap: 8px; }
  #scr-title .menu:not(.small) .btn { width: min(100%, 290px); }
  #scr-title .menu.small { gap: 7px; }
  .note { margin: 8px 0 0; font-size: 12px; }
  .join-row { align-items: stretch; }
  #in-code { min-height: 48px; padding: 8px; font-size: 18px; }
  .lobby-team ol { gap: 5px; }
  .lobby-team li { min-height: 48px; }
  .lobby-me { gap: 8px; }
  .weapon-pick.mini { grid-template-columns: repeat(2, auto); }
  #scr-lobby .panel > h2 { display: flex; flex-wrap: wrap; align-items: center; gap: 3px 6px; }
  .code-label { margin-left: 0; }
  #scorebar {
    top: calc(8px + env(safe-area-inset-top)); gap: 3px; max-width: calc(100vw - 16px);
  }
  .team-icons { gap: 2px; }
  .team-icons span { width: clamp(14px, 4vw, 19px); height: clamp(14px, 4vw, 19px); border-width: 2px; font-size: clamp(9px, 2.7vw, 12px); }
  #scorebar .score b { min-width: clamp(38px, 12vw, 48px); padding: 2px 5px; border-radius: 10px; font-size: clamp(20px, 6vw, 26px); }
  #scorebar .target { font-size: 12px; }
  #netinfo { top: calc(42px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); }
  #killfeed { top: calc(104px + env(safe-area-inset-top)); right: 8px; max-width: 48vw; }
  #killfeed div { max-width: 100%; padding: 3px 8px; font-size: 10px; }
  #gauge {
    top: calc(54px + env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left)); bottom: auto; gap: 6px;
  }
  .gauge-icon { width: 42px; height: 42px; border-width: 2px; font-size: 15px; box-shadow: 0 2px 6px rgba(31,42,68,.22); }
  .gauge-icon small { font-size: 9px; }
  .gauge-bar { width: clamp(74px, 24vw, 104px); height: 14px; border-width: 2px; }
  #gauge-hint { display: none; }
  #weapon-box { top: calc(54px + env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); bottom: auto; }
  #weapon-box b { font-size: 14px; }
  #weapon-box span { font-size: 10px; }
  #center-msg { top: 62%; max-width: 90vw; font-size: 16px; }
  #center-msg .big { font-size: 28px; }
  #countdown { font-size: clamp(72px, 24vw, 110px); }
  #scoreboard { width: calc(100vw - 24px); max-height: 72dvh; overflow: auto; padding: 8px; }
  #click-to-play { top: 26%; width: max-content; max-width: calc(100vw - 36px); padding: 9px 14px; text-align: center; font-size: 13px; }
  .result-model-slot { height: clamp(48px, 14vw, 62px); }
}

@media (max-width: 900px) and (orientation: landscape) {
  .screen {
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }
  #scr-title .logo { font-size: clamp(32px, 7vw, 52px); }
  #scr-title .tagline { margin: 2px 0 6px; }
  #scr-title .panel { padding: 10px 12px; }
  #scr-title .note { margin-top: 4px; }
  .panel.center { gap: 7px; }
  #scr-lobby .lobby-teams { grid-template-columns: 1fr 1fr; }
  #scr-result .result-panel { padding: 8px 12px; }
  #scr-result .result-model-slot { height: clamp(34px, 10vh, 48px); }
  #scr-result .result-player { padding-bottom: 3px; }
  #scr-result .result-team { padding: 4px 6px; }
  #scr-result .result-score { margin-bottom: 2px; font-size: 22px; }
  #scr-result #result-title { margin-bottom: 4px; font-size: 22px; }
  #scr-result .menu { margin-top: 6px; gap: 6px; }
  #scr-result .btn { min-height: 40px; padding: 6px 10px; font-size: 13px; }
  body.touch-mode .touch-stick { width: clamp(96px, 24vh, 120px); }
  body.touch-mode #touch-fire { width: 64px; height: 64px; }
  body.touch-mode #touch-scope { bottom: calc(88px + env(safe-area-inset-bottom)); }
}
