:root {
  --bg: #14101c;
  --bg2: #1d1730;
  --panel: #241b3a;
  --panel2: #2e2350;
  --gold: #e8b84b;
  --gold-soft: #f3d27e;
  --text: #ece6f5;
  --muted: #9a8fb8;
  --green: #4fd47e;
  --red: #ef5d6b;
  --blue: #5aa9ff;
  --common: #9aa6b2;
  --rare: #4f9dff;
  --epic: #c46bff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: radial-gradient(1200px 800px at 50% -10%, var(--bg2), var(--bg));
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app { max-width: 920px; margin: 0 auto; padding: 0 16px 40px; }

/* ---------- topbar ---------- */
#topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 4px; position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 800; font-size: 20px; letter-spacing: 1px; }
.brand span { color: var(--gold); }
.online { font-size: 13px; color: var(--muted); }
.online b { color: var(--green); }

/* ---------- scenes ---------- */
.scene { display: none; animation: fade .35s ease; }
.scene.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.panel {
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  border: 1px solid rgba(232,184,75,.18);
  border-radius: 18px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.center { text-align: center; max-width: 460px; margin: 6vh auto 0; }

.logo {
  font-size: 46px; line-height: 1; font-weight: 900;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 4px 20px rgba(232,184,75,.25); margin-bottom: 12px;
}
.subtitle { color: var(--muted); margin-bottom: 22px; line-height: 1.5; }
.hint { color: var(--muted); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- controls ---------- */
.input {
  width: 100%; padding: 14px 16px; border-radius: 12px;
  background: rgba(0,0,0,.25); border: 1px solid rgba(255,255,255,.1);
  color: var(--text); font-size: 16px; text-align: center; margin-bottom: 14px;
}
.input:focus { outline: none; border-color: var(--gold); }

.btn {
  border: none; border-radius: 12px; padding: 14px 22px; font-size: 15px;
  font-weight: 700; cursor: pointer; transition: transform .12s, filter .12s; color: #fff;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(180deg, var(--gold-soft), var(--gold)); color: #2a2008; }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: rgba(255,255,255,.07); color: var(--text); }
.btn.big { width: 100%; padding: 16px; font-size: 17px; }
.row { display: flex; }
.row.gap { gap: 12px; }
.row .btn { flex: 1; }

/* ---------- searching ---------- */
.searching { margin-top: 22px; }
.searching.hidden { display: none; }
.spinner {
  width: 46px; height: 46px; margin: 0 auto 12px; border-radius: 50%;
  border: 4px solid rgba(232,184,75,.2); border-top-color: var(--gold);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

/* ---------- match found ---------- */
.vs-row { display: flex; align-items: center; justify-content: space-around; margin: 18px 0; }
.vs-side { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.avatar {
  width: 76px; height: 76px; border-radius: 50%; display: grid; place-items: center;
  font-size: 38px; background: rgba(255,255,255,.06); border: 2px solid rgba(232,184,75,.3);
}
.vs { font-size: 26px; font-weight: 900; color: var(--gold); }
.name { font-weight: 700; }

/* ---------- timers ---------- */
.timer-bar { height: 8px; background: rgba(0,0,0,.3); border-radius: 6px; overflow: hidden; margin: 16px 0; }
.timer-bar.small { height: 6px; margin: 8px 0; }
.timer-fill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--green), var(--gold)); transition: width .25s linear; }
.timer-fill.low { background: linear-gradient(90deg, var(--red), #ff9248); }

/* ---------- phase heads ---------- */
.phase-head { text-align: center; margin: 18px 0; }
.phase-head h2 { margin-bottom: 8px; }
.turn-indicator {
  display: inline-block; padding: 6px 16px; border-radius: 20px; font-weight: 700;
  background: rgba(232,184,75,.14); color: var(--gold-soft); border: 1px solid rgba(232,184,75,.3);
}
.turn-indicator.mine { background: rgba(79,212,126,.16); color: var(--green); border-color: rgba(79,212,126,.4); }

/* ---------- chest grid ---------- */
.chest-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin: 10px 0 24px;
}
.chest {
  aspect-ratio: 1; border-radius: 14px; display: grid; place-items: center; font-size: 40px;
  background: linear-gradient(180deg, #3a2c18, #271d10); border: 2px solid #5a431f;
  cursor: default; position: relative; transition: transform .15s, box-shadow .15s;
}
.chest.clickable { cursor: pointer; }
.chest.clickable:hover { transform: translateY(-3px); box-shadow: 0 8px 22px rgba(232,184,75,.3); border-color: var(--gold); }
.chest.opened { background: rgba(255,255,255,.04); border-color: rgba(255,255,255,.08); opacity: .55; }
.chest.opened.mine { border-color: rgba(79,212,126,.5); opacity: .8; }
.chest .who { position: absolute; bottom: 4px; font-size: 10px; color: var(--muted); }
.chest.pop { animation: pop .5s ease; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.18) rotate(-4deg); } 100% { transform: scale(1); } }

/* ---------- inventories ---------- */
.inventories { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.inv-col h3 { font-size: 14px; color: var(--muted); margin-bottom: 8px; font-weight: 700; }
.inv-list { display: flex; flex-direction: column; gap: 6px; min-height: 60px; }

.item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px;
  background: rgba(0,0,0,.22); border: 1px solid rgba(255,255,255,.07); border-left-width: 4px;
}
.item .ic { font-size: 22px; width: 26px; text-align: center; }
.item .meta { flex: 1; min-width: 0; }
.item .nm { font-weight: 700; font-size: 14px; }
.item .ds { font-size: 11px; color: var(--muted); }
.item .val { font-weight: 800; font-size: 14px; }
.item .val.dmg { color: var(--red); }
.item .val.def { color: var(--blue); }
.item.rar-common { border-left-color: var(--common); }
.item.rar-rare { border-left-color: var(--rare); }
.item.rar-epic { border-left-color: var(--epic); }
.item.selectable { cursor: pointer; transition: transform .1s, background .1s; }
.item.selectable:hover { transform: translateX(3px); background: rgba(232,184,75,.1); }
.item.equipped { outline: 2px solid var(--gold); }

/* ---------- equip ---------- */
.equip-slots { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; margin: 8px 0 4px; }
.slot { background: rgba(0,0,0,.22); border: 1px dashed rgba(232,184,75,.35); border-radius: 12px; padding: 12px; text-align: center; min-height: 92px; }
.slot-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.slot-body { font-size: 13px; }
.slot-body .big-ic { font-size: 30px; display: block; margin-bottom: 4px; }
.equip-inventory { display: flex; flex-direction: column; gap: 6px; margin: 14px 0 18px; }

/* ---------- battle ---------- */
.arena {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: radial-gradient(600px 300px at 50% 120%, rgba(232,184,75,.08), transparent);
  border: 1px solid rgba(255,255,255,.06); border-radius: 18px; padding: 28px 16px; margin: 10px 0;
  position: relative; min-height: 220px;
}
.fighter { flex: 1; text-align: center; position: relative; transition: transform .25s ease; }
.fighter-body { font-size: 64px; transition: transform .2s; }
.fighter.right .fighter-body { transform: scaleX(-1); }
.fighter.lunge { transform: translateX(60px); }
.fighter.right.lunge { transform: translateX(-60px); }
.fighter.hurt .fighter-body { animation: shake .3s; }
@keyframes shake { 0%,100%{transform:translateX(0);} 25%{transform:translateX(-8px);} 75%{transform:translateX(8px);} }
.fighter-name { font-weight: 700; margin-bottom: 6px; }
.fighter-gear { font-size: 18px; color: var(--muted); margin-top: 4px; min-height: 22px; }
.hp-bar { height: 16px; background: rgba(0,0,0,.4); border-radius: 8px; overflow: hidden; position: relative; margin-bottom: 8px; }
.hp-fill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--green), #8be36a); transition: width .35s ease; }
.hp-text { position: absolute; inset: 0; display: grid; place-items: center; font-size: 11px; font-weight: 800; text-shadow: 0 1px 2px #000; }
.clash { font-size: 30px; opacity: 0; transition: opacity .15s, transform .15s; }
.clash.show { opacity: 1; transform: scale(1.5); }
.floaters { position: absolute; top: 30px; left: 0; right: 0; height: 0; pointer-events: none; }
.floater { position: absolute; left: 50%; transform: translateX(-50%); font-weight: 900; font-size: 22px; animation: float-up 1s ease forwards; white-space: nowrap; }
.floater.dmg { color: var(--red); }
.floater.heal { color: var(--green); }
.floater.fx { color: var(--gold-soft); font-size: 15px; }
@keyframes float-up { from { opacity: 1; transform: translate(-50%, 0); } to { opacity: 0; transform: translate(-50%, -50px); } }
.battle-log { margin-top: 14px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); max-height: 160px; overflow-y: auto; }
.battle-log .ln { padding: 4px 8px; border-radius: 6px; background: rgba(0,0,0,.2); }

/* ---------- result ---------- */
.result-title { font-size: 44px; font-weight: 900; }
.result-title.win { color: var(--green); text-shadow: 0 0 30px rgba(79,212,126,.4); }
.result-title.lose { color: var(--red); }
.result-title.draw { color: var(--gold); }

/* ---------- responsive ---------- */
@media (max-width: 560px) {
  .chest-grid { grid-template-columns: repeat(4, 1fr); }
  .chest { font-size: 30px; }
  .logo { font-size: 38px; }
  .fighter-body { font-size: 48px; }
  .inventories { grid-template-columns: 1fr; }
}
