/* ==========================================================================
   CHOWDECK DELIVER DASH — styles
   Visual language from the Illustrator mockups: cream ground, Chowdeck-green
   cards with thick black outlines, pill buttons, Matcha Cih display type.
   Colours also live in js/config.js (pushed into these variables at boot).
   ========================================================================== */

@font-face { font-family: 'Matcha Cih'; src: url('../assets/fonts/matcha-cih.woff') format('woff'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Inter Brand'; src: url('../assets/fonts/inter-bold.woff') format('woff'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Inter Brand'; src: url('../assets/fonts/inter-black.woff') format('woff'); font-weight: 900; font-display: swap; }

:root {
  --cream: #EAE4DA;
  --green: #0E5240;
  --yellow: #FFC502;
  --title-fill: #FBE9A5;
  --share-green: #57BE84;
  --ink: #000000;
  --white: #FFFFFF;
  --danger: #E5383B;

  --stroke: 4px;                 /* card outline */
  --stroke-btn: 3px;             /* button outline */

  --font-fun: 'Matcha Cih', 'Arial Rounded MT Bold', 'Trebuchet MS', sans-serif;
  --font-title: 'Inter Brand', 'Inter', 'Arial Black', system-ui, sans-serif;
  --font-body: 'Poppins', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* black outline around display text (works in every browser) */
  --outline-3: 3px 0 0 #000, -3px 0 0 #000, 0 3px 0 #000, 0 -3px 0 #000, 2px 2px 0 #000, -2px 2px 0 #000, 2px -2px 0 #000, -2px -2px 0 #000;
  --outline-2: 2px 0 0 #000, -2px 0 0 #000, 0 2px 0 #000, 0 -2px 0 #000, 1.5px 1.5px 0 #000, -1.5px 1.5px 0 #000, 1.5px -1.5px 0 #000, -1.5px -1.5px 0 #000;
}

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

html, body {
  height: 100%;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font-body);
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-font-smoothing: antialiased;
}
body { position: fixed; inset: 0; }

#app { position: fixed; inset: 0; display: flex; justify-content: center; background: var(--cream); }

/* ---------------- Game column ---------------- */
#game {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 14px) 14px calc(var(--safe-bottom) + 12px);
  touch-action: none;
}

.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 8px;
  min-height: 58px;
  padding: 2px 4px 0;
}
.hud-stat { display: flex; flex-direction: column; gap: 4px; }
.hud-label { font: 18px/1 var(--font-fun); color: var(--ink); }
.hud-value {
  font: 22px/1 var(--font-fun);
  color: var(--yellow);
  text-shadow: var(--outline-2);
  display: inline-block;
  transform-origin: left center;
  padding-left: 2px;
}
.hud-value.bump { animation: bump 0.4s cubic-bezier(.2, 1.6, .4, 1); }

.hud-timer {
  font: 34px/1 var(--font-fun);
  color: var(--green);
  text-align: center;
  padding-top: 4px;
  font-variant-numeric: tabular-nums;
  transition: color .2s;
}
.hud-timer.warn { color: var(--danger); animation: pulse 1s ease-in-out infinite; }

.hud-actions { display: flex; justify-content: flex-end; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 999px;
  background: var(--white);
  border: var(--stroke-btn) solid var(--ink);
  color: var(--green);
  display: grid; place-items: center;
  cursor: pointer;
  transition: transform .1s;
}
.icon-btn:active { transform: scale(0.9); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn[aria-pressed="true"] { background: var(--yellow); color: var(--ink); }
.icon-btn[aria-pressed="false"] { background: var(--white); color: #8B8B8B; }
.icon-btn[hidden] { display: none; }

#stage { position: relative; flex: 1; min-height: 0; margin-top: 10px; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------------- D-pad ---------------- */
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 68px);
  grid-template-rows: repeat(2, 54px);
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
}
.dpad.hidden { display: none; }
.dpad button {
  border: var(--stroke-btn) solid var(--ink);
  background: var(--yellow);
  border-radius: 18px;
  color: var(--ink);
  display: grid; place-items: center;
  box-shadow: 0 4px 0 var(--ink);
  touch-action: none;
}
.dpad button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.dpad svg { width: 22px; height: 22px; fill: currentColor; }
.d-up { grid-column: 2; grid-row: 1; }
.d-left { grid-column: 1; grid-row: 2; }
.d-down { grid-column: 2; grid-row: 2; }
.d-right { grid-column: 3; grid-row: 2; }

/* ---------------- Overlays (start + end screens) ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 36px) 18px calc(var(--safe-bottom) + 20px);
  background: var(--cream);
  overflow-y: auto;
  touch-action: pan-y;
  transition: opacity .25s ease, visibility .25s;
}
.overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.overlay .card { margin: auto; animation: rise .4s cubic-bezier(.2, 1.3, .4, 1); }
.overlay.hidden .card { animation: none; }

/* Green card with thick black outline (MenuBorder) */
.card {
  position: relative;
  width: 100%;
  max-width: 380px;
  text-align: center;
  padding: 52px 20px 30px;
  border-radius: 36px;
  background: var(--green);
  border: var(--stroke) solid var(--ink);
  color: var(--white);
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Logo pill sitting on the card's top edge */
.logo-pill {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -52%);
  width: 132px;
  height: auto;
  display: block;
}

/* Cream title pill (TitleBorder) */
.title {
  width: 100%;
  margin: 8px 0 26px;
  padding: 16px 10px 15px;
  background: var(--title-fill);
  border: var(--stroke) solid var(--ink);
  border-radius: 999px;
  font: 900 clamp(26px, 8.6vw, 34px)/1 var(--font-title);
  letter-spacing: -0.045em;
  color: var(--ink);
  text-wrap: balance;
}

.tagline {
  font: 400 17px/1.4 var(--font-body);
  color: var(--yellow);
  max-width: 280px;
  margin-bottom: 26px;
}

.legend { display: flex; justify-content: center; align-items: center; gap: 8px; margin-bottom: 30px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px 6px 9px;
  border-radius: 999px;
  font: 14px/1 var(--font-fun);
  border: var(--stroke-btn) solid var(--ink);
  color: var(--ink);
}
.chip i { font-style: normal; font-size: 15px; }
.chip-pickup { background: var(--yellow); }
.chip-customer { background: var(--white); }
.legend .arrow { color: var(--yellow); font: 18px/1 var(--font-fun); }

/* Pill buttons with black outline (Play / PlayAgain / Share / OrderFood) */
.btn {
  display: flex; align-items: center; justify-content: center;
  width: 100%;
  min-height: 56px;
  padding: 4px 14px 0;
  border-radius: 999px;
  border: var(--stroke-btn) solid var(--ink);
  font: 24px/1 var(--font-fun);
  color: var(--white);
  cursor: pointer;
  text-decoration: none;
  transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(.96); }
.btn:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }
.btn:disabled { opacity: .6; }
.btn[hidden] { display: none; }

.btn-play { width: 72%; min-height: 62px; font-size: 30px; background: var(--yellow); }
.btn-yellow { background: var(--yellow); border-radius: 22px; }
.btn-share { background: var(--share-green); border-radius: 22px; }
.btn-order { background: var(--white); color: var(--ink); font-size: clamp(15px, 4.6vw, 19px); white-space: nowrap; padding: 4px 10px 0; }
.btn-ghost { background: transparent; border-color: var(--white); color: var(--white); min-height: 46px; font-size: 16px; border-radius: 22px; }

.hint {
  margin-top: 14px;
  font: 300 12.5px/1.45 var(--font-body);
  color: var(--white);
  max-width: 290px;
}
.best { margin-top: 18px; font: 15px/1 var(--font-fun); color: var(--yellow); letter-spacing: .02em; }

/* End card */
.sub { font: 700 17px/1 var(--font-title); color: var(--white); letter-spacing: .01em; margin-top: 4px; }
.score-big {
  font: 92px/1 var(--font-fun);
  color: var(--yellow);
  margin: 26px 0 20px;
  text-shadow: 5px 0 0 #000, -5px 0 0 #000, 0 5px 0 #000, 0 -5px 0 #000, 3.5px 3.5px 0 #000, -3.5px 3.5px 0 #000, 3.5px -3.5px 0 #000, -3.5px -3.5px 0 #000;
}
.unit { font: 22px/1 var(--font-fun); color: var(--yellow); }
.end-msg { margin-top: 18px; font: 400 14px/1.4 var(--font-body); color: var(--white); }
.best-end { margin-top: 12px; color: var(--white); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; width: 100%; }
.btn-row .btn { font-size: clamp(16px, 5vw, 20px); white-space: nowrap; padding: 4px 8px 0; }

/* ---------------- Share panel ---------------- */
.overlay.sheet { z-index: 15; background: rgba(4, 18, 14, 0.62); }
.sheet-card { padding: 26px 18px 22px; gap: 14px; }
.sheet-title { font: 23px/1 var(--font-fun); color: var(--yellow); padding: 6px 44px 0; }
.sheet-close {
  position: absolute; top: 12px; right: 12px;
  width: 38px; height: 38px; border-radius: 999px;
  background: var(--white); color: var(--ink);
  border: var(--stroke-btn) solid var(--ink);
  display: grid; place-items: center; cursor: pointer;
}
.sheet-close svg { width: 16px; height: 16px; }
/* the image must stay saveable: re-enable long-press / right-click on it */
.share-img {
  display: block; width: 100%; height: auto; max-width: 100%;
  border-radius: 16px; border: var(--stroke-btn) solid var(--ink);
  background: var(--green);
  -webkit-touch-callout: default; -webkit-user-select: auto; user-select: auto;
}
.sheet-hint { font: 400 13px/1.4 var(--font-body); color: var(--white); max-width: 290px; }
.social-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
.btn-social { min-height: 50px; font-size: 18px; border-radius: 18px; white-space: nowrap; }
.btn-wa { background: #25D366; }
.btn-x { background: #000000; border-color: #000000; }
.btn-fb { background: #1877F2; }
.btn-copy { background: var(--white); color: var(--ink); }
.btn-save { background: var(--yellow); min-height: 50px; font-size: 18px; border-radius: 18px; }
.btn-social[hidden], .btn-save[hidden] { display: none; }
.btn-fb[hidden] + .btn-copy { grid-column: span 2; }
.cta { margin-top: 16px; width: 100%; }
.cta p { font: 400 14px/1 var(--font-body); color: var(--white); margin-bottom: 12px; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-top) + 84px);
  z-index: 20;
  transform: translate(-50%, 0) scale(.6);
  font: 18px/1 var(--font-fun);
  color: var(--ink);
  padding: 11px 18px 8px;
  border-radius: 999px;
  background: var(--yellow);
  border: var(--stroke-btn) solid var(--ink);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.toast.deliver { background: var(--white); }
.toast.over { background: var(--danger); color: var(--white); font-size: 20px; }
.toast.go { background: var(--share-green); color: var(--white); font-size: 22px; }
.toast.show { animation: toast .95s cubic-bezier(.2, 1.4, .4, 1) forwards; }

/* ---------------- Rotate notice (phones in landscape) ---------------- */
.rotate { display: none; }
@media (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  .rotate {
    display: flex; position: fixed; inset: 0; z-index: 50;
    align-items: center; justify-content: center;
    background: var(--green); color: var(--yellow);
    font: 20px/1.4 var(--font-fun); text-align: center; padding: 24px;
  }
}

/* Short screens */
@media (max-height: 680px) {
  .card { padding: 44px 18px 22px; }
  .title { margin-bottom: 18px; }
  .tagline, .legend { margin-bottom: 18px; }
  .score-big { font-size: 76px; margin: 16px 0 14px; }
  .end-msg { margin-top: 12px; }
}
@media (max-width: 350px) {
  .hud-timer { font-size: 28px; }
  .btn-row .btn { font-size: 17px; }
  .btn-order { font-size: 16px; }
}

/* ---------------- Animations ---------------- */
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.6); } 100% { transform: scale(1); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, 0) scale(.6); }
  14% { opacity: 1; transform: translate(-50%, 0) scale(1.1); }
  24% { transform: translate(-50%, 0) scale(1); }
  75% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -14px) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .hud-timer.warn { animation: none; }
  .overlay .card { animation: none; }
}
