:root {
  --bg: #06070a;
  --panel: rgba(9, 11, 17, 0.84);
  --line: #222838;
  --text: #cfd6e6;
  --dim: #7a8399;
  --accent: #40aaff;
  --win: #7fd4ff;
  --lose: #ff6060;
  --top-h: 32px;
  --console-h: 172px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 12px/1.45 ui-monospace, Consolas, "D2Coding", "Malgun Gothic", monospace;
  user-select: none;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  cursor: default;
}

.hidden { display: none !important; }

button {
  font: inherit;
  color: var(--text);
  background: #141925;
  border: 1px solid #2c3446;
  padding: 3px 8px;
  cursor: pointer;
}
button:hover { border-color: #51618a; }
button:disabled { cursor: default; opacity: 0.6; }
button.on { background: var(--accent); color: #03111d; border-color: var(--accent); }

/* ---------- 인게임 UI ---------- */
kbd {
  display: inline-block;
  min-width: 14px;
  margin-right: 4px;
  padding: 0 3px;
  font: inherit;
  font-size: 10px;
  line-height: 14px;
  text-align: center;
  color: #9fb0d0;
  background: #0a0d14;
  border: 1px solid #2c3446;
}
button.on kbd { color: #03111d; background: rgba(255, 255, 255, 0.4); border-color: transparent; }
.dim { color: var(--dim); }

.panel {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 8px 10px;
}

/* 상단 막대 */
#topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--top-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 10px;
  background: rgba(7, 9, 14, 0.92);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
#topbar .tb-left, #topbar .tb-right { display: flex; align-items: center; gap: 10px; }
#topbar .tb-mid { flex: 1; display: flex; align-items: center; justify-content: center; gap: 16px; min-width: 0; overflow: hidden; }
#topbar .tb-right button { padding: 2px 8px; }
.logo { font-weight: bold; letter-spacing: 2px; color: #fff; }
.logo b { color: var(--accent); }
.stat { display: inline-flex; align-items: center; gap: 6px; }
.stat .k { color: var(--dim); }
.stat .v { color: #fff; }
.stat .hpb { width: 80px; }

/* 순위표 (Tab) */
#board {
  top: calc(var(--top-h) + 8px);
  right: 8px;
  max-height: calc(100% - var(--top-h) - var(--console-h) - 16px);
  overflow-y: auto;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
}
.trow {
  display: grid;
  grid-template-columns: 8px 92px 74px 64px 40px 24px 70px;
  gap: 8px;
  align-items: center;
  height: 18px;
  white-space: nowrap;
  font-size: 11px;
  cursor: pointer;
}
.trow:hover { background: rgba(255, 255, 255, 0.04); }
.trow.head { height: 16px; color: var(--dim); cursor: default; order: -2; }
.trow.head:hover { background: none; }
.trow.me { color: #fff; }
.trow.dead { opacity: 0.35; }
.trow canvas { width: 24px; height: 8px; image-rendering: pixelated; }
.chip { width: 8px; height: 8px; }
.hpb { position: relative; height: 5px; background: #3a1014; }
.hpb i { position: absolute; inset: 0 auto 0 0; background: #a6e88e; }

/* 단축키 도움말 (F1) */
#keys {
  top: calc(var(--top-h) + 8px);
  left: 8px;
  max-height: calc(100% - var(--top-h) - var(--console-h) - 16px);
  overflow-y: auto;
  font-size: 11px;
}
.keys-title { margin-bottom: 6px; color: #fff; }
#keys dl { display: grid; grid-template-columns: auto auto; gap: 3px 14px; margin: 0; }
#keys dt { color: var(--accent); white-space: nowrap; }
#keys dd { margin: 0; color: var(--text); }

/* 하단 콘솔 */
#console {
  position: fixed;
  inset: auto 0 0 0;
  height: var(--console-h);
  display: flex;
  gap: 10px;
  padding: 8px;
  background: rgba(7, 9, 14, 0.94);
  border-top: 1px solid var(--line);
}
#minimap-box {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: #030406;
  border: 1px solid var(--line);
}
#minimap { display: block; cursor: pointer; }
#selpanel {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: rgba(12, 15, 23, 0.8);
}
.sel-title { margin-bottom: 6px; color: #fff; font-size: 13px; }
.sel-title .dim { font-size: 11px; }
.sel-orders { margin-bottom: 8px; color: var(--dim); font-size: 11px; }
.sel-orders b { color: var(--text); font-weight: normal; }
.sel-levels { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; }
.sel-level {
  display: grid;
  grid-template-columns: 15px minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 5px;
  align-items: center;
  min-width: 0;
  padding: 3px 5px;
  border: 1px solid #222a3a;
  background: #0b0e15;
  color: var(--text);
  font: inherit;
  font-size: 11px;
  line-height: 1.3;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}
.sel-level:hover:not(:disabled) { border-color: #51618a; background: #121827; }
.sel-level:disabled { opacity: 0.3; cursor: default; }
.sel-level.empty:not(:disabled) { opacity: 0.45; }
.lv-icon { grid-row: span 2; width: 15px; height: 15px; display: flex; align-items: center; justify-content: center; }
.lv-icon i { display: block; }
.lv-name { color: var(--dim); font-size: 10px; }
.lv-nums { overflow: hidden; text-overflow: ellipsis; }
.lv-count { color: #fff; font-weight: normal; }
.lv-total { color: var(--dim); font-size: 10px; }
.sel-hint { margin-top: 5px; color: var(--dim); font-size: 10px; }
.sel-hint b { color: var(--text); font-weight: normal; }
.sel-hp { margin-top: 6px; display: none; align-items: center; gap: 8px; font-size: 11px; color: var(--dim); }
.has-sel .sel-hp { display: flex; }
.sel-hp .hpb { width: 160px; }
.has-sel .sel-tips { display: none; }
.sel-tips { margin-top: 6px; color: var(--dim); font-size: 11px; line-height: 1.6; }
.sel-tips b { color: var(--text); font-weight: normal; }

#cmdcard { flex: none; width: 300px; display: flex; flex-direction: column; gap: 3px; }
.cmd-title { color: var(--dim); font-size: 10px; }
.cmd-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.cmd-grid button { padding: 4px 4px; text-align: left; }
.cmd-row { display: flex; gap: 4px; margin-top: 4px; }
.cmd-row button { padding: 3px 6px; }
#cmdcard button.armed { background: #5a1a1a; border-color: #ff5a4a; color: #fff; }

#toasts {
  position: fixed;
  top: calc(var(--top-h) + 8px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--c, #fff);
  padding: 4px 10px;
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in { from { transform: translateY(-10px); opacity: 0; } }

@media (max-width: 860px) {
  :root { --console-h: 150px; }
  #cmdcard { width: 240px; }
  .cmd-title .dim, #topbar .tb-right .dim, #topbar [data-action="keys"] { display: none; }
  #topbar .tb-mid { justify-content: flex-start; }
}

/* ---------- 오버레이 (메뉴/종료) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 4, 7, 0.78);
}
.box {
  width: calc(100% - 32px);
  max-width: 640px;
  max-height: calc(100% - 32px);
  overflow: auto;
  padding: 22px 26px;
  background: #0b0e15;
  border: 1px solid var(--line);
}
.box.small { max-width: 420px; text-align: center; }

h1 { margin: 0 0 4px; font-size: 28px; letter-spacing: 6px; color: #fff; }
h1 b { color: var(--accent); }
.sub { margin-bottom: 16px; color: var(--dim); }

.option { display: flex; align-items: center; gap: 6px; margin: 8px 0; flex-wrap: wrap; }
.option .key { width: 92px; color: var(--dim); }

table { width: 100%; margin-top: 14px; border-collapse: collapse; font-size: 11px; }
td, th { padding: 3px 6px; border-bottom: 1px solid #1a1f2c; text-align: left; }
th { color: var(--dim); font-weight: normal; }
.swatch { display: inline-block; vertical-align: middle; }

.actions { display: flex; gap: 8px; margin-top: 16px; }
.box.small .actions { justify-content: center; }
.actions button { padding: 8px 18px; font-size: 13px; }
.actions button.primary { background: var(--accent); color: #03111d; border-color: var(--accent); }

.note { margin-top: 6px; color: var(--accent); font-size: 11px; }
.range-value { min-width: 24px; color: #fff; }
input[type="range"] { width: 120px; accent-color: var(--accent); }

.help { margin-top: 12px; color: var(--dim); font-size: 11px; line-height: 1.7; }

.end-title { margin: 0 0 8px; font-size: 30px; letter-spacing: 4px; color: var(--lose); }
.end-title.win { color: var(--win); }
