/* Base styles and shared components. Pages add their own CSS in pages.css / teams.css / battle.css but reuse these. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font: 400 15px/1.5 var(--font-body);
  background-image: radial-gradient(1200px 500px at 50% -200px, rgba(238, 75, 75, .13), transparent 70%);
  background-repeat: no-repeat;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; line-height: 1.15; margin: 0; letter-spacing: .01em; }
h1 { font-size: 28px; } h2 { font-size: 20px; } h3 { font-size: 16px; }
p { margin: 0; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-sm); }
[hidden] { display: none !important; }
::selection { background: rgba(92, 200, 255, .35); }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.nums, .sol, .table td.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.right { margin-left: auto; }

/* ---------- app header ---------- */
#top {
  position: sticky; top: 0; z-index: 50; height: var(--header-h);
  display: flex; align-items: center; gap: var(--s4); padding: 0 var(--s5);
  background: rgba(10, 15, 31, .88); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: var(--s2); font: 800 20px var(--font-display); color: var(--text); letter-spacing: .02em; }
.brand:hover { text-decoration: none; }
.brand .ball { width: 24px; height: 24px; border-radius: 50%; flex: none;
  background: linear-gradient(var(--red) 0 46%, #10162e 46% 54%, #f4f6ff 54%); border: 2px solid #10162e; box-shadow: 0 0 0 2px var(--text-dim); position: relative; }
.brand .ball::after { content: ''; position: absolute; inset: 50% auto auto 50%; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 50%; background: #f4f6ff; border: 2px solid #10162e; }
.nav { display: flex; gap: var(--s1); margin-left: var(--s4); }
.nav a { display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; color: var(--text-dim); font: 600 14px var(--font-display); letter-spacing: .03em; text-transform: uppercase; }
.nav a:hover { color: var(--text); background: var(--panel); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--text); background: var(--panel-2); box-shadow: inset 0 -2px 0 var(--red); }
.nav svg { width: 16px; height: 16px; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: var(--s3); }
.bal-chip { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font: 700 14px var(--font-display); color: var(--yellow); }
.bal-chip:hover { background: var(--panel-2); text-decoration: none; }
.me-chip { display: flex; align-items: center; gap: var(--s2); padding: 4px 12px 4px 4px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); cursor: pointer; font: 600 14px var(--font-display); }
.me-chip:hover { background: var(--panel-2); }
body[data-view="battle"] #top { height: 48px; }
body[data-view="battle"] .nav { display: none; }

#view { max-width: 1240px; margin: 0 auto; padding: var(--s5); outline: none; }
body[data-view="battle"] #view { max-width: none; padding: 0; }

/* ---------- layout helpers ---------- */
.page { display: flex; flex-direction: column; gap: var(--s5); animation: page-in .25s var(--ease); }
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.page-head { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s3); }
.page-head h1 { margin-right: auto; }
.page-head .sub { flex-basis: 100%; color: var(--text-dim); margin-top: calc(var(--s2) * -1); }
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.stack.tight { gap: var(--s2); }
.row { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.cols-2 { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
@media (max-width: 900px) { .cols-2 { grid-template-columns: 1fr; } }

/* ---------- card ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--s4); box-shadow: var(--shadow-sm); }
.card.flat { box-shadow: none; }
.card-head { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s3); }
.card-head h2, .card-head h3 { margin-right: auto; }
.card.error { border-color: var(--danger); background: rgba(255, 107, 125, .08); display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.card.hero { background: linear-gradient(135deg, var(--panel-2), var(--panel)); border-color: var(--line-2); }

/* ---------- buttons ---------- */
.btn {
  --b: var(--panel-3); --bh: var(--line-2); --fg: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 18px;
  border: 1px solid transparent; border-radius: var(--radius); background: var(--b); color: var(--fg); cursor: pointer;
  font: 700 14px var(--font-display); letter-spacing: .04em; text-transform: uppercase; white-space: nowrap;
  transition: background .15s, transform .08s, box-shadow .15s;
}
.btn:hover { background: var(--bh); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; transform: none; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn.primary { --b: var(--red); --bh: #ff6262; --fg: #fff; box-shadow: 0 3px 0 var(--red-2); }
.btn.primary:active { box-shadow: 0 1px 0 var(--red-2); transform: translateY(2px); }
.btn.gold { --b: var(--yellow); --bh: #ffe07a; --fg: #1c1700; box-shadow: 0 3px 0 var(--yellow-2); }
.btn.gold:active { box-shadow: 0 1px 0 var(--yellow-2); transform: translateY(2px); }
.btn.ghost { --b: transparent; border-color: var(--line-2); }
.btn.ghost:hover { background: var(--panel-2); }
.btn.danger { --b: transparent; --fg: var(--danger); border-color: rgba(255, 107, 125, .5); }
.btn.danger:hover { background: rgba(255, 107, 125, .14); }
.btn.sm { min-height: 32px; padding: 0 12px; font-size: 12px; border-radius: var(--radius-sm); }
.btn.lg { min-height: 52px; padding: 0 28px; font-size: 16px; }
.btn.block { width: 100%; }
.btn.icon { padding: 0; width: 40px; } .btn.icon.sm { width: 32px; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font: 600 12px var(--font-display); letter-spacing: .08em; text-transform: uppercase; color: var(--text-dim); }
.input, .select, textarea.input {
  width: 100%; min-height: 40px; padding: 8px 12px; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.input:hover, .select:hover { border-color: var(--line-2); }
.input:focus, .select:focus { outline: none; border-color: var(--blue); box-shadow: var(--ring); }
.input::placeholder { color: var(--text-faint); }
.select { appearance: none; padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%239fabd6' stroke-width='2' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center; }
.select option { background: var(--panel); color: var(--text); }
.hint { font-size: 13px; color: var(--text-dim); }
.hint.bad { color: var(--danger); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; min-height: 32px; }
.check input { width: 18px; height: 18px; accent-color: var(--red); }
input[type="range"] { accent-color: var(--red); width: 100%; }

/* ---------- pills, badges, tabs ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); font: 600 12px var(--font-display); letter-spacing: .04em; color: var(--text-dim); }
.pill.good { color: var(--green); border-color: rgba(70, 217, 139, .4); }
.pill.warn { color: var(--yellow); border-color: rgba(255, 210, 63, .4); }
.pill.bad { color: var(--danger); border-color: rgba(255, 107, 125, .4); }
.pill.live { color: var(--red); border-color: rgba(238, 75, 75, .5); }
.pill.live::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--red); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--red); color: #fff; font: 700 12px/20px var(--font-display); text-align: center; }
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px; width: max-content; max-width: 100%; overflow-x: auto; }
.tab { padding: 6px 16px; border: 0; border-radius: 999px; background: transparent; color: var(--text-dim); cursor: pointer; font: 600 13px var(--font-display); letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { background: var(--panel-3); color: var(--text); box-shadow: inset 0 -2px 0 var(--red); }

/* ---------- money, avatar, types ---------- */
.sol { font-family: var(--font-display); font-weight: 700; color: var(--yellow); white-space: nowrap; }
.sol::after { content: ' SOL'; font-size: .78em; font-weight: 600; opacity: .8; }
.sol.pos { color: var(--green); } .sol.neg { color: var(--danger); } .sol.zero { color: var(--text-dim); }
.avatar { width: 40px; height: 40px; flex: none; border-radius: 50%; background: var(--panel-3) center top / cover no-repeat; border: 2px solid var(--line-2); image-rendering: pixelated; overflow: hidden; }
.avatar.sm { width: 28px; height: 28px; border-width: 1px; } .avatar.lg { width: 72px; height: 72px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; object-position: center 12%; image-rendering: pixelated; display: block; }
.type { display: inline-block; min-width: 62px; padding: 1px 8px; border-radius: 4px; text-align: center; font: 700 11px/18px var(--font-display); letter-spacing: .06em; text-transform: uppercase; background: var(--tb, var(--t-unknown)); color: var(--tf, var(--on-unknown)); }
.type[data-type="Normal"] { --tb: var(--t-normal); --tf: var(--on-normal); } .type[data-type="Fire"] { --tb: var(--t-fire); --tf: var(--on-fire); }
.type[data-type="Water"] { --tb: var(--t-water); --tf: var(--on-water); } .type[data-type="Electric"] { --tb: var(--t-electric); --tf: var(--on-electric); }
.type[data-type="Grass"] { --tb: var(--t-grass); --tf: var(--on-grass); } .type[data-type="Ice"] { --tb: var(--t-ice); --tf: var(--on-ice); }
.type[data-type="Fighting"] { --tb: var(--t-fighting); --tf: var(--on-fighting); } .type[data-type="Poison"] { --tb: var(--t-poison); --tf: var(--on-poison); }
.type[data-type="Ground"] { --tb: var(--t-ground); --tf: var(--on-ground); } .type[data-type="Flying"] { --tb: var(--t-flying); --tf: var(--on-flying); }
.type[data-type="Psychic"] { --tb: var(--t-psychic); --tf: var(--on-psychic); } .type[data-type="Bug"] { --tb: var(--t-bug); --tf: var(--on-bug); }
.type[data-type="Rock"] { --tb: var(--t-rock); --tf: var(--on-rock); } .type[data-type="Ghost"] { --tb: var(--t-ghost); --tf: var(--on-ghost); }
.type[data-type="Dragon"] { --tb: var(--t-dragon); --tf: var(--on-dragon); } .type[data-type="Dark"] { --tb: var(--t-dark); --tf: var(--on-dark); }
.type[data-type="Steel"] { --tb: var(--t-steel); --tf: var(--on-steel); } .type[data-type="Fairy"] { --tb: var(--t-fairy); --tf: var(--on-fairy); }
.type[data-type="Stellar"] { --tb: var(--t-stellar); --tf: var(--on-stellar); }
.type.sm { min-width: 0; font-size: 10px; line-height: 15px; padding: 0 6px; }
.cat { display: inline-block; padding: 0 6px; border-radius: 4px; font: 700 10px/16px var(--font-display); letter-spacing: .06em; text-transform: uppercase; background: var(--panel-3); color: var(--text-dim); }
.cat[data-cat="Physical"] { color: #ff9f6b; } .cat[data-cat="Special"] { color: #8fb4ff; } .cat[data-cat="Status"] { color: #c5cbe0; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--panel); }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; padding: 10px 14px; font: 600 12px var(--font-display); letter-spacing: .08em; text-transform: uppercase; color: var(--text-dim); background: var(--panel-2); white-space: nowrap; }
.table td { padding: 10px 14px; border-top: 1px solid var(--line); }
.table td.num, .table th.num { text-align: right; }
.table tbody tr:hover { background: rgba(255, 255, 255, .03); }
.table tr.me td { background: rgba(255, 210, 63, .07); }

/* ---------- empty / spinner / skeleton ---------- */
.empty { display: flex; flex-direction: column; align-items: center; gap: var(--s2); padding: var(--s6) var(--s4); text-align: center; color: var(--text-dim); border: 2px dashed var(--line); border-radius: var(--radius-lg); }
.empty .big { font: 700 18px var(--font-display); color: var(--text); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--red); animation: spin .8s linear infinite; margin: var(--s5) auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- hp bar (shared by lobby previews and battle) ---------- */
.hpbar { height: 8px; border-radius: 999px; background: rgba(0, 0, 0, .45); overflow: hidden; border: 1px solid rgba(255, 255, 255, .12); }
.hpbar-fill { height: 100%; width: calc(var(--hp, 100) * 1%); background: var(--hp-high); transition: width .6s var(--ease), background .3s; }
.hpbar[data-level="mid"] .hpbar-fill { background: var(--hp-mid); } .hpbar[data-level="low"] .hpbar-fill { background: var(--hp-low); }

/* ---------- modal + toast ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: var(--s4); background: rgba(3, 6, 18, .72); backdrop-filter: blur(4px); animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius-lg); box-shadow: var(--shadow); animation: pop .2s var(--ease); }
.modal.wide { width: min(860px, 100%); }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.modal-head { display: flex; align-items: center; gap: var(--s3); padding: var(--s4) var(--s4) 0; }
.modal-head h2 { margin-right: auto; }
.modal-body { padding: var(--s4); display: flex; flex-direction: column; gap: var(--s3); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--s2); padding: 0 var(--s4) var(--s4); flex-wrap: wrap; }
#toasts { position: fixed; z-index: 200; right: var(--s4); bottom: var(--s4); display: flex; flex-direction: column; gap: var(--s2); align-items: flex-end; pointer-events: none; }
.toast { pointer-events: auto; max-width: min(380px, calc(100vw - 32px)); padding: 10px 16px; border-radius: var(--radius); background: var(--panel-3); border: 1px solid var(--line-2); box-shadow: var(--shadow); animation: pop .2s var(--ease); font-weight: 500; }
.toast.good { border-color: var(--green); } .toast.bad { border-color: var(--danger); }

/* ---------- login / landing ---------- */
.landing { display: grid; place-items: center; min-height: calc(100vh - var(--header-h) - 48px); }
.landing .card { width: min(520px, 100%); text-align: center; display: flex; flex-direction: column; gap: var(--s4); padding: var(--s6) var(--s5); }
.landing h1 { font-size: 40px; }
.landing .lead { color: var(--text-dim); font-size: 16px; }

/* ---------- small screens: nav moves to a bottom bar ---------- */
@media (max-width: 760px) {
  /* backdrop-filter would make #top the containing block of the fixed bottom nav, so drop it here */
  #top { padding: 0 var(--s3); gap: var(--s2); backdrop-filter: none; background: var(--bg); }
  .brand span.word { display: none; }
  .me-chip .nm { display: none; } .me-chip { padding: 4px; }
  #view { padding: var(--s4) var(--s4) calc(var(--s6) + 64px); }
  .nav { position: fixed; z-index: 60; left: 0; right: 0; bottom: 0; margin: 0; justify-content: space-around; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: rgba(10, 15, 31, .96); border-top: 1px solid var(--line); gap: 0; }
  .nav a { flex-direction: column; gap: 2px; padding: 6px 10px; font-size: 11px; border-radius: var(--radius); flex: 1; justify-content: center; }
  .nav a svg { width: 20px; height: 20px; }
  h1 { font-size: 24px; }
  #toasts { bottom: 76px; right: var(--s3); }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---------- header user menu ---------- */
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 180px; padding: 6px; background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; z-index: 70; }
.menu a, .menu button { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 0; background: none; border-radius: var(--radius-sm); color: var(--text); cursor: pointer; font: 600 14px var(--font-display); text-align: left; }
.menu a:hover, .menu button:hover { background: var(--panel-2); text-decoration: none; }
.menu svg { width: 16px; height: 16px; color: var(--text-dim); }
