:root {
  --bg: #0d1117;
  --panel: #161b22;
  --line: #30363d;
  --fg: #e6edf3;
  --muted: #8b949e;
  --accent: #f0a020;
  --blue: #5b8def;
  --red: #ef6b6b;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
  overflow: hidden;
  user-select: none;
}
.hidden { display: none !important; }

/* ── 메뉴 ── */
.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2430, var(--bg));
}
/* 메뉴 배경: 생성한 키 아트 위에 어둡게 깔아 패널/텍스트 가독성 확보 */
#menu {
  background:
    linear-gradient(rgba(13,17,23,.74), rgba(13,17,23,.92)),
    url('menu-bg.jpg') center / cover no-repeat,
    var(--bg);
}
#logo {
  width: 92px; height: 92px; border-radius: 50%;
  margin: 0 auto 6px; display: block;
  box-shadow: 0 6px 26px rgba(91,141,239,.35);
}
.panel {
  width: min(560px, 92vw);
  max-height: 96vh; overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 26px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.panel h1 {
  font-size: 40px; letter-spacing: 2px;
  background: linear-gradient(90deg, var(--blue), var(--accent), var(--red));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { color: var(--muted); margin: 8px 0 24px; font-size: 14px; }
.cls-pick { text-align: left; margin-bottom: 20px; }
.cls-pick > label { font-size: 12px; color: var(--muted); }
.cls-row { display: flex; gap: 10px; margin-top: 8px; }
.cls-btn {
  flex: 1; display: flex; flex-direction: column; gap: 4px;
  padding: 14px; border-radius: 12px; cursor: pointer;
  background: #0d1117; color: var(--fg);
  border: 2px solid var(--line); font-size: 16px; font-weight: 600;
}
.cls-btn small { color: var(--muted); font-weight: 400; font-size: 11px; }
.cls-btn.selected { border-color: var(--accent); background: #1c1710; }
.map-pick { text-align: left; margin: 6px 0 4px; display: flex; align-items: center; gap: 10px; }
.map-pick label { font-size: 12px; color: var(--muted); }
.map-pick select {
  flex: 1; background: #0d1117; color: var(--fg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 14px;
}
button.primary, button.ghost {
  width: 100%; padding: 14px; margin-top: 10px; border-radius: 12px;
  font-size: 16px; font-weight: 700; cursor: pointer; border: none;
}
button.primary { background: var(--accent); color: #1a1206; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
button:disabled { opacity: .5; cursor: not-allowed; }
.hint { margin-top: 18px; font-size: 12px; color: var(--muted); line-height: 1.7; }

/* ── 게임 ── */
#game { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
#cv {
  background: linear-gradient(#0b1a2e, #14253b);
  width: min(100vw, 177.78vh); height: auto; aspect-ratio: 16/9;
  image-rendering: auto; touch-action: none;
}
#hud { position: fixed; inset: 0; pointer-events: none; font-size: 14px; }
#wind {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(13,17,23,.78); border: 1px solid var(--line);
  padding: 6px 16px; border-radius: 20px; font-weight: 600;
}
#turn {
  position: absolute; top: 14px; left: 16px;
  background: rgba(13,17,23,.78); border: 1px solid var(--line);
  padding: 6px 14px; border-radius: 10px;
}
#controls {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 14px; align-items: center;
  background: rgba(13,17,23,.85); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 14px; pointer-events: auto;
}
.ctl { display: flex; flex-direction: column; align-items: center; min-width: 56px; }
.ctl span { font-size: 11px; color: var(--muted); }
.ctl b { font-size: 18px; }
#fire-btn {
  pointer-events: auto; padding: 12px 22px; border: none; border-radius: 12px;
  background: var(--accent); color: #1a1206; font-weight: 800; font-size: 15px; cursor: pointer;
}
#fire-btn:disabled { opacity: .45; cursor: default; }
#order {
  position: absolute; top: 14px; right: 16px;
  background: rgba(13,17,23,.78); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 10px; font-size: 12px; display: flex; gap: 8px; align-items: center;
}
#order .slot { opacity: .55; }
#order .slot.next { opacity: 1; font-weight: 700; color: var(--accent); }
#net-status {
  position: absolute; bottom: 70px; left: 50%; transform: translateX(-50%);
  font-size: 12px; color: var(--muted); background: rgba(13,17,23,.7);
  padding: 4px 12px; border-radius: 8px;
}
#banner {
  position: fixed; top: 40%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(13,17,23,.92); border: 1px solid var(--accent);
  padding: 24px 40px; border-radius: 16px; font-size: 28px; font-weight: 800;
  text-align: center;
}
#banner small { display: block; font-size: 14px; font-weight: 400; color: var(--muted); margin-top: 8px; }

/* 무기 전환 버튼(ctl 모양) · 아이콘 버튼 */
.ctl.tap { background: #0d1117; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; color: var(--fg); padding: 4px 8px; }
.ctl.tap:hover { border-color: var(--accent); }
.iconbtn {
  pointer-events: auto; width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(13,17,23,.85); color: var(--fg); font-size: 20px; cursor: pointer; line-height: 1;
}

/* ── 계정 / 랭킹 (M4) ── */
#account { margin: -8px 0 18px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #0d1117; }
.acct-info { text-align: left; color: var(--fg); font-size: 13px; line-height: 1.55; }
.acct-info .warn { color: #e3b341; font-weight: 700; }
.acct-info .acct-stat { color: var(--muted); font-size: 12px; }
.acct-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.acct-row input {
  flex: 1; min-width: 140px; background: #161b22; color: var(--fg); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 10px; font-size: 14px;
}
.acct-row button.mini { flex: 0 0 auto; }
.email-claim { margin-top: 10px; }
.email-claim > .link { padding: 0; }
#claim-form { margin-top: 4px; }
button.mini { flex: 1; padding: 9px; border-radius: 8px; border: 1px solid var(--line); background: #161b22; color: var(--fg); font-weight: 700; font-size: 13px; cursor: pointer; }
button.mini:hover { border-color: var(--accent); }
button.link { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; text-decoration: underline; }
.acct-msg { font-size: 12px; margin-top: 8px; min-height: 14px; }

/* 전적 저장 유도 모달 */
#email-prompt { z-index: 50; background: rgba(8, 11, 16, .82); }
.ep-card {
  width: min(440px, 92vw); background: #0d1117; border: 1px solid var(--line);
  border-radius: 16px; padding: 22px; box-shadow: 0 18px 60px rgba(0, 0, 0, .55); text-align: center;
}
.ep-card h2 { margin: 0 0 10px; font-size: 20px; }
.ep-card p { color: var(--muted); font-size: 13px; line-height: 1.65; margin: 0 0 14px; }
.ep-card .acct-row { justify-content: center; }
#ep-msg { text-align: center; }
.ep-actions { margin-top: 12px; }
.ep-actions .ghost { width: auto; padding: 8px 18px; }

#leaderboard { margin-top: 8px; border: 1px solid var(--line); border-radius: 10px; background: #0d1117; overflow: hidden; text-align: left; }
.lb-head { padding: 8px 12px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
.lb-load { padding: 14px; text-align: center; color: var(--muted); font-size: 13px; }
.lb-row { display: flex; align-items: center; gap: 10px; padding: 7px 12px; font-size: 13px; border-bottom: 1px solid #1c2230; }
.lb-row:last-child { border-bottom: none; }
.lb-row.me { background: #1c1710; }
.lb-rank { width: 24px; color: var(--accent); font-weight: 800; text-align: center; }
.lb-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-mmr { width: 52px; text-align: right; font-variant-numeric: tabular-nums; }
.lb-bp { width: 48px; text-align: right; color: var(--muted); }

/* 서브 버튼 행 */
.sub-row { display: flex; gap: 8px; margin-top: 10px; }
.sub-row .ghost { margin-top: 0; padding: 10px; font-size: 13px; }

/* 리플레이 목록 */
#replays { margin-top: 8px; border: 1px solid var(--line); border-radius: 10px; background: #0d1117; text-align: left; overflow: hidden; }
.rp-row { display: flex; align-items: center; gap: 10px; padding: 7px 12px; font-size: 13px; border-bottom: 1px solid #1c2230; }
.rp-row:last-child { border-bottom: none; }
.rp-map { flex: 1; font-weight: 600; }
.rp-turns { color: var(--muted); font-size: 12px; }
.rp-play { padding: 5px 10px !important; flex: none !important; }

/* 꾸미기 */
.cosmetics { margin-top: 10px; }
.cos-label { font-size: 11px; color: var(--muted); margin-bottom: 6px; text-align: left; }
.cos-row { display: flex; flex-wrap: wrap; gap: 6px; }
.cos-btn {
  display: flex; align-items: center; gap: 5px; padding: 6px 9px; border-radius: 8px; cursor: pointer;
  background: #161b22; color: var(--fg); border: 2px solid var(--line); font-size: 12px;
}
.cos-btn.selected { border-color: var(--accent); }
.cos-btn.locked { opacity: .5; cursor: not-allowed; }
.cos-sw { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }

/* 맵 에디터 */
.ed-panel {
  width: min(96vw, 1000px); max-height: 96vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; text-align: center;
}
.ed-panel h2 { margin-bottom: 10px; }
#ed-canvas { width: 100%; height: auto; aspect-ratio: 16/9; background: #0b1a2e; border: 1px solid var(--line); border-radius: 8px; touch-action: none; cursor: crosshair; }
.ed-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; margin-top: 12px; }
.ed-tools .ed-mat { padding: 8px 12px; border-radius: 8px; border: 2px solid var(--line); background: #0d1117; color: var(--fg); cursor: pointer; font-size: 13px; }
.ed-tools .ed-mat.selected { border-color: var(--accent); }
.ed-tools .mini, .ed-tools .primary, .ed-tools .ghost { width: auto; margin-top: 0; flex: none; padding: 8px 14px; }
.ed-size { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

/* ── 모바일 ── */
@media (max-width: 760px), (pointer: coarse) {
  .panel { padding: 20px 16px; }
  .panel h1 { font-size: 30px; }
  .cls-btn { padding: 10px; font-size: 14px; }
  .cls-btn small { font-size: 10px; }
  #controls { gap: 8px; padding: 8px 10px; bottom: 10px; flex-wrap: wrap; justify-content: center; max-width: 96vw; }
  .ctl { min-width: 44px; }
  .ctl b { font-size: 16px; }
  #fire-btn { padding: 12px 18px; font-size: 16px; }
  #turn, #order, #wind { font-size: 11px; padding: 5px 10px; }
  #order { max-width: 46vw; flex-wrap: wrap; }
}
