* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: #0a0a14; color: #e8e8ff; font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif; touch-action: none; overscroll-behavior: none; }
body { position: fixed; inset: 0; user-select: none; -webkit-user-select: none; }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
#app { position: fixed; inset: 0; }
#app canvas { display: block; }
.hidden { display: none !important; }

#hud { position: fixed; top: env(safe-area-inset-top, 0); left: 0; right: 0; z-index: 8; min-height: 58px; padding: 8px 12px; display: grid; grid-template-columns: minmax(100px,1fr) auto minmax(100px,1fr); align-items: center; gap: 10px; pointer-events: none; background: linear-gradient(180deg, rgba(4,5,14,.72), rgba(4,5,14,0)); text-shadow: 0 2px 10px #000; }
.brand-wrap { justify-self: start; min-width: 0; }
.title { font-size: 14px; line-height: 1.1; font-weight: 900; letter-spacing: 1.4px; background: linear-gradient(90deg,#63ffff,#6d95ff,#ef70ff); -webkit-background-clip: text; background-clip: text; color: transparent; white-space: nowrap; }
.mode-badge { display: inline-block; margin-top: 3px; padding: 2px 6px; border: 1px solid rgba(120,160,255,.35); border-radius: 99px; font-size: 8px; letter-spacing: 1px; color: #aab9e9; background: rgba(20,25,50,.55); }
.stats { display: flex; justify-content: center; gap: clamp(10px,3vw,22px); text-align: center; }
.stats .v { display: block; min-width: 34px; font-size: 17px; line-height: 1; font-weight: 800; color: #7ff; }
.stats .l { display: block; margin-top: 3px; font-size: 8px; letter-spacing: 1px; color: #8790b0; }
.hud-buttons { justify-self: end; display: flex; gap: 6px; pointer-events: auto; }
.icon-btn { width: 38px; height: 38px; border-radius: 12px; border: 1px solid rgba(130,150,220,.3); color: #dfe6ff; background: rgba(29,35,66,.72); font-weight: 800; font-size: 12px; cursor: pointer; backdrop-filter: blur(8px); }
.icon-btn.off { opacity: .42; text-decoration: line-through; }
.icon-btn:active { transform: scale(.94); }

#camHint { position: fixed; top: calc(env(safe-area-inset-top, 0px) + 62px); left: 50%; transform: translateX(-50%); z-index: 4; width: max-content; max-width: 70vw; font-size: 10px; text-align: center; color: #6e7698; text-shadow: 0 1px 6px #000; pointer-events: none; }

#opponentPanel { position: fixed; z-index: 7; top: calc(env(safe-area-inset-top, 0px) + 72px); right: 12px; width: min(210px, 38vw); padding: 10px; border: 1px solid rgba(123,148,230,.28); border-radius: 16px; background: rgba(12,15,31,.76); box-shadow: 0 10px 35px rgba(0,0,0,.3); backdrop-filter: blur(8px); }
.opponent-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 7px; }
.eyebrow { font-size: 7px; letter-spacing: 1.4px; color: #737eaa; }
.opponent-name { max-width: 125px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 800; color: #f1f4ff; }
.opponent-meta { font-size: 10px; color: #8ceeff; }
.opponent-board { display: grid; grid-template-rows: repeat(12, 1fr); gap: 2px; height: 118px; transform: rotate(180deg); }
.opp-layer { display: grid; grid-template-columns: repeat(16, 1fr); gap: 1px; min-height: 0; }
.opp-cell { border-radius: 1px; background: rgba(112,124,165,.10); }
.opp-cell.filled { background: rgba(100,205,255,.72); box-shadow: 0 0 4px rgba(80,200,255,.35); }
.opp-cell.active { background: rgba(247,113,255,.9); }
.garbage-row { display: flex; justify-content: space-between; align-items: center; margin-top: 7px; font-size: 9px; color: #8992b4; }
.garbage-row strong { color: #ffb5e8; font-size: 13px; }

.connection-badge { position: fixed; z-index: 6; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 8px); transform: translateX(-50%); padding: 4px 9px; border-radius: 99px; border: 1px solid rgba(100,130,200,.24); color: #7680a0; background: rgba(7,8,18,.66); font-size: 8px; letter-spacing: .8px; pointer-events: none; }
.connection-badge.online { color: #7cebc2; border-color: rgba(80,220,170,.25); }
.connection-badge.match { color: #8eeeff; border-color: rgba(80,220,255,.36); }

.attack-notice { position: fixed; z-index: 10; top: 50%; left: 50%; transform: translate(-50%,-50%); padding: 10px 16px; border: 1px solid rgba(255,120,220,.5); border-radius: 14px; color: #ffd6f5; background: rgba(80,15,70,.78); font-weight: 900; letter-spacing: .6px; box-shadow: 0 0 30px rgba(255,70,200,.2); pointer-events: none; animation: attack-pop .7s ease both; }
@keyframes attack-pop { 0% { opacity:0; transform:translate(-50%,-35%) scale(.75); } 25% { opacity:1; transform:translate(-50%,-50%) scale(1.08); } 100% { opacity:0; transform:translate(-50%,-62%) scale(.96); } }

#controls { position: fixed; z-index: 5; left: 0; right: 0; bottom: env(safe-area-inset-bottom, 0px); padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px)); display: flex; justify-content: space-between; align-items: flex-end; pointer-events: none; }
.btn { pointer-events: auto; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #dde4ff; background: rgba(40,46,78,.72); border: 1px solid rgba(120,150,220,.35); border-radius: 16px; box-shadow: 0 2px 12px rgba(0,0,0,.45); backdrop-filter: blur(7px); cursor: pointer; transition: transform .06s, background .1s; }
.btn:active { transform: scale(.9); background: rgba(80,130,230,.9); }
.btn .ic { font-size: 24px; line-height: 1; }
.btn .lb { margin-top: 3px; font-size: 9px; color: #aab3d0; }
#dpad { pointer-events: none; display: grid; grid-template-columns: repeat(3, 58px); grid-template-rows: repeat(3, 58px); gap: 7px; }
#dpad .sp { visibility: hidden; }
#dpad .btn { width: 58px; height: 58px; }
#dpad .soft { background: rgba(0,180,220,.34); border-color: rgba(0,220,255,.5); }
#actions { pointer-events: none; display: flex; flex-direction: column; align-items: flex-end; gap: 9px; }
.rotrow { display: flex; gap: 9px; }
.rot { width: 66px; height: 62px; }
.hard { width: 141px; height: 50px; flex-direction: row; gap: 7px; background: rgba(220,80,180,.31); border-color: rgba(255,120,220,.5); }
.hard .lb { margin: 0; font-size: 11px; color: #ffd2f1; }

.overlay { position: fixed; z-index: 30; inset: 0; display: flex; align-items: center; justify-content: center; padding: max(18px, env(safe-area-inset-top, 0px)) 18px max(18px, env(safe-area-inset-bottom, 0px)); background: rgba(5,6,16,.88); backdrop-filter: blur(7px); overflow-y: auto; touch-action: pan-y; }
.card { width: min(390px, 100%); max-height: calc(100dvh - 36px); overflow-y: auto; padding: 24px 22px; border: 1px solid #363b65; border-radius: 22px; color: #e8ecff; background: linear-gradient(180deg, rgba(25,28,51,.97), rgba(15,17,34,.97)); box-shadow: 0 20px 80px rgba(0,0,0,.55); text-align: center; }
.logo-chip { display: inline-block; margin-bottom: 9px; padding: 4px 8px; border-radius: 99px; border: 1px solid rgba(110,220,255,.28); color: #7cecff; font-size: 9px; font-weight: 800; letter-spacing: 1.6px; background: rgba(20,100,130,.18); }
.card h1 { margin: 0 0 10px; font-size: 29px; letter-spacing: .4px; background: linear-gradient(90deg,#64ffff,#6e91ff,#f06eff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.card h2 { margin: 6px 0 12px; font-size: 24px; }
.card p { color: #a8b0d0; font-size: 13px; line-height: 1.65; }
.lead { margin: 0 0 17px; }
.card button { cursor: pointer; border: 0; }
.wide { width: 100%; }
.primary, .accent, .secondary { min-height: 45px; padding: 11px 16px; border-radius: 13px; font-weight: 850; }
.primary { color: #07141d; background: linear-gradient(90deg,#72f7ff,#60bfff); box-shadow: 0 6px 18px rgba(60,190,255,.18); }
.accent { margin-top: 10px; color: #24091f; background: linear-gradient(90deg,#ff9fe8,#c696ff); box-shadow: 0 6px 18px rgba(220,100,255,.16); }
.secondary { color: #dce5ff; background: #2a3156; border: 1px solid #3d497a !important; }
.primary:active, .accent:active, .secondary:active, .small-btn:active { transform: scale(.98); }
.primary:disabled, .accent:disabled, .secondary:disabled { opacity: .42; cursor: not-allowed; }
.divider { display: flex; align-items: center; gap: 10px; margin: 19px 0 12px; color: #667097; font-size: 9px; letter-spacing: 1.5px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: #303655; }
.field-label { display: block; margin-bottom: 6px; text-align: left; color: #acb7dc; font-size: 11px; font-weight: 700; }
.text-input { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #3d4770; border-radius: 12px; outline: none; color: #f2f4ff; background: #11162b; user-select: text; -webkit-user-select: text; touch-action: manipulation; }
.text-input:focus { border-color: #6aaeea; box-shadow: 0 0 0 3px rgba(75,160,230,.12); }
.tiny { margin-top: 5px; text-align: left; color: #707a9e; font-size: 9px; }
.friend-box { margin-top: 13px; padding: 12px; border: 1px solid #303858; border-radius: 15px; background: rgba(6,8,22,.27); }
.friend-title { margin-bottom: 8px; text-align: left; color: #b9c3e6; font-size: 11px; font-weight: 800; }
.code-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.code-input { text-align: center; font-size: 20px; font-weight: 900; letter-spacing: 5px; font-variant-numeric: tabular-nums; }
.small-btn { min-width: 62px; border-radius: 11px; color: #d8e4ff; background: #273153; border: 1px solid #39456f !important; font-size: 11px; font-weight: 750; }
.friend-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.friend-actions .secondary { min-height: 40px; padding: 8px; font-size: 11px; }
.guide { margin-top: 14px; padding: 11px 12px; border-radius: 12px; text-align: left; color: #929dbc; background: rgba(0,0,0,.22); font-size: 11px; line-height: 1.65; }
.guide b { color: #8cecff; }
.guide.compact { font-size: 10px; }
.status { min-height: 16px; margin-top: 9px; color: #f6a8dd; font-size: 10px; line-height: 1.5; }
.spinner { width: 44px; height: 44px; margin: 2px auto 18px; border: 4px solid rgba(100,130,200,.2); border-top-color: #79efff; border-radius: 50%; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.room-code { margin: 13px 0; font-size: 34px; font-weight: 950; letter-spacing: 8px; color: #9df6ff; font-variant-numeric: tabular-nums; }
.result-score { margin: 14px 0; padding: 12px; border-radius: 13px; color: #8deeff; background: rgba(30,100,130,.15); font-weight: 800; }
#resultScreen .secondary, #pauseScreen .secondary { margin-top: 8px; }

.countdown { position: fixed; z-index: 40; inset: 0; display: grid; place-items: center; pointer-events: none; color: white; font-size: min(34vw, 180px); font-weight: 950; text-shadow: 0 0 40px rgba(80,220,255,.6), 0 4px 20px #000; background: rgba(6,7,18,.32); }
.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 90px); transform: translateX(-50%); max-width: min(86vw, 420px); padding: 9px 13px; border-radius: 12px; border: 1px solid rgba(150,170,230,.25); color: #e9edff; background: rgba(20,24,45,.94); box-shadow: 0 10px 35px rgba(0,0,0,.4); font-size: 11px; text-align: center; pointer-events: none; }

@media (max-width: 760px) {
  #hud { grid-template-columns: 1fr auto; grid-template-areas: "brand buttons" "stats stats"; gap: 4px; padding-top: 7px; }
  .brand-wrap { grid-area: brand; }
  .stats { grid-area: stats; margin-top: -2px; }
  .hud-buttons { grid-area: buttons; }
  #camHint { top: calc(env(safe-area-inset-top, 0px) + 90px); }
  #opponentPanel { top: calc(env(safe-area-inset-top, 0px) + 105px); right: 8px; width: 145px; padding: 8px; }
  .opponent-board { height: 88px; }
  .opponent-name { max-width: 90px; font-size: 10px; }
}

@media (max-width: 470px), (max-height: 680px) {
  #controls { padding-left: 9px; padding-right: 9px; padding-bottom: calc(9px + env(safe-area-inset-bottom, 0px)); }
  #dpad { grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(3, 48px); gap: 5px; }
  #dpad .btn { width: 48px; height: 48px; border-radius: 14px; }
  .btn .ic { font-size: 20px; }
  .btn .lb { font-size: 7px; }
  .rot { width: 55px; height: 51px; border-radius: 14px; }
  .hard { width: 119px; height: 43px; }
  .card { padding: 19px 17px; }
  .card h1 { font-size: 25px; }
  .lead { font-size: 11px !important; }
}

@media (orientation: landscape) and (max-height: 560px) {
  #opponentPanel { top: 64px; width: 155px; }
  .opponent-board { height: 72px; }
  #camHint { display: none; }
  #dpad { grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(3, 44px); }
  #dpad .btn { width: 44px; height: 44px; }
  .rot { width: 54px; height: 46px; }
  .hard { width: 117px; height: 40px; }
}
