:root{
  --bg:#10141f;
  --panel:#1a2030;
  --panel-2:#232b3f;
  --line:#3b4562;
  --text:#f5f7ff;
  --muted:#aeb8d4;
  --accent:#ffcb05;
  --accent-2:#3c5aa6;
  --danger:#ef476f;
  --good:#20bf55;
  --water:#4cc9f0;
  --grass:#6ede8a;
  --shadow:0 18px 40px rgba(0,0,0,.35);
  --pixel-border:3px solid #0a0d14;
  --radius:18px;
  --font: ui-monospace, "SFMono-Regular", "Cascadia Mono", "Consolas", monospace;
}

*{box-sizing:border-box}
html,body{margin:0;min-height:100%;background:linear-gradient(135deg,#0c1020,#141b2d 55%,#0d111d);color:var(--text);font-family:var(--font);overflow:hidden}
button,input{font-family:inherit}
button{cursor:pointer}

.hidden{display:none!important}

.pixel-card{
  border:var(--pixel-border);
  background:linear-gradient(180deg,var(--panel),#141a28);
  box-shadow:var(--shadow), inset 0 0 0 2px rgba(255,255,255,.04);
}

.boot-screen,.auth-screen{
  min-height:100dvh;
  display:grid;
  place-items:center;
  padding:24px;
}

.boot-card,.auth-card{
  width:min(560px,100%);
  padding:28px;
  border-radius:var(--radius);
}

.boot-card h1,.auth-card h1{margin:0 0 8px;font-size:clamp(1.35rem,3vw,2.2rem);letter-spacing:.02em}
.boot-card p,.auth-card p{color:var(--muted);line-height:1.45}
.boot-bar{height:16px;border:2px solid #0a0d14;background:#0b0f1a;border-radius:999px;overflow:hidden;margin-top:18px}
.boot-bar span{display:block;height:100%;width:62%;background:linear-gradient(90deg,var(--accent),#ff7b00);animation:boot 1.2s infinite alternate}
@keyframes boot{from{width:16%}to{width:96%}}

.brand{display:flex;gap:14px;align-items:center;margin-bottom:18px}
.brand-ball,.tiny-ball{
  display:inline-block;border-radius:50%;background:linear-gradient(#f54646 0 45%,#111 45% 55%,#fff 55%);border:3px solid #111;box-shadow:inset 0 0 0 2px rgba(255,255,255,.2)
}
.brand-ball{width:54px;height:54px;flex:0 0 54px}
.tiny-ball{width:26px;height:26px;flex:0 0 26px;border-width:2px}

.auth-tabs{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin:16px 0}
.auth-tabs button,.tabs button,.bottom-nav button,.primary-btn,.secondary-btn,.ghost-btn,.logout-btn,.battle-menu button,.inventory-row button,.shop-controls button,.team-actions button,.chat-form button{
  border:2px solid #090c13;
  background:var(--panel-2);
  color:var(--text);
  border-radius:10px;
  padding:10px 12px;
  font-weight:800;
  text-transform:uppercase;
  box-shadow:inset 0 -3px 0 rgba(0,0,0,.25);
}
.auth-tabs button.active,.tabs button.active,.bottom-nav button.active{background:var(--accent);color:#15110a}
.auth-form{display:grid;gap:12px}
.auth-form label{display:grid;gap:6px;color:var(--muted);font-size:.9rem}
.auth-form input,.chat-form input{
  width:100%;
  background:#0b0f1a;
  border:2px solid var(--line);
  color:var(--text);
  border-radius:10px;
  padding:12px;
  outline:none;
}
.auth-form input:focus,.chat-form input:focus{border-color:var(--accent)}
.primary-btn{background:linear-gradient(#ffdf51,#ffb703);color:#15110a}
.secondary-btn{background:linear-gradient(#405fb5,#263f86)}
.ghost-btn{background:#101827;color:var(--muted)}
.auth-actions{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:12px}
.auth-actions .secondary-btn{grid-column:1/-1}
.status-text{min-height:24px;font-size:.85rem;color:var(--muted)}
.status-text.error{color:#ff9db3}
.status-text.ok{color:#9affc0}

.game-app{height:100dvh;display:flex;flex-direction:column}
.topbar{
  height:58px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
  padding:10px 16px;
  background:#0c111d;
  border-bottom:3px solid #080b11;
}
.title-wrap{display:flex;align-items:center;gap:10px;min-width:0}
.title-wrap h1{font-size:clamp(1rem,2.5vw,1.35rem);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin:0}
.top-stats{display:flex;gap:8px;align-items:center}
.badge{display:inline-flex;align-items:center;padding:6px 9px;border:2px solid #080b11;background:#192238;border-radius:999px;font-weight:900;font-size:.8rem;color:var(--accent)}
.logout-btn{padding:7px 10px;background:#2b1420;color:#ffb1c2}

.layout{height:calc(100dvh - 58px);display:grid;grid-template-columns:minmax(0,70%) minmax(330px,30%);min-height:0}
.game-stage{display:flex;flex-direction:column;align-items:center;justify-content:center;padding:16px;min-width:0;min-height:0}
.game-shell{
  position:relative;
  width:min(100%,1024px);
  aspect-ratio:4/3;
  max-height:calc(100dvh - 98px);
  border:5px solid #080b11;
  border-radius:18px;
  background:#090e15;
  overflow:hidden;
  box-shadow:var(--shadow);
}
#game-canvas{width:100%;height:100%;display:block;image-rendering:pixelated;background:#84d66b}
.route-toast{
  position:absolute;left:16px;bottom:16px;background:rgba(10,14,22,.86);
  border:2px solid #fff;color:#fff;padding:10px 14px;border-radius:12px;max-width:calc(100% - 32px);
}
.side-panel{
  border-left:3px solid #080b11;
  background:linear-gradient(#141b29,#0f1420);
  padding:12px;
  min-width:0;
  display:flex;
  flex-direction:column;
  gap:10px;
  overflow:hidden;
}
.trainer-card{border-radius:14px;padding:12px;display:flex;justify-content:space-between;gap:10px;align-items:center}
.trainer-card small{display:block;color:var(--muted);margin-top:4px;word-break:break-word}
.money{color:var(--accent);white-space:nowrap;font-weight:900}
.tabs{display:grid;grid-template-columns:repeat(2,1fr);gap:8px}
.panel-content{flex:1;overflow:auto;border-radius:14px;padding:12px;scrollbar-width:thin}
.panel-title{margin:0 0 10px;font-size:1rem;color:var(--accent)}
.mini-map{
  display:grid;
  grid-template-columns:repeat(9,1fr);
  gap:2px;
  background:#0a0d14;
  padding:6px;
  border-radius:12px;
  margin:8px 0 12px;
}
.mini-map span{aspect-ratio:1;border-radius:3px;display:grid;place-items:center;font-size:.7rem}
.tile-grass{background:#61d46c}
.tile-wall{background:#315329}
.tile-water{background:#3d8bd4}
.tile-tall{background:#44b85f}
.tile-road{background:#d5bd7b}
.tile-player{background:#ffcb05!important;color:#111}
.help-box{border:2px solid var(--line);background:#111827;border-radius:12px;padding:10px;color:var(--muted);line-height:1.5}
.team-list,.bag-list,.online-list,.box-list{display:grid;gap:8px}
.team-slot,.inventory-row,.online-row,.box-row{
  border:2px solid var(--line);
  border-radius:12px;
  background:#101827;
  padding:10px;
}
.team-slot{display:grid;grid-template-columns:42px 1fr;gap:10px;align-items:center}
.team-slot img{width:42px;height:42px;image-rendering:pixelated}
.team-empty{opacity:.55}
.hp-mini{height:10px;background:#0b0f1a;border:2px solid #090c13;border-radius:999px;overflow:hidden;margin-top:5px}
.hp-mini i{display:block;height:100%;background:var(--good);width:100%}
.team-actions,.shop-controls{display:flex;gap:6px;flex-wrap:wrap;margin-top:8px}
.team-actions button,.shop-controls button,.inventory-row button{font-size:.72rem;padding:7px 8px}
.inventory-row{display:grid;grid-template-columns:1fr auto;gap:8px;align-items:center}
.shop-card{border-top:2px solid var(--line);margin-top:14px;padding-top:12px}
.shop-item{display:grid;grid-template-columns:1fr auto;align-items:center;gap:8px;margin:10px 0}
.shop-controls{align-items:center}
.qty{min-width:26px;text-align:center;color:var(--accent);font-weight:900}
.chat-log{height:260px;overflow:auto;display:flex;flex-direction:column;gap:8px;border:2px solid var(--line);border-radius:12px;background:#0b0f1a;padding:10px;margin:10px 0}
.chat-msg{line-height:1.35}
.chat-msg strong{color:var(--accent)}
.chat-form{display:grid;grid-template-columns:1fr auto;gap:8px}
.log-list{display:grid;gap:6px;color:var(--muted);font-size:.85rem}
.log-list p{margin:0;padding:7px;border-left:3px solid var(--accent);background:#101827;border-radius:6px}

.battle-screen{
  position:absolute;inset:0;
  background:linear-gradient(180deg,#d7f5ff 0 48%,#92d36b 48% 100%);
  color:#111;
  padding:18px;
  display:flex;
  flex-direction:column;
}
.battle-area{position:relative;flex:1;min-height:0}
.enemy-side,.player-side{position:absolute;left:0;right:0;display:flex;align-items:center;justify-content:space-between}
.enemy-side{top:4%}
.player-side{bottom:5%}
.poke-card{
  min-width:260px;
  background:#f9f7df;
  border:4px solid #222;
  border-radius:18px 6px 18px 6px;
  padding:12px;
  box-shadow:5px 5px 0 rgba(0,0,0,.3);
}
.poke-line{display:flex;justify-content:space-between;gap:16px;font-weight:900}
.hp-wrap{display:grid;grid-template-columns:auto 1fr auto;align-items:center;gap:6px;margin-top:8px;font-weight:900}
.hp-bar{height:14px;border:2px solid #111;border-radius:999px;background:#ccc;overflow:hidden}
.hp-bar i{display:block;height:100%;background:#20bf55;width:100%}
.battle-sprite{width:180px;height:180px;object-fit:contain;image-rendering:pixelated;filter:drop-shadow(0 9px 2px rgba(0,0,0,.2))}
.enemy-sprite{margin-right:12%}
.player-sprite{margin-left:10%;transform:scale(1.45);transform-origin:center}
.battle-console{
  background:#f8f2d0;
  border:5px solid #111;
  border-radius:16px;
  padding:12px;
  display:grid;
  grid-template-columns:1.05fr 1fr;
  gap:12px;
  min-height:154px;
  box-shadow:0 -6px 0 rgba(0,0,0,.18);
}
.battle-log{
  border:3px solid #2d4163;
  background:#fff;
  border-radius:10px;
  padding:12px;
  color:#111;
  font-weight:900;
  line-height:1.35;
}
.battle-menu.grid-2x2{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.battle-menu button{
  background:#fff;
  color:#111;
  border:3px solid #111;
  border-radius:10px;
  text-align:left;
  font-size:.95rem;
}
.battle-menu button.selected{background:var(--accent);box-shadow:inset 0 0 0 3px #fff, 0 0 0 2px #111}

.gba-controller{display:none}
.bottom-nav{display:none}

@media (max-width: 860px){
  html,body{overflow:hidden}
  .topbar{height:48px;padding:7px 10px}
  .title-wrap h1{font-size:.95rem}
  .badge{font-size:.66rem;padding:5px 7px}
  #net-mode,.logout-btn{display:none}
  .layout{
    height:calc(100dvh - 48px - 54px);
    display:flex;
    flex-direction:column;
  }
  .game-stage{
    padding:8px;
    flex:1;
    justify-content:flex-start;
    min-height:0;
    overflow:hidden;
  }
  .game-shell{
    width:100%;
    max-height:42dvh;
    aspect-ratio:4/3;
    border-width:4px;
    border-radius:14px;
  }
  .side-panel{
    display:none;
    border-left:0;
    border-top:3px solid #080b11;
    padding:8px;
    flex:1;
    overflow:auto;
  }
  .side-panel.mobile-open{display:flex}
  .trainer-card,.tabs{display:none}
  .panel-content{min-height:0;flex:1;border-radius:12px}
  .bottom-nav{
    height:54px;
    display:grid;
    grid-template-columns:repeat(4,1fr);
    gap:4px;
    padding:5px;
    background:#0c111d;
    border-top:3px solid #080b11;
  }
  .bottom-nav button{padding:8px 2px;border-radius:9px;font-size:.72rem}
  .gba-controller{
    width:100%;
    max-width:520px;
    margin:8px auto 0;
    min-height:180px;
    display:grid;
    grid-template-columns:1fr 1fr;
    grid-template-rows:auto 1fr auto;
    align-items:center;
    gap:4px;
    background:linear-gradient(155deg,#343b4e,#171d2b);
    border:4px solid #080b11;
    border-radius:36px 36px 48px 48px;
    padding:10px 18px 12px;
    box-shadow:inset 0 0 0 3px rgba(255,255,255,.05), var(--shadow);
  }
  .speaker-lines{grid-column:1/-1;display:flex;gap:7px;justify-content:center;padding:3px 0 0}
  .speaker-lines span{width:4px;height:18px;border-radius:999px;background:#0b0f1a;transform:rotate(10deg)}
  .dpad{
    position:relative;
    width:132px;height:132px;
    justify-self:start;
  }
  .dpad button,.dpad-center{
    position:absolute;
    width:44px;height:44px;
    border:3px solid #070a10;
    background:#111827;
    color:#fff;
    display:grid;
    place-items:center;
    font-weight:900;
    box-shadow:inset 0 -5px 0 rgba(0,0,0,.35);
  }
  .dpad-up{left:44px;top:0;border-radius:10px 10px 2px 2px}
  .dpad-down{left:44px;bottom:0;border-radius:2px 2px 10px 10px}
  .dpad-left{left:0;top:44px;border-radius:10px 2px 2px 10px}
  .dpad-right{right:0;top:44px;border-radius:2px 10px 10px 2px}
  .dpad-center{left:44px;top:44px;border-radius:3px;z-index:1}
  .gba-actions{
    justify-self:end;
    display:grid;
    grid-template-columns:58px 58px;
    grid-template-rows:58px auto;
    gap:12px;
    transform:rotate(-15deg);
  }
  .gba-actions button{
    width:58px;height:58px;
    border-radius:50%;
    border:4px solid #070a10;
    color:#fff;
    background:linear-gradient(#d14b71,#8b1f43);
    font-weight:900;
    font-size:1.2rem;
    box-shadow:inset 0 -7px 0 rgba(0,0,0,.24);
  }
  .gba-actions small{
    grid-column:1/-1;
    display:flex;
    justify-content:space-between;
    transform:rotate(15deg);
    color:#cbd4eb;
    font-size:.62rem;
    padding:0 4px;
  }
  .gba-system{
    grid-column:1/-1;
    display:flex;
    justify-content:center;
    gap:32px;
    padding-top:2px;
  }
  .gba-system button{
    border:3px solid #070a10;
    border-radius:999px;
    background:#101827;
    color:#cbd4eb;
    padding:6px 14px;
    font-size:.7rem;
    font-weight:900;
  }
  .battle-screen{padding:8px}
  .battle-sprite{width:96px;height:96px}
  .player-sprite{transform:scale(1.2)}
  .poke-card{min-width:150px;padding:8px;border-width:3px;font-size:.72rem}
  .hp-wrap{grid-template-columns:auto 1fr;gap:4px}
  .hp-wrap small{grid-column:1/-1}
  .battle-console{grid-template-columns:1fr;gap:8px;min-height:136px;padding:8px;border-width:4px}
  .battle-log{font-size:.78rem;padding:8px}
  .battle-menu button{font-size:.74rem;padding:7px}
  .chat-log{height:170px}
}

@media (max-width: 380px){
  .gba-controller{min-height:164px;padding:8px 12px}
  .dpad{width:112px;height:112px}
  .dpad button,.dpad-center{width:38px;height:38px}
  .dpad-up,.dpad-down,.dpad-center{left:37px}
  .dpad-left,.dpad-right,.dpad-center{top:37px}
  .gba-actions{grid-template-columns:50px 50px;grid-template-rows:50px auto}
  .gba-actions button{width:50px;height:50px}
}
