:root {
  --bg: #020714;
  --panel: rgba(4, 17, 36, 0.86);
  --line: rgba(98, 183, 255, 0.45);
  --blue: #00a8ff;
  --blue2: #004eea;
  --orange: #ff8a00;
  --orange2: #d94800;
  --green: #75ff52;
  --red: #ff4b36;
  --text: #f7fbff;
  --muted: #a9bad2;
  --blue-territory: 50%;
  --orange-territory: 50%;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: radial-gradient(circle at top, #08234b 0, var(--bg) 45%, #01030a 100%); color: var(--text); font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; overscroll-behavior: none; }
body::before { content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 0; background: linear-gradient(90deg, rgba(0,168,255,.24) 0 var(--blue-territory), rgba(255,138,0,.24) var(--blue-territory) 100%); filter: saturate(1.2); transition: background .25s ease; }
body::after { content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 0; background: radial-gradient(circle at center, transparent 0 38%, rgba(0,0,0,.45) 82%); }
button, input { font: inherit; }
button { border: 0; border-radius: 14px; padding: 10px 14px; color: #fff; background: linear-gradient(135deg, var(--blue), var(--blue2)); font-weight: 900; cursor: pointer; box-shadow: 0 0 18px rgba(0,168,255,.38); }
button.secondary { background: rgba(255,255,255,.08); border: 1px solid var(--line); }
button.mode-chip { color: #fff; box-shadow: none; cursor: pointer; }
input { width: 100%; min-width: 0; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: rgba(0,0,0,.35); color: #fff; outline: none; }
h2, h3, p { margin-top: 0; }
.hidden { display: none !important; }
.stars { position: fixed; inset: 0; z-index: 1; pointer-events: none; background-image: radial-gradient(#fff8 1px, transparent 1px); background-size: 38px 38px; opacity: .12; }
.app { position: relative; z-index: 2; width: min(1120px, 100%); height: 100dvh; margin: 0 auto; padding: 8px 10px; display: flex; flex-direction: column; gap: 8px; }
.hero { display: grid; grid-template-columns: 42px 1fr 42px; align-items: center; gap: 8px; flex: 0 0 auto; }
h1 { margin: 0; text-align: center; font-size: clamp(22px, 4.8vw, 44px); font-style: italic; letter-spacing: -0.05em; line-height: 1; text-shadow: 0 0 12px var(--blue), 4px 0 0 rgba(255,138,0,.45); }
.icon-btn { width: 42px; height: 42px; padding: 0; background: rgba(255,255,255,.06); border: 1px solid var(--line); font-size: 22px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 12px; box-shadow: inset 0 0 24px rgba(0,168,255,.08), 0 0 20px rgba(0,0,0,.35); }
.entry-card { margin-top: 3vh; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.share { color: var(--muted); word-break: break-all; }
#game { flex: 1 1 auto; min-height: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; gap: 8px; }
.top-bar { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; }
.timer, .room-chip, .mode-chip { border: 2px solid var(--line); border-radius: 18px; padding: 7px 12px; background: rgba(0,0,0,.45); font-weight: 900; text-align: center; }
.room-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.header-reset { padding: 7px 9px; border-radius: 999px; font-size: 12px; white-space: nowrap; box-shadow: 0 0 14px rgba(255,223,107,.25); }
.mode-chip.admin { border-color: #ffdf6b; color: #ffdf6b; }
.mode-chip.player { border-color: #80dfff; color: #80dfff; }
.timer strong { color: #fff05a; font-size: clamp(24px, 5vw, 42px); margin: 0 5px; text-shadow: 0 0 12px #ffea00aa; }
.waiting-card { text-align: center; }
.waiting-card h2 { margin-bottom: 6px; }
.waiting-card p { margin-bottom: 8px; color: var(--muted); }
.members { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 6px; margin: 8px 0; max-height: 32dvh; overflow: hidden; }
.member { border-radius: 12px; padding: 7px; background: rgba(255,255,255,.06); border: 1px solid #ffffff22; font-size: 13px; }
.member.blue { color: #8fdbff; } .member.orange { color: #ffc18a; }
.admin-actions { display: flex; gap: 8px; justify-content: center; }
.countdown { position: fixed; inset: 0; z-index: 5; display: grid; place-items: center; background: rgba(0,0,0,.62); font-size: min(40vw, 240px); font-weight: 1000; text-shadow: 0 0 35px var(--blue); }
.battle-grid { min-height: 0; display: grid; grid-template-columns: minmax(150px, .75fr) minmax(220px, 1.1fr) minmax(150px, .75fr); grid-template-rows: auto minmax(0, 1fr) auto; gap: 8px; align-items: stretch; padding: 8px; border-radius: 22px; border: 1px solid rgba(255,255,255,.12); background: linear-gradient(90deg, rgba(0,168,255,.18) 0 var(--blue-territory), rgba(255,138,0,.18) var(--blue-territory) 100%); box-shadow: inset 0 -28px 70px rgba(0,0,0,.22); transition: background .25s ease; }
.switch-panel { grid-column: 1 / -1; min-height: 88px; display: grid; grid-template-columns: 132px 1fr; gap: 12px; align-items: center; padding: 10px 14px; border-radius: 18px; border: 2px solid var(--green); background: linear-gradient(135deg, rgba(22,255,0,.18), rgba(3,26,9,.9)); box-shadow: 0 0 20px rgba(117,255,82,.28); }
.switch-panel.off { border-color: var(--red); background: linear-gradient(135deg, rgba(255,65,45,.18), rgba(30,5,5,.9)); box-shadow: 0 0 20px rgba(255,75,54,.28); }
.switch-visual { width: 128px; height: 56px; border-radius: 999px; border: 4px solid #fff9; background: #42d936; position: relative; box-shadow: inset 0 0 14px #0008; }
.switch-panel.off .switch-visual { background: #a91515; }
.knob { position: absolute; top: 5px; left: 68px; width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(#fff,#bbb); transition: .12s; }
.switch-panel.off .knob { left: 12px; }
.switch-copy { display: flex; align-items: center; gap: 14px; justify-content: center; }
.switch-text { font-size: clamp(48px, 11vw, 86px); line-height: .9; font-weight: 1000; color: #c9ffc0; text-shadow: 0 0 18px var(--green); }
.switch-panel.off .switch-text { color: #ffb3a8; text-shadow: 0 0 18px var(--red); }
.switch-help { border: 1px solid #fff4; border-radius: 999px; padding: 8px 12px; text-align: center; font-weight: 900; }
.switch-help .off { color: var(--red); }
.score-card, .rank-card { background: rgba(0,0,0,.4); border: 1px solid var(--line); border-radius: 14px; padding: 10px; font-size: clamp(13px, 2vw, 16px); font-weight: 800; overflow: hidden; }
.score-card h3, .rank-card h3 { margin-bottom: 5px; }
.score-card strong, .rank-card strong { font-size: clamp(28px, 5vw, 42px); line-height: 1; }
.record, small { color: var(--muted); font-size: 12px; }
.penalty strong { color: #ff6a5b; }
.blue { color: #79d7ff; } .orange { color: #ffb064; } .vs { text-align: center; font-size: 22px; margin: 3px; }
.tap-button { width: min(38dvh, 330px, 100%); aspect-ratio: 1 / 1; border-radius: 50%; justify-self: center; align-self: center; display: grid; place-items: center; align-content: center; font-size: clamp(24px, 5vw, 42px); border: 8px solid #9be9ff; background: radial-gradient(circle, #0cb7ff, #004bea 72%); box-shadow: 0 0 28px var(--blue), inset 0 0 38px rgba(255,255,255,.18); user-select: none; touch-action: manipulation; }
.tap-button:active, body.tapped .tap-button { transform: scale(.985); filter: brightness(1.22); }
.tap-icon { font-size: clamp(44px, 10vw, 88px); }
.result-card { text-align: center; }
.result-card h2 { margin-bottom: 6px; }
.result-records { display: flex; justify-content: center; gap: 18px; margin-bottom: 8px; font-weight: 900; }
.territory-card { min-height: 104px; background: rgba(2,7,20,.72); border: 1px solid rgba(255,255,255,.18); border-radius: 18px; padding: 8px 10px 10px; box-shadow: 0 0 24px rgba(0,0,0,.35), inset 0 0 24px rgba(255,255,255,.05); }
.territory-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 10px; font-weight: 1000; margin-bottom: 6px; }
.territory-head h3 { margin: 0; font-size: clamp(16px, 3vw, 24px); text-align: center; }
.team-pct { display: flex; align-items: baseline; gap: 8px; }
.team-pct.orange { justify-content: flex-end; }
.team-pct span { font-size: 13px; opacity: .9; text-transform: uppercase; letter-spacing: .08em; }
.team-pct strong { font-size: clamp(24px, 5vw, 42px); line-height: .9; }
#bluePct { color: #8fe2ff; text-shadow: 0 0 14px rgba(0,168,255,.7); }
#orangePct { color: #ffc075; text-shadow: 0 0 14px rgba(255,138,0,.7); }
.territory-stage { position: relative; display: flex; height: clamp(48px, 10dvh, 92px); border-radius: 16px; overflow: hidden; border: 2px solid rgba(255,255,255,.4); background: #090d17; }
.territory-side { height: 100%; display: grid; place-items: center; min-width: 6%; transition: width .25s ease; font-size: clamp(16px, 4vw, 36px); font-weight: 1000; letter-spacing: .08em; text-shadow: 0 2px 10px rgba(0,0,0,.65); }
.blue-side { background: linear-gradient(135deg, #002e94, #00a8ff); box-shadow: inset -18px 0 38px rgba(255,255,255,.16); }
.orange-side { background: linear-gradient(135deg, #ff9d1b, #d94800); box-shadow: inset 18px 0 38px rgba(255,255,255,.16); }
.frontline { position: absolute; top: 50%; left: var(--blue-territory); transform: translate(-50%, -50%); width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.95); color: #1a1a1a; box-shadow: 0 0 24px #fff, 0 0 42px rgba(255,240,90,.7); font-size: 24px; transition: left .25s ease; }
.menu-panel { position: fixed; inset: 0; z-index: 30; display: grid; place-items: start center; padding: max(70px, 12dvh) 12px 12px; background: rgba(0,0,0,.48); }
.menu-card { width: min(460px, 100%); position: relative; }
.menu-card h2 { margin-bottom: 8px; }
.menu-close { position: absolute; top: 10px; right: 10px; }
.menu-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.qr-card { text-align: center; }
.qr-image { width: min(260px, 72vw); height: min(260px, 72vw); border-radius: 18px; padding: 10px; background: #fff; box-shadow: 0 0 28px rgba(255,255,255,.28); }
.confetti-burst { position: fixed; inset: 0; z-index: 40; pointer-events: none; overflow: hidden; }
.confetti-piece { position: absolute; top: -24px; left: 50%; width: 12px; height: 18px; border-radius: 3px; background: var(--color); animation: confetti-fall 2.3s cubic-bezier(.12,.72,.34,1) var(--delay) forwards; box-shadow: 0 0 10px color-mix(in srgb, var(--color), transparent 35%); }
.confetti-piece:nth-child(3n) { width: 9px; height: 9px; border-radius: 50%; }
.confetti-piece:nth-child(4n) { width: 16px; height: 8px; }
@keyframes confetti-fall { to { transform: translate3d(var(--x), 110dvh, 0) rotate(var(--r)); opacity: .05; } }
.toast-stack { position: fixed; z-index: 20; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); display: grid; gap: 8px; width: min(340px, calc(100vw - 20px)); pointer-events: none; }
.toast { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: center; padding: 11px 13px; border-radius: 16px; background: rgba(5,12,28,.9); border: 1px solid rgba(255,255,255,.22); box-shadow: 0 10px 28px rgba(0,0,0,.38), inset 0 0 18px rgba(255,255,255,.06); color: #fff; font-weight: 900; animation: toast-in .22s ease-out both; }
.toast.blue { border-color: rgba(0,168,255,.7); box-shadow: 0 10px 28px rgba(0,0,0,.38), 0 0 20px rgba(0,168,255,.34); }
.toast.orange { border-color: rgba(255,138,0,.7); box-shadow: 0 10px 28px rgba(0,0,0,.38), 0 0 20px rgba(255,138,0,.34); }
.toast.leaving { animation: toast-out .45s ease-in both; }
.toast-dot { width: 10px; height: 10px; border-radius: 50%; background: #8aff70; box-shadow: 0 0 12px currentColor; }
.toast.blue .toast-dot { background: var(--blue); }
.toast.orange .toast-dot { background: var(--orange); }
@keyframes toast-in { from { opacity: 0; transform: translateX(24px) scale(.96); } to { opacity: 1; transform: translateX(0) scale(1); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(28px) scale(.96); } }
@media (max-width: 760px) {
  .app { padding: 6px; gap: 5px; }
  .hero { grid-template-columns: 34px 1fr 34px; }
  .icon-btn { width:34px;height:34px;font-size:18px;}
  .form-row { grid-template-columns: 1fr; }
  #game { gap: 5px; grid-template-rows: auto auto minmax(0, 1fr) auto; }
  .top-bar { grid-template-columns: 1fr auto; }
  .mode-chip { grid-column: 1 / -1; padding: 4px 8px; }
  .timer, .room-chip { padding: 5px 8px; border-radius: 14px; }
  .room-actions { gap: 4px; }
  .header-reset { padding: 5px 7px; font-size: 11px; }
  .battle-grid { grid-template-columns: 1fr 1fr; grid-template-rows: auto minmax(0, 1fr) auto; gap: 5px; padding: 5px; }
  .switch-panel { grid-template-columns: 86px 1fr; min-height: 64px; padding: 7px; }
  .switch-visual { width: 82px; height: 38px; border-width: 3px; }
  .knob { top: 4px; left: 43px; width: 26px; height: 26px; }
  .switch-panel.off .knob { left: 7px; }
  .switch-copy { gap: 7px; }
  .switch-help { font-size: 12px; padding: 5px 7px; }
  .tap-button { grid-column: 1 / -1; grid-row: 2; width: min(34dvh, 250px); }
  .score-card, .rank-card { text-align:center; padding: 7px; }
  .personal-rank, .team-rank { display: none; }
  .territory-card { min-height: 92px; padding: 6px; }
  .territory-stage { height: clamp(44px, 9dvh, 76px); }
  .team-pct span { display: none; }
  .frontline { width: 34px; height: 34px; font-size: 19px; }
  .toast-stack { top: 8px; right: 8px; width: min(300px, calc(100vw - 16px)); }
  .toast { padding: 9px 11px; font-size: 13px; }
  .members { max-height: 42dvh; }
}
@media (max-height: 680px) {
  .card { padding: 8px; }
  .tap-button { width: min(32dvh, 250px, 100%); }
  .territory-card { min-height: 78px; }
  .territory-stage { height: 42px; }
  .territory-head h3 { font-size: 15px; }
  .team-pct strong { font-size: 22px; }
}
