:root {
  --ink: #20231f;
  --paper: #f3efe2;
  --cream: #fffaf0;
  --green: #76b947;
  --green-dark: #2f6136;
  --orange: #ff8a3d;
  --pink: #ff6e91;
  --blue: #68b8cc;
  --line: #20231f;
  --shadow: 4px 4px 0 var(--line);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(circle at 15px 15px, rgba(32, 35, 31, .055) 1.5px, transparent 1.6px) 0 0 / 30px 30px,
    var(--paper);
  font-family: ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, a { font: inherit; }
button { color: inherit; }

.game {
  width: min(100%, 610px);
  margin: 0 auto;
  padding: 14px 12px 64px;
}

.topbar {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.back, .help-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--ink);
  background: var(--cream);
  border: 2px solid var(--line);
  border-radius: 12px;
  box-shadow: 2px 2px 0 var(--line);
  text-decoration: none;
  cursor: pointer;
}

.kicker {
  margin: 0 0 2px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .15em;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(22px, 7vw, 32px); line-height: .95; letter-spacing: -.04em; }
h2 { margin-bottom: 0; font-size: 22px; letter-spacing: -.03em; }

.delivered {
  min-width: 68px;
  padding: 5px 8px;
  text-align: center;
  background: #ffe06b;
  border: 2px solid var(--line);
  border-radius: 12px;
  box-shadow: 2px 2px 0 var(--line);
}
.delivered > span { display: block; font-size: 20px; font-weight: 950; line-height: 1; }
.delivered small { font-size: 9px; font-weight: 900; text-transform: uppercase; }
.delivered b { font: inherit; }
.coin-mark {
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  color: #553b00;
  font-size: 11px;
  font-style: normal;
  font-weight: 950;
  line-height: 1;
  vertical-align: 2px;
  background: #ffc928;
  border: 1.5px solid var(--line);
  border-radius: 50%;
}

.shop-window {
  position: relative;
  overflow: hidden;
  padding: 27px 10px 12px;
  background: #bfe4ec;
  border: 3px solid var(--line);
  border-radius: 18px 18px 8px 8px;
  box-shadow: var(--shadow);
}

.awning {
  position: absolute;
  inset: 0 0 auto;
  height: 18px;
  border-bottom: 3px solid var(--line);
  background: repeating-linear-gradient(90deg, var(--pink) 0 34px, var(--cream) 34px 68px);
}

.window-top { display: flex; align-items: center; gap: 7px; font-size: 10px; font-weight: 950; letter-spacing: .11em; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); border: 1.5px solid var(--line); }
.timer { margin-left: auto; padding: 3px 7px; font-size: 13px; letter-spacing: 0; background: var(--cream); border: 2px solid var(--line); border-radius: 8px; }
.timer.urgent { color: #fff; background: #da3a31; animation: timerPulse .65s steps(2) infinite; }

.customers {
  display: flex;
  justify-content: center;
  align-items: end;
  gap: 7px;
  min-height: 111px;
  padding-top: 7px;
}

.customer {
  position: relative;
  display: grid;
  grid-template-rows: 64px 32px;
  place-items: center;
  width: min(23%, 105px);
  min-width: 67px;
  padding: 3px;
  background: rgba(255,255,255,.34);
  border: 2px solid var(--line);
  border-radius: 46px 46px 10px 10px;
  cursor: pointer;
  transition: transform .12s ease, opacity .2s ease;
}
.customer:active { transform: translateY(3px); }
.customer.fulfilled { opacity: .38; filter: grayscale(1); }
.customer > img { width: 58px; height: 58px; object-fit: contain; filter: drop-shadow(0 2px 0 rgba(0,0,0,.14)); }
.order { display: flex; align-items: center; justify-content: center; gap: 2px; width: 100%; height: 30px; background: var(--cream); border: 2px solid var(--line); border-radius: 8px; font-weight: 950; }
.order .product-icon { width: 25px; height: 25px; }
.order span { font-size: 17px; }

.prompt {
  margin: 6px 2px 0;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
  background: var(--cream);
  border: 2px solid var(--line);
  border-radius: 9px;
}

.tray-wrap {
  position: sticky;
  z-index: 5;
  top: 6px;
  display: grid;
  grid-template-columns: 68px 1fr 48px;
  align-items: center;
  gap: 7px;
  margin: 16px 0 18px;
  padding: 7px;
  background: var(--orange);
  border: 3px solid var(--line);
  border-radius: 13px;
  box-shadow: 3px 3px 0 var(--line);
}
.tray-label { padding-left: 2px; font-size: 11px; font-weight: 950; text-transform: uppercase; line-height: 1.05; }
.tray-label small { display: block; margin-top: 4px; font-size: 10px; }
.basket { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.basket-slot { display: grid; place-items: center; aspect-ratio: 1; min-width: 0; background: rgba(255,255,255,.42); border: 2px dashed var(--line); border-radius: 9px; }
.basket-slot.filled { background: var(--cream); border-style: solid; cursor: pointer; }
.product-icon {
  display: block;
  width: 86%;
  height: 86%;
  background: var(--product-color);
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}
.basket-slot .product-icon { width: 86%; height: 86%; }
.store-button {
  position: relative;
  display: grid;
  place-items: center;
  align-self: stretch;
  padding: 2px;
  font-size: 9px;
  font-weight: 950;
  background: #ffe06b;
  border: 2px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
}
.store-button b {
  position: absolute;
  top: -8px;
  right: -7px;
  display: grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  color: #fff;
  font-size: 10px;
  background: #da3a31;
  border: 2px solid var(--line);
  border-radius: 20px;
}
.hidden { display: none !important; }

.storage-heading { display: flex; align-items: end; justify-content: space-between; margin: 0 3px 8px; }
.help-button { width: 35px; height: 35px; font-weight: 950; }
.storage-frame { padding: 6px; background: #744a2c; border: 3px solid var(--line); border-radius: 13px; box-shadow: var(--shadow); }
.storage-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }

.cell {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  padding: 3px;
  background: #e5cc9d;
  border: 2px solid var(--line);
  border-radius: 9px;
  box-shadow: inset 0 -4px 0 rgba(83,48,24,.18);
  cursor: pointer;
  touch-action: manipulation;
}
.cell img { width: 88%; height: 88%; object-fit: contain; pointer-events: none; }
.cell .product-icon { width: 88%; height: 88%; pointer-events: none; }
.cell.empty::after { content: ""; width: 24%; height: 24%; border-radius: 50%; background: rgba(87,52,26,.18); }
.cell.blocked { cursor: pointer; background: #567064; box-shadow: inset 0 0 0 4px rgba(255,255,255,.1); }
.cell.blocked::before { content: ""; width: 56%; height: 56%; border-radius: 10px; background: #334b42; border: 2px solid var(--line); }
.cell.bomb { overflow: hidden; background: #ff754d; animation: bombFlash .8s steps(2) infinite; }
.cell.bomb img { width: 78%; height: 78%; }
.cell.pop { animation: pop .25s ease; }
.cell.shuffling { animation: shuffle .32s ease; }

.overlay { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(32,35,31,.66); backdrop-filter: blur(4px); }
.overlay.hidden { display: none; }
.modal { width: min(100%, 390px); padding: 24px; text-align: center; background: var(--cream); border: 3px solid var(--line); border-radius: 18px; box-shadow: 7px 7px 0 var(--line); }
.modal h2 { margin-bottom: 10px; font-size: 32px; }
.modal > p:not(.kicker) { margin-bottom: 18px; line-height: 1.45; }
.event-copy .product-icon {
  display: inline-block;
  width: 38px;
  height: 38px;
  margin: -9px 3px;
  vertical-align: middle;
}
.primary-button { width: 100%; padding: 13px 16px; font-weight: 950; background: #ffe06b; border: 3px solid var(--line); border-radius: 11px; box-shadow: 3px 3px 0 var(--line); cursor: pointer; }
.primary-button:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--line); }
.store-modal {
  position: relative;
  width: min(100%, 470px);
  max-height: min(90vh, 720px);
  overflow-y: auto;
  text-align: left;
}
.store-modal > h2 { margin-bottom: 12px; font-size: 30px; }
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 35px;
  height: 35px;
  padding: 0;
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
}
.store-balance {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
  padding: 9px 11px;
  font-size: 11px;
  font-weight: 850;
  background: #ffe9a0;
  border: 2px solid var(--line);
  border-radius: 10px;
}
.store-balance strong { font-size: 18px; white-space: nowrap; }
.store-balance span:last-child { text-align: right; }
.store-list { display: grid; gap: 9px; }
.store-item {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 9px;
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: 11px;
}
.store-item-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  font-size: 16px;
  font-weight: 950;
  background: #bfe4ec;
  border: 2px solid var(--line);
  border-radius: 10px;
}
.breaker-icon { color: #fff; background: #da3a31; }
.refill-icon { font-size: 28px; background: #8fd06d; }
.store-item h3 { margin: 0 0 3px; font-size: 14px; }
.store-item p { margin: 0; font-size: 10px; line-height: 1.3; }
.store-item button {
  min-width: 56px;
  padding: 8px 5px;
  font-size: 10px;
  font-weight: 950;
  background: #ffe06b;
  border: 2px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.store-item button:disabled { opacity: .4; cursor: not-allowed; filter: grayscale(1); }
.store-status { min-height: 18px; margin: 9px 0 5px; font-size: 11px; font-weight: 900; text-align: center; }
.store-modal > .primary-button { text-align: center; }
.toast { position: fixed; z-index: 30; left: 50%; bottom: 20px; max-width: calc(100% - 32px); padding: 9px 13px; color: #fff; font-size: 12px; font-weight: 900; text-align: center; background: var(--ink); border-radius: 9px; opacity: 0; transform: translate(-50%, 12px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes bombFlash { 50% { background: #ffbd32; transform: rotate(1deg); } }
@keyframes timerPulse { 50% { transform: scale(1.07); } }
@keyframes pop { 50% { transform: scale(.72); } }
@keyframes shuffle { 50% { transform: scale(.75) rotate(10deg); } }

@media (min-width: 650px) {
  .game { padding-top: 24px; }
  .cell { border-radius: 11px; }
  .shop-window { padding-inline: 18px; }
}

@media (max-width: 420px) {
  .store-modal { padding: 19px; }
  .store-item { grid-template-columns: 42px minmax(0, 1fr); }
  .store-item-icon { width: 40px; height: 40px; }
  .store-item button { grid-column: 2; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
