/* Plett Pet Patrol — mobile only, unapologetically chunky.
   Palette is lifted straight from the map renderer so the whole app and the
   whole town agree on what green looks like. */

:root {
  --sea: #2b6a94;
  --sea-lit: #3f8cb5;
  --sky: #a8dcef;
  --sand: #ecd9a6;
  --cream: #f5ecd2;
  --veld: #86a95e;
  --forest: #4a7340;
  --wood: #9c7c66;
  --wood-dark: #7a5f4d;
  --gold: #f5cf72;
  --rose: #e2607a;
  --ink: #2f2a24;
  --ink-soft: #6a6055;

  --pixel: 3px;
  --edge: 0 0 0 var(--pixel) var(--ink);
  --lift: 0 0 0 var(--pixel) var(--ink), 0 4px 0 var(--pixel) rgba(47, 42, 36, .28);
  --pad: env(safe-area-inset-bottom, 0px);
  --tabbar: 68px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Every layout rule below sets an explicit `display`, which quietly beats the
   UA stylesheet's `[hidden] { display: none }`. Settle it once, here. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--ink);
  color: var(--ink);
  font: 15px/1.45 ui-rounded, "SF Pro Rounded", "Avenir Next", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

img, canvas { image-rendering: pixelated; }

.pixel-small, .logo, .btn, .tab span:not(.tab-ico):not(.paw), .map-title, .segmented button, .map-label {
  font-family: "Press Start 2P", ui-monospace, monospace;
  letter-spacing: .02em;
}

/* ─────────────────────────────────────────────── views */
.view {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
}
.view.on { display: flex; }

/* ─────────────────────────────────────────────── buttons */
.btn {
  display: block;
  width: 100%;
  padding: 14px 12px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--sand);
  border: 0;
  box-shadow: var(--lift);
  cursor: pointer;
  transition: transform .06s;
}
.btn:active { transform: translateY(3px); box-shadow: var(--edge); }
.btn-primary { background: var(--gold); }
.btn:disabled { opacity: .55; }

.pixel-btn {
  width: 40px;
  height: 40px;
  font-size: 18px;
  line-height: 1;
  color: var(--ink);
  background: var(--cream);
  border: 0;
  box-shadow: var(--lift);
  cursor: pointer;
}
.pixel-btn:active { transform: translateY(3px); box-shadow: var(--edge); }

.link {
  display: block;
  margin: 10px auto 0;
  padding: 6px;
  color: var(--ink-soft);
  font-size: 13px;
  text-decoration: underline;
  background: none;
  border: 0;
  cursor: pointer;
}
.link.danger { color: var(--rose); }

/* ─────────────────────────────────────────────── auth */
.auth-sky {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(var(--sky) 0 42%, var(--veld) 42% 100%);
}
.auth-card {
  width: 100%;
  max-width: 360px;
  padding: 26px 20px;
  text-align: center;
  background: var(--cream);
  box-shadow: var(--lift);
}
.logo {
  margin: 0 0 14px;
  font-size: 22px;
  line-height: 1.5;
  color: var(--sea);
  text-shadow: 3px 3px 0 var(--gold);
}
.tagline { margin: 0 0 20px; color: var(--ink-soft); font-size: 14px; }
#auth-form input {
  display: block;
  width: 100%;
  margin-bottom: 10px;
  padding: 13px 12px;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 0;
  box-shadow: var(--edge);
}
#auth-form input:focus { outline: 0; box-shadow: 0 0 0 var(--pixel) var(--sea); }
.auth-error {
  margin: 12px 0 0;
  padding: 8px;
  color: #fff;
  font-size: 13px;
  background: var(--rose);
  box-shadow: var(--edge);
}

/* ─────────────────────────────────────────────── map */
.map-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--sea);
  touch-action: none;
  cursor: grab;
}
.map-stage.placing { cursor: crosshair; }
.map-stage.placing::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 4px var(--gold);
  pointer-events: none;
  animation: pulse-edge 1.1s steps(2, end) infinite;
}
@keyframes pulse-edge { 50% { box-shadow: inset 0 0 0 4px transparent; } }

.map-world { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.map-world > img { display: block; width: 100%; height: 100%; }
.map-labels, .map-pins { position: absolute; inset: 0; }

.map-label {
  position: absolute;
  color: var(--cream);
  font-size: 7px;
  white-space: nowrap;
  text-shadow: 1px 1px 0 var(--ink), -1px 1px 0 var(--ink), 1px -1px 0 var(--ink), -1px -1px 0 var(--ink);
  pointer-events: none;
}
.map-label.rank-0 { font-size: 10px; color: #fff; }
.map-label.kind-beach { color: var(--sand); }
.map-label.kind-shop { color: var(--gold); }

.map-pin {
  position: absolute;
  display: grid;
  place-items: center;
  padding: 0;
  background: none;
  border: 0;
  cursor: pointer;
  animation: pin-drop .32s cubic-bezier(.2, 1.6, .4, 1);
}
@keyframes pin-drop { from { transform: translate(-50%, -160%) scale(.6); } }
.map-pin img { display: block; width: 40px; height: auto; filter: drop-shadow(2px 2px 0 rgba(47, 42, 36, .5)); }
.pin-wait {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  font-size: 15px;
  background: var(--cream);
  box-shadow: var(--edge);
}
.pin-stem {
  display: block;
  width: 3px;
  height: 7px;
  margin-top: -1px;
  background: var(--ink);
}

.map-me {
  position: absolute;
  width: 16px;
  height: 16px;
  background: var(--sea-lit);
  box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--sea);
  animation: me-pulse 1.6s steps(3, end) infinite;
}
@keyframes me-pulse { 50% { box-shadow: 0 0 0 3px #fff, 0 0 0 10px rgba(43, 106, 148, .35); } }

.map-hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 12px 12px;
  pointer-events: none;
}
.map-hud > * { pointer-events: auto; }
.map-title {
  padding: 9px 10px;
  font-size: 9px;
  color: var(--ink);
  background: var(--cream);
  box-shadow: var(--edge);
}
.map-buttons { display: flex; flex-direction: column; gap: 8px; }

.place-hint {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(var(--tabbar) + var(--pad) + 14px);
  padding: 12px;
  text-align: center;
  font-size: 14px;
  background: var(--gold);
  box-shadow: var(--lift);
}
.place-hint .link { margin-top: 2px; }

/* ─────────────────────────────────────────────── garden */
#view-garden { background: var(--forest); }
.garden-wrap {
  position: absolute;
  inset: 0 0 calc(var(--tabbar) + var(--pad)) 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--forest);
}
#garden-canvas { display: block; }
.garden-empty {
  position: absolute;
  inset: auto 24px 24px;
  padding: 16px;
  text-align: center;
  background: var(--cream);
  box-shadow: var(--lift);
}
.garden-empty p { margin: 4px 0; }
.garden-empty .pixel-small { font-size: 10px; line-height: 1.7; }
.garden-hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 12px 12px;
}

/* ─────────────────────────────────────────────── tab bar */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: calc(var(--tabbar) + var(--pad));
  padding-bottom: var(--pad);
  background: var(--cream);
  box-shadow: 0 -3px 0 var(--ink);
}
.tab {
  display: grid;
  gap: 3px;
  place-items: center;
  padding: 8px 0;
  color: var(--ink-soft);
  font-size: 8px;
  background: none;
  border: 0;
  cursor: pointer;
}
.tab.on { color: var(--sea); }
.tab-ico { font-size: 19px; line-height: 1; }
.tab-snap {
  width: 62px;
  height: 62px;
  margin-top: -22px;
  background: var(--gold);
  box-shadow: var(--lift);
}
.tab-snap:active { transform: translateY(3px); box-shadow: var(--edge); }
.paw { font-size: 26px; }

/* ─────────────────────────────────────────────── sheets */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  background: rgba(47, 42, 36, .55);
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet-inner {
  position: relative;
  width: 100%;
  max-height: 92vh;
  padding: 22px 18px calc(26px + var(--pad));
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--cream);
  box-shadow: 0 -3px 0 var(--ink);
  animation: rise .22s cubic-bezier(.2, .9, .3, 1);
}
@keyframes rise { from { transform: translateY(24px); } }
/* Sticky, because the dossier is long and losing the ✕ off the top of a
   scrolled sheet is a genuinely annoying way to be trapped. */
.sheet-bar {
  position: sticky;
  top: -22px;
  z-index: 5;
  display: flex;
  justify-content: flex-end;
  margin: -22px -18px 8px;
  padding: 12px 12px 8px;
  background: var(--cream);
}
.sheet-close {
  width: 34px;
  height: 34px;
  font-size: 15px;
  background: var(--sand);
  border: 0;
  box-shadow: var(--edge);
  cursor: pointer;
}

.snap-step h2 { margin: 0 0 16px; font-size: 12px; line-height: 1.7; }

.dropzone {
  display: grid;
  gap: 10px;
  place-items: center;
  padding: 42px 20px;
  text-align: center;
  background: var(--sand);
  box-shadow: var(--edge);
  cursor: pointer;
}
.dropzone-paw { font-size: 44px; }
.snap-photo-wrap {
  margin-bottom: 16px;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  box-shadow: var(--edge);
}
.snap-photo-wrap img { width: 100%; height: 100%; object-fit: cover; image-rendering: auto; }

.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 7px; font-size: 9px; color: var(--ink-soft); }
.field input, .field textarea {
  width: 100%;
  padding: 12px;
  font: inherit;
  background: #fff;
  border: 0;
  box-shadow: var(--edge);
  resize: none;
}
.field input:focus, .field textarea:focus { outline: 0; box-shadow: 0 0 0 var(--pixel) var(--sea); }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.segmented button {
  padding: 12px 4px;
  font-size: 9px;
  background: #fff;
  border: 0;
  box-shadow: var(--edge);
  cursor: pointer;
}
.segmented button.on { color: #fff; background: var(--sea); }

.name-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.name-row .pixel-btn { height: 100%; }
.vibe { margin: 8px 0 0; color: var(--ink-soft); font-size: 13px; font-style: italic; }

.loc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  font-size: 14px;
  background: #fff;
  box-shadow: var(--edge);
}
.loc-row .link { margin: 0; flex: none; font-size: 12px; }

/* ─────────────────────────────────────────────── the reveal */
.pixel-stage {
  position: relative;
  margin: 0 auto 16px;
  aspect-ratio: 1;
  max-width: 300px;
  overflow: hidden;
  background: var(--sea);
  box-shadow: var(--edge);
}
.pixel-stage img,
.pixel-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: opacity .5s;
}
.pixel-stage img { object-fit: cover; image-rendering: auto; }
.pixel-stage.working img { animation: shimmer 1.4s steps(4, end) infinite; }
@keyframes shimmer { 50% { filter: saturate(.3) contrast(1.5) brightness(1.1); } }
.scanline {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(rgba(47, 42, 36, .16) 0 2px, transparent 2px 5px);
  pointer-events: none;
  opacity: 0;
}
.pixel-stage.working .scanline { opacity: 1; animation: scan 1.1s linear infinite; }
@keyframes scan { from { background-position-y: 0; } to { background-position-y: 5px; } }
.pixel-status { margin: 0 0 16px; text-align: center; color: var(--ink-soft); font-size: 13px; }
.pixel-status b { color: var(--ink); font-style: normal; }

/* ─────────────────────────────────────────────── pet sheet */
.pet-head { display: grid; grid-template-columns: 84px 1fr; gap: 14px; align-items: center; margin-bottom: 16px; }
.pet-sprite {
  width: 84px;
  height: 84px;
  object-fit: contain;
  background: var(--veld);
  box-shadow: var(--edge);
}
.pet-sprite.missing { background: var(--sand); }
.pet-name { margin: 0 0 4px; font-size: 19px; line-height: 1.25; }
.pixel-small#pet-known { display: block; margin-top: 6px; font-size: 8px; line-height: 1.7; color: var(--ink-soft); }
.pixel-small#pet-known.known { color: var(--forest); }
.pet-photo { width: 100%; margin-bottom: 16px; image-rendering: auto; box-shadow: var(--edge); }

.dossier { margin-bottom: 14px; background: var(--sand); box-shadow: var(--edge); }
.dossier summary { padding: 13px; font-size: 9px; cursor: pointer; }
.dossier-hint { color: var(--ink-soft); font-size: 7px; }
.dossier > .field { padding: 0 13px; }
.dossier > .field label { font-family: inherit; font-size: 12px; }
.dossier > .btn { width: calc(100% - 26px); margin: 0 13px 14px; }
.saved-flash { margin: -6px 13px 12px; color: var(--forest); font-size: 13px; text-align: center; }

.pet-meta { text-align: center; color: var(--ink-soft); font-size: 13px; }

/* ─────────────────────────────────────────────── toast */
.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--tabbar) + var(--pad) + 18px);
  z-index: 90;
  padding: 13px;
  text-align: center;
  font-size: 14px;
  color: var(--cream);
  background: var(--ink);
  box-shadow: 0 0 0 var(--pixel) var(--cream);
  animation: rise .2s ease;
}

/* This is a phone toy. On a desktop, sit it in a phone-shaped hole. */
@media (min-width: 620px) {
  body { display: grid; place-items: center; background: var(--sea); }
  body::before {
    content: "Plett Pet Patrol is a phone. Squash your window, or open it on one.";
    position: fixed;
    top: 24px;
    left: 0;
    right: 0;
    color: var(--cream);
    font-size: 13px;
    text-align: center;
  }
  .view, .sheet, .tabbar, .toast { max-width: 420px; margin-inline: auto; }
  .view, .sheet { left: 50%; right: auto; width: 420px; transform: translateX(-50%); }
  .tabbar, .toast { left: 50%; right: auto; width: 420px; transform: translateX(-50%); }
  .toast { width: 388px; }
}
