:root {
  --bg: #3d7a35;
  --card: #e8dcc4;
  --ink: #1a1a2e;
  --gold: #c9a227;
  --gold-hi: #f0d070;
  --muted: #5a5348;
  --panel: #efe4c8;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; width: 100%; height: 100%; overflow: hidden;
  background: #2a5524; color: var(--ink);
  font-family: "Segoe UI", system-ui, sans-serif;
  touch-action: none; user-select: none;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; }
button { border: 0; background: none; color: inherit; cursor: pointer; }
img { display: block; pointer-events: none; -webkit-user-drag: none; image-rendering: pixelated; }
input {
  width: 100%; margin-top: 4px; padding: 12px;
  border-radius: 10px; border: 3px solid #2a2a40;
  background: #f7f0dc; color: var(--ink);
}
#app { position: fixed; inset: 0; touch-action: none; }
.screen { position: absolute; inset: 0; }
[hidden] { display: none !important; }

#screen-auth {
  display: flex; align-items: center; justify-content: center;
  padding: 20px; touch-action: manipulation;
  background: linear-gradient(180deg, #5aaa45, #2a5524);
}
.auth-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 4px solid #1a1a2e;
  border-radius: 16px; padding: 22px;
  box-shadow: 0 10px 0 #1a1a2e55;
}
.logo-build { width: 84px; height: 84px; margin: 0 auto 8px; object-fit: contain; image-rendering: pixelated; }
.auth-card h1 { margin: 0; text-align: center; color: #3d5a9a; letter-spacing: .08em; }
.tag { text-align: center; color: var(--muted); font-size: 12px; margin: 4px 0 14px; }
.auth-card label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.row { display: flex; gap: 8px; }
.row .btn { flex: 1; }

.btn {
  padding: 12px 14px; border-radius: 12px; font-weight: 800;
  background: #6aa8c8; color: #fff; border: 3px solid #1a1a2e;
  box-shadow: 0 4px 0 #1a1a2e;
}
.btn.gold {
  background: linear-gradient(180deg, #f0d070, #c9a227);
  color: #2a1a08;
}
.btn.wide { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .45; box-shadow: none; }
.err { color: #c04040; font-size: 13px; margin-top: 8px; }
.muted { color: var(--muted); font-size: 13px; }

#screen-game { display: flex; flex-direction: column; background: var(--bg); }
.top {
  z-index: 20; padding: calc(8px + var(--safe-t)) 10px 8px;
  background: linear-gradient(180deg, rgba(20,40,18,.92), rgba(20,40,18,.55));
  color: #f4f1e6;
}
.player { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.player img { width: 40px; height: 40px; object-fit: contain; image-rendering: pixelated; }
.player b { display: block; color: var(--gold-hi); }
.player span { font-size: 12px; color: #c8d4c0; }
.player i { font-style: normal; color: #fff; font-weight: 800; }
.res { display: flex; flex-wrap: wrap; gap: 4px; }
.res span {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(0,0,0,.4); border: 2px solid rgba(255,255,255,.12);
  border-radius: 10px; padding: 3px 7px 3px 4px; font-size: 12px; font-weight: 800;
}
.res img { width: 20px; height: 20px; object-fit: contain; image-rendering: pixelated; }
.res b { color: var(--gold-hi); }

.view { flex: 1; min-height: 0; position: relative; touch-action: none; overflow: hidden; }
#game, #game canvas {
  width: 100% !important; height: 100% !important; display: block;
  touch-action: none;
}
.sheet { overflow: auto; padding: 12px; background: #2f5e2a; touch-action: pan-y; color: #f4f1e6; }
.sheet h2 { margin: 0 0 6px; color: var(--gold-hi); }
.card, .qitem {
  background: rgba(0,0,0,.28); border: 2px solid rgba(232,220,196,.35);
  border-radius: 12px; padding: 10px; margin-bottom: 8px;
}
.card { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card .stats { width: 100%; font-size: 11px; color: #c8d4c0; margin-top: 4px; }
.qitem { color: #9ec5ff; font-weight: 700; font-size: 13px; }

.panel {
  position: absolute; left: 10px; right: 10px;
  bottom: calc(78px + var(--safe-b)); z-index: 30;
  max-height: 48%; overflow: auto;
  background: var(--panel) url("../assets/ui/ts/paper_fill.png") center/64px;
  border: 4px solid #1a1a2e;
  border-radius: 14px; padding: 12px 14px;
  box-shadow: 0 8px 0 #1a1a2e66;
  color: var(--ink);
  touch-action: pan-y;
}
.panel .x {
  position: absolute; right: 8px; top: 8px; width: 36px; height: 36px;
  padding: 0; background: transparent;
}
.panel .x img { width: 100%; height: 100%; object-fit: contain; }
.phead { display: flex; gap: 10px; align-items: center; margin-right: 36px; }
.phead img { width: 56px; height: 56px; object-fit: contain; image-rendering: pixelated; }
.panel h2 { margin: 0; color: #3d5a9a; font-size: 18px; }
.panel h3 {
  margin: 12px 0 8px; font-size: 13px; color: #3d5a9a;
  border-top: 2px solid #1a1a2e33; padding-top: 10px;
}
.cost { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.cost span {
  background: #f7f0dc; border: 2px solid #1a1a2e;
  border-radius: 8px; padding: 4px 8px; font-size: 11px; font-weight: 700;
}
.timer { color: #3d5a9a; font-weight: 800; }
.train, .resrow {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px;
  background: #f7f0dc; border: 2px solid #1a1a2e55; border-radius: 10px; padding: 8px;
}
.train .meta, .resrow .meta { flex: 1 1 130px; font-size: 12px; }
.train input { width: 70px; margin: 0; padding: 8px; }
.tiny { font-size: 11px; color: var(--muted); }

.toast {
  position: absolute; left: 10px; right: 10px;
  bottom: calc(78px + var(--safe-b)); z-index: 40;
  display: flex; gap: 10px; align-items: center;
  background: var(--panel); border: 4px solid #1a1a2e;
  border-radius: 14px; padding: 12px; color: var(--ink);
}
.toast ul { margin: 4px 0 0; padding-left: 16px; font-size: 12px; color: var(--muted); }

.nav {
  z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 4px; padding: 8px 6px calc(8px + var(--safe-b));
  background: #1e3a1c;
  border-top: 4px solid #1a1a2e;
}
.nav button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 4px 2px 2px; border-radius: 10px;
  font-size: 10px; font-weight: 800; color: #b8c8b0;
}
.nav-ico {
  width: 44px; height: 44px;
  background: url("../assets/ui/ts/nav_btn.png") center/100% 100% no-repeat;
  display: grid; place-items: center;
  image-rendering: pixelated;
}
.nav-ico img {
  width: 26px; height: 26px; object-fit: contain;
  image-rendering: pixelated; filter: none; opacity: 1;
}
.nav button.on { color: var(--gold-hi); }
.nav button.on .nav-ico {
  background-image: url("../assets/ui/ts/nav_btn_on.png");
  transform: translateY(1px);
}
.nav button:disabled { opacity: .4; }

@media (min-width: 700px) {
  #screen-game { max-width: 420px; margin: 0 auto; border-left: 3px solid #1a1a2e; border-right: 3px solid #1a1a2e; }
}
