/* Pixel-game look: chunky stepped borders, hard shadows, limited palette, bitmap + techno Thai fonts. */
@font-face { font-family: 'Press Start 2P'; src: url('/fonts/press-start-2p/files/press-start-2p-latin-400-normal.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Chakra Petch'; font-weight: 400; src: url('/fonts/chakra-petch/files/chakra-petch-thai-400-normal.woff2') format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; font-display: swap; }
@font-face { font-family: 'Chakra Petch'; font-weight: 600; src: url('/fonts/chakra-petch/files/chakra-petch-thai-600-normal.woff2') format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; font-display: swap; }
@font-face { font-family: 'Chakra Petch'; font-weight: 700; src: url('/fonts/chakra-petch/files/chakra-petch-thai-700-normal.woff2') format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; font-display: swap; }
@font-face { font-family: 'Chakra Petch'; font-weight: 400; src: url('/fonts/chakra-petch/files/chakra-petch-latin-400-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215; font-display: swap; }
@font-face { font-family: 'Chakra Petch'; font-weight: 700; src: url('/fonts/chakra-petch/files/chakra-petch-latin-700-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215; font-display: swap; }

:root {
  --ink: #2d2438;
  --night: #1f2440;
  --night2: #2a3156;
  --paper: #f6ebcf;
  --paper2: #e8d4a2;
  --orange: #ef7d57;
  --green: #38b764;
  --blue: #41a6f6;
  --yellow: #ffcd75;
  --red: #e8505b;
  --pink: #ff9fb2;
  --dim: #7a6a5a;
  --b: 3px;
  --px: 'Press Start 2P', 'Chakra Petch', monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background-color: var(--night);
  background-image: linear-gradient(45deg, var(--night2) 25%, transparent 25% 75%, var(--night2) 75%), linear-gradient(45deg, var(--night2) 25%, transparent 25% 75%, var(--night2) 75%);
  background-size: 8px 8px;
  background-position: 0 0, 4px 4px;
  color: var(--ink);
  font-family: 'Chakra Petch', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  image-rendering: pixelated;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.wrap { max-width: 520px; margin: 0 auto; padding: 0 14px 110px; }

/* ---- stepped pixel frame ---- */
.px {
  background: var(--paper);
  margin: var(--b);
  box-shadow:
    0 calc(var(--b) * -1) 0 0 var(--ink), 0 var(--b) 0 0 var(--ink),
    calc(var(--b) * -1) 0 0 0 var(--ink), var(--b) 0 0 0 var(--ink),
    inset calc(var(--b) * -1) calc(var(--b) * -1) 0 0 var(--paper2);
  filter: drop-shadow(4px 5px 0 rgba(0, 0, 0, 0.35));
}
.panel, .card { background: var(--paper); margin: 20px var(--b) 0; padding: 14px; position: relative;
  box-shadow: 0 calc(var(--b) * -1) 0 0 var(--ink), 0 var(--b) 0 0 var(--ink), calc(var(--b) * -1) 0 0 0 var(--ink), var(--b) 0 0 0 var(--ink), inset calc(var(--b) * -1) calc(var(--b) * -1) 0 0 var(--paper2);
  filter: drop-shadow(4px 5px 0 rgba(0, 0, 0, 0.35)); }
.panel h2 { font-size: 0.95rem; margin: 0 0 10px; font-weight: 700; letter-spacing: 0.02em; display: flex; align-items: center; gap: 8px; }
.panel h2::before { content: ''; width: 8px; height: 8px; background: var(--orange); box-shadow: 0 0 0 2px var(--ink); }

/* ---- HUD ---- */
.hud { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 12px 0 10px; background: linear-gradient(var(--night) 80%, transparent); }
.hud .title { flex: 1; font-family: var(--px); font-size: 0.62rem; color: var(--yellow); text-shadow: 2px 2px 0 var(--ink); letter-spacing: 0.04em; line-height: 1.5; }
.hud .title small { display: block; font-family: 'Chakra Petch', sans-serif; font-size: 0.72rem; color: #c9c3e0; text-shadow: none; letter-spacing: 0; font-weight: 400; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--ink); color: var(--yellow); padding: 4px 9px; font-family: var(--px); font-size: 0.6rem; box-shadow: 0 0 0 2px #000; }
.chip .px-ic { margin: -2px 0; }
.hud-btn { background: var(--paper); border: 0; height: 34px; padding: 0 10px; font-weight: 700; font-size: 0.8rem; box-shadow: 0 -2px 0 var(--ink), 0 2px 0 var(--ink), -2px 0 0 var(--ink), 2px 0 0 var(--ink); }

/* ---- buttons ---- */
.btn {
  border: 0; background: var(--paper2); color: var(--ink); padding: 10px 14px; font-weight: 700; margin: 3px;
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset 0 -4px 0 0 rgba(0, 0, 0, 0.18), inset 0 3px 0 0 rgba(255, 255, 255, 0.35);
  position: relative; top: 0;
}
.btn:active:not(:disabled) { top: 3px; box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset 0 3px 0 0 rgba(0, 0, 0, 0.2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; filter: grayscale(0.6); }
.btn.pri { background: var(--orange); color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3); }
.btn.good { background: var(--green); color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3); }
.btn.block { display: block; width: calc(100% - 6px); }
.btn.sm { padding: 5px 9px; font-size: 0.85rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.dim { color: var(--dim); font-size: 0.85rem; }
.err { color: var(--red); font-weight: 700; font-size: 0.9rem; min-height: 1.4em; margin-top: 6px; }
.field { display: block; margin-top: 12px; }
.field > span { display: block; font-size: 0.8rem; font-weight: 700; color: var(--dim); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.04em; }
.field input[type='text'], .field input[type='password'] { width: calc(100% - 6px); margin: 3px; padding: 10px 12px; border: 0; background: #fffaf0; box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset 3px 3px 0 0 rgba(0, 0, 0, 0.12); outline: none; }
.field input:focus { background: #fff; box-shadow: 0 -3px 0 0 var(--blue), 0 3px 0 0 var(--blue), -3px 0 0 0 var(--blue), 3px 0 0 0 var(--blue), inset 3px 3px 0 0 rgba(0, 0, 0, 0.12); }

/* ---- nav ---- */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--ink); display: flex; justify-content: center; gap: 10px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); border-top: 4px solid #000; }
.nav button { flex: 1; max-width: 150px; background: var(--night2); border: 0; color: #c9c3e0; padding: 8px 4px 6px; font-size: 0.78rem; font-weight: 700; display: flex; flex-direction: column; align-items: center; gap: 4px; box-shadow: 0 -2px 0 #000, 0 2px 0 #000, -2px 0 0 #000, 2px 0 0 #000; }
.nav button.on { background: var(--yellow); color: var(--ink); }
.nav .px-ic { image-rendering: pixelated; }

/* ---- pet selector ---- */
.pet-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 6px 4px 8px; margin-top: 4px; }
.pet-tabs button { flex: none; border: 0; background: var(--paper2); padding: 6px 12px; font-weight: 700; font-size: 0.85rem; box-shadow: 0 -2px 0 var(--ink), 0 2px 0 var(--ink), -2px 0 0 var(--ink), 2px 0 0 var(--ink); display: flex; align-items: center; gap: 6px; }
.pet-tabs button.on { background: var(--yellow); }

/* ---- scene ---- */
.scene { position: relative; aspect-ratio: 16 / 10; margin: 14px var(--b) 0; overflow: hidden; box-shadow: 0 -4px 0 0 var(--ink), 0 4px 0 0 var(--ink), -4px 0 0 0 var(--ink), 4px 0 0 0 var(--ink); filter: drop-shadow(4px 5px 0 rgba(0, 0, 0, 0.35)); background: #79c7f5; }
.sc-wrap { position: absolute; inset: 0; }
.scene-svg, .preview .scene-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.scene .pet { position: absolute; left: 50%; bottom: -2%; height: 104%; aspect-ratio: 1; transform: translateX(-50%); cursor: pointer; }
.pet-svg { width: 100%; height: 100%; overflow: visible; display: block; }
.pet-svg.wiggle { animation: wiggle 0.5s steps(2) infinite; transform-origin: 50% 90%; }
.pet.bounce .pet-svg { animation: hop 0.5s steps(5); }
.fx { pointer-events: none; }
.fx.bob { animation: bob 1.2s steps(3) infinite; }
.fx.bob2 { animation: bob 0.9s steps(3) infinite reverse; }
.fx.zzz { animation: bob 1.8s steps(4) infinite; }
.fx.twinkle { animation: twinkle 1.2s steps(2) infinite; }
.fx.twinkle2 { animation: twinkle 1.7s steps(2) infinite 0.5s; }
@keyframes wiggle { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } }
@keyframes hop { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-34px); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes twinkle { 0%, 100% { opacity: 0.15; } 50% { opacity: 1; } }

.nameplate { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 16px var(--b) 0; padding: 10px 12px; background: var(--ink); color: var(--paper); box-shadow: 0 -3px 0 #000, 0 3px 0 #000, -3px 0 0 #000, 3px 0 0 #000; }
.nameplate h2 { margin: 0; font-size: 1.15rem; flex: 1 1 100%; }
.tag { font-size: 0.72rem; font-weight: 700; padding: 1px 8px; background: var(--yellow); color: var(--ink); box-shadow: 0 0 0 2px #000; }
.tag.alt { background: var(--paper2); }

/* ---- meters ---- */
.stat { display: grid; grid-template-columns: 22px 62px 1fr 30px; gap: 8px; align-items: center; margin: 9px 0; font-size: 0.85rem; font-weight: 700; }
.stat em { font-style: normal; text-align: right; font-family: var(--px); font-size: 0.55rem; }
.meter { height: 14px; padding: 2px; background: var(--ink); }
.meter > div { height: 100%; background: repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.12) 0 8px, transparent 8px 10px); }
.meter i { display: block; height: 100%; background: repeating-linear-gradient(90deg, var(--c) 0 8px, transparent 8px 10px); transition: width 0.4s steps(10); }
.xp { margin-top: 12px; }

/* ---- action buttons ---- */
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 14px 0 0; }
.act { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 4px 9px; font-size: 0.82rem; }

/* ---- grids / items ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px 8px; padding: 3px; }
.tile { background: #fffaf0; border: 0; padding: 8px 4px 7px; text-align: center; font-size: 0.8rem; font-weight: 700; margin: 3px; box-shadow: 0 -2px 0 var(--ink), 0 2px 0 var(--ink), -2px 0 0 var(--ink), 2px 0 0 var(--ink), inset 0 -3px 0 rgba(0, 0, 0, 0.1); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.tile.on { background: var(--yellow); }
.tile:disabled { opacity: 0.5; cursor: not-allowed; }
.tile .ico { height: 44px; display: flex; align-items: center; justify-content: center; }
.tile .thumb { width: 100%; aspect-ratio: 16 / 10; overflow: hidden; box-shadow: 0 0 0 2px var(--ink); }
.tile .thumb .scene-svg { position: static; }
.tile .sub { font-weight: 400; color: var(--dim); font-size: 0.74rem; display: flex; align-items: center; gap: 3px; justify-content: center; }
.species-grid { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
.species-grid .tile { padding: 4px 2px; font-size: 0.72rem; }
.species-grid .pv { width: 60px; height: 60px; }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 3px; }
.sw { width: 26px; height: 26px; border: 0; padding: 0; box-shadow: 0 0 0 2px var(--ink); }
.sw.on { box-shadow: 0 0 0 2px var(--ink), 0 0 0 5px var(--yellow), 0 0 0 7px var(--ink); margin: 0 3px; }
input[type='color'] { width: 34px; height: 28px; border: 0; padding: 0; background: none; }
.preview { position: relative; aspect-ratio: 16 / 9; overflow: hidden; margin: 4px; box-shadow: 0 0 0 3px var(--ink); }
.preview .pet { position: absolute; left: 50%; bottom: 0; width: 56%; aspect-ratio: 1; transform: translateX(-50%); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; padding: 3px; }
.seg button { border: 0; background: #fffaf0; padding: 5px 12px; font-weight: 700; font-size: 0.82rem; box-shadow: 0 -2px 0 var(--ink), 0 2px 0 var(--ink), -2px 0 0 var(--ink), 2px 0 0 var(--ink); }
.seg button.on { background: var(--yellow); }

/* ---- plaza ---- */
.dot { display: inline-block; width: 8px; height: 8px; background: #9a9a9a; margin-right: 5px; box-shadow: 0 0 0 1px var(--ink); }
.dot.on { background: var(--green); }
.pcard { background: #fffaf0; border: 0; padding: 4px 4px 8px; text-align: center; font-size: 0.8rem; margin: 3px; box-shadow: 0 -2px 0 var(--ink), 0 2px 0 var(--ink), -2px 0 0 var(--ink), 2px 0 0 var(--ink); }
.pcard .pv { width: 100%; aspect-ratio: 1; }
.pcard b { display: block; font-size: 0.88rem; }
.lb { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 2px dashed var(--paper2); }
.lb .pv { width: 48px; height: 48px; flex: none; }
.lb .n { width: 22px; text-align: center; font-family: var(--px); font-size: 0.65rem; color: var(--orange); }
.feed { font-size: 0.8rem; background: var(--ink); color: var(--yellow); padding: 4px 8px; margin: 5px 0 0; display: block; }

/* ---- sheet ---- */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgba(15, 12, 30, 0.7); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--paper); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; padding: 16px 14px 28px; border-top: 5px solid var(--ink); box-shadow: inset 0 3px 0 var(--paper2); animation: up 0.18s steps(4); }
.sheet h3 { margin: 0 0 10px; font-size: 1.05rem; font-weight: 700; }
@keyframes up { from { transform: translateY(40px); } to { transform: none; } }

/* ---- toast ---- */
#toasts { position: fixed; top: 64px; left: 0; right: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: var(--ink); color: var(--paper); padding: 9px 14px; font-size: 0.88rem; font-weight: 600; max-width: 92%; box-shadow: 0 -3px 0 var(--yellow), 0 3px 0 var(--yellow), -3px 0 0 var(--yellow), 3px 0 0 var(--yellow); animation: up 0.15s steps(3); }
.toast.bad { box-shadow: 0 -3px 0 var(--red), 0 3px 0 var(--red), -3px 0 0 var(--red), 3px 0 0 var(--red); }

/* ---- minigame ---- */
.mg { position: relative; height: 330px; overflow: hidden; margin: 4px; box-shadow: 0 0 0 3px var(--ink); background: #a5dcfa; touch-action: manipulation; user-select: none; }
.mg .drop { position: absolute; cursor: pointer; transition: top linear; }
.mg .hud2 { position: absolute; top: 6px; left: 8px; right: 8px; display: flex; justify-content: space-between; font-family: var(--px); font-size: 0.6rem; color: var(--ink); z-index: 2; }

/* ---- auth ---- */
.logo { text-align: center; padding: 26px 0 4px; }
.logo h1 { font-family: var(--px); font-size: 1.15rem; line-height: 1.6; margin: 10px 0 4px; color: var(--yellow); text-shadow: 3px 3px 0 var(--ink), -1px -1px 0 var(--ink); }
.logo p { margin: 0; color: #c9c3e0; font-size: 0.85rem; }
.logo-pets { display: flex; justify-content: center; gap: 0; height: 74px; overflow: hidden; }
.logo-pets .pv { width: 74px; height: 74px; margin: 0 -6px; }
.tabs-auth { display: flex; gap: 4px; }
.tabs-auth .btn { flex: 1; margin: 3px; }
.tabs-auth .btn.on { background: var(--orange); color: #fff; }
.px-ic { image-rendering: pixelated; display: block; }

/* ---- social sign-in ---- */
.social { margin-top: 6px; }
.social .or { text-align: center; color: var(--dim); font-size: 0.8rem; font-weight: 700; margin: 14px 0 6px; display: flex; align-items: center; gap: 10px; }
.social .or::before, .social .or::after { content: ''; flex: 1; height: 3px; background: var(--paper2); }
.sso { text-align: center; text-decoration: none; margin-top: 8px; }
.sso.google { background: #ffffff; color: var(--ink); }
.sso.line { background: #06c755; color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); }
