/* 인게임 셸 — 플레이 필드는 그대로 두고 패널과 모바일 컨트롤만 스티커 문법으로 정리한다. */
#game{
  --paper:#f4efe6;
  --ink:#14161c;
  --table:#14161c;
  --p1:#ff7a1c;
  --p2:#31a8ff;
  --dim:#8b93a3;
  --shadow:#07080b;
  --disp:'Lilita One','Arial Black',Impact,sans-serif;
  --kr:'Jua','Apple SD Gothic Neo','Malgun Gothic',sans-serif;
  --body:'Gowun Dodum','Apple SD Gothic Neo','Malgun Gothic',sans-serif;
  color:var(--paper);
  font-family:var(--body);
  -webkit-font-smoothing:antialiased;
}

/* 게임 화면의 바닥 = 타이틀·방 화면과 같은 테이블(40px 그리드 + 가장자리 비네트).
   #game 은 내용 크기의 flex 박스라 body 에 건다(:has 미지원 브라우저는 기존 솔리드로 폴백).
   캔버스는 그 위에 놓인 보드(솔리드 + 둥근 모서리 + 그림자)로 읽히고, 캔버스 안에는 그리드를
   두지 않아 스케일에 따른 이음새가 없다. 움직이는 잉크/공은 경기 중 주의를 끌므로 넣지 않는다. */
body:has(#game.on){
  background-color:#0b0c10;
  background-image:
    radial-gradient(circle at 50% 43%,transparent 0 30%,rgba(0,0,0,.58) 100%),
    repeating-linear-gradient(0deg,rgba(255,255,255,.035) 0 1px,transparent 1px 40px),
    repeating-linear-gradient(90deg,rgba(255,255,255,.035) 0 1px,transparent 1px 40px);
  background-attachment:fixed;
}

#game #side{
  min-height:0;
  padding:8px;
  gap:9px;
  color:var(--paper);
  background:#11141a;
  border:1px solid #05070a;
  border-radius:14px;
  box-shadow:5px 6px 0 var(--shadow);
}

#game #side > .bar{
  flex:none;
  padding:9px 10px;
  color:var(--dim);
  background:#1a1d25;
  border:1px solid #05070a;
  border-radius:10px;
  box-shadow:2px 3px 0 var(--shadow);
  font-family:var(--body);
  font-size:12px;
}

#game #side > .bar:first-child > div:first-child{
  flex-wrap:wrap;
  gap:7px;
}

#game #sideTitle{
  min-width:0;
  display:inline-flex;
  align-items:center;
  gap:7px;
  color:var(--paper);
  font-family:var(--kr);
  font-size:15px;
  font-weight:700;
  line-height:1.2;
}

#game #sideTitle::before{
  width:10px;
  height:10px;
  flex:none;
  content:'';
  background:var(--p1);
  border:2px solid var(--ink);
  border-radius:58% 42% 55% 45%/48% 62% 38% 52%;
  box-shadow:1px 1px 0 var(--shadow);
}

#game #sideSub{
  margin-top:6px!important;
  color:var(--dim);
  font-size:12px;
  line-height:1.35;
}

#game .net{
  flex:none;
  display:inline-flex;
  align-items:center;
  gap:5px;
  min-height:24px;
  padding:2px 8px;
  color:var(--ink);
  background:var(--paper);
  border:2px solid var(--ink);
  border-radius:999px;
  box-shadow:2px 2px 0 var(--shadow);
  font-family:var(--kr);
  font-size:10px;
  line-height:1;
  white-space:nowrap;
}

#game .net i{
  width:8px;
  height:8px;
  flex:none;
  display:inline-block;
  background:#45c969;
  border:1px solid var(--ink);
  border-radius:50%;
}

#game .net i[data-cq="0"]{background:#45c969}
#game .net i[data-cq="1"]{background:#ffd23f}
#game .net i[data-cq="2"]{background:#ff5f64}
#game .net i[data-cq="3"]{position:relative;background:#14161c}
#game .net i[data-cq="3"]::after{
  position:absolute;
  top:3px;
  left:1px;
  width:6px;
  height:1px;
  content:'';
  background:#f4efe6;
  border-radius:1px;
  transform:rotate(-48deg);
}

#game .net i.off{background:#ff5f64}
#game .net i.off::after{display:none}

#game #side > .bar#keyhint{
  display:flex;
  flex-direction:column;
  gap:5px;
  color:#b5bbc6;
  font-size:10.5px;
  line-height:1.2;
}

#game #keyhint .keyrow{
  min-width:0;
  min-height:20px;
  display:flex;
  align-items:center;
  gap:6px;
}

#game #paramDebugHint[hidden],#game #debugHint[hidden]{display:none}
#game #keyhint a.keyrow{color:inherit;text-decoration:none}
#game #keyhint a.keyrow:hover span{color:#f4efe6;text-decoration:underline}

#game #keyhint .keycaps{
  display:inline-flex;
  align-items:center;
  gap:3px;
}

#game #keyhint .keycaps i{
  color:#6f7785;
  font-style:normal;
}

#game #keyhint kbd{
  min-width:20px;
  min-height:18px;
  display:inline-grid;
  place-items:center;
  padding:1px 5px;
  color:var(--ink);
  background:var(--paper);
  border:2px solid var(--ink);
  border-radius:6px;
  box-shadow:1px 1px 0 var(--shadow);
  font-family:var(--disp);
  font-size:11px;
  font-weight:400;
  line-height:1;
}

#game #side > .chat{
  min-width:0;
  min-height:min(140px,22vh);   /* 짧은 뷰포트에서는 하한이 버튼을 밀어내지 않게 */
  max-height:480px;
  flex:1 1 auto;
  display:flex;
  flex-direction:column;
  overflow:hidden;
  color:var(--paper);
  background:var(--table);
  border:2px solid #05070a;
  border-radius:12px;
  box-shadow:3px 4px 0 var(--shadow);
}

#game .chatTools{
  flex:none;
  display:flex;
  justify-content:flex-end;
}

#game #btnMuteGame{
  min-height:28px;
  padding:4px 9px;
  color:var(--paper);
  background:transparent;
  border:1.5px solid #666e7d;
  border-radius:999px;
  box-shadow:1px 2px 0 var(--shadow);
  font-family:var(--kr);
  font-size:10px;
  line-height:1;
}

#game .chat .log{
  min-height:0;
  flex:1;
  overflow-y:auto;
  padding:9px 10px;
  color:var(--paper);
  font-size:12px;
  line-height:1.5;
  scrollbar-color:#626a78 transparent;
  scrollbar-width:thin;
}

#game .chat .log div{
  margin-bottom:4px;
  word-break:break-word;
}

#game .chat .log div.muted-msg{display:none}

#game .chat .log .sys{
  color:#aeb4bf;
  font-size:11px;
  font-style:italic;
}

#game .chat .log b.p1{color:#ff9b56}
#game .chat .log b.p2{color:#69c2ff}

#game .chat form{
  flex:none;
  display:flex;
  align-items:center;
  gap:6px;
  padding:7px;
  background:#0e1015;
  border-top:1px solid #373d49;
}

#game .chat #gameChatInput{
  min-width:0;
  flex:1;
  padding:8px 9px;
  color:var(--paper);
  background:#1d2028;
  border:1.5px solid #596171;
  border-radius:999px;
  box-shadow:none;
  outline:none;
  font-family:var(--body);
  font-size:12px;
}

#game .chat #gameChatInput::placeholder{color:#9199a8}

#game .chat #gameChatInput:focus-visible{
  border-color:var(--p2);
  box-shadow:inset 0 0 0 2px var(--paper);
}

#game .chat form button{
  min-height:32px;
  flex:none;
  padding:5px 11px;
  color:var(--ink);
  background:var(--p2);
  border:2px solid var(--ink);
  border-radius:999px;
  box-shadow:2px 2px 0 #000;
  font-family:var(--kr);
  font-size:11px;
}

#game #gameBtns{
  min-width:0;
  flex:none;
  display:flex;
  gap:8px;
  margin-top:auto;
}

#game #gameBtns button,
#game #mobileEndBar button{
  min-width:0;
  min-height:44px;
  flex:1;
  padding:8px 10px;
  border:2px solid var(--ink);
  border-radius:999px;
  box-shadow:3px 3px 0 var(--shadow);
  font-family:var(--kr);
  font-size:13px;
  line-height:1.15;
}

#game #btnQuit,
#game #btnQuit2{
  color:var(--paper);
  background:transparent;
  border-color:var(--paper);
}

#game #btnRematch,
#game #btnRematch2{
  color:var(--ink);
  background:var(--p1);
  border-color:var(--ink);
}

#game #btnRematch.wants,
#game #btnRematch2.wants{
  color:var(--ink);
  background:var(--paper);
  border-color:var(--p1);
  box-shadow:0 0 0 3px var(--ink),5px 5px 0 var(--shadow);
  animation:rematchWantPulse 1.4s ease-in-out infinite;
}

@keyframes rematchWantPulse{
  0%,100%{transform:scale(1)}
  50%{transform:scale(1.035)}
}

#game button:hover:not(:disabled){filter:brightness(1.06)}

#game button:active:not(:disabled){
  transform:translate(2px,2px);
  box-shadow:1px 1px 0 var(--shadow);
}

#game button:focus-visible{
  outline:2px solid var(--paper);
  outline-offset:2px;
}

#game button:disabled{
  opacity:.4;
  cursor:default;
  filter:saturate(.45);
}

#game .touch-hint{display:none}

/* 연습 모드 파라미터 창 — 온라인에서는 열리지 않는다. */
#game #gameDebug{
  position:fixed;
  top:12px;
  right:12px;
  z-index:60;
  width:min(520px,calc(100vw - 24px));
  max-height:min(800px,calc(100dvh - 24px));
  display:flex;
  flex-direction:column;
  padding:13px 14px;
  color:#c9cfda;
  background:#14161c;
  border:2px solid #05070a;
  border-radius:14px;
  box-shadow:5px 6px 0 var(--shadow),0 0 28px #0009;
  font-size:12px;
}

#game #gameDebug[hidden]{display:none}

#game #gameDebug .debugHead{
  flex:none;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  margin-bottom:8px;
  padding-bottom:8px;
  border-bottom:1px solid #353b48;
}

#game #gameDebug .debugHead b{
  color:var(--paper);
  font-family:var(--kr);
  font-size:14px;
}

#game #gameDebug .debugHead output{
  min-width:52px;
  padding:3px 6px 2px;
  color:#b8f6cd;
  background:#10251a;
  border:1px solid #2c7a4b;
  border-radius:6px;
  font-family:var(--disp);
  font-size:11px;
  line-height:1;
  text-align:center;
  font-variant-numeric:tabular-nums;
  white-space:nowrap;
}

#game #gameDebug .debugHead output[data-level="warn"]{
  color:#ffe49a;
  background:#2a2411;
  border-color:#8a7129;
}

#game #gameDebug .debugHead output[data-level="low"]{
  color:#ffb2b2;
  background:#2d1518;
  border-color:#963d46;
}

#game #gameDebug .debugHead span{
  color:#8b93a3;
  font-size:10px;
  white-space:nowrap;
}

#game #gameDebug .debugHead kbd{
  padding:1px 4px;
  color:var(--ink);
  background:var(--paper);
  border:1px solid var(--ink);
  border-radius:4px;
  font-family:var(--disp);
}

#game #gameDebug .debugFxActions{
  flex:none;
  display:flex;
  align-items:center;
  gap:9px;
  margin-bottom:8px;
  padding:8px;
  background:#0d1016;
  border:1px solid #353b48;
  border-radius:9px;
}

#game #gameDebug .debugFxActions button{
  min-width:94px;
  min-height:36px;
  padding:7px 12px;
  color:#fff;
  background:linear-gradient(135deg,var(--p1),#e9f4ff 48%,var(--p2));
  border:2px solid #05070a;
  border-radius:8px;
  box-shadow:2px 2px 0 var(--shadow);
  font-family:var(--disp);
  font-size:13px;
}

#game #gameDebug .debugFxActions button:active{transform:translate(1px,1px);box-shadow:1px 1px 0 var(--shadow)}

#game #gameDebug .debugFxActions span{
  min-width:0;
  color:#aeb7c5;
  font-size:10px;
  line-height:1.35;
}

#game #gameDebug .debugParamLayout{
  min-height:0;
  flex:1 1 auto;
  display:flex;
  gap:12px;
}

#game #gameDebug .debugParamTabs{
  width:126px;
  min-width:126px;
  overflow-x:hidden;
  overflow-y:auto;
  padding:2px 9px 2px 2px;
  border-right:1px solid #353b48;
  scrollbar-color:#626a78 transparent;
  scrollbar-width:thin;
}

#game #gameDebug .debugParamTabs button{
  width:100%;
  min-height:34px;
  margin:0 0 5px;
  padding:7px 8px;
  color:#8f98a7;
  background:#0d1016;
  border:1px solid #303642;
  border-radius:7px;
  box-shadow:none;
  font-family:var(--kr);
  font-size:10px;
  line-height:1.25;
  text-align:left;
}

#game #gameDebug .debugParamTabs button:hover{
  color:#dce3ed;
  background:#1b1f28;
}

#game #gameDebug .debugParamTabs button[aria-selected="true"]{
  color:#fff4e9;
  background:#392116;
  border-color:var(--p1);
  box-shadow:inset 3px 0 0 var(--p1);
}

#game #gameDebug .debugParamTabs button:focus-visible{
  outline:2px solid var(--p2);
  outline-offset:1px;
}

#game #gameParamWrap{
  min-width:0;
  min-height:0;
  flex:1 1 auto;
  overflow-y:auto;
  padding-right:5px;
  scrollbar-color:#626a78 transparent;
  scrollbar-width:thin;
}

#game #gameDebug .debugParamPanel[hidden]{display:none}

#game #gameDebug .sec{
  margin:0 0 10px!important;
  padding:2px 0 8px;
  color:#929aaa;
  border-bottom:1px solid #353b48;
  font-family:var(--disp);
  font-size:10px;
  letter-spacing:1px;
}

#game #gameDebug .prm{margin-bottom:9px}

#game #gameDebug .prm .lb{
  display:flex;
  justify-content:space-between;
  gap:10px;
  margin-bottom:3px;
  font-size:11px;
}

#game #gameDebug .prm .lb b{color:#ffd9b8;font-weight:600}
#game #gameDebug .prm .lb span{color:var(--p2);font-variant-numeric:tabular-nums}
#game #gameDebug .prm input[type=range]{width:100%;margin:0;accent-color:var(--p1)}
#game #gameDebug .prm.disabled{opacity:.5}

#game #gameDebug .prm .desc{
  display:none;
  margin-top:5px;
  padding:6px 7px;
  color:#aeb7c5;
  background:#0d1016;
  border:1px solid #353b48;
  border-radius:7px;
  font-size:10px;
  line-height:1.4;
}

#game #gameDebug .prm:hover .desc,
#game #gameDebug .prm:focus-within .desc{display:block}

/* 타점별 플리퍼 힘 보정 — 로비/방/연습 디버그가 같은 3점 그래프를 공유한다. */
.paramCurve{
  --curve-bg:#e8e1d6;
  --curve-border:#b8afa2;
  --curve-grid:#c7bfb3;
  --curve-text:#59606b;
  --curve-line:var(--p1);
  margin:10px 0 13px;
  padding:8px;
  border:1px solid var(--curve-border);
  border-radius:9px;
  background:var(--curve-bg);
}

.paramCurve .curveHead{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin-bottom:4px;
  font-size:11px;
}

.paramCurve .curveHead b{color:#753914}
.paramCurve .curveHead span{color:#087ab9;font-variant-numeric:tabular-nums}
.paramCurve .curveGraph{
  display:block;
  width:100%;
  height:112px;
  cursor:crosshair;
  touch-action:none;
  user-select:none;
}

.paramCurve .curveGrid,
.paramCurve .curveBase{stroke:var(--curve-grid);stroke-width:1}
.paramCurve .curveBase{stroke-dasharray:4 3;stroke-width:1.5}
.paramCurve .curveLine{fill:none;stroke:var(--curve-line);stroke-width:3;stroke-linecap:round;stroke-linejoin:round}
.paramCurve .curvePoint{fill:var(--curve-line);stroke:#fff;stroke-width:2;filter:drop-shadow(1px 1px 0 #0005)}
.paramCurve .curvePoint.disabled{opacity:.4}
.paramCurve .curveYLabel,
.paramCurve .curveXLabel{fill:var(--curve-text);font-size:9px;font-family:system-ui,sans-serif}
.paramCurve .curveControls{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:7px}
.paramCurve .curveControl{
  min-width:0;
  display:grid;
  grid-template-columns:1fr auto;
  align-items:center;
  gap:2px 5px;
  color:var(--curve-text);
  font-size:9px;
}
.paramCurve .curveControl output{font-variant-numeric:tabular-nums}
.paramCurve .curveControl input[type=range]{grid-column:1/-1;width:100%;margin:0;accent-color:var(--p1)}
.paramCurve .curveControl input[type=range]:disabled{opacity:.4}
.paramCurve .curveDesc{margin-top:7px;color:var(--curve-text);font-size:9px;line-height:1.4}

#game .paramCurve{
  --curve-bg:#0d1016;
  --curve-border:#353b48;
  --curve-grid:#343b48;
  --curve-text:#aeb7c5;
}
#game .paramCurve .curveHead b{color:#ffd9b8}
#game .paramCurve .curveHead span{color:var(--p2)}

#game #gameDebug .paramActions{
  flex:none;
  display:flex;
  gap:7px;
  margin-top:9px;
}

#game #gameDebug .paramActions button{
  min-height:34px;
  flex:1;
  padding:6px 8px;
  border:1.5px solid #626a78;
  border-radius:8px;
  box-shadow:2px 2px 0 var(--shadow);
  font-size:11px;
}

#game #gameDebug .debugNote{
  flex:none;
  margin-top:8px;
  color:#7f8795;
  font-size:10px;
  line-height:1.4;
}

@media (max-width:760px){
  #game #gameDebug{
    inset:8px;
    width:auto;
    max-height:calc(100dvh - 16px);
  }

  #game #gameDebug .debugParamLayout{gap:8px}
  #game #gameDebug .debugParamTabs{
    width:104px;
    min-width:104px;
    padding-right:7px;
  }
  #game #gameDebug .debugParamTabs button{
    min-height:32px;
    padding:6px;
    font-size:9px;
  }

  #game #side{
    gap:8px;
    padding:calc(62px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
    color:var(--paper);
    background-color:rgba(11,12,16,.985);
    background-image:
      radial-gradient(circle at 50% 20%,rgba(49,168,255,.08),transparent 42%),
      repeating-linear-gradient(0deg,rgba(255,255,255,.025) 0 1px,transparent 1px 40px),
      repeating-linear-gradient(90deg,rgba(255,255,255,.025) 0 1px,transparent 1px 40px);
    border:0;
    border-radius:0;
    box-shadow:none;
    overflow:hidden;
  }

  #game #side::before{
    position:absolute;
    top:calc(15px + env(safe-area-inset-top));
    left:50%;
    width:54px;
    height:6px;
    content:'';
    background:var(--paper);
    border:2px solid var(--ink);
    border-radius:999px;
    box-shadow:2px 2px 0 var(--shadow);
    transform:translateX(-50%);
  }

  #game #side > .bar{padding:8px 9px}

  #game #keyhint{
    display:flex;
    flex-flow:row wrap;
    gap:5px 7px;
  }

  #game #keyhint .keyrow{
    min-height:19px;
    flex:1 1 calc(50% - 4px);
  }

  #game #keyhint kbd{
    min-height:17px;
    padding-inline:4px;
  }

  #game #side > .chat{
    min-height:0;
    max-height:none;
    flex:1 1 auto;
  }

  #game #chatFab{
    top:calc(8px + env(safe-area-inset-top));
    left:calc(8px + env(safe-area-inset-left));
    right:auto;
    width:44px;
    height:44px;
    padding:0;
    display:flex;
    align-items:center;
    justify-content:center;
    color:var(--ink);
    background:var(--paper);
    border:3px solid var(--ink);
    border-radius:50%;
    box-shadow:4px 4px 0 var(--shadow);
    font-family:var(--body);
    font-size:18px;
    line-height:1;
  }

  #game #chatFab:hover:not(:disabled){background:var(--paper)}
  #game #chatFab svg{width:22px;height:22px;display:block}
  #game #chatFab .x,#game #chatFab[data-open="1"] .bubble{display:none}
  #game #chatFab[data-open="1"] .x{display:block}

  #game.ended #mobileEndBar{
    left:10px;
    right:10px;
    bottom:max(12px,env(safe-area-inset-bottom));
    gap:8px;
    padding:5px;
    background:rgba(11,12,16,.88);
    border:1px solid #05070a;
    border-radius:999px;
    box-shadow:3px 4px 0 var(--shadow);
  }

  #game #mobileEndBar button{
    min-height:46px;
    padding:8px 12px;
    font-size:14px;
  }
}

@media (pointer:coarse) and (max-width:760px){
  #game.on:not(.ended) .touch-hint{
    position:absolute;
    right:12px;
    bottom:clamp(78px,13dvh,116px);
    left:12px;
    z-index:5;
    display:flex;
    justify-content:space-between;
    gap:12px;
    visibility:hidden;
    pointer-events:none;
    animation:gameHintFade 4.5s ease both;
  }

  #game .touch-hint span{
    max-width:47%;
    padding:5px 8px;
    color:rgba(244,239,230,.76);
    background:rgba(20,22,28,.7);
    border:1.5px solid rgba(244,239,230,.58);
    border-radius:999px;
    box-shadow:2px 2px 0 rgba(7,8,11,.72);
    font-family:var(--kr);
    font-size:11px;
    line-height:1.15;
    text-align:center;
    white-space:nowrap;
  }

  #game.ended .touch-hint{
    visibility:hidden;
    opacity:0;
    animation:none;
  }
}

@keyframes gameHintFade{
  0%{visibility:hidden;opacity:0;transform:translateY(6px)}
  9%,56%{visibility:visible;opacity:1;transform:translateY(0)}
  88%{visibility:visible;opacity:0;transform:translateY(0)}
  100%{visibility:hidden;opacity:0;transform:translateY(0)}
}

@media (prefers-reduced-motion:reduce){
  /* :not(.ended) 를 붙여 표시 규칙과 같은 특이도로 — display 만으로는 애니메이션이 남는다 */
  #game.on:not(.ended) .touch-hint{animation:none;visibility:hidden;display:none}
  #game button{transition:none}
  #game #btnRematch.wants,
  #game #btnRematch2.wants{animation:none}
}
