/* Paw Defense: "pet-shop label" look. Cream cards, navy ink, tomato / teal / mustard.
   Every price is a punched hang-tag (.tag, .card .cost); that is the one loud element, the rest stays quiet.
   Sections: tokens, page, frame, field HUD, shop, next wave, controls, dock, overlays, motion, phone, short screens. */

/* ---------- tokens ---------- */
:root {
  --ink: #1d2a3a;
  --cream: #fbf3dc;
  --paper: #f3e6c3;
  --rule: #c9b98e;
  --tomato: #e2553d;
  --teal: #1f8a84;
  --mustard: #f2b63c;
  --leaf: #2f5d3a;
  --sprout: #e7f1dc;
  --blush: #f6c9bd;
  --muted: #6b6a5c;
  /* type scale (px): 10.5 / 12 / 13.5 / 16 / 20 / 24 */
  --t-xs: 10.5px; --t-s: 12px; --t-m: 13.5px; --t-l: 16px; --t-xl: 20px; --t-xxl: 24px;
  --shop-w: 244px;
  --dock-h: 126px;
  --top-h: 40px;
  /* Field height is derived from the viewport so the whole game fits without scrolling. */
  --field-h: min(calc(100dvh - var(--top-h) - var(--dock-h) - 28px), calc((100vw - var(--shop-w) - 28px) / 1.5));
  color-scheme: light;
}

/* ---------- page ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  display: flex; flex-direction: column; justify-content: center;   /* header + game sit together, centered */
  background: var(--leaf) radial-gradient(#3a6f46 1.5px, transparent 1.6px) 0 0 / 18px 18px;
  color: var(--ink);
  font: var(--t-m)/1.35 "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible, .field canvas:focus-visible { outline: 3px solid var(--mustard); outline-offset: 2px; }
.field canvas:focus-visible { outline-offset: -3px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.ico { width: 18px; height: 18px; display: block; margin: auto; fill: currentColor; }

.top {
  height: var(--top-h); flex: none;
  width: calc(var(--field-h) * 1.5 + var(--shop-w) + 6px); max-width: 100%; margin: 0 auto;
  display: flex; align-items: center; gap: 16px;
  padding: 0 4px; color: var(--cream);
}
.top a { color: #cfe3c4; text-decoration: none; font-size: var(--t-s); font-weight: bold; }
.top a:hover { color: var(--cream); text-decoration: underline; }
.top h1 { margin: 0; font-size: var(--t-xl); line-height: 1; letter-spacing: -.2px; }
.top h1 span { font-weight: normal; font-size: var(--t-m); color: var(--mustard); margin-left: 8px; letter-spacing: 0; }

/* ---------- frame ---------- */
.game {
  width: calc(var(--field-h) * 1.5 + var(--shop-w) + 6px); /* + the two 3px side borders, so the field is exactly 3:2 */
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr var(--shop-w);
  grid-template-rows: var(--field-h) var(--dock-h);
  border: 3px solid var(--ink); border-radius: 14px; overflow: hidden;
  background: var(--cream);
  box-shadow: 0 6px 0 #1b3a25;
  -webkit-user-select: none; user-select: none;
}

/* ---------- field + HUD ---------- */
.field { position: relative; background: #6fb650; min-width: 0; overflow: hidden; touch-action: none; }
.field canvas { display: block; width: 100%; height: 100%; }
.field.placing { cursor: none; }
.hud { position: absolute; top: 8px; left: 8px; display: flex; gap: 6px; pointer-events: none; }
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--cream); border: 2px solid var(--ink); border-radius: 99px;
  padding: 2px 10px 2px 6px; font-size: var(--t-m); box-shadow: 0 2px 0 var(--ink);
}
.pill i { font-style: normal; font-size: 15px; }
.pill b { font-size: 15px; font-variant-numeric: tabular-nums; }
.pill.wave { padding-left: 10px; }
.pill.wave span { color: var(--muted); }
.bossbar {
  position: absolute; left: 50%; top: 46px; transform: translateX(-50%); width: min(46%, 300px);
  display: flex; align-items: center; gap: 8px; pointer-events: none;
  background: var(--ink); color: var(--cream); border-radius: 99px; padding: 3px 12px;
  font-size: var(--t-s); box-shadow: 0 2px 0 rgba(0, 0, 0, .3);
}
.bossbar b { white-space: nowrap; color: var(--mustard); }
.bossbar .track { flex: 1; height: 9px; background: #3a4658; border-radius: 99px; overflow: hidden; }
.bossbar i { display: block; height: 100%; width: 100%; background: var(--tomato); border-radius: 99px; transition: width .15s; }
.bossbar.rage i { background: #ff2d55; }
.toast, .reason {
  position: absolute; left: 50%; transform: translateX(-50%); pointer-events: none; white-space: nowrap;
  border-radius: 99px; font-weight: bold;
}
.toast { top: 80px; background: var(--cream); border: 2px solid var(--ink); box-shadow: 0 2px 0 var(--ink); font-size: var(--t-m); padding: 3px 14px; }
.toast.ok { background: var(--teal); color: #fff; }
.toast.bad { background: var(--tomato); color: #fff; }
.reason { bottom: 10px; background: var(--ink); color: var(--cream); font-size: var(--t-s); padding: 4px 12px; }
.reason.ok { background: var(--teal); }
.reason.bad { background: var(--tomato); }

/* ---------- price tags (the signature) ---------- */
/* A punched hang-tag: pointed left end with a hole. Mustard = you can buy it; blush = not enough treats. */
.tag, .card .cost {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  height: 18px; padding: 0 7px 0 13px; white-space: nowrap;
  background: var(--mustard); color: var(--ink);
  font-size: var(--t-s); font-weight: bold; font-variant-numeric: tabular-nums; line-height: 1;
  clip-path: polygon(7px 0, 100% 0, 100% 100%, 7px 100%, 0 50%);
}
.tag::before, .card .cost::before {
  content: ""; position: absolute; left: 5px; top: 50%; width: 4px; height: 4px; margin-top: -2px;
  border-radius: 50%; background: var(--cream); box-shadow: inset 0 0 0 1px rgba(29, 42, 58, .5);
}
.poor .tag, .card.poor .cost { background: var(--blush); color: #9a2f1d; }

/* ---------- shop ---------- */
.shop {
  grid-row: 1 / span 2; grid-column: 2;
  border-left: 3px solid var(--ink); background: var(--paper);
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px 9px 9px; min-height: 0; overflow-y: auto;
}
.shop h2 { margin: 2px 0 0; font-size: var(--t-m); color: var(--ink); display: flex; align-items: baseline; gap: 6px; }
.shop h2 small { font-size: var(--t-xs); font-weight: normal; color: var(--muted); }
.shelves { display: contents; }
.shelf { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.shelf.toys { grid-template-columns: repeat(4, 1fr); }
.card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 0 0 5px; min-width: 0; min-height: 44px;
  background: var(--cream); border: 2px solid var(--ink); border-radius: 9px;
  box-shadow: 0 2px 0 var(--ink); overflow: hidden; line-height: 1.1;
}
.card:hover { transform: translateY(-1px); }
.card:active { transform: translateY(1px); box-shadow: none; }
.card .art { width: 100%; aspect-ratio: 5 / 4; object-fit: cover; object-position: 50% 22%; display: block; border-bottom: 2px solid var(--ink); image-rendering: pixelated; background: #cfe3c4; }
.card canvas.art { image-rendering: auto; }
.card strong { font-size: var(--t-xs); white-space: nowrap; letter-spacing: -.2px; }
.card .cost { font-size: var(--t-xs); height: 16px; }
.card.poor .art { filter: grayscale(.8) opacity(.7); }
.card.armed { border-color: var(--tomato); box-shadow: 0 0 0 2px var(--tomato); }
.card.placed .cost { background: var(--teal); color: #fff; }
.card.placed::after {
  content: "\2713"; position: absolute; top: 3px; right: 3px; width: 16px; height: 16px;
  display: grid; place-items: center; font-size: 11px; font-weight: bold;
  background: var(--teal); color: #fff; border-radius: 50%; border: 1.5px solid var(--ink);
}

/* ---------- next wave ---------- */
.next { margin-top: auto; border-top: 2px dashed var(--rule); padding-top: 7px; }
.next h2 { justify-content: space-between; }
.next h2 .tough { white-space: nowrap; font-size: var(--t-xs); font-weight: bold; color: var(--cream); background: var(--ink); border-radius: 99px; padding: 1px 7px; }
.next-list { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 5px; font-size: var(--t-s); font-weight: bold; }
.next-list span { display: inline-flex; align-items: center; gap: 4px; }
.next-list canvas { width: 26px; height: 26px; border-radius: 50%; background: #cfe3c4; border: 1.5px solid var(--ink); }
.next-list .none { color: var(--muted); font-weight: normal; }
.next-list .warn { flex-basis: 100%; margin: 3px 0 0; font-size: var(--t-xs); font-weight: normal; color: var(--tomato); line-height: 1.3; }

/* ---------- controls ---------- */
.send-row { display: flex; gap: 5px; }
.send, .ctl { min-height: 46px; border: 2px solid var(--ink); border-radius: 10px; box-shadow: 0 3px 0 var(--ink); font-weight: bold; }
.send { flex: 1; min-width: 0; padding: 0 6px; font-size: 15px; white-space: nowrap; background: var(--tomato); color: #fff; }
.send:disabled { background: var(--mustard); color: var(--ink); box-shadow: 0 1px 0 var(--ink); transform: translateY(2px); }
.ctl { width: 40px; flex: none; font-size: 15px; background: var(--cream); }
.ctl.on { background: var(--ink); color: var(--cream); }
.send:active, .ctl:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }

/* ---------- dock (selected defender) ---------- */
.dock {
  grid-row: 2; grid-column: 1;
  border-top: 3px solid var(--ink); background: var(--cream);
  display: flex; align-items: center; gap: 12px; padding: 8px 12px; min-width: 0; overflow: hidden;
}
.dock .hint { margin: auto; max-width: 62ch; color: var(--muted); font-size: var(--t-m); text-align: center; }
.dock .hint b { color: var(--ink); }
.dock .hint.tip { color: var(--ink); background: #fff3c9; border: 2px dashed var(--mustard); border-radius: 10px; padding: 8px 14px; }

.who { display: flex; align-items: center; gap: 10px; flex: 0 1 250px; min-width: 0; }
.who .portrait { position: relative; flex: none; }
.who .art { width: 64px; height: 64px; border-radius: 50%; border: 2px solid var(--ink); object-fit: cover; object-position: 50% 22%; image-rendering: pixelated; background: #cfe3c4; display: block; }
.who .perch {
  position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%);
  font-size: 9.5px; font-weight: bold; white-space: nowrap; color: #fff; background: var(--teal);
  border: 1.5px solid var(--ink); border-radius: 99px; padding: 0 5px;
}
.who .id { min-width: 0; }
.who h3 { margin: 0; font-size: var(--t-xl); line-height: 1.1; }
.who .role { font-size: var(--t-xs); font-weight: normal; color: var(--muted); margin-left: 3px; white-space: nowrap; }
.who p { margin: 2px 0 0; font-size: var(--t-s); color: var(--muted); line-height: 1.3; }
.chips { display: flex; flex-wrap: wrap; gap: 2px 4px; margin-top: 3px; }
.chips span { font-size: var(--t-xs); line-height: 1.4; background: var(--paper); border-radius: 5px; padding: 0 5px; white-space: nowrap; color: var(--muted); }
.chips b { color: var(--ink); }
.stats { display: grid; grid-template-columns: auto auto; gap: 1px 10px; align-content: center; font-size: var(--t-s); margin: 0; flex: 0 0 auto; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; font-weight: bold; text-align: right; font-variant-numeric: tabular-nums; }

.paths { display: flex; gap: 8px; flex: 1 1 320px; min-width: 0; align-self: stretch; }
.path {
  flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  background: var(--sprout); border: 2px solid var(--ink); border-radius: 10px; padding: 5px 9px 6px; box-shadow: 0 2px 0 var(--ink);
}
.path:disabled { background: #ece6d2; box-shadow: none; color: var(--muted); }
.path .pname { align-self: stretch; font-size: var(--t-xs); font-weight: bold; color: var(--teal); display: flex; justify-content: space-between; align-items: center; gap: 6px; white-space: nowrap; }
.path .pips { flex: none; }
.path:disabled .pname { color: var(--muted); }
.path .pips { display: inline-flex; gap: 3px; align-items: center; }
.path .pips i { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--ink); background: #fff; }
.path .pips i.on { background: var(--mustard); }
.path .pips i.t4 { border-radius: 2px; transform: rotate(45deg) scale(.9); border-color: var(--tomato); }
.path .pips i.t4.on { background: var(--tomato); }
.path b { font-size: var(--t-m); line-height: 1.15; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.path[data-t4] b, .path.t4 b { color: var(--tomato); }
.path small { font-size: var(--t-xs); color: var(--muted); line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.path .tag { margin-top: auto; }
.path .when { margin-top: auto; font-size: var(--t-xs); font-weight: bold; color: var(--tomato); }

.acts { display: flex; flex-direction: column; gap: 5px; justify-content: center; flex: 0 0 auto; }
.acts button { min-width: 0; width: 132px; min-height: 27px; font-size: var(--t-s); font-weight: bold; border: 2px solid var(--ink); border-radius: 8px; background: var(--paper); box-shadow: 0 2px 0 var(--ink); padding: 2px 8px; }
.acts button:disabled { opacity: .55; }
.acts .ability { display: flex; flex-direction: column; align-items: center; line-height: 1.15; padding: 3px 8px; width: 132px; }
.acts .ability.ready { background: var(--mustard); }
.acts .ability:not(.ready) { color: var(--muted); box-shadow: none; }
.acts .ability small { font-weight: normal; font-size: 9.5px; white-space: normal; opacity: .85; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.acts .sell { background: var(--blush); }

/* ---------- overlays ---------- */
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(29, 42, 58, .45); padding: 12px; }
.card-pop {
  background: var(--cream); border: 3px solid var(--ink); border-radius: 14px; box-shadow: 0 5px 0 var(--ink);
  padding: 16px 22px 18px; text-align: center; max-width: 360px; width: 100%;
}
.card-pop h2 { margin: 0 0 4px; font-size: var(--t-xxl); color: var(--tomato); }
.card-pop p { margin: 0 0 12px; color: var(--muted); font-size: var(--t-m); }
.card-pop .big {
  min-height: 46px; padding: 0 26px; font-size: var(--t-l); font-weight: bold;
  background: var(--tomato); color: #fff; border: 2px solid var(--ink); border-radius: 10px; box-shadow: 0 3px 0 var(--ink);
}
.card-pop .big.alt { background: var(--cream); color: var(--ink); }
.pop-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.summary { display: grid; grid-template-columns: 1fr auto; gap: 3px 12px; margin: 0 auto 14px; max-width: 250px; font-size: var(--t-m); text-align: left; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; font-weight: bold; text-align: right; }

/* ---------- motion (each answers something the player did or must do) ---------- */
.pill.bump { animation: bump .25s; }
@keyframes bump { 50% { transform: scale(1.15); } }
.card.nudge, .send.nudge { animation: nudge 1.1s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateY(-3px); box-shadow: 0 5px 0 var(--ink), 0 0 0 4px rgba(242, 182, 60, .7); } }
.acts .ability.ready { animation: glow 1.4s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 2px 0 var(--ink), 0 0 0 3px rgba(242, 182, 60, .55); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- portrait phones: field on top at its true 3:2 shape, shop becomes a tray, dock below ---------- */
@media (max-width: 720px) and (orientation: portrait) {
  :root { --field-h: calc((100vw - 6px) / 1.5); }
  body { justify-content: flex-start; }
  .top { padding: 0 12px; }
  .top h1 { font-size: var(--t-l); }
  .game { width: 100%; margin: 0; grid-template-columns: minmax(0, 1fr); grid-template-rows: var(--field-h) auto auto; border-radius: 0; border-left: 0; border-right: 0; }
  .hud { top: 4px; left: 4px; gap: 4px; }
  .pill { font-size: 11px; padding: 0 7px 0 4px; box-shadow: 0 1px 0 var(--ink); }
  .pill b, .pill i { font-size: 12px; }
  .bossbar { top: auto; bottom: 6px; width: 70%; font-size: 10px; }
  .toast { top: auto; bottom: 34px; font-size: var(--t-s); }

  .shop { grid-row: 2; grid-column: 1; border-left: 0; border-top: 3px solid var(--ink); display: flex; flex-direction: column; gap: 8px; overflow: visible; }
  .shelves > h2 { display: none; }
  .shelves { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 4px; min-width: 0; }
  .shop .shelf { display: flex; gap: 6px; }
  .shop .shelf + h2 + .shelf { border-left: 2px dashed var(--rule); padding-left: 6px; }
  .shop .shelf .card { flex: 0 0 62px; }
  .next { margin: 0; padding-top: 6px; }
  .card.placed .cost { font-size: 9.5px; padding: 0 5px 0 11px; }

  .dock { grid-row: 3; flex-wrap: wrap; min-height: 150px; gap: 8px; }
  .who { flex: 1 1 100%; }
  .who p { display: none; }
  .paths { flex: 1 1 100%; order: 3; }
  .acts { flex-direction: row; flex: 1 1 100%; order: 4; }
  .acts button, .acts .ability { flex: 1; min-height: 40px; width: auto; }
  .acts .ability small { display: none; }
  .card-pop { padding: 10px 14px 12px; }
  .card-pop h2 { font-size: var(--t-xl); }
  .summary { font-size: var(--t-s); margin-bottom: 8px; }
}

/* ---------- landscape phones and short windows: tighten the dock ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  :root { --dock-h: 84px; --top-h: 0px; --shop-w: 190px; }
  .top { display: none; }
  .who p, .who .chips { display: none; }
  .who .art { width: 48px; height: 48px; }
  .path small { -webkit-line-clamp: 1; }
}
