:root {
  --bg: #0e1020;
  --bg2: #151932;
  --panel: #1b2040;
  --panel2: #232a52;
  --ink: #e8ecff;
  --muted: #98a0cc;
  --line: #2c3468;
  --gold: #ffd166;
  --hp: #47d16c;
  --hp2: #2ea34e;
  --xp: #4aa8ff;
  --xp2: #2f74c9;
  --danger: #ff6b6b;
  --accent: #b98bff;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, #1d2350, transparent),
    radial-gradient(900px 500px at -10% 10%, #241a44, transparent),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
.pixel { font-family: 'Press Start 2P', monospace; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; top: 18px; transform: translateX(-50%);
  background: var(--panel2); color: var(--ink);
  border: 1px solid var(--line); border-left: 4px solid var(--gold);
  padding: 12px 18px; border-radius: 10px; z-index: 50;
  box-shadow: 0 10px 40px rgba(0,0,0,.5); max-width: 90vw;
  font-weight: 600; animation: pop .25s ease;
}
.toast.good { border-left-color: var(--hp); }
.toast.bad { border-left-color: var(--danger); }
.toast.level { border-left-color: var(--gold); background: linear-gradient(90deg, #3a2f00, var(--panel2)); }
@keyframes pop { from { transform: translateX(-50%) translateY(-10px); opacity: 0; } }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 30px 26px; box-shadow: 0 20px 60px rgba(0,0,0,.45); text-align: center;
}
.crest { font-size: 44px; }
.logo, .brand span, .logo span { }
.logo {
  font-family: 'Press Start 2P', monospace; font-size: 22px; margin: 8px 0 6px;
  letter-spacing: 1px;
}
.logo span { color: var(--gold); }
.tagline { color: var(--muted); font-size: 14px; margin: 0 0 20px; line-height: 1.5; }
.tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab {
  flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); cursor: pointer; font-weight: 700;
}
.tab.active { background: var(--panel2); color: var(--ink); border-color: var(--accent); }

/* ---------- Fields ---------- */
.field { text-align: left; margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
input, select {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg2); color: var(--ink);
  font-size: 15px; font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
input[readonly] { color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Buttons ---------- */
.btn {
  padding: 12px 18px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 800; cursor: pointer; font-family: inherit; font-size: 14px;
  transition: transform .05s ease, filter .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(180deg, var(--accent), #8a5cf0); color: #120a24; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.btn-block { width: 100%; margin-top: 6px; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.err { color: var(--danger); font-size: 13px; margin: 4px 0 10px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 14px; }

/* ---------- Game layout ---------- */
.game { max-width: 620px; margin: 0 auto; padding: 0 16px 40px; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 4px; position: sticky; top: 0; background: linear-gradient(var(--bg), rgba(14,16,32,.6));
  backdrop-filter: blur(6px); z-index: 10;
}
.brand { font-family: 'Press Start 2P', monospace; font-size: 14px; }
.brand span { color: var(--gold); }
.whoami { display: flex; align-items: center; gap: 12px; }
#who { color: var(--muted); font-weight: 700; font-size: 14px; }

/* ---------- Hero panel ---------- */
.hero-panel {
  display: flex; gap: 18px; align-items: center;
  background: linear-gradient(135deg, var(--panel), var(--bg2));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 18px;
}
.avatar { position: relative; flex: 0 0 auto; }
.avatar-face {
  width: 78px; height: 78px; border-radius: 18px;
  background: radial-gradient(circle at 50% 35%, var(--panel2), #10132b);
  border: 1px solid var(--line); display: grid; place-items: center; font-size: 40px;
}
.level-badge {
  position: absolute; top: -10px; left: -10px;
  min-width: 30px; height: 30px; padding: 0 6px; border-radius: 50%;
  background: linear-gradient(180deg, var(--gold), #e0a83a); color: #3a2600;
  font-weight: 800; display: grid; place-items: center; font-size: 14px;
  border: 2px solid #fff3d0; box-shadow: 0 4px 14px rgba(255,209,102,.4);
}
.bars { flex: 1; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.bar-row { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 10px; }
.bar-label { font-size: 11px; font-weight: 800; color: var(--muted); }
.bar {
  height: 16px; background: #0c0f22; border: 1px solid var(--line);
  border-radius: 9px; overflow: hidden;
}
.bar-fill { height: 100%; width: 0; border-radius: 9px 0 0 9px; transition: width .5s cubic-bezier(.2,.8,.2,1); }
.bar-fill.hp { background: linear-gradient(90deg, var(--hp2), var(--hp)); }
.bar-fill.xp { background: linear-gradient(90deg, var(--xp2), var(--xp)); }
.bar-fill.low { background: linear-gradient(90deg, #a33, var(--danger)); }
.bar-val { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.level-line { font-size: 12px; color: var(--gold); font-weight: 700; margin-top: 2px; }

/* ---------- Stats strip ---------- */
.stats-strip {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 14px 0;
}
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 8px; text-align: center;
}
.stat-num { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-cap { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-top: 2px; }

/* ---------- Nav ---------- */
.nav { display: flex; gap: 8px; margin: 6px 0 14px; }
.nav-btn {
  flex: 1; padding: 11px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--panel); color: var(--muted); cursor: pointer; font-weight: 700; font-size: 13px;
}
.nav-btn.active { background: var(--panel2); color: var(--ink); border-color: var(--accent); }

/* ---------- Cards / panels ---------- */
.panel { display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
}
.card h2 { margin: 0 0 14px; font-size: 16px; }
.muted { color: var(--muted); font-size: 13px; }
.muted.small { font-size: 12px; margin-top: 6px; }

/* ---------- Workout grid ---------- */
.workout-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.wk {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 6px; text-align: center; cursor: pointer; transition: .12s;
}
.wk:hover { border-color: var(--accent); }
.wk.sel { border-color: var(--gold); background: var(--panel2); box-shadow: 0 0 0 1px var(--gold) inset; }
.wk-emoji { font-size: 24px; }
.wk-name { font-size: 11px; margin-top: 4px; font-weight: 600; }
.wk-cal { font-size: 10px; color: var(--muted); margin-top: 2px; }

/* ---------- Log lists ---------- */
.log-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.log-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.log-list li.empty { justify-content: center; color: var(--muted); font-size: 13px; }
.li-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.li-name { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-sub { font-size: 11px; color: var(--muted); }
.li-delta { text-align: right; font-size: 12px; font-weight: 700; white-space: nowrap; }
.d-hp-pos { color: var(--hp); }
.d-hp-neg { color: var(--danger); }
.d-xp { color: var(--xp); }

.rules { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.rules li { font-size: 13px; color: var(--ink); line-height: 1.4; }
.rules b { color: var(--gold); }

.foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 24px; }

@media (max-width: 480px) {
  .workout-grid { grid-template-columns: repeat(4, 1fr); }
  .wk-name { font-size: 10px; }
  .stats-strip { grid-template-columns: repeat(2, 1fr); }
}
