:root {
  color-scheme: light;
  --ink: #261c18;
  --muted: #6d5a52;
  --panel: #fff8ef;
  --panel-2: #ffe8c8;
  --line: #dfb986;
  --pink: #ff7eb6;
  --choc: #6d3f29;
  --mint: #3bbf9c;
  --bad: #d94141;
  --good: #247c55;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.38) 1px, transparent 1px) 0 0 / 42px 42px,
    linear-gradient(#ffe5a8, #ffc3d7 55%, #a5e6dc);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  filter: brightness(var(--brightness, 1));
  touch-action: manipulation;
}

button {
  min-height: 42px;
  border: 2px solid #321f18;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 4px 0 #321f18;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}

button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #321f18;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.app {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 14px;
  display: grid;
  gap: 12px;
}

.topbar,
.stats,
.tutorial,
.screen,
.customer,
.station,
.grandpa,
.pack-card,
.inventory,
.leaderboard-panel,
.game-chat-panel,
.staff-chat-panel,
.multiplayer-panel {
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 248, 239, 0.94);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.eyebrow,
.label {
  margin: 0 0 4px;
  color: #9b3b6a;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 6vw, 54px);
  line-height: 0.96;
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  overflow: hidden;
}

.stats div {
  padding: 10px 12px;
  border-right: 2px solid var(--line);
}

.stats div:last-child {
  border-right: 0;
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stats strong {
  display: block;
  margin-top: 2px;
  font-size: clamp(20px, 4vw, 32px);
}

.social-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.leaderboard-panel,
.game-chat-panel,
.staff-chat-panel,
.multiplayer-panel {
  padding: 12px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.panel-head h2 {
  margin-bottom: 0;
  font-size: 22px;
}

.leaderboard-list {
  margin: 0;
  padding-left: 28px;
  display: grid;
  gap: 8px;
}

.leaderboard-list li {
  min-height: 44px;
  padding: 8px 10px;
  border: 2px solid #321f18;
  border-radius: 8px;
  background: #fff;
}

.leaderboard-list strong {
  margin-right: 8px;
}

.leaderboard-list span:not(.owner-badge) {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.owner-badge {
  display: inline-grid;
  place-items: center;
  min-height: 22px;
  margin-left: 4px;
  padding: 1px 7px;
  border: 2px solid #321f18;
  border-radius: 999px;
  background: #ffd34f;
  color: #4d2b00;
  font-size: 11px;
  font-weight: 900;
}

.role-badge {
  display: inline-grid;
  place-items: center;
  min-height: 22px;
  margin-left: 4px;
  padding: 1px 7px;
  border: 2px solid #321f18;
  border-radius: 999px;
  color: #fff;
  font-size: 11px;
  font-weight: 900;
}

.role-admin {
  background: #2f7df6;
}

.role-mod {
  background: #e33d3d;
}

.staff-chat-messages {
  min-height: 136px;
  max-height: 180px;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 10px;
  border: 2px solid #321f18;
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-weight: 800;
}

.staff-chat-messages div {
  display: block;
  color: var(--ink);
}

.staff-chat-messages strong {
  margin-right: 4px;
}

.staff-chat-messages div > span:last-child {
  display: block;
  margin-top: 2px;
  overflow-wrap: anywhere;
  color: var(--muted);
}

.staff-chat-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 8px;
}

.staff-chat-controls input {
  min-height: 42px;
  border: 2px solid #321f18;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  padding: 0 10px;
}

.multiplayer-panel {
  display: grid;
  gap: 10px;
}

#multiplayerRoomCode {
  min-height: 34px;
  display: inline-grid;
  place-items: center;
  padding: 4px 10px;
  border: 2px solid #321f18;
  border-radius: 8px;
  background: #fff;
}

.multiplayer-controls {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 8px;
}

.multiplayer-controls input {
  min-height: 42px;
  border: 2px solid #321f18;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  padding: 0 10px;
  text-transform: uppercase;
}

.multiplayer-list {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding-left: 0;
  list-style: none;
}

.screen {
  padding: 12px;
}

.hidden {
  display: none;
}

.customer {
  display: grid;
  grid-template-columns: 90px 1fr 150px;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #fff;
}

.person,
.grandpa-face {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border: 3px solid #321f18;
  border-radius: 50%;
  background: #ffd9b5;
  font-size: 28px;
  font-weight: 900;
}

#orderTitle {
  margin-bottom: 4px;
}

#orderDetails,
#message,
.pack-card p,
#grandpaText {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.4;
}

.timer {
  display: grid;
  gap: 8px;
  text-align: right;
  font-weight: 900;
  font-size: 28px;
}

.timer div {
  height: 14px;
  overflow: hidden;
  border: 2px solid #321f18;
  border-radius: 999px;
  background: #ffe1e1;
}

.timer i {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--good), #f7cf45, var(--bad));
}

.game-grid {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 12px;
  margin-top: 12px;
}

.station {
  padding: 14px;
}

.station-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.donut-preview {
  min-height: 260px;
  display: grid;
  place-items: center;
  border: 2px dashed var(--line);
  border-radius: 8px;
  background: #fff3dc;
}

.donut {
  position: relative;
  width: min(210px, 55vw);
  aspect-ratio: 1;
  border: 18px solid #c47c3f;
  border-radius: 50%;
  background: #f3bd77;
  box-shadow: inset 0 0 0 28px var(--glaze, transparent), 0 12px 0 rgba(50, 31, 24, 0.12);
}

.donut::before {
  content: "";
  position: absolute;
  inset: 31%;
  border-radius: 50%;
  background: #fff3dc;
}

.donut::after {
  content: "";
  position: absolute;
  inset: 7%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 22% 32%, var(--sprinkle, transparent) 0 4px, transparent 5px),
    radial-gradient(circle at 65% 24%, var(--sprinkle2, transparent) 0 4px, transparent 5px),
    radial-gradient(circle at 74% 66%, var(--sprinkle, transparent) 0 4px, transparent 5px),
    radial-gradient(circle at 34% 73%, var(--sprinkle2, transparent) 0 4px, transparent 5px);
}

.base-chocolate {
  border-color: #5c3225;
  background: #82513d;
}

.base-blueberry {
  border-color: #4862a8;
  background: #8197dc;
}

.base-cinnamon {
  border-color: #9c5c31;
  background: #d4975d;
}

.base-red {
  border-color: #7f1f26;
  background: #b6313c;
}

.base-birthday,
.base-rainbow {
  border-color: #f2a1d1;
  background: #ffe6f3;
}

.base-maple,
.base-honey {
  border-color: #b97922;
  background: #f4bd52;
}

.base-pumpkin {
  border-color: #c96f24;
  background: #f2953d;
}

.base-lemon {
  border-color: #e6c72e;
  background: #fff36d;
}

.base-coconut {
  border-color: #d8cdb7;
  background: #fff7e8;
}

.base-strawberry {
  border-color: #d84f7d;
  background: #ff95b7;
}

.base-banana {
  border-color: #d8ba30;
  background: #ffe66d;
}

.base-caramel,
.base-peanut {
  border-color: #8b5b32;
  background: #c6864a;
}

.base-oreo,
.base-coffee {
  border-color: #2f241f;
  background: #6b5144;
}

.base-mint {
  border-color: #3bbf9c;
  background: #9de8d0;
}

.base-galaxy {
  border-color: #41267a;
  background: #7452cc;
}

.base-cj {
  border-color: #156b8f;
  background: #4fc3f7;
}

.base-noelly {
  border-color: #b8326a;
  background: #ff9ec7;
}

.base-mrpepper {
  border-color: #171717;
  background: #ef4444;
}

.base-coellack {
  border-color: #2e6a35;
  background: #89d66f;
}

.glaze-strawberry {
  --glaze: #ff7eb6;
}

.glaze-chocolate {
  --glaze: #6d3f29;
}

.glaze-vanilla {
  --glaze: #fff4bc;
}

.glaze-matcha {
  --glaze: #80c96d;
}

.topping-sprinkles {
  --sprinkle: #2f7cff;
  --sprinkle2: #ffcf33;
}

.topping-crumbs {
  --sprinkle: #b5793a;
  --sprinkle2: #7c4b23;
}

.topping-stars {
  --sprinkle: #ffe45e;
  --sprinkle2: #fff;
}

.current-build {
  margin-top: 12px;
  min-height: 42px;
  color: var(--muted);
  font-weight: 800;
}

.controls h3 {
  margin: 12px 0 8px;
}

.controls h3:first-child {
  margin-top: 0;
}

.choices {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.choice.selected {
  background: #321f18;
  color: #fff;
}

.round-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.round-actions button {
  min-width: 150px;
}

.home-layout {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 12px;
}

.drive-head,
.drive-controls {
  display: block;
}

.drive-stats {
  display: grid;
  gap: 4px;
  text-align: right;
}

.drive-stats strong {
  font-size: 32px;
}

.drive-stats span {
  color: var(--muted);
  font-weight: 800;
}

.drive-road {
  position: relative;
  height: 420px;
  margin-top: 12px;
  overflow: hidden;
  border: 3px solid #321f18;
  border-radius: 8px;
  background:
    repeating-linear-gradient(0deg, transparent 0 58px, rgba(255, 255, 255, 0.15) 58px 60px),
    linear-gradient(0deg, #7ccf72 0 14%, #4c4b4d 14% 86%, #7ccf72 86% 100%);
}

.tap-zone {
  position: absolute;
  z-index: 3;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  touch-action: manipulation;
}

.tap-zone:active {
  transform: none;
  box-shadow: none;
  background: rgba(255, 255, 255, 0.15);
}

.tap-up {
  top: 0;
  left: 22%;
  right: 22%;
  height: 42%;
}

.tap-down {
  bottom: 0;
  left: 22%;
  right: 22%;
  height: 33%;
}

.tap-left {
  top: 22%;
  bottom: 12%;
  left: 0;
  width: 38%;
}

.tap-right {
  top: 22%;
  bottom: 12%;
  right: 0;
  width: 38%;
}

.drive-road::before {
  content: "";
  position: absolute;
  inset: 16% 0 14%;
  background: repeating-linear-gradient(90deg, transparent 0 44px, #fff2a8 44px 68px, transparent 68px 112px);
  opacity: 0.65;
}

.house {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 74px;
  display: grid;
  place-items: center;
  border: 3px solid #321f18;
  border-radius: 8px;
  background: #ffd9b5;
  font-weight: 900;
}

.car {
  position: absolute;
  width: 92px;
  height: 48px;
  transform: translate(-50%, -50%);
  border: 3px solid #321f18;
  border-radius: 14px;
}

.crossing-player {
  position: absolute;
  z-index: 2;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  border: 3px solid #321f18;
  border-radius: 10px;
  background: #ff7eb6;
  font-weight: 900;
}

.traffic-car {
  z-index: 2;
  background: #46a7ff;
}

.drive-meter {
  height: 18px;
  margin-top: 12px;
  overflow: hidden;
  border: 2px solid #321f18;
  border-radius: 999px;
  background: #fff;
}

.drive-meter i {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #3bbf9c, #ffd95a);
}

#driveMessage {
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  margin-bottom: 0;
  color: var(--muted);
  text-align: center;
  font-weight: 900;
}

.grandpa {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: #fff;
}

.grandpa-face {
  background: #f2c39e;
}

.grandpa-face.ready-drop {
  outline: 5px solid #3bbf9c;
  outline-offset: 4px;
}

.grandpa-face.eating {
  animation: eatCookie 0.72s ease-in-out;
}

.pack-card,
.inventory,
.owner-card,
.exp-shop,
.ending-card {
  padding: 14px;
}

.pack-card,
.owner-card,
.exp-shop,
.ending-card {
  display: grid;
  gap: 12px;
}

.ending-card {
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.ending-meter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 2px solid #321f18;
  border-radius: 8px;
  background: #fff3dc;
  font-weight: 900;
}

#endingMessage {
  margin-bottom: 0;
  color: var(--muted);
  font-weight: 800;
}

.privacy-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #fff;
  cursor: default;
}

.privacy-screen.privacy-black {
  background: #000;
}

.exp-shop p {
  margin-bottom: 0;
  color: var(--muted);
}

.exp-shop-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.exp-buy {
  display: grid;
  gap: 4px;
  align-content: center;
  min-height: 68px;
  text-align: left;
}

.exp-buy small {
  color: var(--muted);
  font-weight: 800;
}

.exp-buy.unlocked {
  background: #321f18;
  color: #fff;
}

.exp-buy.unlocked small {
  color: #ffe8c8;
}

.owner-card select {
  min-height: 42px;
  border: 2px solid #321f18;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  padding: 0 10px;
}

.cookie-reveal {
  min-height: 96px;
  display: grid;
  place-items: center;
  padding: 14px;
  border: 2px dashed var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: center;
  font-weight: 900;
}

.held-cookie-slot {
  min-height: 88px;
  display: grid;
  place-items: center;
  padding: 12px;
  border: 2px dashed var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  text-align: center;
  font-weight: 900;
}

.draggable-cookie {
  width: 74px;
  height: 74px;
  display: grid;
  place-items: center;
  border: 4px solid #8b5b32;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 35%, #6d3f29 0 5px, transparent 6px),
    radial-gradient(circle at 66% 52%, #6d3f29 0 5px, transparent 6px),
    radial-gradient(circle at 48% 72%, #6d3f29 0 4px, transparent 5px),
    #d99b55;
  color: #321f18;
  cursor: grab;
  font-size: 11px;
  text-align: center;
  user-select: none;
}

.draggable-cookie:active {
  cursor: grabbing;
}

@keyframes eatCookie {
  0% { transform: scale(1); }
  25% { transform: scale(1.18) rotate(-4deg); }
  50% { transform: scale(0.92) rotate(4deg); }
  75% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.common {
  color: #7b5b44;
}

.rare {
  color: #1d75d8;
}

.epic {
  color: #9737c9;
}

.legendary {
  color: #d88900;
}

.inventory ul {
  margin: 0;
  padding-left: 18px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(38, 28, 24, 0.52);
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(720px, 100%);
  border: 3px solid #321f18;
  border-radius: 8px;
  background: #fff8ef;
  box-shadow: 0 18px 0 rgba(50, 31, 24, 0.24);
  padding: 16px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.settings-card {
  display: grid;
  gap: 12px;
}

.settings-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 900;
}

.owner-login {
  display: grid;
  gap: 8px;
  margin-top: 8px;
  padding-top: 12px;
  border-top: 2px solid var(--line);
}

.settings-owner-tools {
  display: grid;
  gap: 8px;
}

.settings-owner-tools select,
.settings-owner-tools input,
#usernameInput {
  min-height: 42px;
  border: 2px solid #321f18;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  padding: 0 10px;
}

.settings-owner-tools label {
  display: grid;
  gap: 6px;
}

.setting-note,
.error-text {
  margin-bottom: 0;
  color: var(--muted);
  font-weight: 800;
}

.error-text {
  min-height: 20px;
  color: var(--bad);
}

.owner-login p {
  margin-bottom: 0;
  color: var(--muted);
  font-weight: 800;
}

.settings-card input[type="range"] {
  width: 100%;
}

.tutorial-video {
  display: grid;
  gap: 14px;
}

.video-stage {
  height: 270px;
  overflow: hidden;
  border: 3px solid #321f18;
  border-radius: 8px;
  background: linear-gradient(#ffe5a8 0 45%, #fff8ef 45% 100%);
}

.video-shop {
  position: relative;
  height: 100%;
}

.video-customer,
.video-grandpa {
  position: absolute;
  top: 28px;
  width: 108px;
  height: 72px;
  display: grid;
  place-items: center;
  border: 3px solid #321f18;
  border-radius: 8px;
  background: #ffd9b5;
  font-weight: 900;
}

.video-customer {
  left: 8%;
  animation: customerPulse 3.6s infinite;
}

.video-grandpa {
  right: 8%;
  animation: grandpaPulse 3.6s infinite;
}

.video-donut {
  position: absolute;
  left: 50%;
  top: 128px;
  width: 92px;
  height: 92px;
  margin-left: -46px;
  border: 14px solid #c47c3f;
  border-radius: 50%;
  background: #ff7eb6;
  animation: donutMove 3.6s infinite;
}

.video-donut::before {
  content: "";
  position: absolute;
  inset: 30%;
  border-radius: 50%;
  background: #fff8ef;
}

.video-car {
  position: absolute;
  left: 18%;
  bottom: 22px;
  width: 58px;
  height: 82px;
  border: 3px solid #321f18;
  border-radius: 12px;
  background: #46a7ff;
  animation: carDrive 3.6s infinite;
}

@keyframes customerPulse {
  0%, 25% { transform: scale(1); }
  12% { transform: scale(1.08); }
}

@keyframes donutMove {
  0% { transform: translateX(-180px) scale(0.8); opacity: 0; }
  18%, 52% { transform: translateX(0) scale(1); opacity: 1; }
  70%, 100% { transform: translateX(190px) scale(0.8); opacity: 0; }
}

@keyframes carDrive {
  0%, 48% { transform: translateX(0); }
  72%, 100% { transform: translateX(360px); }
}

@keyframes grandpaPulse {
  0%, 62% { transform: scale(1); }
  82% { transform: scale(1.08); }
}

@media (max-width: 780px) {
  .topbar,
  .round-actions,
  .grandpa,
  .drive-head {
    align-items: stretch;
    flex-direction: column;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .stats div:nth-child(2n) {
    border-right: 0;
  }

  .stats div:not(:last-child) {
    border-bottom: 2px solid var(--line);
  }

  .customer,
  .game-grid,
  .home-layout,
  .social-grid,
  .modal-head {
    grid-template-columns: 1fr;
  }

  .staff-chat-controls {
    grid-template-columns: 1fr;
  }

  .multiplayer-controls,
  .multiplayer-list {
    grid-template-columns: 1fr;
  }

  .topbar,
  .modal-head {
    align-items: stretch;
    flex-direction: column;
  }

  .timer {
    text-align: left;
  }

  .choices {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .exp-shop-list {
    grid-template-columns: 1fr;
  }
}
