@font-face {
  font-family: 'Fredoka';
  src: url('assets/fonts/Fredoka.ttf') format('truetype');
  font-weight: 300 700;
  font-display: swap;
}

:root {
  --wood-1: #7a4a24;
  --wood-2: #5b3417;
  --wood-3: #3d220e;
  --cream: #fff4dc;
  --cream-2: #f3e1b8;
  --ink: #2a1a0c;
  --gold: #ffd23a;
  --red: #e5433a;
  --green: #4cc14a;
  --green-dark: #2e8a2d;
  --blue: #2e86f0;
  --shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
  --font: 'Fredoka', 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at 30% 20%, #3b2512 0%, #1d1208 70%) fixed;
  color: var(--cream);
  font-family: var(--font);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
button { font-family: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.app { display: flex; height: 100vh; height: 100dvh; width: 100vw; }
.stage { flex: 1; display: flex; align-items: center; justify-content: center; min-width: 0; padding: 10px; }
.field {
  position: relative; border-radius: 14px; overflow: hidden;
  box-shadow: 0 0 0 4px var(--wood-3), 0 0 0 7px #8a5a2c, 0 12px 40px rgba(0, 0, 0, 0.6);
}
.field canvas { display: block; touch-action: none; }

/* ---------------------------------------------------------------- sidebar */
.side {
  width: 312px; flex-shrink: 0; display: flex; flex-direction: column; gap: 8px; padding: 10px 10px 10px 0;
  overflow-y: auto; scrollbar-width: thin;
}
.hud {
  display: grid; grid-template-columns: auto 1fr auto auto; gap: 6px; align-items: stretch;
}
.stat {
  display: flex; align-items: center; justify-content: center; gap: 5px; padding: 6px 8px;
  background: linear-gradient(#6a3f1e, #4a2a12); border-radius: 12px; border: 2px solid #2a1608;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.12), var(--shadow);
  font-weight: 700; font-size: 20px; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5); white-space: nowrap;
}
.stat.long { font-size: 15px; padding: 6px 5px; }
.stat.xlong { font-size: 11px; padding: 6px 4px; }
.stat.long .ico, .stat.xlong .ico { width: 16px; height: 16px; }
.stat .ico { width: 22px; height: 22px; flex-shrink: 0; }
.stat.lives .ico { fill: #ff4f5e; stroke: #5a0b12; stroke-width: 1.5; }
.stat.cash .ico circle { fill: #ffd23a; stroke: #7a5200; stroke-width: 1.5; }
.stat.cash .ico text { fill: #7a5200; font-family: var(--font); }
.stat.round { flex-direction: column; gap: 0; line-height: 1; font-size: 19px; }
.stat.round .lbl { font-size: 9px; letter-spacing: 1.5px; opacity: 0.75; }
.stat.round .of { font-size: 11px; opacity: 0.7; }
.stat.flash-red { animation: flashRed 0.5s; }
.stat.flash-gold { animation: flashGold 0.4s; }
@keyframes flashRed { 0% { background: #c0282a; transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes flashGold { 0% { background: #a88312; transform: scale(1.05); } 100% { transform: scale(1); } }

.icon-btn {
  width: 40px; border-radius: 12px; border: 2px solid #2a1608; background: linear-gradient(#8a5a2c, #62391a);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.15), var(--shadow); display: grid; place-items: center; padding: 0;
}
.icon-btn svg { width: 20px; height: 20px; fill: var(--cream); }
.icon-btn:active { transform: translateY(2px); box-shadow: none; }

.shop {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 8px;
  background: linear-gradient(#5b3417, #472810); border-radius: 14px; border: 2px solid #2a1608;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.08), var(--shadow);
}
.card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 4px 2px 5px;
  background: linear-gradient(#fff8e6, #f0dcae); color: var(--ink); border: 2px solid #3d220e; border-radius: 11px;
  box-shadow: 0 3px 0 #2a1608; transition: transform 0.08s, filter 0.15s;
}
.card img { width: 54px; height: 54px; pointer-events: none; }
.card .nm { font-size: 11.5px; font-weight: 600; line-height: 1.05; text-align: center; min-height: 24px; display: flex; align-items: center; }
.card .pr { font-size: 14px; font-weight: 700; color: #2e7d32; }
.card .hk { position: absolute; top: 3px; left: 5px; font-size: 10px; font-weight: 700; opacity: 0.55; }
.card:hover { transform: translateY(-2px); filter: brightness(1.05); }
.card:active { transform: translateY(1px); box-shadow: 0 1px 0 #2a1608; }
.card.poor { filter: grayscale(0.7) brightness(0.8); }
.card.poor .pr { color: #b3261e; }
.card.active { outline: 3px solid var(--gold); outline-offset: 1px; }

.panel {
  background: linear-gradient(#fff8e6, #f0dcae); color: var(--ink); border-radius: 14px; border: 2px solid #3d220e;
  box-shadow: var(--shadow); padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 7px;
}
.panel .head { display: flex; align-items: center; gap: 8px; }
.panel .head img { width: 50px; height: 50px; background: radial-gradient(#fff, #e6cf9a); border-radius: 12px; border: 2px solid #c9a86a; }
.panel .head .t { flex: 1; min-width: 0; }
.panel .head h3 { margin: 0; font-size: 17px; line-height: 1.1; }
.panel .head .sub { font-size: 12px; opacity: 0.75; }
.panel .close { width: 28px; height: 28px; border-radius: 50%; border: 2px solid #3d220e; background: #e8cf98; font-weight: 700; color: var(--ink); padding: 0; }
.target-row { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.target-row .lbl { font-weight: 600; opacity: 0.8; }
.target-row .sel { flex: 1; display: flex; align-items: center; justify-content: space-between; background: #3d220e; color: var(--cream); border-radius: 10px; padding: 2px; }
.target-row .sel button { border: 0; background: #6a3f1e; color: var(--cream); width: 26px; height: 24px; border-radius: 8px; font-weight: 700; }
.target-row .sel span { font-weight: 600; }
.path { background: rgba(255, 255, 255, 0.55); border: 2px solid #d2b577; border-radius: 12px; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.path .ph { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 600; opacity: 0.85; }
.pips { display: flex; gap: 3px; }
.pips i { width: 11px; height: 11px; border-radius: 3px; background: #d8c08c; border: 1.5px solid #8a6a36; }
.pips i.on { background: var(--green); border-color: var(--green-dark); }
.upg {
  display: flex; align-items: center; gap: 6px; width: 100%; text-align: left; border: 2px solid #2e6b2d; border-radius: 10px;
  background: linear-gradient(#7ad66b, #46a843); color: #10300f; padding: 5px 7px; box-shadow: 0 3px 0 #1f4d1e;
}
.upg .info { flex: 1; min-width: 0; }
.upg .n { font-weight: 700; font-size: 13.5px; line-height: 1.1; }
.upg .d { font-size: 11px; line-height: 1.2; opacity: 0.85; }
.upg .c { font-weight: 700; font-size: 15px; white-space: nowrap; }
.upg:active { transform: translateY(2px); box-shadow: 0 1px 0 #1f4d1e; }
.upg.poor { background: linear-gradient(#e6d3a8, #cdb27a); border-color: #8a6a36; color: #4a3417; box-shadow: 0 3px 0 #6b5025; }
.upg.poor .c { color: #b3261e; }
.upg.locked, .upg.max { background: #d9c79d; border-color: #a58a55; color: #6b5530; box-shadow: none; cursor: default; }
.caps { display: flex; flex-wrap: wrap; gap: 4px; font-size: 11px; }
.caps span { padding: 1px 6px; border-radius: 8px; font-weight: 600; }
.caps .y { background: #cdeec5; color: #1f5a1d; }
.caps .n { background: #f5cdc5; color: #7a1d12; }
.stat-line { font-size: 11.5px; opacity: 0.8; display: flex; gap: 10px; flex-wrap: wrap; }
.panel-actions { display: flex; gap: 6px; }
.btn {
  border: 2px solid #2a1608; border-radius: 12px; padding: 8px 10px; font-weight: 700; font-size: 15px; color: #fff;
  background: linear-gradient(#8a5a2c, #62391a); box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.18), var(--shadow);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn.sell { background: linear-gradient(#f06a5a, #c23a2c); flex: 1; }
.btn.bank { background: linear-gradient(#63c95c, #2e8a2d); flex: 1; }
.btn.ability { background: linear-gradient(#ffcf4a, #e59a12); color: #3d2200; text-shadow: none; flex: 1; }
.btn.ability:disabled { filter: grayscale(0.8); opacity: 0.7; cursor: default; }

.preview {
  background: linear-gradient(#5b3417, #472810); border-radius: 14px; border: 2px solid #2a1608; padding: 8px 10px;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.08), var(--shadow);
}
.preview h4 { margin: 0 0 6px; font-size: 13px; letter-spacing: 1px; opacity: 0.85; display: flex; justify-content: space-between; }
.rtitle { margin: -3px 0 6px; font-size: 13px; font-weight: 600; color: var(--gold); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: flex; align-items: center; gap: 2px; background: rgba(0, 0, 0, 0.25); border-radius: 10px; padding: 1px 7px 1px 2px; font-size: 13px; font-weight: 600; }
.chip img { width: 22px; height: 22px; }
.chip .tag { font-size: 9px; padding: 0 4px; border-radius: 6px; margin-left: 2px; }
.chip .tag.c { background: #5d7a2a; }
.chip .tag.r { background: #2f9a44; }
.warn { margin-top: 6px; font-size: 12px; line-height: 1.3; background: rgba(255, 90, 60, 0.18); border: 1px solid rgba(255, 120, 90, 0.5); border-radius: 8px; padding: 4px 7px; }
.warn b { color: #ffcf6a; }

.tips { font-size: 12.5px; line-height: 1.35; color: #f3e1b8; background: rgba(0, 0, 0, 0.18); border: 1px dashed rgba(243, 225, 184, 0.35); border-radius: 12px; padding: 7px 10px; }
.tips b { color: var(--gold); }
.controls { display: flex; flex-direction: column; gap: 6px; margin-top: auto; }
.btn.play { background: linear-gradient(#72dc5f, #34a02f); font-size: 20px; padding: 10px; border-color: #1d5a1a; }
.btn.play.running { background: linear-gradient(#4aa3df, #2a6fa8); border-color: #173e5e; }
.btn.play.pulse { animation: pulse 1.4s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.18), 0 3px 0 rgba(0, 0, 0, 0.35), 0 0 0 0 rgba(120, 230, 100, 0.6); } 50% { box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.18), 0 3px 0 rgba(0, 0, 0, 0.35), 0 0 0 8px rgba(120, 230, 100, 0); } }
.control-row { display: grid; grid-template-columns: 1fr 1.5fr 1fr; gap: 6px; }
.btn.small { font-size: 14px; padding: 6px 4px; }
.btn.toggle.on { background: linear-gradient(#ffcf4a, #e59a12); color: #3d2200; text-shadow: none; }
.btn.speed2 { background: linear-gradient(#ffb347, #e07a12); }
.btn.speed3 { background: linear-gradient(#ff6a5a, #c2362a); }

/* ---------------------------------------------------------------- field overlays */
.banner {
  position: absolute; left: 50%; top: 18%; transform: translate(-50%, -30px) scale(0.9); opacity: 0; pointer-events: none;
  text-align: center; transition: opacity 0.3s, transform 0.3s; width: 90%;
}
.banner.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.banner .big {
  font-size: clamp(28px, 5vw, 54px); font-weight: 700; color: #fff; letter-spacing: 1px;
  text-shadow: 0 4px 0 #2a1608, 0 0 3px #2a1608, 3px 3px 0 #2a1608, -3px 3px 0 #2a1608, 3px -2px 0 #2a1608, -3px -2px 0 #2a1608;
}
.banner .sub { margin-top: 2px; font-size: clamp(14px, 2vw, 22px); font-weight: 600; color: var(--gold); text-shadow: 0 2px 0 #2a1608, 2px 2px 0 #2a1608, -2px 2px 0 #2a1608, 0 0 6px #2a1608; }
.banner.danger .big { color: #ff5a4a; }
.banner .intro { display: inline-flex; align-items: center; gap: 8px; margin-top: 8px; background: rgba(30, 15, 5, 0.82); border: 2px solid var(--gold); border-radius: 12px; padding: 6px 12px; max-width: 520px; font-size: 14px; text-align: left; line-height: 1.3; }
.banner .intro img { width: 34px; height: 34px; }

.abilities { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 6px; }
.ab {
  position: relative; width: 52px; height: 52px; border-radius: 50%; border: 3px solid #2a1608; background: #fff4dc; padding: 0;
  box-shadow: var(--shadow); overflow: hidden;
}
.ab img { width: 44px; height: 44px; position: relative; z-index: 1; }
.ab .cd { position: absolute; inset: 0; z-index: 2; background: conic-gradient(rgba(20, 10, 5, 0.65) var(--p), transparent 0); }
.ab .cdt { position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; font-weight: 700; color: #fff; text-shadow: 0 1px 2px #000; font-size: 14px; }
.ab.ready { border-color: var(--gold); animation: glow 1s infinite alternate; }
@keyframes glow { from { box-shadow: 0 0 4px 1px rgba(255, 210, 60, 0.6); } to { box-shadow: 0 0 12px 4px rgba(255, 210, 60, 0.9); } }

.toast {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: rgba(30, 15, 5, 0.88); border: 2px solid #8a5a2c; color: var(--cream); padding: 6px 14px; border-radius: 12px; font-weight: 600;
  transition: opacity 0.2s, transform 0.2s; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { border-color: #e5433a; color: #ffd0c8; }
.paused-tag { position: absolute; top: 12px; right: 14px; background: rgba(30, 15, 5, 0.8); padding: 4px 12px; border-radius: 10px; font-weight: 700; letter-spacing: 2px; }

.tooltip {
  position: fixed; z-index: 50; max-width: 260px; background: #2a1a0c; color: var(--cream); border: 2px solid #8a5a2c; border-radius: 12px;
  padding: 8px 10px; font-size: 13px; line-height: 1.35; pointer-events: none; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.tooltip h5 { margin: 0 0 2px; font-size: 15px; color: var(--gold); }
.tooltip .caps { margin-top: 5px; }

/* ---------------------------------------------------------------- screens */
.screen {
  position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  background: rgba(15, 8, 3, 0.62); backdrop-filter: blur(3px); animation: fadeIn 0.25s;
}
.screen.title-screen { background: none; backdrop-filter: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.screen canvas.bgfx { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; }
.box {
  background: linear-gradient(#fff8e6, #f0dcae); color: var(--ink); border: 3px solid #3d220e; border-radius: 22px;
  box-shadow: 0 6px 0 #2a1608, 0 20px 60px rgba(0, 0, 0, 0.5); padding: 22px 26px; max-width: min(94vw, 900px); max-height: 92vh; overflow: auto;
  animation: popIn 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes popIn { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.box h2 { margin: 0 0 10px; font-size: 32px; text-align: center; }
.box p { margin: 6px 0; }
.btn-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.btn.big { font-size: 22px; padding: 12px 26px; border-radius: 16px; }
.btn.green { background: linear-gradient(#72dc5f, #34a02f); border-color: #1d5a1a; }
.btn.blue { background: linear-gradient(#5ab4f0, #2a6fa8); border-color: #173e5e; }
.btn.gold { background: linear-gradient(#ffcf4a, #e59a12); color: #3d2200; text-shadow: none; border-color: #6b4a00; }
.btn.red { background: linear-gradient(#f06a5a, #c23a2c); border-color: #6b1a12; }

.logo { text-align: center; margin-bottom: 8px; }
.logo .word { display: inline-block; margin: 0 0.12em; font-size: clamp(56px, 11vw, 124px); font-weight: 700; line-height: 0.95; letter-spacing: 2px; }
.logo .word span {
  display: inline-block; animation: bob 2.4s ease-in-out infinite; color: #fff;
  -webkit-text-stroke: 3px #2a1608; paint-order: stroke fill;
  text-shadow: 0 8px 0 #2a1608, 0 14px 20px rgba(0, 0, 0, 0.35);
}
.logo .word span:nth-child(odd) { animation-delay: -0.6s; }
.logo .pop span { color: #ff4f5e; }
.logo .squad span { color: #ffd23a; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-8px) rotate(2deg); } }
.logo .tag { font-size: 20px; font-weight: 600; color: var(--cream); text-shadow: 0 2px 0 #2a1608; letter-spacing: 3px; }
.title-menu { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.title-menu .btn { min-width: 260px; }
.title-foot { position: fixed; bottom: 10px; left: 0; right: 0; text-align: center; font-size: 12px; opacity: 0.6; }

.maps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.mapcard { border: 3px solid #c9a86a; border-radius: 16px; background: #fff; padding: 8px; text-align: left; color: var(--ink); transition: transform 0.12s; }
.mapcard img { width: 100%; border-radius: 10px; display: block; border: 2px solid #3d220e; }
.mapcard h3 { margin: 6px 0 0; font-size: 19px; }
.mapcard .tier { font-size: 12px; font-weight: 700; color: #8a5a2c; letter-spacing: 1px; }
.mapcard .bl { font-size: 12.5px; line-height: 1.3; opacity: 0.85; min-height: 48px; }
.mapcard.on { border-color: var(--green); box-shadow: 0 0 0 3px var(--green); transform: translateY(-3px); }
.medals { display: flex; gap: 4px; margin-top: 4px; }
.medal { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 8px; background: #e6d8b8; color: #9a8a6a; }
.medal.got { background: var(--gold); color: #5a3a00; }
.diffs { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.diff { border: 3px solid #c9a86a; background: #fff; border-radius: 14px; padding: 8px 14px; min-width: 170px; color: var(--ink); text-align: center; }
.diff b { display: block; font-size: 18px; }
.diff small { font-size: 11.5px; opacity: 0.8; }
.diff.on { border-color: var(--green); box-shadow: 0 0 0 3px var(--green); }

.help { max-width: 860px; font-size: 14px; line-height: 1.45; }
.help h3 { margin: 14px 0 6px; font-size: 19px; }
.help .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px 14px; }
.help .row { display: flex; gap: 8px; align-items: flex-start; }
.help .row img { width: 34px; height: 34px; flex-shrink: 0; }
.help kbd { background: #3d220e; color: var(--cream); border-radius: 6px; padding: 0 6px; font-family: var(--font); font-size: 12px; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 10px 0; }
.stats-grid div { background: rgba(255, 255, 255, 0.6); border: 2px solid #d2b577; border-radius: 12px; padding: 6px; text-align: center; }
.stats-grid b { display: block; font-size: 22px; }
.stats-grid small { font-size: 11px; opacity: 0.75; letter-spacing: 0.5px; }
.toggles { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }

@media (max-width: 900px) {
  body { overflow: auto; }
  .app { flex-direction: column; height: auto; min-height: 100vh; }
  .stage { padding: 6px; }
  .side { width: 100%; padding: 0 8px 12px; overflow: visible; }
  .shop { grid-template-columns: repeat(5, 1fr); }
  .maps { grid-template-columns: 1fr; }
}
