* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --bg0: #0a0814; --bg1: #120f24; --panel: #181430; --panel2: #1f1a3a;
  --ink: #ece9ff; --sub: #9a93c4; --line: rgba(255,255,255,.08);
  --gold: #f2c14e; --hp: #ff4d6d; --xp: #5ad1ff; --acc: #8b5cf6;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "Apple SD Gothic Neo", sans-serif;
  background: radial-gradient(120% 80% at 50% -10%, #1b1640 0%, var(--bg1) 45%, var(--bg0) 100%);
  color: var(--ink); overflow: hidden; user-select: none; -webkit-user-select: none;
}

/* topbar */
#topbar {
  height: 50px; display: flex; align-items: center; gap: 12px; padding: 0 14px;
  border-bottom: 1px solid var(--line); background: rgba(10,8,20,.6); backdrop-filter: blur(10px);
  position: relative; z-index: 5;
}
#topbar .back { color: var(--sub); font-size: 14px; font-weight: 600; }
#topbar .brand { font-weight: 800; letter-spacing: -.01em; display: flex; align-items: center; gap: 6px; }
#topbar .brand .ic { font-size: 19px; }
#topbar .spacer { flex: 1; }
#topbar .hs { font-size: 12px; color: var(--sub); font-weight: 600; }
#topbar .hs b { color: var(--gold); font-size: 14px; }

/* layout */
#wrap { display: flex; height: calc(100% - 50px); gap: 14px; padding: 14px; }
#stage { position: relative; flex: 1 1 auto; display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0; }
#game { border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.5), inset 0 0 0 1px var(--line); touch-action: none; cursor: pointer; }
#flash {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%) translateY(-8px);
  background: rgba(255,70,90,.92); color: #fff; font-weight: 700; font-size: 13px;
  padding: 8px 14px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s; white-space: nowrap;
}
#flash.on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* side */
#side { width: 300px; flex: 0 0 300px; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.stats { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.floorrow { display: flex; justify-content: space-between; align-items: center; margin-bottom: 9px; font-size: 13px; color: var(--sub); }
.floorrow b { color: var(--ink); font-size: 17px; }
.floorrow .fl b { color: var(--gold); }
.poison { color: var(--hp); font-weight: 700; margin-left: 6px; font-size: 12px; }
.bar { position: relative; height: 20px; border-radius: 8px; background: #0c0a1c; overflow: hidden; margin-bottom: 7px; border: 1px solid var(--line); }
.bar i { position: absolute; inset: 0; width: 0; transition: width .25s; }
.bar.hp i { background: linear-gradient(90deg, #ff4d6d, #ff8a5a); }
.bar.xp { height: 8px; }
.bar.xp i { background: linear-gradient(90deg, #5ad1ff, #8b5cf6); }
.bar span { position: relative; z-index: 1; display: flex; align-items: center; justify-content: center; height: 100%; font-size: 12px; font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.grid4 { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 9px; }
.st { background: var(--panel2); border-radius: 10px; padding: 7px 9px; display: flex; flex-direction: column; gap: 2px; }
.st span { font-size: 11px; color: var(--sub); }
.st b { font-size: 16px; font-weight: 800; }
.st.keys { grid-column: 1 / 3; }
.st.keys b { display: flex; gap: 12px; font-size: 13px; }
.st.keys .ky { font-style: normal; display: inline-flex; align-items: center; gap: 3px; }
.st.keys .ky em { font-style: normal; font-weight: 800; }

/* monster info */
#monInfo { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 11px 12px; min-height: 86px; font-size: 13px; }
#monInfo.empty { display: flex; align-items: center; justify-content: center; text-align: center; }
#monInfo .hint { color: var(--sub); font-size: 12px; line-height: 1.5; }
.mi-top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.mi-top .mi-ic { font-size: 22px; }
.mi-top .mi-nm { font-weight: 800; flex: 1; }
.mi-top b { font-variant-numeric: tabular-nums; font-weight: 800; }
.mi-top b.ok { color: #7fe6a8; } .mi-top b.warn { color: var(--gold); } .mi-top b.lethal { color: #ff5a7a; }
.mi-row { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--sub); font-size: 12px; font-weight: 600; }
.mi-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.mi-tags .tag { font-style: normal; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 7px; background: rgba(255,255,255,.08); }
.t-first { background: rgba(255,138,90,.22); color: #ffb38a; }
.t-magic { background: rgba(138,92,246,.25); color: #c4adff; }
.t-dbl { background: rgba(255,80,122,.22); color: #ff8aa6; }
.t-solid { background: rgba(110,140,255,.22); color: #a8b8ff; }
.t-regen { background: rgba(80,200,140,.22); color: #8ee6b4; }
.t-poison { background: rgba(120,200,70,.22); color: #b6e08a; }

/* log */
#log { flex: 1 1 auto; min-height: 60px; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; font-size: 12.5px; line-height: 1.6; color: var(--sub); }
#log div { padding: 1px 0; }
#log div:last-child { color: var(--ink); }

/* dpad */
#dpad { display: none; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 48px); gap: 6px; }
#dpad .pad { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; color: var(--ink); font-size: 18px; font-weight: 800; cursor: pointer; }
#dpad .pad:active { background: var(--acc); }
#padU { grid-area: 1 / 2; } #padL { grid-area: 2 / 1; } #padD { grid-area: 2 / 2; } #padR { grid-area: 2 / 3; }

/* overlays */
.ov { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 18px; background: rgba(5,4,12,.78); backdrop-filter: blur(6px); }
.ov.hidden { display: none; }
.ovcard { width: 100%; max-width: 420px; background: linear-gradient(180deg, #1c1740, #14112a); border: 1px solid rgba(255,255,255,.12); border-radius: 20px; padding: 26px 22px; text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.ovcard.wide { max-width: 560px; }
.ovcard h1 { font-size: 34px; font-weight: 900; letter-spacing: -.02em; }
.ovcard h1 .sub2 { display: block; font-size: 14px; font-weight: 600; color: var(--acc); letter-spacing: .35em; margin-top: 4px; }
.ovcard h2 { font-size: 22px; font-weight: 800; margin-bottom: 6px; }
.lead { color: var(--sub); font-size: 13.5px; line-height: 1.65; margin: 12px 0 18px; }
.lead b { color: var(--ink); }
.ovbtns { display: flex; flex-direction: column; gap: 10px; }
.ovbtns.row { flex-direction: row; }
.ovbtns.row button { flex: 1; }
.primary, .danger { padding: 13px 20px; border: 0; border-radius: 12px; font-size: 15px; font-weight: 800; cursor: pointer; color: #fff; }
.primary { background: linear-gradient(90deg, #7c5cf0, #5a8af0); }
.danger { background: linear-gradient(90deg, #ff5a5a, #ff7a4d); }
.link { background: none; border: 0; color: var(--sub); font-size: 13px; margin-top: 14px; cursor: pointer; text-decoration: underline; }

/* classes */
.classes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 6px; }
.classcard { background: var(--panel2); border: 1px solid var(--line); border-radius: 14px; padding: 16px 10px; cursor: pointer; color: var(--ink); transition: .15s; text-align: center; }
.classcard:hover { border-color: var(--acc); transform: translateY(-3px); background: #251f4a; }
.classcard .c-ic { font-size: 34px; }
.classcard .c-nm { font-weight: 800; font-size: 16px; margin: 4px 0; }
.classcard .c-stats { font-size: 11px; color: var(--gold); font-weight: 600; }
.classcard .c-pas { font-size: 11px; color: var(--sub); line-height: 1.45; margin-top: 6px; }

/* rules */
.rules { text-align: left; color: var(--sub); font-size: 13px; line-height: 1.5; padding-left: 18px; display: flex; flex-direction: column; gap: 7px; margin-bottom: 18px; }
.rules b { color: var(--ink); }

/* shop */
.shopopts { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 16px; }
.shopbtn { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; color: var(--ink); font-size: 14px; font-weight: 700; cursor: pointer; transition: .12s; }
.shopbtn:hover { border-color: var(--acc); }
.shopbtn b { color: var(--gold); }
.shopbtn.nope { animation: shake .3s; border-color: #ff5a5a; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-5px)} 75%{transform:translateX(5px)} }

/* overstats */
.overstats { display: flex; justify-content: center; gap: 24px; margin: 18px 0; }
.overstats div { display: flex; flex-direction: column; }
.overstats span { font-size: 30px; font-weight: 900; color: var(--gold); }
.overstats small { font-size: 12px; color: var(--sub); margin-top: 2px; }
.bestline { color: var(--sub); font-size: 13px; margin-bottom: 16px; }

/* responsive */
@media (max-width: 760px) {
  #wrap { flex-direction: column; padding: 10px; gap: 10px; }
  #stage { flex: 0 0 auto; }
  #side { width: 100%; flex: 1 1 auto; }
  #dpad { display: grid; max-width: 230px; margin: 2px auto 0; }
  #log { min-height: 48px; max-height: 90px; }
  .classes { grid-template-columns: 1fr; }
}
