@import url("../assets/pixelfonts/fonts.css");

:root {
  --outline: #543847;
  --sky: #4EC0CA;
  --panel: #DED895;
  --panel-in: #EFE9B4;
  --bevel: #CBB968;
  --accent: #F07A28;
  --green: #5EC650;
  --gold: #F5B700;
  --gold-l: #FFE14D;
  --pixel: "Press Start 2P", monospace;
  --body: "Pixelify Sans", sans-serif;
  --step: 5px;
  --pscale: 2px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--body);
  color: var(--outline);
  background: var(--sky);
  overflow: hidden;
  overscroll-behavior: none;
  image-rendering: pixelated;
}
#app { position: fixed; inset: 0; }
#game-canvas { position: absolute; inset: 0; overflow: hidden; background: var(--sky); }
#game-canvas canvas { display: block; image-rendering: pixelated; }

/* stepped pixel corner shape */
.step {
  clip-path: polygon(
    var(--step) 0, calc(100% - var(--step)) 0, 100% var(--step),
    100% calc(100% - var(--step)), calc(100% - var(--step)) 100%,
    var(--step) 100%, 0 calc(100% - var(--step)), 0 var(--step));
}

/* ---------------- screens ---------------- */
.screen {
  position: absolute; inset: 0;
  display: none; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: max(10px, env(safe-area-inset-top)) 12px max(14px, env(safe-area-inset-bottom));
  z-index: 10;
}
.screen.active { display: block; }
.screen.dim { background: rgba(20, 40, 44, .45); }
.wrap { max-width: calc(var(--pscale) * 232); margin: 0 auto; }

/* ---------------- panel ---------------- */
.panel {
  background: var(--panel);
  border: 3px solid var(--outline);
  box-shadow: inset 3px 3px 0 var(--panel-in), inset -3px -3px 0 var(--bevel);
  padding: calc(var(--pscale) * 7);
}
.panel-mini {
  background: var(--panel);
  border: 3px solid var(--outline);
  box-shadow: inset 3px 3px 0 var(--panel-in), inset -3px -3px 0 var(--bevel);
  padding: calc(var(--pscale) * 4) calc(var(--pscale) * 5);
}

/* ---------------- typography ---------------- */
.pix { font-family: var(--pixel); text-transform: uppercase; letter-spacing: 0; }
h1, h2, h3, .head { font-family: var(--pixel); font-weight: 400; text-transform: uppercase; margin: 0; }
.outline-text {
  color: #fff;
  text-shadow: 2px 0 var(--outline), -2px 0 var(--outline), 0 2px var(--outline), 0 -2px var(--outline),
    2px 2px var(--outline), -2px -2px var(--outline), 2px -2px var(--outline), -2px 2px var(--outline);
}
.head-orange {
  color: var(--accent);
  text-shadow: 2px 0 var(--outline), -2px 0 var(--outline), 0 2px var(--outline), 0 -2px var(--outline),
    2px 2px var(--outline), -2px -2px var(--outline), 2px -2px var(--outline), -2px 2px var(--outline);
}

/* ---------------- buttons ---------------- */
.btn {
  font-family: var(--pixel);
  text-transform: uppercase;
  font-size: calc(var(--pscale) * 8);
  color: var(--outline);
  background: var(--panel-in);
  border: 3px solid var(--outline);
  padding: calc(var(--pscale) * 8) calc(var(--pscale) * 10);
  cursor: pointer;
  user-select: none;
  display: inline-flex; align-items: center; justify-content: center; gap: calc(var(--pscale) * 4);
  line-height: 1;
  box-shadow: inset 0 0 0 3px var(--accent), inset 0 4px 0 rgba(255,255,255,.6), inset 0 -4px 0 rgba(0,0,0,.13);
  filter: drop-shadow(0 4px 0 var(--outline));
  transition: transform .05s steps(2);
  clip-path: polygon(4px 0, calc(100% - 4px) 0, 100% 4px, 100% calc(100% - 4px), calc(100% - 4px) 100%, 4px 100%, 0 calc(100% - 4px), 0 4px);
}
.btn:active { transform: translateY(2px); filter: drop-shadow(0 2px 0 var(--outline)); }
.btn.primary {
  background: var(--green); color: #fff;
  box-shadow: inset 0 0 0 3px var(--accent), inset 0 4px 0 rgba(255,255,255,.45), inset 0 -4px 0 rgba(0,0,0,.18);
  text-shadow: 2px 0 var(--outline), -2px 0 var(--outline), 0 2px var(--outline), 0 -2px var(--outline), 2px 2px var(--outline), -2px -2px var(--outline);
}
.btn.gold { background: var(--gold-l); }
.btn.wide { width: 100%; }
.btn.small { font-size: 9px; padding: 10px 12px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.play-tri {
  width: 0; height: 0; border-style: solid; border-width: 7px 0 7px 11px;
  border-color: transparent transparent transparent #fff;
  filter: drop-shadow(1px 1px 0 var(--outline)) drop-shadow(-1px -1px 0 var(--outline));
}
.arrow { width: 0; height: 0; border-style: solid; border-width: 6px 9px 6px 0; border-color: transparent #fff transparent transparent; filter: drop-shadow(1px 0 0 var(--outline)); }
.arrow.right { border-width: 6px 0 6px 9px; border-color: transparent transparent transparent #fff; }

/* square toggle buttons */
.sqbtn {
  width: calc(var(--pscale) * 18); height: calc(var(--pscale) * 17); padding: 0; cursor: pointer; position: relative;
  background: var(--panel-in); border: 3px solid var(--outline);
  box-shadow: inset 0 0 0 3px var(--accent), inset 0 3px 0 rgba(255,255,255,.6), inset 0 -3px 0 rgba(0,0,0,.13);
  filter: drop-shadow(0 4px 0 var(--outline));
  clip-path: polygon(3px 0, calc(100% - 3px) 0, 100% 3px, 100% calc(100% - 3px), calc(100% - 3px) 100%, 3px 100%, 0 calc(100% - 3px), 0 3px);
  display: grid; place-items: center; color: var(--outline);
}
.sqbtn:active { transform: translateY(2px); filter: drop-shadow(0 2px 0 var(--outline)); }
.sqbtn svg { width: calc(var(--pscale) * 9); height: calc(var(--pscale) * 9); }
.sqbtn.off::after {
  content: ""; position: absolute; inset: 6px; background:
    linear-gradient(45deg, transparent 44%, var(--accent) 44%, var(--accent) 56%, transparent 56%),
    linear-gradient(-45deg, transparent 44%, var(--accent) 44%, var(--accent) 56%, transparent 56%);
}

/* ---------------- menu top bar ---------------- */
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
.topleft { display: flex; flex-direction: column; gap: 6px; }
.topchip { display: flex; flex-direction: column; gap: calc(var(--pscale) * 3); min-width: calc(var(--pscale) * 96); }
.topchip .row1 { display: flex; align-items: center; gap: calc(var(--pscale) * 4); }
.lvl { display: flex; align-items: center; gap: 6px; }
.lvl-medal {
  width: calc(var(--pscale) * 20); height: calc(var(--pscale) * 20); border: 3px solid var(--outline); background: var(--gold);
  display: grid; place-items: center; font-family: var(--pixel); font-size: calc(var(--pscale) * 9); color: var(--outline);
  box-shadow: inset 0 3px 0 var(--gold-l), inset 0 -3px 0 #C77A00;
  clip-path: polygon(3px 0, calc(100% - 3px) 0, 100% 3px, 100% calc(100% - 3px), calc(100% - 3px) 100%, 3px 100%, 0 calc(100% - 3px), 0 3px);
}
.lvl-lbl { font-family: var(--pixel); font-size: calc(var(--pscale) * 7); }
.xpwrap { min-width: calc(var(--pscale) * 70); flex: 1; }
.xpbar { height: calc(var(--pscale) * 6); background: #b9b083; border: 2px solid var(--outline); overflow: hidden; }
.xpbar i { display: block; height: 100%; width: 0%; background: var(--green); box-shadow: inset 0 3px 0 #8BE07A; }
.xptext { font-family: var(--pixel); font-size: calc(var(--pscale) * 5); margin-top: calc(var(--pscale) * 2); }
.coinrow { display: flex; align-items: center; gap: calc(var(--pscale) * 3); font-family: var(--pixel); font-size: calc(var(--pscale) * 7); }
.coin-dot { width: 16px; height: 16px; display: inline-block; background: var(--gold); border: 3px solid var(--outline); box-shadow: inset 0 2px 0 var(--gold-l); }
.coin-ico { width: calc(var(--pscale) * 9); height: calc(var(--pscale) * 9); image-rendering: pixelated; display: inline-block; vertical-align: middle; }
#hud .chip .coin-ico { width: calc(var(--pscale) * 8); height: calc(var(--pscale) * 8); }
.card .price .coin-ico { width: calc(var(--pscale) * 7); height: calc(var(--pscale) * 7); }
.right-toggles { display: flex; gap: 8px; }

/* ---------------- logo ---------------- */
.logo {
  font-family: var(--pixel);
  font-size: calc(var(--pscale) * 19);
  text-align: center;
  margin: calc(var(--pscale) * 4) 0 calc(var(--pscale) * 10);
  line-height: 1;
  background: linear-gradient(180deg, #FFE14D 0 34%, #F8A830 34% 67%, #F07A28 67% 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter:
    drop-shadow(1px 0 0 var(--outline)) drop-shadow(-1px 0 0 var(--outline))
    drop-shadow(0 1px 0 var(--outline)) drop-shadow(0 -1px 0 var(--outline))
    drop-shadow(0 2px 0 var(--outline)) drop-shadow(0 3px 0 var(--outline));
}
.logo .lbird { display: inline-block; }
.logo .lbird img { height: 1.5em; vertical-align: -0.22em; image-rendering: pixelated; margin-left: calc(var(--pscale) * 2); }

/* ---------------- nickname field ---------------- */
.field { margin-bottom: 14px; }
.field label { font-family: var(--pixel); font-size: calc(var(--pscale) * 7); display: block; margin-bottom: calc(var(--pscale) * 4); }
.field input {
  width: 100%; background: #EFE9B4; border: 3px solid var(--outline);
  font-family: var(--body); font-size: calc(var(--pscale) * 9); padding: calc(var(--pscale) * 5) calc(var(--pscale) * 4); color: var(--outline);
  box-shadow: inset 3px 3px 0 rgba(0,0,0,.12);
}
.field input::placeholder { color: #8a8468; }
.field input:focus { outline: none; background: #fff; }

.menu-buttons { display: flex; flex-direction: column; gap: calc(var(--pscale) * 5); }
.menu-buttons .btn.primary { font-size: calc(var(--pscale) * 11); padding: calc(var(--pscale) * 10); }

/* ---------------- shop ---------------- */
.shopbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.shopbar h2 { font-size: calc(var(--pscale) * 11); }
.shopbar .coins { display: flex; align-items: center; gap: 6px; font-family: var(--pixel); font-size: 12px; }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; flex-wrap: wrap; }
.tab {
  font-family: var(--pixel); text-transform: uppercase; font-size: calc(var(--pscale) * 5);
  background: var(--bevel); border: 2px solid var(--outline); color: var(--outline);
  padding: calc(var(--pscale) * 4) calc(var(--pscale) * 2); cursor: pointer; white-space: nowrap;
  clip-path: polygon(3px 0, calc(100% - 3px) 0, 100% 3px, 100% 100%, 0 100%, 0 3px);
}
.tab.active { background: var(--panel-in); transform: translateY(-2px); box-shadow: inset 0 -4px 0 var(--accent); }
.preview { margin-bottom: 10px; display: grid; grid-template-columns: 1.3fr 1fr; gap: 10px; align-items: center; }
.preview .shot { position: relative; border: 3px solid var(--outline); aspect-ratio: 16/10; overflow: hidden; background: var(--sky); }
.preview .shot img.bg { width: 100%; height: 100%; object-fit: cover; display: block; image-rendering: pixelated; }
.preview .shot .pv-bird { position: absolute; left: 14%; bottom: 10%; width: 30%; }
.preview .shot .pv-bird img { width: 100%; image-rendering: pixelated; }
.preview .meta h3 { font-size: 11px; margin-bottom: 6px; }
.preview .rows { font-family: var(--body); font-size: 14px; line-height: 1.5; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.card {
  position: relative; background: var(--panel-in); border: 3px solid var(--outline);
  box-shadow: inset 0 3px 0 rgba(255,255,255,.35), inset 0 -3px 0 rgba(0,0,0,.12);
  padding: 6px 5px 6px; cursor: pointer; text-align: center;
}
.card:active { transform: translateY(2px); }
.card.equipped { box-shadow: inset 0 0 0 3px var(--gold-l); border-color: var(--outline); }
.card .thumb { position: relative; aspect-ratio: 1; display: grid; place-items: center; background: #cfe9dd; border: 2px solid rgba(84,56,71,.35); }
.card .thumb img { width: 92%; height: 92%; object-fit: contain; image-rendering: pixelated; }
.card.locked .thumb { filter: grayscale(1) brightness(.7); }
.card .name { font-family: var(--body); font-size: 12px; line-height: 1.1; margin-top: 4px; font-weight: 700; }
.card .price { font-family: var(--pixel); font-size: 8px; margin-top: 3px; display: flex; align-items: center; justify-content: center; gap: 4px; }
.card .price .coin-dot { width: 12px; height: 12px; border-width: 2px; }
.card .rarity { position: absolute; top: 3px; left: 3px; width: 8px; height: 8px; border: 2px solid var(--outline); }
.card .lock { position: absolute; top: 40%; left: 50%; transform: translate(-50%,-50%); font-size: 20px; }
.card .tick { position: absolute; top: 2px; right: 3px; color: var(--green); font-size: 16px; font-weight: 900; text-shadow: 1px 1px 0 var(--outline); }
.card .seal {
  position: absolute; top: 3px; right: 3px; background: var(--gold-l); color: var(--outline);
  font-family: var(--pixel); font-size: 6px; padding: 3px 3px; border: 2px solid var(--outline);
}
.card .cond { font-family: var(--body); font-size: 10px; line-height: 1.05; margin-top: 2px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 14px 0; font-family: var(--pixel); font-size: 10px; }
.pager .btn { padding: 10px 14px; }

/* ---------------- ranking ---------------- */
.rank-head { font-family: var(--pixel); font-size: 9px; color: var(--outline); margin: 6px 8px 8px; }
.ledger { padding: 4px 0; }
.rank-row {
  display: grid; grid-template-columns: 34px 1fr auto auto; gap: 6px; align-items: center;
  padding: 9px 10px; font-size: 14px; font-family: var(--body);
}
.rank-row:nth-child(even) { background: var(--panel-in); }
.rank-row.head { font-family: var(--pixel); font-size: 8px; background: transparent; border-bottom: 3px solid var(--outline); }
.rank-row.me { box-shadow: inset 0 0 0 3px var(--accent); background: var(--gold-l); }
.rank-row .pl { font-family: var(--pixel); font-size: 9px; display: flex; align-items: center; gap: 4px; }
.rank-row .sc { font-family: var(--pixel); font-size: 10px; }
.rank-row .lv { font-family: var(--pixel); font-size: 8px; }
.rank-medal { width: 18px; height: 18px; border: 2px solid var(--outline); display: inline-block; }

/* ---------------- settings ---------------- */
.setrow { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 3px solid rgba(84,56,71,.25); }
.setrow:last-child { border-bottom: none; }
.setrow .lbl { font-family: var(--pixel); font-size: 9px; }
.setrow .sub { font-family: var(--body); font-size: 13px; }
.switch {
  font-family: var(--pixel); font-size: 8px; border: 3px solid var(--outline); cursor: pointer;
  background: var(--green); color: #fff; padding: 8px 12px;
  box-shadow: inset 0 3px 0 rgba(255,255,255,.4);
  clip-path: polygon(3px 0, calc(100% - 3px) 0, 100% 3px, 100% calc(100% - 3px), calc(100% - 3px) 100%, 3px 100%, 0 calc(100% - 3px), 0 3px);
}
.switch.off { background: #b9b083; color: #6b6450; box-shadow: inset 0 3px 0 rgba(255,255,255,.3); }
.bar { display: flex; gap: 2px; }
.bar i { width: 10px; height: 14px; background: var(--bevel); border: 2px solid var(--outline); }
.bar i.on { background: var(--green); box-shadow: inset 0 2px 0 #8BE07A; }

/* ---------------- HUD ---------------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 8; display: none; }
#hud.on { display: block; }
#hud .score {
  position: absolute; top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  font-family: var(--pixel); font-size: clamp(32px, 11vw, 64px); color: #fff;
  text-shadow: 3px 0 var(--outline), -3px 0 var(--outline), 0 3px var(--outline), 0 -3px var(--outline),
    3px 3px var(--outline), -3px -3px var(--outline), 3px -3px var(--outline), -3px 3px var(--outline),
    0 5px var(--outline);
}
#hud .chip {
  position: absolute; top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: calc(var(--pscale) * 3); font-family: var(--pixel); font-size: calc(var(--pscale) * 7);
  background: var(--panel); border: 3px solid var(--outline); padding: 4px 8px;
  box-shadow: inset 0 2px 0 var(--panel-in), inset 0 -2px 0 var(--bevel);
}
#hud .chip .coin-dot { width: calc(var(--pscale) * 7); height: calc(var(--pscale) * 7); border-width: 2px; }
#hud .chip.lvlpill { background: var(--gold-l); }
#hud .chip.boostpill { background: var(--gold-l); left: 50%; transform: translateX(-50%); top: calc(var(--pscale) * 44); }
#hud .levelbanner {
  position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%) scale(.6);
  font-family: var(--pixel); font-size: calc(var(--pscale) * 15); color: var(--gold-l);
  letter-spacing: 1px; white-space: nowrap; opacity: 0; pointer-events: none;
  text-shadow: 3px 0 var(--outline), -3px 0 var(--outline), 0 3px var(--outline), 0 -3px var(--outline),
    3px 3px var(--outline), -3px -3px var(--outline);
}
#hud .levelbanner.show { animation: lvlpop 1.3s steps(8) forwards; }
@keyframes lvlpop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.5); }
  16% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  30% { transform: translate(-50%, -50%) scale(1); }
  72% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -95%) scale(1); }
}
#hud .hudbtns { position: absolute; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); display: flex; align-items: center; gap: 6px; pointer-events: auto; }
#hud .hudbtns .coincount { position: static; top: auto; left: auto; pointer-events: none; }
#hud .hudbtn { width: 42px; height: 40px; }
#hud .hudbtn svg { width: 20px; height: 20px; }
#hud .getready {
  position: absolute; top: 20%; left: 50%; transform: translateX(-50%); text-align: center; width: 94%;
}
.getready-inner {
  display: inline-block; background: rgba(20, 40, 44, .5); border: 3px solid rgba(255, 255, 255, .6);
  box-shadow: 0 4px 0 rgba(0, 0, 0, .25); padding: 12px 16px;
}
#hud .getready .t { font-family: var(--pixel); font-size: calc(var(--pscale) * 10); color: var(--green); text-shadow: 2px 0 var(--outline), -2px 0 var(--outline), 0 2px var(--outline), 0 -2px var(--outline); margin-bottom: 12px; }
#hud .getready .h { font-family: var(--pixel); font-size: 10px; color: #fff; text-shadow: 2px 2px 0 var(--outline); }

/* ---------------- game over ---------------- */
#gameover { z-index: 20; }
.go-title { text-align: center; font-family: var(--pixel); font-size: clamp(18px, 6.4vw, 30px); margin: 8px 0 14px; }
.go-card { max-width: 460px; margin: 0 auto; }
.go-body { display: flex; justify-content: center; align-items: center; gap: 12px; }
.go-medal { width: calc(var(--pscale) * 28); }
.go-medal:empty { display: none; }
.go-medal img { width: 100%; image-rendering: pixelated; }
.go-rows { display: grid; gap: 6px; width: 100%; max-width: 300px; }
.go-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-bottom: 2px solid rgba(84,56,71,.3); padding-bottom: 5px; font-family: var(--body); font-size: 15px; }
.go-row .k { }
.go-row .v { font-family: var(--pixel); font-size: 11px; display: flex; align-items: center; gap: 6px; }
.newtag { font-family: var(--pixel); font-size: 7px; background: #D6452F; color: #fff; padding: 3px 4px; }
.go-buttons { display: flex; gap: 12px; margin-top: 16px; }
.go-buttons .btn { flex: 1; }

/* ---------------- toast + loader ---------------- */
#toast {
  position: fixed; left: 50%; bottom: -120px; transform: translateX(-50%);
  background: var(--outline); color: #fff; font-family: var(--pixel); font-size: 9px;
  padding: 10px 14px; z-index: 50; transition: bottom .18s steps(3); max-width: 90vw; text-align: center;
}
#toast.show { bottom: 18px; }
#loader { position: absolute; inset: 0; display: grid; place-items: center; background: var(--sky); z-index: 60; }
#loader .panel { font-family: var(--pixel); font-size: 12px; padding: 18px 22px; }

/* ---------------- responsive ---------------- */
@media (min-width: 760px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
}
@media (max-width: 360px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
  .card .name { font-size: 11px; }
}
@media (max-height: 600px) and (orientation: landscape) {
  .wrap { max-width: 760px; }
  #menu .wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
  #menu .topbar { grid-column: 1 / -1; }
  .menu-buttons { gap: 8px; }
}

/* ---------------- language selector ---------------- */
.langpanel { margin-bottom: 14px; }
.langlabel {
  font-family: var(--pixel); font-size: calc(var(--pscale) * 6); letter-spacing: 1px;
  text-align: center; margin-bottom: calc(var(--pscale) * 4);
}
.langwrap { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.langrow .langwrap { justify-content: flex-end; }
.langbtn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  background: var(--panel-in); border: 3px solid var(--outline); color: var(--outline);
  font-family: var(--body); font-size: 13px; font-weight: 700; line-height: 1;
  padding: 6px 8px;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.5), inset 0 -2px 0 rgba(0,0,0,.12);
  clip-path: polygon(3px 0, calc(100% - 3px) 0, 100% 3px, 100% calc(100% - 3px), calc(100% - 3px) 100%, 3px 100%, 0 calc(100% - 3px), 0 3px);
}
.langbtn:active { transform: translateY(2px); }
.langbtn.active { background: var(--gold-l); box-shadow: inset 0 0 0 3px var(--accent); }
.langbtn .lg-flag { width: 24px; height: 16px; display: block; flex: none; border: 2px solid var(--outline); }
@media (max-width: 380px) {
  .langbtn .lg-name { display: none; }
  .langbtn { padding: 6px 7px; }
  .langbtn .lg-flag { width: 26px; height: 17px; }
}
