* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #0d1226; color: #e9edff;
  font-family: -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  user-select: none; -webkit-user-select: none;
  overscroll-behavior: none;
}
canvas#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 12px; color: inherit; }
button:disabled { opacity: .4; cursor: default; }

/* 아래쪽 패널 */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-width: 520px; margin: 0 auto;
  background: rgba(20, 26, 54, .94);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-radius: 20px 20px 0 0;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0,0,0,.4);
}
.sheet.full { top: calc(40px + env(safe-area-inset-top)); display: flex; flex-direction: column; }
h1 { margin: 0 0 10px; font-size: 22px; letter-spacing: .5px; }
h1::before { content: "●"; color: #ff6b8b; margin-right: 6px; }
h2 { margin: 0 0 4px; font-size: 22px; }
.row { display: flex; gap: 8px; align-items: center; }
.row + .row { margin-top: 10px; }
input[type=text] {
  flex: 1; min-width: 0; font: inherit; font-size: 16px;
  padding: 11px 12px; border-radius: 12px; border: 1px solid #36406e;
  background: #0f1430; color: #fff; outline: none;
}
input[type=text]:focus { border-color: #7d8cff; }
.primary { background: #5865f2; padding: 11px 18px; font-weight: 700; }
.go { background: #22c55e; color: #05230f; padding: 12px 22px; font-weight: 800; font-size: 17px; margin-left: auto; }
.ghost-btn { background: transparent; color: #9aa4d6; padding: 8px 6px; font-size: 13px; }
.bounce .lbl { font-weight: 700; width: 34px; flex: none; }
.seg {
  flex: 1; padding: 10px 4px; background: #1d2550; color: #b8c0ee; font-weight: 700; font-size: 14px;
  box-shadow: inset 0 0 0 1px #36406e;
}
.seg.on { background: #ff6b8b; color: #2a0612; box-shadow: none; }
.hint { margin: 6px 0 0; font-size: 12px; color: #8f98c7; line-height: 1.4; }
#count { font-size: 13px; color: #9aa4d6; font-variant-numeric: tabular-nums; }

#players {
  list-style: none; margin: 10px 0 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: 6px;
  max-height: 22vh; overflow-y: auto;
}
#players li {
  display: flex; align-items: center; gap: 6px;
  background: #1d2550; border-radius: 999px; padding: 4px 6px 4px 8px; font-size: 13px;
}
#players li .dot { width: 14px; height: 14px; border-radius: 50%; box-shadow: inset 0 0 0 2px rgba(255,255,255,.35); }
#players li small { color: #9aa4d6; }
#players li button { background: transparent; color: #8f98c7; padding: 0 4px; font-size: 15px; line-height: 1; }
#players:empty::before { content: "아직 공이 없습니다. 이름과 탄성을 고르고 생성을 누르세요."; font-size: 13px; color: #8f98c7; }

/* 경기 중 */
#hud {
  position: fixed; left: 0; right: 0; top: 0;
  padding: calc(8px + env(safe-area-inset-top)) 10px 0;
  display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none;
}
#hud > * { pointer-events: auto; }
#board {
  background: rgba(13, 18, 38, .78); border-radius: 12px; padding: 8px 10px;
  font-size: 13px; min-width: 150px; max-width: 58vw;
}
#board .meta { color: #9aa4d6; font-size: 12px; margin-bottom: 4px; font-variant-numeric: tabular-nums; }
#board .line { display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; }
#board .line .rk { width: 18px; color: #9aa4d6; font-variant-numeric: tabular-nums; }
#board .line .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
#board .line .nm { overflow: hidden; text-overflow: ellipsis; }
#board .line.done .nm::after { content: " ✓"; color: #22c55e; }
.hud-right { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.chip-btn { background: rgba(13, 18, 38, .78); padding: 8px 12px; font-size: 13px; font-weight: 700; }

#countdown {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 96px; font-weight: 900; color: #fff; text-shadow: 0 6px 30px rgba(0,0,0,.6);
  pointer-events: none;
}
#countdown.pop { animation: pop .6s ease-out; }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* 결과 */
#resultMeta { margin: 0 0 10px; color: #9aa4d6; font-size: 13px; }
#ranking { list-style: none; margin: 0 0 12px; padding: 0; overflow-y: auto; flex: 1; }
#ranking li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 12px; background: #1a2148; margin-bottom: 6px; font-size: 15px;
}
#ranking li .rk { width: 34px; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; }
#ranking li .dot { width: 16px; height: 16px; border-radius: 50%; flex: none; }
#ranking li .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
#ranking li small { color: #9aa4d6; font-variant-numeric: tabular-nums; }
#ranking li.top1 { background: linear-gradient(90deg, #6b5310, #1a2148); }
#ranking li.top2 { background: linear-gradient(90deg, #4b5263, #1a2148); }
#ranking li.top3 { background: linear-gradient(90deg, #5d3a1d, #1a2148); }

/* 최근 이름: 눌러서 바로 추가 */
#recent { display: flex; gap: 6px; margin-top: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
#recent::-webkit-scrollbar { display: none; }
#recent .lbl { flex: none; font-size: 12px; color: #8f98c7; align-self: center; }
#recent button {
  flex: none; background: #1d2550; color: #cfd5ff; padding: 6px 10px; border-radius: 999px; font-size: 13px;
  box-shadow: inset 0 0 0 1px #36406e;
}
#recent button.all { background: transparent; color: #9aa4d6; box-shadow: none; }
#players li { cursor: pointer; }
#players li:active { transform: scale(.96); }

/* 순위판: 꼴찌 줄 */
#board .sep { color: #6b75a8; text-align: center; line-height: 1; margin: 1px 0; }
#board .line.last .nm { color: #ffb3c1; }
#board .line .tag { margin-left: auto; font-size: 11px; color: #ff6b8b; font-weight: 700; padding-left: 4px; }

/* 큰 알림 (1등, 꼴찌 결정전, 꼴찌 확정) */
#banner {
  position: fixed; left: 50%; top: 30%; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 14px 26px; border-radius: 20px; pointer-events: none; text-align: center;
  background: rgba(13, 18, 38, .82); box-shadow: 0 10px 40px rgba(0,0,0,.5); max-width: 90vw;
}
#banner b { font-size: 34px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 84vw; }
#banner span { font-size: 16px; font-weight: 700; color: #cfd5ff; }
#banner.win { box-shadow: 0 0 0 3px #ffd43b, 0 10px 40px rgba(255,212,59,.35); }
#banner.win b { color: #ffd43b; }
#banner.duel { box-shadow: 0 0 0 3px #ff6b8b, 0 10px 40px rgba(255,107,139,.35); }
#banner.last { box-shadow: 0 0 0 3px #ff4d6d, 0 10px 50px rgba(255,77,109,.5); }
#banner.last b { color: #ff8fa3; }
#banner.show { animation: bannerIn .45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes bannerIn { from { transform: translate(-50%, -50%) scale(.4); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }

/* 작은 알림 (역전, 결승 임박) */
#toast {
  position: fixed; left: 50%; bottom: calc(18% + env(safe-area-inset-bottom)); transform: translateX(-50%);
  padding: 8px 16px; border-radius: 999px; font-size: 15px; font-weight: 800; white-space: nowrap;
  background: rgba(255, 107, 139, .92); color: #2a0612; pointer-events: none; max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}
#toast.show { animation: toastIn .3s ease-out; }
@keyframes toastIn { from { transform: translate(-50%, 16px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* 결과: 1등·꼴찌 요약 */
#resultHead { display: flex; gap: 8px; margin: 6px 0 8px; }
#resultHead > div { flex: 1; min-width: 0; border-radius: 14px; padding: 10px 12px; background: #1a2148; }
#resultHead small { display: block; font-size: 12px; color: #9aa4d6; font-weight: 700; }
#resultHead b { display: block; font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#resultHead .w { box-shadow: inset 0 0 0 2px #ffd43b; }
#resultHead .w b { color: #ffd43b; }
#resultHead .l { box-shadow: inset 0 0 0 2px #ff4d6d; }
#resultHead .l b { color: #ff8fa3; }
/* 결과 화면 왼쪽 아래: 의견 남기기 (다시 하기와 같은 높이의 테두리 버튼) */
.feedback {
  display: inline-flex; align-items: center; justify-content: center; min-height: 46px;
  padding: 0 16px; border-radius: 12px; font-size: 15px; font-weight: 700;
  color: #cfd5ff; text-decoration: none; box-shadow: inset 0 0 0 1px #36406e;
}
.feedback:active { background: #1d2550; }
#ranking li.last { background: linear-gradient(90deg, #6b1a2c, #1a2148); }

#loadError {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 24px; background: #0d1226; line-height: 1.6;
}
