:root {
  --bg: #171d22;
  --panel: #222b31;
  --panel-2: #2c363d;
  --line: #45515b;
  --text: #f3f0df;
  --muted: #aeb9bd;
  --accent: #e8c547;
  --ok: #7ccf8a;
  --danger: #e66a61;
  --tile: 30px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  position: fixed;
  inset: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  background: #344049;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  color: #7d888d;
  cursor: not-allowed;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #11171b;
  color: var(--text);
  padding: 8px 10px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

h1,
h2,
p {
  margin: 0;
}

.hidden {
  display: none !important;
}

.app-shell {
  height: 100svh;
  overflow: hidden;
}

.login-view,
.start-view {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.login-panel,
.start-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.login-panel h1,
.start-panel h1 {
  font-size: 24px;
}

.primary-action {
  background: var(--accent);
  border-color: #bda43e;
  color: #1e2322;
  font-weight: 700;
}

.message {
  min-height: 20px;
  color: var(--danger);
  font-size: 14px;
}

.starter-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.starter-choice {
  min-height: 98px;
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 8px;
}

.starter-choice.active {
  border-color: var(--accent);
  background: #40433a;
}

.starter-choice img {
  width: 42px;
  height: 42px;
  image-rendering: pixelated;
}

.starter-choice span {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.game-view {
  height: 100svh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.topbar {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #12181d;
}

.topbar strong,
.map-header h2 {
  display: block;
  font-size: 16px;
}

.topbar span,
.map-header span {
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.topbar-actions button {
  min-width: 68px;
}

.play-area {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(280px, 28vw, 400px);
  gap: 12px;
  padding: 12px;
}

.map-section,
.side-panel {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
}

.map-section {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.map-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.map-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.map-stage {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.map-frame {
  min-height: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0d1215;
  padding: 0;
  position: relative;
  touch-action: none;
}

.world-canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #0d1215;
  image-rendering: pixelated;
  touch-action: none;
}

.map-grid {
  display: grid;
  width: max-content;
  min-width: 0;
  align-content: start;
  justify-content: start;
  transform: translate3d(0, 0, 0);
  transition: transform 180ms linear;
  will-change: transform;
}

.tile {
  width: var(--tile);
  height: var(--tile);
  background-size: 100% 100%;
  image-rendering: pixelated;
  position: relative;
}

.tile.player {
  z-index: 3;
}

.character-sprite {
  position: absolute;
  --sprite-x: 0%;
  --sprite-y: 0%;
  left: 50%;
  bottom: -7px;
  width: 32px;
  height: 48px;
  transform: translateX(-50%);
  background-image: url("/static/sprites/characters/player_boy_run.png");
  background-repeat: no-repeat;
  background-size: 400% 400%;
  background-position: var(--sprite-x) var(--sprite-y);
  image-rendering: pixelated;
  pointer-events: none;
}

.facing-down {
  --sprite-y: 0%;
}

.facing-left {
  --sprite-y: 33.333333%;
}

.facing-right {
  --sprite-y: 66.666667%;
}

.facing-up {
  --sprite-y: 100%;
}

.player-avatar {
  z-index: 4;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.42));
}

.player-avatar.walking {
  --walk-from-x: 0;
  --walk-from-y: 0;
  animation: player-step 180ms steps(1, end), player-slide 180ms linear;
}

@keyframes player-step {
  0% {
    background-position: 0% var(--sprite-y);
  }

  25% {
    background-position: 33.333333% var(--sprite-y);
  }

  50% {
    background-position: 66.666667% var(--sprite-y);
  }

  75% {
    background-position: 100% var(--sprite-y);
  }

  100% {
    background-position: 0% var(--sprite-y);
  }
}

@keyframes player-slide {
  from {
    transform: translate(
      calc(-50% + var(--walk-from-x)),
      var(--walk-from-y)
    );
  }

  to {
    transform: translateX(-50%);
  }
}

.map-item-marker {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 50%;
  width: 23px;
  height: 23px;
  transform: translate(-50%, -50%);
  background: url("/static/sprites/tiles/essentials/object_ball.png") center / contain no-repeat;
  image-rendering: pixelated;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.55));
}

.map-npc-marker {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: -2px;
  width: 26px;
  height: 34px;
  transform: translateX(-50%);
  background: url("/static/sprites/tiles/essentials/npc.png") center bottom / contain no-repeat;
  image-rendering: pixelated;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.55));
}

.map-npc-marker.trainer {
  background-image: url("/static/sprites/tiles/essentials/trainer.png");
}

.map-warp-marker {
  position: absolute;
  z-index: 1;
  left: 50%;
  bottom: 0;
  width: 28px;
  height: 18px;
  transform: translateX(-50%);
  background: url("/static/sprites/tiles/essentials/warp.png") center bottom / contain no-repeat;
  image-rendering: pixelated;
  opacity: 0.92;
}

.minimap-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #151d21;
  overflow: hidden;
}

.minimap-heading {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.minimap-heading strong {
  color: var(--text);
  font-size: 12px;
}

.minimap-grid {
  --mini-tile: 4px;
  display: grid;
  width: max-content;
  max-width: 100%;
  max-height: 100%;
  align-content: start;
  justify-content: start;
  justify-self: center;
  overflow: hidden;
  border: 1px solid #0b1013;
  background: #0b1013;
}

.minimap-canvas {
  width: 100%;
  height: 100%;
  min-height: 70px;
  display: block;
  border: 1px solid #0b1013;
  background: #0b1013;
  image-rendering: pixelated;
}

.minimap-tile {
  width: var(--mini-tile);
  height: var(--mini-tile);
  background: #79bf76;
}

.minimap-ground {
  background: #79bf76;
}

.minimap-path {
  background: #d8be76;
}

.minimap-grass {
  background: #2f8f52;
}

.minimap-water {
  background: #407fbd;
}

.minimap-building {
  background: #c56f5f;
}

.minimap-wall {
  background: #686e76;
}

.minimap-special {
  background: #d3ca55;
}

.minimap-has-item {
  box-shadow: inset 0 0 0 1px #f1f0d0;
}

.minimap-has-npc {
  box-shadow: inset 0 0 0 1px #1b1d20;
}

.minimap-warp {
  box-shadow: inset 0 0 0 1px #82d7df;
}

.minimap-player {
  background: #e74d45;
}

.minimap-remote {
  background: #5fb3d1;
}

.remote-player-avatar {
  z-index: 3;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.65)) hue-rotate(150deg) saturate(1.1);
}

.remote-player-0 {
  transform: translateX(-50%);
}

.remote-player-1 {
  transform: translateX(calc(-50% - 9px));
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.65)) hue-rotate(35deg) saturate(1.15);
}

.remote-player-2 {
  transform: translateX(calc(-50% + 9px));
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.65)) hue-rotate(245deg) saturate(1.15);
}

.remote-player-name {
  position: absolute;
  left: 50%;
  bottom: 33px;
  max-width: 78px;
  transform: translateX(-50%);
  padding: 1px 4px 2px;
  border-radius: 4px;
  background: rgba(7, 12, 15, 0.86);
  border: 1px solid rgba(243, 240, 223, 0.22);
  color: #f3f0df;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.remote-player-more {
  position: absolute;
  z-index: 5;
  right: -4px;
  top: -4px;
  min-width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border: 1px solid #11171b;
  border-radius: 50%;
  background: #f08f6e;
  color: #071014;
  font-size: 8px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.45);
}

.message-bar {
  min-height: 38px;
  padding: 9px 12px;
  border-top: 1px solid var(--line);
  color: var(--accent);
  font-size: 14px;
}

.side-panel {
  display: grid;
  grid-template-rows: clamp(110px, 22%, 170px) auto auto minmax(0, 1fr);
  overflow: hidden;
}

.quick-controls {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  background: #182126;
}

.quick-controls button,
.panel-tabs button {
  min-width: 0;
  overflow-wrap: anywhere;
}

.quick-controls button.active {
  background: var(--accent);
  border-color: #bda43e;
  color: #1e2322;
  font-weight: 800;
}

.panel-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
}

.panel-tabs button {
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel-2);
}

.panel-tabs button:last-child {
  border-right: 0;
}

.panel-tabs button.active {
  background: #3c493f;
  color: var(--accent);
}

.panel-body {
  grid-row: 4;
  min-height: 0;
  overflow: hidden;
  padding: 10px;
  display: grid;
  gap: 8px;
  align-content: start;
}

.side-canvas {
  grid-row: 4;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  background: #10181d;
  image-rendering: pixelated;
  touch-action: manipulation;
}

.legacy-panel {
  display: none !important;
}

.monster-row,
.item-row,
.battle-box {
  display: grid;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--line);
  background: #1a2227;
  border-radius: 6px;
}

.monster-head,
.item-row {
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
}

.monster-head {
  display: grid;
  gap: 8px;
}

.monster-head img {
  width: 42px;
  height: 42px;
  image-rendering: pixelated;
}

.battle-monster img {
  width: 96px;
  height: 96px;
  object-fit: contain;
  image-rendering: pixelated;
}

.monster-name,
.item-name {
  overflow-wrap: anywhere;
}

.hp-bar {
  height: 7px;
  background: #3b4349;
  border-radius: 999px;
  overflow: hidden;
}

.hp-fill {
  height: 100%;
  width: 0;
  background: var(--ok);
}

.move-list,
.battle-actions {
  display: grid;
  gap: 7px;
}

.move-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.battle-monster {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.social-block {
  min-width: 0;
  display: grid;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--line);
  background: #1a2227;
  border-radius: 6px;
}

.social-block h3 {
  margin: 0;
  font-size: 14px;
}

.panel-heading,
.trade-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.panel-heading button {
  min-width: 62px;
  min-height: 34px;
}

.online-list,
.trade-list {
  display: grid;
  gap: 8px;
}

.online-player,
.trade-card {
  min-width: 0;
  display: grid;
  gap: 8px;
  padding: 8px;
  border: 1px solid #39464f;
  background: #141b20;
  border-radius: 6px;
}

.online-player {
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
}

.player-badge {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid #6aa6b8;
  border-radius: 50%;
  background: #5fb3d1;
  color: #071014;
  font-size: 12px;
  font-weight: 800;
}

.online-main {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.online-main strong,
.online-main small,
.trade-heading strong,
.trade-heading span {
  overflow-wrap: anywhere;
}

.online-main small,
.trade-heading span,
.trade-monster small,
.trade-monster span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.mini-team {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.mini-team img,
.trade-monster img {
  width: 28px;
  height: 28px;
  image-rendering: pixelated;
}

.trade-controls,
.trade-actions,
.chat-form {
  display: grid;
  gap: 7px;
}

.trade-controls {
  grid-template-columns: minmax(0, 1fr) 82px;
}

.trade-actions {
  grid-template-columns: minmax(0, 1fr) repeat(2, 78px);
}

.trade-target {
  color: var(--accent);
  overflow-wrap: anywhere;
}

.trade-monster {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.chat-box {
  min-height: 240px;
}

.chat-messages {
  min-height: 150px;
  max-height: 260px;
  overflow: hidden;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 8px;
  border: 1px solid #39464f;
  background: #10161a;
  border-radius: 6px;
}

.chat-message {
  display: grid;
  gap: 2px;
  font-size: 13px;
}

.chat-message strong {
  color: var(--accent);
}

.chat-message.map strong {
  color: #7ccf8a;
}

.chat-message span {
  overflow-wrap: anywhere;
}

.chat-form {
  grid-template-columns: 92px minmax(0, 1fr) 78px;
}

.touch-controls {
  display: none;
  grid-template-columns: repeat(3, 58px);
  grid-template-rows: repeat(3, 52px);
  justify-content: center;
  gap: 7px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: #12181d;
}

.touch-controls button {
  font-size: 22px;
  font-weight: 800;
}

.touch-controls [data-move="up"] {
  grid-column: 2;
}

.touch-controls [data-move="left"] {
  grid-column: 1;
  grid-row: 2;
}

.touch-controls [data-move="right"] {
  grid-column: 3;
  grid-row: 2;
}

.touch-controls #interactTouchButton {
  grid-column: 2;
  grid-row: 2;
  background: var(--accent);
  border-color: #bda43e;
  color: #1e2322;
}

.touch-controls [data-move="down"] {
  grid-column: 2;
  grid-row: 3;
}

@media (max-width: 820px) {
  :root {
    --tile: 24px;
  }

  .game-view {
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .topbar {
    align-items: start;
  }

  .play-area {
    grid-template-columns: minmax(0, 1fr) clamp(136px, 38vw, 220px);
    grid-template-rows: minmax(0, 1fr);
    padding: 8px;
    gap: 8px;
  }

  .map-stage {
    grid-template-columns: 1fr;
  }

  .minimap-panel {
    padding: 6px;
  }

  .minimap-heading {
    font-size: 10px;
  }

  .side-panel {
    grid-template-rows: clamp(82px, 19%, 118px) auto auto minmax(0, 1fr);
  }

  .quick-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    padding: 6px;
  }

  .quick-controls button,
  .panel-tabs button {
    min-height: 34px;
    padding: 4px;
    font-size: 11px;
    white-space: nowrap;
  }

  .online-player {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .online-player button {
    grid-column: 1 / -1;
  }

  .trade-controls,
  .trade-actions,
  .chat-form {
    grid-template-columns: 1fr;
  }

  .chat-messages {
    max-height: 190px;
  }

  .touch-controls {
    display: grid;
  }

  .starter-list {
    grid-template-columns: 1fr;
  }

  .move-list {
    grid-template-columns: 1fr;
  }

  .minimap-grid {
    --mini-tile: 3px;
  }

  .battle-monster {
    grid-template-columns: 88px minmax(0, 1fr);
  }

  .battle-monster img {
    width: 80px;
    height: 80px;
  }
}

@media (min-width: 1200px) {
  :root {
    --tile: 34px;
  }

  .play-area {
    grid-template-columns: minmax(0, 1fr) 400px;
  }
}
