:root {
  --bg: #14171f;
  --card: #1f2430;
  --card-2: #2a3040;
  --line: #333a4c;
  --text: #e8ecf4;
  --muted: #98a2b4;
  --gold: #ffd84a;
  --accent: #3a6fd8;
  --accent-hover: #4b80e8;
  --danger: #d8504a;
  --good: #60e060;
  --r0: #d0d4dc;
  --r1: #5aa0f0;
  --r2: #c070f0;
  --r3: #ffa030;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
}

#stage {
  position: relative;
  flex: none;
  height: 33.34dvh;
  overflow: hidden;
  background: #6fb7e9;
  touch-action: none;
}

#stage.big { flex: 1; height: auto; min-height: 0; }

#scene, #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#scene { image-rendering: pixelated; }

#overlay { pointer-events: none; }

#joystick {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: grid;
  place-items: center;
  width: 104px;
  height: 104px;
  border-radius: 50%;
  background: #0006;
  border: 2px solid #fff5;
  touch-action: none;
}

#joystick[hidden], #action[hidden] { display: none; }

#knob {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #fffb;
  pointer-events: none;
}

#action {
  position: absolute;
  right: 14px;
  bottom: 30px;
  min-width: 72px;
  height: 72px;
  padding: 0 8px;
  border: 2px solid #fff8;
  border-radius: 36px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

#action:disabled { background: #0006; color: #fff8; cursor: default; }

#status {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: var(--card);
  font-size: 14px;
  flex: none;
}

#status[hidden], #tabs[hidden], #toast[hidden] { display: none; }

#status b { color: var(--gold); font-weight: 600; }

#stage.big ~ #body { flex: none; max-height: 34dvh; }

#body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 10px 12px;
  -webkit-overflow-scrolling: touch;
}

#tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  flex: none;
}

#tabs button {
  position: relative;
  min-height: 38px;
  padding: 0 2px;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

#tabs button[aria-current="page"] { color: var(--gold); font-weight: 600; }

#tabs .badge {
  position: absolute;
  top: 6px;
  right: 8%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
}

.card {
  background: var(--card);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}

.card h2 { margin: 0 0 4px; font-size: 16px; }

.card.tap { display: block; width: 100%; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; }

.card.tap:hover { background: var(--card-2); }

.muted { color: var(--muted); font-size: 13px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.row > :first-child { min-width: 0; flex: 1; }

.gold { color: var(--gold); }

.warn { color: #ff8f88; }

.good { color: var(--good); }

.r0 { color: var(--r0); }
.r1 { color: var(--r1); }
.r2 { color: var(--r2); }
.r3 { color: var(--r3); }

button.btn, a.btn {
  display: inline-block;
  min-height: 44px;
  padding: 10px 14px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

button.btn:hover:not(:disabled), a.btn:hover { background: var(--accent-hover); }

button.btn:disabled { background: var(--card-2); color: var(--muted); cursor: default; }

button.btn.secondary { background: var(--card-2); }

button.btn.danger { background: var(--danger); }

.btn.wide { display: block; width: 100%; margin-top: 8px; }

:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

input {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

.bar {
  height: 6px;
  margin: 4px 0;
  border-radius: 3px;
  background: #101218;
  overflow: hidden;
}

.bar i { display: block; height: 100%; background: var(--good); }

.bar.xp i { background: var(--r1); }

.bar.age i { background: var(--gold); }

.bar.boss { height: 10px; }

.bar.boss i { background: var(--danger); }

.bar.low i { background: var(--danger); }

.bar.mid i { background: #f0c040; }

.chat { display: flex; flex-direction: column; gap: 6px; height: 100%; }

.channels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }

.channels button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: var(--card);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.channels .on { background: var(--card-2); color: var(--gold); }

.ch-trade { color: #ffc98a; }

.ch-local { color: #a8e0b0; }

.ch-private { color: var(--gold); }

.chat-form { display: flex; gap: 6px; padding-top: 2px; }

.actions { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; margin-top: 6px; }

.actions .btn { padding: 8px 4px; font-size: 13px; }

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 6px 0;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  cursor: pointer;
}

.cell.empty { background: #191d27; border-style: dashed; cursor: default; }

.cell.rc1 { border-color: var(--r1); }
.cell.rc2 { border-color: var(--r2); }
.cell.rc3 { border-color: var(--r3); }

.cell.broken canvas { opacity: .45; }

.cell.picked { outline: 3px solid var(--gold); outline-offset: 1px; }

.cell .wear {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 4px;
  height: 3px;
  border-radius: 2px;
  background: #101218;
  overflow: hidden;
}

.cell .wear i { display: block; height: 100%; background: var(--good); }

.icon { width: 60%; aspect-ratio: 1; image-rendering: pixelated; }

.icon.big { width: 84px; flex: none; }

.card.row-item { display: flex; align-items: center; gap: 10px; }

.row-item > .icon { width: 44px; flex: none; }

.row-item > div { flex: 1; min-width: 0; }

.item-head { display: flex; gap: 12px; align-items: center; }

.item-head > div { flex: 1; min-width: 0; }

.option.on { outline: 2px solid var(--gold); }

.chat-log { flex: 1; min-height: 0; overflow-y: auto; }

.chat-log p { margin: 0; padding: 3px 0; overflow-wrap: anywhere; cursor: pointer; }

.chat-log b { color: var(--r1); font-weight: 600; }


.login {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 28px 18px;
  text-align: center;
}

.login h1 { margin: 0; font-size: 28px; }

.login p { margin: 0; max-width: 340px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
  border-radius: 6px;
  background: #000d;
  color: #fff;
  z-index: 10;
}

dialog {
  width: min(92vw, 400px);
  max-height: 88dvh;
  overflow-y: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
}

dialog::backdrop { background: #0009; }

dialog h3 { margin: 0 0 6px; font-size: 17px; }

dialog p { margin: 0 0 8px; }

dialog label { display: block; margin-top: 8px; font-size: 13px; color: var(--muted); }

dialog .btn { display: block; width: 100%; margin-top: 8px; }

/* Все 6 рядов сумки помещаются в экран без прокрутки */
.grid.fit { width: min(100%, calc((66.6dvh - 170px) * 0.66)); margin-inline: auto; }

.cell { touch-action: none; user-select: none; -webkit-user-select: none; }

.grid.small { grid-template-columns: repeat(6, 1fr); gap: 4px; }

.grid.five { grid-template-columns: repeat(5, 1fr); gap: 4px; margin: 4px 0; }

.grid.craft { grid-template-columns: repeat(3, 1fr); width: 60%; margin-inline: auto; }

.grid.small .cell .wear { left: 3px; right: 3px; bottom: 2px; height: 2px; }

.grid.small .cell, .grid.five .cell { border-radius: 6px; }

.grid.five .cell.empty { cursor: pointer; }

.grid.five .cell:disabled { cursor: default; }

.icon.ghost {
  position: fixed;
  z-index: 50;
  width: 52px;
  transform: translate(-50%, -60%);
  pointer-events: none;
}

.pages { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0; }

.pages .btn { width: auto; min-width: 64px; margin: 0; }

.trade-head { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }

.trade-arrows { text-align: center; font-size: 22px; color: var(--gold); line-height: 1.1; }

.gold-cell {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--gold);
  font: inherit;
  text-align: left;
}

.gold-cell.tap { cursor: pointer; border-color: var(--gold); }
