:root {
  --bg: #05060a;
  --panel: rgba(14, 16, 26, 0.82);
  --line: rgba(255, 255, 255, 0.08);
  --text: #e8eaf3;
  --muted: #8a90a8;
  --accent: #7fb2ff;
  --hp: #e0556a;
  --mana: #4f8dff;
  --font: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;
}

canvas#game { display: block; cursor: crosshair; }

[hidden] { display: none !important; }

/* 대기실 */
#join {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: auto;
}

#lobbybox {
  width: min(1000px, 100%);
  padding: 24px 24px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.brand { text-align: center; margin-bottom: 18px; }
.brand h1 {
  margin: 0;
  font-size: 44px;
  letter-spacing: 0.12em;
  color: #dbe7ff;
  text-shadow: 0 0 22px rgba(127, 178, 255, 0.6), 0 2px 0 #1b2c55;
}
.brand .sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.cols { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 20px; }
.cols h2 { margin: 0 0 10px; font-size: 15px; color: #cfd6ee; letter-spacing: 0.05em; }

button, select, input { font: inherit; }
button {
  height: 40px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
}
button:hover { background: rgba(255, 255, 255, 0.11); }
button.primary { border: 0; background: linear-gradient(180deg, #6ea6ff, #4a7fe0); color: #fff; font-weight: 700; }
button.primary:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.45; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#name {
  display: block;
  width: 100%;
  height: 44px;
  margin: 0 0 12px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 16px;
  outline: none;
  user-select: text;
}
#name:focus { border-color: var(--accent); }

.classes { display: grid; gap: 8px; text-align: left; }
.cls {
  --h: 200;
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  height: auto;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  text-align: left;
}
.cls:hover { background: rgba(255, 255, 255, 0.06); }
.cls[aria-pressed="true"] {
  border-color: hsl(var(--h) 70% 60%);
  background: hsl(var(--h) 50% 30% / 0.25);
  box-shadow: 0 0 0 1px hsl(var(--h) 70% 60% / 0.5) inset;
}
.cls .portrait { width: 72px; height: 72px; border-radius: 10px; background: radial-gradient(circle at 50% 45%, hsl(var(--h) 40% 30% / 0.45), rgba(0,0,0,0.25) 70%); }
.cls .info { display: grid; gap: 3px; min-width: 0; }
.cls .top { display: flex; align-items: baseline; gap: 8px; }
.cls strong { font-size: 16px; color: hsl(var(--h) 80% 75%); }
.cls small { font-size: 12px; color: var(--muted); }
.cls .desc { font-size: 12.5px; line-height: 1.4; color: #c7cbdb; }
.cls ul { list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 1px 8px; margin: 3px 0 0; padding: 0; font-size: 12px; color: #c7cbdb; }
.cls li b { display: inline-block; min-width: 44px; color: var(--muted); font-weight: 600; }

.roomhead { display: flex; justify-content: space-between; align-items: baseline; }
#lobbystat { color: var(--muted); font-size: 12px; }

#invite {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 217, 138, 0.4);
  border-radius: 10px;
  background: rgba(255, 217, 138, 0.08);
}
#invite span { flex: 1; }
#invite code { color: #ffd98a; font-weight: 700; letter-spacing: 0.1em; }

#roomlist {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  max-height: 330px;
  overflow: auto;
  display: grid;
  gap: 6px;
}
.room {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 4px 10px;
  align-items: center;
  padding: 9px 10px 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}
.room.invited { border-color: rgba(255, 217, 138, 0.5); }
.room .rname { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room .rmeta { grid-column: 1; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room .rnow { grid-row: 1 / span 2; grid-column: 2; text-align: right; font-size: 12px; color: #c7cbdb; white-space: nowrap; }
.room .rnow b { display: block; font-size: 14px; color: var(--text); }
.room button { grid-row: 1 / span 2; grid-column: 3; height: 36px; padding: 0 12px; }
.room.empty { display: block; color: var(--muted); text-align: center; font-size: 13px; }
.chip { display: inline-block; margin-right: 6px; padding: 1px 6px; border-radius: 5px; background: rgba(127, 178, 255, 0.15); color: #b8d0ff; font-size: 11px; font-weight: 700; vertical-align: 1px; }
.chip.main { background: rgba(255, 217, 138, 0.15); color: #ffd98a; }

.roombtns { display: flex; gap: 8px; }
.roombtns button { flex: 1; }

#createform {
  display: grid;
  gap: 10px;
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.2);
}
#createform .field { display: grid; gap: 5px; margin: 0; padding: 0; border: 0; font-size: 13px; color: #c7cbdb; }
#createform legend { padding: 0; margin-bottom: 5px; }
#createform input[type="text"], #createform input:not([type]), #createform select {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  user-select: text;
}
#createform select option { background: #141826; }
#createform .two { grid-template-columns: 1fr 1fr; gap: 10px; }
#createform .two label { display: grid; gap: 5px; }
.choices { display: flex; flex-wrap: wrap; gap: 6px; }
.choices label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
}
.choices label:has(input:checked) { border-color: var(--accent); background: rgba(127, 178, 255, 0.12); }
.choices small { color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #c7cbdb; cursor: pointer; }
.row { display: flex; gap: 8px; }
.row button { flex: 1; }

#joinmsg { min-height: 20px; margin: 12px 0 2px; color: #ffb0a0; font-size: 14px; text-align: center; }
#joinmsg.ok { color: var(--muted); }

.keys {
  list-style: none;
  margin: 6px 0 0;
  padding: 12px 0 0;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
}
.keys b { color: var(--text); font-weight: 600; }
.soundbtn { display: block; margin: 10px auto 0; height: 30px; font-size: 12px; color: var(--muted); }

/* 게임 화면 위 표시 */
#hud { position: fixed; inset: 0; pointer-events: none; font-size: 14px; }

#topleft, #topright, #match {
  position: absolute;
  top: 12px;
  padding: 6px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
}
#topleft { left: 12px; display: flex; gap: 10px; align-items: center; padding: 4px 10px 4px 4px; pointer-events: auto; }
#topleft button { height: 26px; padding: 0 9px; font-size: 12px; }
#roomname { color: var(--text); font-weight: 600; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#topright { right: 12px; }

#match {
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  align-items: baseline;
  white-space: nowrap;
  color: var(--text);
  font-weight: 600;
}
#match .mode { color: #cfe0ff; }
#match .clock { font-variant-numeric: tabular-nums; color: var(--muted); }
#match .score { font-size: 17px; font-weight: 800; }

#feed {
  position: absolute;
  top: 52px;
  right: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
#feed div {
  padding: 4px 10px;
  background: var(--panel);
  border-radius: 6px;
  transition: opacity 0.6s;
}
#feed .sys { color: var(--muted); }
#feed .flag { border: 1px solid rgba(255, 220, 120, 0.25); }
#feed .ult { border: 1px solid rgba(255, 200, 90, 0.45); color: #ffe6a8; }
#feed .arrow { color: var(--muted); margin: 0 6px; }

#banner {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  padding: 14px 26px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  text-align: center;
  animation: pop 0.25s ease-out;
}
#banner strong { display: block; font-size: 26px; letter-spacing: 0.04em; color: #cfe0ff; }
#banner small { display: block; margin-top: 4px; color: #c7cbdb; font-size: 14px; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -8px); } }

#bottom {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#nextcls {
  padding: 3px 10px;
  background: var(--panel);
  border-radius: 6px;
  color: #ffd98a;
  font-size: 13px;
}

.bars { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.bar {
  position: relative;
  width: 300px;
  height: 18px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
}
.bar.mana { height: 12px; }
#hpfill { height: 100%; width: 100%; background: linear-gradient(180deg, #ff7184, var(--hp)); transition: width 0.12s; }
#manafill { height: 100%; width: 100%; background: linear-gradient(180deg, #78a8ff, var(--mana)); transition: width 0.12s; }
/* 기사: 마나 대신 방패 내구도 */
.bar.mana.guard #manafill { background: linear-gradient(180deg, #e9eef7, #8d9bb4); }
.bar.mana.guard.broken { border-color: rgba(255, 110, 125, 0.8); }
.bar.mana.guard.broken #manafill { background: linear-gradient(180deg, #ff9aa5, #b8384c); }
#buffs { display: flex; gap: 6px; }
#buffs span { padding: 3px 10px; border-radius: 6px; background: var(--panel); font-size: 13px; font-weight: 800; border: 1px solid; }
#buffs .power { color: #ffab5c; border-color: rgba(255, 150, 60, 0.6); box-shadow: 0 0 10px rgba(255, 120, 40, 0.4); }
#buffs .ward { color: #ffe08a; border-color: rgba(255, 214, 107, 0.7); box-shadow: 0 0 10px rgba(255, 210, 100, 0.5); }
#feed .item { border: 1px solid rgba(255, 255, 255, 0.18); }
#hptext, #manatext { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; font-weight: 700; text-shadow: 0 1px 2px #000; }
#manatext { font-size: 10px; }

.skills { display: flex; gap: 8px; }
.skill {
  position: relative;
  display: grid;
  grid-template-columns: 34px auto;
  align-items: center;
  gap: 0 6px;
  min-width: 104px;
  padding: 5px 10px 5px 5px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
}
.skill .ico { grid-row: 1 / span 2; width: 34px; height: 34px; background: center / contain no-repeat; position: relative; }
.skill b { position: relative; font-size: 11px; color: var(--muted); font-weight: 600; }
.skill span { position: relative; font-weight: 700; font-size: 13px; white-space: nowrap; }
.skill i {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0;
  background: rgba(0, 0, 0, 0.62);
  z-index: 1;
}
.skill.nomana span { color: #7f8bb8; }
.skill.nomana .ico { opacity: 0.45; }
.skill.nomana { border-color: rgba(79, 141, 255, 0.35); }
.skill.silenced { border-color: rgba(200, 120, 255, 0.6); }
.skill.silenced span { color: #b58ad6; text-decoration: line-through; }
.skill.silenced .ico { opacity: 0.35; }
.skill.on { border-color: #9cc8ff; box-shadow: 0 0 10px rgba(156, 200, 255, 0.4) inset; }
.skill.ready { animation: ready 0.35s ease-out; }
/* 궁극기 칸: 금빛 게이지가 아래에서 차오르고, 다 차면 빛난다 */
.skill.ult { border-color: rgba(255, 200, 90, 0.4); margin-left: 6px; }
.skill.ult i { background: linear-gradient(0deg, rgba(255, 176, 50, 0.5), rgba(255, 226, 140, 0.22)); z-index: 0; transition: height 0.2s; }
.skill.ult b { color: #e9c987; }
.skill.ult .ico { opacity: 0.6; }
.skill.ult.charged { border-color: #ffd66b; animation: ultpulse 1.1s ease-in-out infinite; }
.skill.ult.charged .ico, .skill.ult.on .ico { opacity: 1; }
.skill.ult.charged b { color: #fff1c4; }
.skill.ult.on { border-color: #fff1c4; box-shadow: 0 0 16px rgba(255, 220, 130, 0.8); }
@keyframes ultpulse {
  0%, 100% { box-shadow: 0 0 6px rgba(255, 200, 80, 0.45), 0 0 0 1px rgba(255, 214, 107, 0.4) inset; }
  50% { box-shadow: 0 0 18px rgba(255, 200, 80, 0.95), 0 0 0 1px rgba(255, 236, 170, 0.9) inset; }
}
#match .stand { color: #ffd66b; font-weight: 800; }
.cls li.ult b { color: #ffd66b; }
@keyframes ready { from { box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.6) inset; } }

#status {
  position: absolute;
  top: 32%;
  left: 50%;
  transform: translateX(-50%);
  padding: 14px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 18px;
  text-align: center;
  white-space: nowrap;
}
#status small { display: block; margin-top: 4px; color: var(--muted); font-size: 14px; }
#status.spec { top: 56px; padding: 8px 16px; font-size: 15px; } /* 관전 중에는 가운데 싸움을 가리지 않게 위로 */
#status.spec small { font-size: 12px; }
.clsrow { display: flex; gap: 6px; justify-content: center; margin-top: 10px; font-size: 13px; }
.clsrow span { padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); }
.clsrow .pick { border-color: #ffd98a; color: #ffd98a; }
.clsrow .cur { color: var(--text); }

#result {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  width: min(380px, calc(100% - 32px));
  padding: 18px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  text-align: center;
}
#result h2 { margin: 0; font-size: 26px; }
#result .sub { margin: 6px 0 0; color: var(--muted); }
#result ol { margin: 14px 0 0; padding: 0 0 0 22px; text-align: left; }
#result li { padding: 3px 0; }
#result li .name { font-weight: 700; }
#result li .stat { float: right; color: var(--muted); font-variant-numeric: tabular-nums; }

#board {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(520px, calc(100% - 32px));
  max-height: 80vh;
  overflow: auto;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}
#board h2 { margin: 0 0 10px; font-size: 16px; }
#board table { width: 100%; border-collapse: collapse; }
#board th, #board td { padding: 5px 6px; text-align: left; }
#board th { color: var(--muted); font-weight: 600; font-size: 12px; border-bottom: 1px solid var(--line); }
#board td.n { text-align: right; font-variant-numeric: tabular-nums; }
#board th.n { text-align: right; }
#board td:nth-child(2) { color: var(--muted); font-size: 13px; }
#board tr.me td { color: #fff; font-weight: 700; }
#board tr.team td { padding-top: 10px; font-weight: 700; font-size: 13px; }
#board .dot { display: inline-block; width: 10px; height: 10px; margin-right: 8px; border-radius: 50%; vertical-align: -1px; }
#board .bot { color: var(--muted); font-size: 12px; margin-left: 6px; }

#help { position: absolute; left: 12px; bottom: 12px; color: var(--muted); font-size: 12px; opacity: 0.7; }

#conn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 16px 22px;
  background: var(--panel);
  border: 1px solid #a04b4b;
  border-radius: 10px;
  text-align: center;
  pointer-events: auto;
}
#conn button { margin-top: 10px; }

#menu {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(3, 4, 9, 0.55);
  pointer-events: auto;
}
.menubox {
  width: min(340px, calc(100% - 32px));
  display: grid;
  gap: 12px;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.menubox h2 { margin: 0; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menubox .code { margin: -6px 0 0; color: var(--muted); font-size: 13px; }
.menubox .code b { color: #ffd98a; letter-spacing: 0.1em; }
.vol { display: flex; align-items: center; gap: 10px; font-size: 14px; color: #c7cbdb; }
.vol input { flex: 1; accent-color: var(--accent); }
#voltext { width: 36px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

@media (max-width: 820px) {
  .cols { grid-template-columns: 1fr; }
  #roomlist { max-height: none; }
}

@media (max-width: 520px) {
  .room { grid-template-columns: minmax(0, 1fr) auto; }
  .room .rnow { grid-row: 3; grid-column: 1; text-align: left; }
  .room .rnow b { display: inline; margin-right: 6px; }
  .room button { grid-row: 1 / span 3; grid-column: 2; }
}

@media (max-width: 700px) {
  .bar { width: 220px; }
  .skill { min-width: 0; grid-template-columns: 30px; padding: 4px; }
  .skill .ico { width: 30px; height: 30px; }
  .skill span { display: none; }
  .skill b { grid-row: 2; font-size: 10px; text-align: center; }
  #help { display: none; }
  #match { top: 48px; font-size: 13px; }
  #roomname { max-width: 110px; }
  .brand h1 { font-size: 34px; }
  #lobbybox { padding: 18px 14px 14px; }
}
