:root {
  --bg: #0b0e14;
  --panel: rgba(18, 22, 32, 0.78);
  --text: #e8ecf4;
  --muted: #8d98ad;
  --accent: #5eead4;
  --danger: #ff6b81;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  overflow: hidden;
  user-select: none;
  /* 한글이 단어 중간("만/큼", "버/튼")에서 줄바꿈되지 않게 띄어쓰기 단위로만 넘긴다. 아주 긴 이름은 어디서든 넘긴다 */
  word-break: keep-all;
  overflow-wrap: anywhere;
}

canvas#game { position: fixed; inset: 0; display: block; width: 100vw; height: 100vh; }

canvas#minimap {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 170px;
  height: 170px;
  border-radius: 50%;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

.hidden { display: none !important; }

.panel {
  position: fixed;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  backdrop-filter: blur(6px);
  padding: 10px 14px;
  font-size: 14px;
}

#hud { left: 16px; bottom: 16px; display: grid; gap: 4px; }
#hud .label { color: var(--muted); margin-right: 6px; }
#hud strong { font-size: 18px; font-variant-numeric: tabular-nums; }

#leaderboard { right: 16px; top: 16px; min-width: 190px; }

/* ── 휴대폰 조작 버튼 ── */
body.touch .keys-only { display: none; }
body:not(.touch) .touch-only { display: none; }
#touch-controls {
  position: fixed;
  inset: auto 0 0 0;
  height: 0;
  pointer-events: none;
  touch-action: none;
}
#touch-controls .steer {
  position: fixed;
  left: calc(18px + env(safe-area-inset-left));
  bottom: calc(18px + env(safe-area-inset-bottom));
  display: flex;
  gap: 18px;
}
#touch-controls .pad {
  position: relative;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  width: calc(100px * var(--pad-scale, 1));
  height: calc(100px * var(--pad-scale, 1));
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.55);
  background: rgba(18, 22, 32, 0.42);
  color: #fff;
  display: grid;
  place-items: center;
  padding: 0;
  backdrop-filter: blur(4px);
  transition: transform 0.06s, background 0.06s;
}
#touch-controls .pad svg { width: calc(40px * var(--pad-scale, 1)); height: calc(40px * var(--pad-scale, 1)); fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
/* 눈에 보이는 원보다 넓게 눌리도록 둘레에 보이지 않는 누름 영역을 둔다(엄지가 조금 빗나가도 먹게) */
#touch-controls .pad::before { content: ''; position: absolute; inset: -22px; border-radius: 50%; }
#touch-controls .steer .pad[data-kind='left']::before { right: -12px; } /* 두 버튼 사이 틈은 살짝 겹치게 나눠 빈틈이 없게 한다 */
#touch-controls .steer .pad[data-kind='right']::before { left: -12px; }
#touch-controls .pad.held { background: rgba(94, 234, 212, 0.45); border-color: var(--accent); transform: scale(0.94); }
#touch-controls .boost {
  position: fixed;
  right: calc(22px + env(safe-area-inset-right));
  bottom: calc(22px + env(safe-area-inset-bottom));
  width: calc(116px * var(--pad-scale, 1));
  height: calc(116px * var(--pad-scale, 1));
  font-size: calc(18px * var(--pad-scale, 1));
  font-weight: 800;
  letter-spacing: 0.02em;
}
#touch-controls .boost.held { background: rgba(255, 170, 60, 0.55); border-color: #ffc46b; }
#touch-controls.no-steer .steer { display: none; }

/* 드래그로 돌 때 손가락 자리에 뜨는 원: 도는 쪽 화살표가 밝아진다 */
#drag-ring {
  position: fixed;
  width: 84px;
  height: 84px;
  margin: -42px 0 0 -42px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.5);
  background: rgba(18, 22, 32, 0.18);
  pointer-events: none;
}
#drag-ring .arrow {
  position: absolute;
  top: 50%;
  width: 0;
  height: 0;
  margin-top: -9px;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  opacity: 0.4;
}
#drag-ring .arrow.left { left: -22px; border-right: 13px solid #fff; }
#drag-ring .arrow.right { right: -22px; border-left: 13px solid #fff; }
#drag-ring[data-dir="left"] .arrow.left { opacity: 1; border-right-color: var(--accent); }
#drag-ring[data-dir="right"] .arrow.right { opacity: 1; border-left-color: var(--accent); }

/* 설정 */
#settings-btn {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: grid;
  place-items: center;
}
#settings-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: round; }
.menu-links { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid rgba(255, 255, 255, 0.16);
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
}
.menu-btn .swatch i { width: 9px; height: 12px; }
/* 꾸미기 미리보기 */
#skin-preview { width: 100%; height: 190px; display: block; border-radius: 12px; background: #cdeee0; }
/* 꾸미기 창(설정 창과 같은 틀) */
#skins {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.45);
  padding: 16px;
}
#skins .sheet {
  width: min(560px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: #141a26;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 18px 20px;
  display: grid;
  gap: 10px;
}
#skins h2 { margin: 0; font-size: 20px; }
#skins h3 { margin: 6px 0 0; font-size: 14px; color: var(--muted); font-weight: 600; }
#skins .skins-note { margin: 0; font-size: 12px; color: var(--muted); }
#skins .actions { display: flex; justify-content: flex-end; }
.look-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
.look-card {
  display: grid;
  justify-items: center;
  gap: 5px;
  padding: 10px 6px 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 2px solid rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 13px;
}
.look-card.selected { border-color: var(--accent); background: rgba(94, 234, 212, 0.1); }
.look-name { font-weight: 700; }
.look-tag { font-size: 11px; color: var(--muted); }
.look-tag.paid { color: #ffd75e; }
.look-tag.free, .look-tag.owned { color: var(--accent); }
.look-card.locked .swatch, .look-card.locked .hat-icon { opacity: 0.55; }
.look-detail { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); font-size: 13px; color: var(--text); }
.look-detail button { padding: 8px 14px; font-size: 14px; }
.swatch { display: flex; gap: 2px; }
.swatch i { width: 12px; height: 14px; border-radius: 4px; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15); }
.hat-icon svg { width: 32px; height: 22px; color: var(--muted); }
.link-btn { margin-top: 10px; background: none; border: none; color: var(--muted); text-decoration: underline; padding: 4px 8px; font-size: 14px; }
#settings {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.45);
  padding: 16px;
}
#settings .sheet {
  width: min(420px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: #141a26;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 18px 20px;
  display: grid;
  gap: 14px;
}
#settings h2 { margin: 0; font-size: 20px; }
#settings .row { display: grid; gap: 6px; font-size: 15px; }
#settings .row > span { display: flex; justify-content: space-between; gap: 12px; }
#settings output { color: var(--accent); font-variant-numeric: tabular-nums; font-weight: 700; }
#settings small { color: var(--muted); font-size: 12px; }
#settings .check { grid-template-columns: auto 1fr; align-items: start; gap: 10px; }
#settings .check span { display: grid; gap: 2px; justify-content: start; }
#settings input[type=range] { width: 100%; accent-color: var(--accent); height: 28px; }
#settings input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; }
#settings .actions { display: flex; justify-content: flex-end; gap: 10px; }
#settings .ghost { background: transparent; border: 1px solid rgba(255, 255, 255, 0.2); color: var(--text); }
#settings .noads { border-top: 1px solid rgba(255, 255, 255, 0.08); padding-top: 12px; }
#settings .noads > span { display: grid; gap: 2px; justify-content: start; }
#settings .noads-actions { display: flex; gap: 10px; }
#settings .noads-actions button { flex: 1; }
#settings #noads-msg:empty { display: none; }
/* 휴대폰에서는 아래 양쪽을 버튼이 쓰므로 레이더와 길이 표시를 위쪽 왼편으로 옮긴다 */
body.touch canvas#minimap { left: calc(12px + env(safe-area-inset-left)); right: auto; top: 12px; bottom: auto; width: 118px; height: 118px; }
body.touch #hud { left: calc(140px + env(safe-area-inset-left)); bottom: auto; top: 12px; padding: 6px 10px; }
body.touch #leaderboard { top: 8px; right: calc(8px + env(safe-area-inset-right)); min-width: 150px; font-size: 12px; padding: 6px 10px; }
body.touch canvas#game { touch-action: none; }

/* 내 꼬리를 먹히는 중: 위쪽 가운데 경고 띠 + 화면 가장자리 붉은 맥박 */
#bite-alert {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 18px;
  border-radius: 999px;
  background: rgba(200, 20, 45, 0.88);
  border: 1px solid rgba(255, 190, 200, 0.6);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 6px 22px rgba(160, 0, 30, 0.45);
  animation: bite-shake 0.35s ease-in-out infinite;
  pointer-events: none;
}
/* 처치 알림: 꼬리 먹힘 경고(빨강)와 겹치지 않게 그 아래, 금색 */
#kill-toast {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 20px;
  border-radius: 999px;
  background: rgba(30, 24, 8, 0.86);
  border: 1px solid rgba(255, 210, 90, 0.75);
  color: #ffd75e;
  font-size: 17px;
  font-weight: 800;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
#kill-toast.pop { animation: kill-pop 0.32s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes kill-pop {
  from { transform: translateX(-50%) scale(0.6); opacity: 0; }
  to { transform: translateX(-50%) scale(1); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  #kill-toast.pop { animation: none; }
}
#bite-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 90px 28px rgba(255, 20, 50, 0.55);
  animation: bite-pulse 0.5s ease-in-out infinite alternate;
}
@keyframes bite-shake {
  0%, 100% { transform: translateX(-50%); }
  25% { transform: translateX(calc(-50% - 3px)); }
  75% { transform: translateX(calc(-50% + 3px)); }
}
@keyframes bite-pulse {
  from { opacity: 0.35; }
  to { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  #bite-alert, #bite-vignette { animation: none; }
}
#leaderboard h2 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: 0.04em; }
#leaderboard ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; }
#leaderboard li { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
#leaderboard li .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 120px; }
#leaderboard li .len { color: var(--muted); font-variant-numeric: tabular-nums; }
#leaderboard li.me { color: var(--accent); font-weight: 700; }
#leaderboard li.me .len { color: var(--accent); }
#leaderboard li.first .name { display: flex; align-items: center; gap: 5px; color: #ffd75e; font-weight: 700; }
#leaderboard li.first.me .name { color: var(--accent); }
#leaderboard .crown { width: 16px; height: 12px; flex: none; filter: drop-shadow(0 0 3px rgba(255, 200, 60, 0.6)); }
#leaderboard .crown-gold { fill: #ffc93c; }
#leaderboard .crown-gem { fill: #ff4466; }


.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(8, 10, 16, 0.72);
  padding: 16px;
}

.card {
  width: min(460px, 100%);
  background: #131826;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  padding: 28px 26px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

/* 시작 화면: 가로가 넓으면(폰 가로 화면 포함) 왼쪽에 이름·버튼, 오른쪽에 규칙 설명을 나란히 놓는다 */
.menu-card { max-height: calc(100vh - 32px); overflow-y: auto; }
@media (min-width: 640px) {
  .menu-card {
    width: min(920px, 100%);
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 28px;
    align-items: center;
  }
  .menu-card .rules { margin: 0; }
}
.card h1 { margin: 0 0 6px; font-size: 32px; letter-spacing: 0.01em; }
.card .sub { margin: 0 0 18px; color: var(--muted); line-height: 1.5; }
.card .sub b, .rules b { color: var(--accent); font-weight: 700; }
.card .score { margin: 0 0 18px; color: var(--muted); }
.card .score strong { color: var(--text); font-size: 20px; }

form { display: flex; gap: 8px; }

input[type='text'] {
  flex: 1;
  min-width: 0;
  background: #0d111b;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  padding: 12px 14px;
  outline: none;
  user-select: text;
}
input[type='text']:focus { border-color: var(--accent); }

button {
  background: var(--accent);
  color: #06201c;
  border: 0;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  padding: 12px 22px;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.5; cursor: default; }

.error { min-height: 1.2em; margin: 10px 0 0; color: var(--danger); font-size: 13px; }

.rules { margin: 8px 0 0; padding: 0; list-style: none; text-align: left; display: grid; gap: 8px; color: var(--muted); font-size: 13.5px; line-height: 1.45; }
kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  margin-right: 3px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: #0d111b;
  color: var(--text);
  font-size: 12px;
  text-align: center;
}

@media (max-width: 640px) {
  #leaderboard { top: 8px; right: 8px; min-width: 150px; font-size: 12px; }
}
