body {
  display: grid;
  grid-template-rows: 52px minmax(0, 1fr) auto;
  grid-template-columns: 92px 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar content"
    "sidebar legal";
  height: calc(100vh / var(--ui-zoom, 1));
  overflow: hidden;
}

#topbar {
  grid-area: topbar;
  background: linear-gradient(180deg, #1b2c4d, #132139);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 2px solid #0a1120;
  box-shadow: 0 2px 0 #2b4270 inset;
  z-index: 10;
}
.logo { display: flex; align-items: center; gap: 8px; font-family: var(--pixel); font-size: 1.35rem; font-weight: 700; letter-spacing: 0.5px; }
.logo-sprite { display: inline-flex; width: 30px; height: 30px; align-items: flex-end; justify-content: center; }
.logo > span:not(.logo-sprite) { color: #a86bff; }

.hud-user { gap: 8px; font-family: 'Inter', sans-serif; font-size: 0.85rem; }
.hud-user #hud-user { font-weight: 600; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-logout { color: var(--muted); font-size: 0.75rem; padding: 2px 6px; border-radius: 6px; border: 1px solid var(--line); }
.hud-logout:hover { color: #fff; border-color: var(--red); background: #3a1c2a; }
.hud-staff { color: var(--accent); text-decoration: none; }
.hud-staff[hidden] { display: none; }

/* login */
.auth-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center; padding: 16px;
  background:
    radial-gradient(circle at 50% 35%, #3b2366cc, transparent 60%),
    radial-gradient(circle at center, #1a1433f0, #06040df8);
}
.auth-box {
  width: 100%; max-width: 380px; text-align: center;
  background: var(--bg-2); border: 2px solid #4b3685; border-radius: 18px;
  padding: 28px 28px 22px; box-shadow: 0 20px 60px #000c, 0 0 0 4px #a86bff14;
}
.auth-mascot {
  width: 112px; height: 104px; margin: -6px auto 4px;
  display: grid; place-items: end center;
  background: radial-gradient(ellipse at bottom, #6b3fc455, transparent 70%);
}
.auth-title { font-family: var(--pixel); font-size: 2rem; letter-spacing: 0.5px; }
.auth-title span { color: #a86bff; }
.auth-form { display: grid; gap: 10px; margin-top: 18px; text-align: left; }
.auth-form .input { min-width: 0; width: 100%; padding: 10px 12px; }
.auth-tabs { justify-self: center; margin-bottom: 4px; }
.auth-submit { width: 100%; padding: 10px; font-size: 1.05rem; margin-top: 2px; }
.auth-error { color: #ff7a8a; font-size: 0.85rem; min-height: 1.2em; }
.auth-notice { margin-top: 12px; padding: 8px 10px; border-radius: 8px; background: #ffb34722; border: 1px solid #ffb34766; color: #ffd28a; font-size: 0.9rem; }
.auth-hint { text-align: center; }
.auth-hint:empty { display: none; }
.auth-consent { display: grid; gap: 6px; }
.auth-consent[hidden] { display: none; }
/* the trademark notice, under the login box */
.auth-legal {
  position: absolute; left: 16px; right: 16px; bottom: 12px;
  text-align: center; font-size: 0.72rem; color: #8a93ad; line-height: 1.4;
}
@media (max-height: 640px) { .auth-legal { position: static; } }
/* the language picker, in the login box's top-right corner (beside the mascot) */
.auth-box { position: relative; }
.auth-lang { position: absolute; top: 12px; right: 12px; }
.auth-lang .lang-btn { height: 28px; font-size: 0.8rem; }
.auth-lang .lang-list { left: auto; right: 0; }
@media (max-width: 420px) {
  .auth-lang { position: static; display: flex; justify-content: flex-end; margin: -14px -14px 6px 0; }
}

#hud { display: flex; gap: 10px; align-items: center; }
.hud-item {
  display: flex; align-items: center; gap: 6px;
  background: #0b1424; border: 1px solid var(--line); border-radius: 8px;
  padding: 4px 10px; font-family: var(--pixel); font-size: 0.95rem;
}
.hud-item img { width: 18px; height: 18px; image-rendering: pixelated; }
.hud-level { flex-direction: column; align-items: stretch; gap: 2px; padding: 3px 10px; min-width: 96px; }
.hud-level span { font-size: 0.85rem; text-align: center; }
.hud-exp { height: 4px; background: #000; border-radius: 2px; overflow: hidden; }
#hud-exp-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }

#sidebar {
  grid-area: sidebar;
  background: #111c31;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 6px;
  border-right: 2px solid #0a1120;
  /* the menu never makes the page taller than the screen: it scrolls (no bar) if it can't fit */
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
}
#sidebar::-webkit-scrollbar { display: none; }
.nav-btn {
  flex: none;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 5px 2px;
  font-family: var(--pixel); font-size: 0.75rem;
  border-radius: 10px;
  color: var(--muted);
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s;
}
.nav-btn img { width: 40px; height: 40px; object-fit: contain; image-rendering: pixelated; filter: grayscale(0.4) brightness(0.85); transition: filter 0.15s, transform 0.15s; }
.nav-btn:hover { background: #1a2a47; color: var(--text); }
.nav-btn:hover img { filter: none; transform: translateY(-1px); }
.nav-btn.active { background: #1f3460; color: var(--accent); border-color: var(--line); }
.nav-btn.active img { filter: none; }
/* very short screens (the page is already scaled down to fit, engine/uizoom.js, down to its least):
   tighter buttons, so the whole menu still fits without scrolling */
@media (min-width: 721px) and (max-height: 780px) {
  #sidebar { gap: 3px; padding-block: 6px; }
  .nav-btn { gap: 2px; padding: 5px 2px; }
  .nav-btn img { width: 34px; height: 34px; }
}
@media (min-width: 721px) and (max-height: 660px) {
  #sidebar { gap: 2px; }
  .nav-btn { gap: 1px; padding: 3px 2px; }
  .nav-btn img { width: 26px; height: 26px; }
}

#content {
  grid-area: content;
  overflow-y: auto;
  position: relative;
  background: radial-gradient(ellipse at top, #16243f, var(--bg) 70%);
}
/* the trademark notice: a thin strip under the stage */
.legal-bar {
  grid-area: legal; min-width: 0;
  padding: 2px 10px; text-align: center; font-size: 0.68rem; line-height: 1.35; color: #7d87a3;
  background: #0b1120; border-top: 1px solid #1a2540;
}
.panel { display: none; padding: 16px; }
.panel.active { display: block; }
.panel-full.active { display: flex; padding: 0; height: 100%; }

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.panel-head h2 { font-family: var(--pixel); font-size: 1.5rem; }

.muted { color: var(--muted); }
.small { font-size: 0.75rem; }
.error { color: var(--red); }
.loading { text-align: center; padding: 40px; color: var(--muted); font-family: var(--pixel); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-top: 10px; }

.btn {
  background: var(--card-2);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  font-family: var(--pixel);
  font-size: 0.95rem;
  transition: background 0.15s, transform 0.05s;
}
.btn:hover:not(:disabled) { background: #2a4170; }
.btn:active:not(:disabled) { transform: translateY(1px); border-bottom-width: 2px; }
.btn-primary { background: #d93a52; border-color: #8e1d30; }
.btn-primary:hover:not(:disabled) { background: #ee4a63; }
.btn-danger { background: #3a1c2a; border-color: #6b2b40; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-icon {
  width: 34px; height: 34px; border-radius: 8px;
  background: #101a2ee6; border: 1px solid var(--line);
  font-size: 1.1rem; font-weight: 700;
}
.btn-icon:hover { background: #22365c; }

.input {
  background: #0b1424; border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); padding: 8px 12px; font: inherit; min-width: 240px;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.seg { display: inline-flex; background: #0b1424; border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { padding: 6px 16px; border-radius: 7px; font-family: var(--pixel); color: var(--muted); }
.seg button.active { background: var(--card-2); color: var(--accent); }

.chip { padding: 4px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-size: 0.75rem; color: var(--muted); }
.chip.active { background: var(--red); border-color: var(--red); color: #fff; }

.empty { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 60px 16px; text-align: center; }
.empty img { width: 64px; image-rendering: pixelated; opacity: 0.8; }

.tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: #fff;
  text-shadow: 0 1px 0 #0006;
}
.tag-level { background: var(--red); font-family: var(--pixel); font-size: 0.8rem; }
.tag-fire { background: #e25822; }
.tag-water { background: #3b82f6; }
.tag-grass { background: #22a24a; }
.tag-electric { background: #eab308; color: #000; text-shadow: none; }
.tag-normal { background: #6b7280; }
.tag-fighting { background: #b91c1c; }
.tag-poison { background: #7c3aed; }
.tag-ground { background: #92400e; }
.tag-flying { background: #60a5fa; }
.tag-psychic { background: #ec4899; }
.tag-bug { background: #65a30d; }
.tag-rock { background: #78716c; }
.tag-ghost { background: #581c87; }
.tag-dragon { background: #4f46e5; }
.tag-dark { background: #3f3a36; }
.tag-steel { background: #64748b; }
.tag-ice { background: #22b8cf; }
.tag-fairy { background: #e879b9; }
.tag-neutral { background: #9ca3af; }

.tag-common { background: #6b7280; }
.tag-uncommon { background: #22a24a; }
.tag-rare { background: #3b82f6; }
.tag-epic { background: #7c3aed; }
.tag-legendary { background: #eab308; color: #000; text-shadow: none; }
.tag-mythic { background: var(--red); }

/* first-run starter picker */
.starter-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: radial-gradient(circle at center, #1d2f55ee, #070c16f5);
  padding: 16px;
}
.starter-box {
  background: var(--bg-2); border: 2px solid var(--line); border-radius: 16px;
  padding: 28px; max-width: 640px; width: 100%; text-align: center;
  box-shadow: 0 20px 60px #000a;
}
.starter-logo { width: 48px; margin: 0 auto 8px; image-rendering: pixelated; }
.starter-box h1 { font-family: var(--pixel); font-size: 1.8rem; margin-bottom: 4px; }
.starter-trainers { display: flex; justify-content: center; gap: 12px; margin: 18px 0; }
.starter-trainer {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 18px; border-radius: 12px; border: 2px solid var(--line); background: var(--card);
  font-family: var(--pixel);
}
.starter-trainer.active { border-color: var(--accent); background: #2a3a20; }
.starter-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.starter-card {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 16px 8px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--card); transition: transform 0.12s, border-color 0.12s;
}
.starter-card strong { font-family: var(--pixel); font-size: 1.1rem; }
.starter-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.starter-card.type-grass { background: linear-gradient(180deg, #1f4a33, var(--card)); }
.starter-card.type-fire { background: linear-gradient(180deg, #5a2a1a, var(--card)); }
.starter-card.type-water { background: linear-gradient(180deg, #1c3a66, var(--card)); }

@media (max-width: 720px) {
  body { grid-template-columns: 1fr; grid-template-rows: 52px minmax(0, 1fr) auto 64px; grid-template-areas: "topbar" "content" "legal" "sidebar"; }
  #sidebar { flex-direction: row; justify-content: space-around; padding: 4px; border-right: 0; border-top: 2px solid #0a1120; }
  .nav-btn { flex: 1; padding: 4px 0; }
  .nav-btn img { width: 26px; height: 26px; }
  .logo > span:not(.logo-sprite), .hud-level, .hud-user #hud-user { display: none; }
  .panel { padding: 10px; }
  .starter-list { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------- windows over the stage (ui.js)
   The hunt/town or the map (the stage) stays on screen and running; Pokémon, Mochila, PvP… open
   as a window over it: a title bar and a body that scrolls on its own, centered in the content area
   (under the top bar, right of the sidebar). The layer behind dims the stage. */
:root { --win-top: 52px; --win-left: 92px; --win-bottom: 0px; }
.win-layer {
  display: none; position: fixed; z-index: 30;
  top: var(--win-top); left: var(--win-left); right: 0; bottom: var(--win-bottom);
  --win-pad: 22px; padding: var(--win-pad) 24px; place-items: center;
  background: #050a149c;
}
.window-open .win-layer { display: grid; }
.win {
  --win-w: 1240px;
  display: flex; flex-direction: column;
  width: min(var(--win-w), 100%);
  max-height: calc(calc(100vh / var(--ui-zoom, 1)) - var(--win-top) - var(--win-bottom) - 2 * var(--win-pad, 22px));
  border-radius: 14px; border: 2px solid #2b3f66; overflow: hidden;
  background: var(--bg);
  box-shadow: 0 0 0 1px #000a, 0 28px 70px #000e;
  animation: window-in 0.16s ease-out;
}
.win[data-size="sm"] { --win-w: 760px; }
.win[data-size="md"] { --win-w: 1020px; }
.win-bar {
  flex: none; display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px;
  background: linear-gradient(180deg, #1f3156, #172644); border-bottom: 2px solid #0a1120;
}
.win-bar img { width: 26px; height: 26px; image-rendering: pixelated; }
.win-bar b { font-family: var(--pixel); font-size: 1.05rem; color: var(--accent); letter-spacing: 0.5px; }
.win-close {
  margin-left: auto; display: grid; place-items: center; width: 32px; height: 32px;
  border-radius: 8px; border: 1px solid #ffffff1c; background: #0b1424; color: var(--muted);
  font-size: 1rem; cursor: pointer;
}
.win-close:hover { color: #fff; background: var(--red); border-color: var(--red); }
.win-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  background: radial-gradient(ellipse at top, #16243f, var(--bg) 70%);
  scrollbar-width: thin; scrollbar-color: #34507f transparent;
}
.win-body::-webkit-scrollbar { width: 10px; }
.win-body::-webkit-scrollbar-thumb { background: #34507f; border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
.win-body > .panel.active { padding: 16px 20px 20px; }
/* the title bar already names the window */
.win-body > .panel > .panel-head h2 { display: none; }
@keyframes window-in { from { opacity: 0; transform: translateY(10px) scale(0.985); } }
@media (prefers-reduced-motion: reduce) { .win { animation: none; } }
@media (max-width: 720px) {
  :root { --win-left: 0px; --win-bottom: 64px; }
  .win-layer { --win-pad: 6px; padding: 6px; }
  /* the bottom menu stays usable over the dimmed stage */
  #sidebar { position: relative; z-index: 31; }
  .win { border-radius: 12px; }
  .win-body > .panel.active { padding: 12px; }
}

/* the language picker (systems/langpicker.js) */
.lang-select { position: relative; display: inline-flex; flex: none; }
.lang-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--line);
  background: #0b1424; color: var(--text); font: inherit; font-size: 0.85rem; cursor: pointer;
}
.lang-btn:hover { border-color: var(--accent); }
.lang-flag { width: 22px; height: 15px; border-radius: 2px; box-shadow: 0 0 0 1px #0006; flex: none; }
.lang-caret { font-style: normal; font-size: 0.7rem; color: var(--muted); }
.lang-list {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 240; display: grid; gap: 2px; min-width: 150px; padding: 4px;
  background: #0b1424; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 24px #000a;
}
.lang-list[hidden] { display: none; }
.lang-list button {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; border: 0;
  background: none; color: var(--text); font: inherit; font-size: 0.85rem; text-align: left; cursor: pointer;
}
.lang-list button:hover { background: #17284a; }
.lang-list button.on { background: #1f3460; color: var(--accent); }

/* longer words in other languages ("Calculadora", "Tienda VIP"): the side menu's labels fit its width */
.nav-btn span { max-width: 100%; font-size: 0.7rem; text-align: center; line-height: 1.15; white-space: nowrap; }

@media (max-width: 720px) {
  /* the top bar: the logo keeps only Gengar's sprite; the counters scroll sideways if they don't fit */
  #topbar { gap: 8px; padding-inline: 8px; }
  .logo { font-size: 0; flex: none; }
  #hud { min-width: 0; overflow-x: auto; scrollbar-width: none; gap: 6px; }
  #hud::-webkit-scrollbar { display: none; }
  .hud-item { flex: none; padding: 4px 7px; gap: 4px; font-size: 0.85rem; }
  .hud-item img { width: 18px; height: 18px; }
  /* the bottom menu: every button whole, sliding sideways when they don't all fit */
  #sidebar { justify-content: flex-start; overflow-x: auto; scrollbar-width: none; }
  #sidebar::-webkit-scrollbar { display: none; }
  .nav-btn { flex: 0 0 auto; min-width: 56px; padding: 4px 4px; }
  .nav-btn span { font-size: 0.6rem; white-space: nowrap; overflow-wrap: normal; }
}

/* Phones: the page is exactly the screen's width. A grid column of 1fr never gets narrower than its
   widest content, so one wide thing on any screen widened the whole page and the phone zoomed out. */
@media (max-width: 720px) {
  body { grid-template-columns: minmax(0, 1fr); }
  #topbar, #content, #sidebar, .legal-bar { min-width: 0; max-width: calc(100vw / var(--ui-zoom, 1)); }
  .panel { min-width: 0; }
}

/* ping and players online in the top bar (ui.js, net-stats) */
/* ping · online: a small chip; the dot is the connection (green / yellow / red) */
.hud-net { --q: #8fa3c9; gap: 5px; padding-inline: 8px; font-family: var(--pixel); font-size: 0.72rem; color: var(--muted); cursor: default; }
.hud-net[data-q="good"] { --q: #4ade80; }
.hud-net[data-q="ok"] { --q: #ffd75e; }
.hud-net[data-q="bad"], .hud-net[data-q="off"] { --q: #ff7a8a; }
.hud-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--q); box-shadow: 0 0 5px var(--q); }
.hud-ping { color: var(--q); }
.hud-sep { opacity: 0.6; }

/* town channels: the button on the town's title and its list (battle.js paintChannel) */
.town-channel { position: relative; display: inline-flex; }
.tag-channel { cursor: pointer; border: 1px solid #3d5d9e; background: #13213d; color: #cfe0ff; }
.tag-channel:hover { border-color: var(--accent); }
.channel-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; display: grid; gap: 2px; min-width: 170px; padding: 6px;
  border-radius: 10px; background: #0b1424; border: 1px solid #2a3f6b; box-shadow: 0 10px 30px #000c;
}
.channel-row { display: flex; justify-content: space-between; gap: 10px; padding: 6px 10px; border: 0; border-radius: 8px; background: none; color: inherit; font: inherit; font-size: 0.85rem; cursor: pointer; }
.channel-row:hover:not(:disabled) { background: #1b2c50; }
.channel-row.on { background: #1f3460; box-shadow: inset 3px 0 0 var(--accent); }
.channel-row:disabled { opacity: 0.45; cursor: not-allowed; }

/* windows dragged by their bar (systems/draggable.js) */
.drag-handle { cursor: move; touch-action: none; }
.drag-handle button, .drag-handle input, .drag-handle a { cursor: pointer; }
.dragging { user-select: none; transition: none !important; animation: none !important; box-shadow: 0 30px 80px #000e; }
html.mobile .drag-handle { cursor: default; }
/* a window put somewhere by hand doesn't replay its opening animation from there */
.moved { animation: none !important; }
