:root {
  --font-display: "Fredoka", ui-rounded, system-ui, sans-serif;
  --font-sans: "Nunito", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #1e0b09;
  color: #fff8eb;
  font-family: var(--font-sans);
  touch-action: manipulation;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

button, input {
  font-family: inherit;
}

.hidden { display: none !important; }
.font-display { font-family: var(--font-display); }
.font-mono-num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.cartoon-box {
  border: 3px solid #1e0b09;
  box-shadow: 0 4px 0 #1e0b09;
}

.cartoon-box-sm {
  border: 2.5px solid #1e0b09;
  box-shadow: 0 3px 0 #1e0b09;
}

.cartoon-btn {
  border: 3px solid #1e0b09;
  box-shadow: 0 4px 0 #1e0b09;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
  transition: transform 120ms cubic-bezier(0.16, 1, 0.3, 1), box-shadow 120ms cubic-bezier(0.16, 1, 0.3, 1), filter 120ms ease;
}

.cartoon-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 5px 0 #1e0b09;
}

.cartoon-btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #1e0b09;
}

.cartoon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.bg-china-wall {
  background-color: #290e0b;
  background-image:
    radial-gradient(circle at 24px 24px, rgba(250, 204, 21, 0.08) 2px, transparent 2.5px),
    linear-gradient(to right, rgba(16, 185, 129, 0.06) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(16, 185, 129, 0.06) 1px, transparent 1px);
  background-size: 48px 48px;
}

/* Title Screen */
.app-root {
  position: relative;
  height: 100dvh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.title-screen {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}

.title-backdrop {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #450a0a, #290e0b, #1e0b09);
}

.title-backdrop img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.title-scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(to right, rgba(30, 11, 9, 0.95), rgba(30, 11, 9, 0.76), rgba(30, 11, 9, 0.25));
}

.title-top-bar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px 28px 0;
}

.title-hero {
  position: relative;
  z-index: 10;
  flex: 1;
  display: flex;
  align-items: center;
  padding: 0 44px 20px;
}

.title-hero-inner {
  max-width: 560px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.title-lockup-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.sushiman-avatar-lg {
  width: 78px;
  height: 78px;
  border-radius: 16px;
  overflow: hidden;
  background: #fff8eb;
  flex-shrink: 0;
}

.sushiman-avatar-lg img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.title-desc {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: #fef3c7;
  line-height: 1.35;
  max-width: 460px;
}

.title-ctas {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.top3-box {
  background: rgba(30, 11, 9, 0.92);
  border-radius: 16px;
  padding: 14px;
  max-width: 440px;
}

.top3-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 800;
  color: #fde68a;
  margin-bottom: 8px;
}

.top3-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 700;
  padding: 3px 0;
}

.title-hint {
  position: relative;
  z-index: 10;
  padding: 0 28px 16px;
  font-size: 13px;
  font-weight: 700;
  color: #fde68a;
}

/* Playing Screen */
.play-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.hud-bar {
  flex-shrink: 0;
  background: #450a0a;
  border-bottom: 3px solid #1e0b09;
  padding: 8px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.hud-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid #1e0b09;
  background: #fff8eb;
  flex-shrink: 0;
}

.hud-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hud-xp-track {
  width: 128px;
  height: 10px;
  background: #1e0b09;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid #7f1d1d;
}

.hud-xp-fill {
  height: 100%;
  background: #10b981;
  transform-origin: left;
  transition: transform 200ms ease;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.lives-box {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #1e0b09;
  padding: 6px 10px;
  border-radius: 12px;
}

.play-main {
  flex: 1;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 10px 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  overflow: hidden;
  position: relative;
}

.level-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  background: #f59e0b;
  color: #1e0b09;
  padding: 8px 20px;
  border-radius: 14px;
  font-family: var(--font-display);
  font-weight: 700;
  pointer-events: none;
  white-space: nowrap;
}

.customers-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  flex-shrink: 0;
}

.customer-card {
  border-radius: 16px;
  padding: 9px 10px;
  background: #3d1610;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 140ms ease;
}

.customer-card.is-vip { background: #5c1414; box-shadow: 0 3px 0 #1e0b09, 0 0 0 2px #fbbf24; }
.customer-card.can-serve { background: #451a03; box-shadow: 0 3px 0 #1e0b09, 0 0 0 2px #34d399; cursor: pointer; }
.customer-card.drag-hover { background: #059669; transform: scale(1.03); }

.cust-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.cust-portrait {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid #1e0b09;
  background: #7f1d1d;
  flex-shrink: 0;
}

.cust-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cust-reqs {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0;
}

.req-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  border-radius: 11px;
  border: 2px solid #1e0b09;
  background: #fff8eb;
  color: #1e0b09;
  font-weight: 700;
  font-size: 11px;
}

.req-pill-btn.ready {
  background: #d1fae5;
  box-shadow: 0 0 0 2px #34d399;
  cursor: pointer;
}

.req-pill-btn.done {
  background: #064e3b;
  color: #6ee7b7;
  opacity: 0.65;
}

.patience-track {
  width: 100%;
  height: 8px;
  background: #1e0b09;
  border-radius: 999px;
  overflow: hidden;
}

.patience-fill {
  height: 100%;
  transition: width 200ms linear;
}

/* 6x5 Board */
.board-wrap {
  position: relative;
  flex: 1;
  width: 100%;
  max-width: 660px;
  max-height: 430px;
  margin: 8px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.board-grid {
  position: relative;
  width: 100%;
  height: 100%;
  background: #7f1d1d;
  border-radius: 18px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 8px;
}

.board-cell {
  position: relative;
  border-radius: 12px;
  border: 2px solid rgba(30, 11, 9, 0.78);
  background: rgba(61, 14, 14, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  cursor: pointer;
  transition: transform 140ms ease;
}

.board-cell.has-tile { background: #5c1414; cursor: grab; }
.board-cell.has-tile:hover { background: #6e1a1a; }
.board-cell.is-selected { background: #fde68a; box-shadow: 0 0 0 3px #fff8eb; transform: scale(1.05); }
.board-cell.is-merge-hint { background: #fef3c7; box-shadow: 0 0 0 3px #f59e0b; transform: scale(1.03); }
.board-cell.is-hover-merge { background: #fef08a; box-shadow: 0 0 0 3px #10b981; transform: scale(1.06); }
.board-cell.is-hover { background: #991b1b; box-shadow: 0 0 0 2px #fbbf24; }

.tile-inner {
  width: 100%;
  height: 100%;
  padding: 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

.tile-badge-art {
  width: 82%;
  height: 76%;
  border-radius: 9px;
  border: 2px solid #1e0b09;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile-label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 10px;
  color: #fff8eb;
  line-height: 1;
  margin-top: 2px;
  max-width: 96%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile-ready-dot {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #10b981;
  border: 2px solid #1e0b09;
  color: #1e0b09;
  font-weight: 900;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.dock-row {
  width: 100%;
  max-width: 660px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.drag-ghost {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.1);
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: #fff8eb;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 640px;
  max-height: 88dvh;
  background: #fff8eb;
  color: #1e0b09;
  border-radius: 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-card.sm {
  max-width: 400px;
  padding: 24px;
  text-align: center;
  gap: 14px;
}

.modal-header {
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 3px solid #1e0b09;
  color: #fff;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

/* Animations */
@keyframes pop-in {
  0% { transform: scale(0.55); opacity: 0; }
  70% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes merge-squash {
  0% { transform: scale(0.72, 1.25); }
  55% { transform: scale(1.18, 0.86); }
  100% { transform: scale(1, 1); }
}

@keyframes float-up-fade {
  0% { transform: translate(-50%, -50%) scale(0.9); opacity: 1; }
  100% { transform: translate(-50%, calc(-50% - 38px)) scale(1.06); opacity: 0; }
}

.animate-pop-in { animation: pop-in 180ms cubic-bezier(0.16, 1, 0.3, 1) forwards; }
.animate-merge-squash { animation: merge-squash 220ms cubic-bezier(0.16, 1, 0.3, 1) forwards; }
.animate-float-up { animation: float-up-fade 850ms cubic-bezier(0.16, 1, 0.3, 1) forwards; }

@media (max-width: 640px) {
  .title-hero { padding: 0 20px 16px; }
  .hud-bar { padding: 8px 10px; }
  .hud-avatar { display: none; }
  .play-main { padding: 8px 10px; }
  .customers-grid { gap: 6px; }
  .customer-card { padding: 6px 7px; }
  .cust-portrait { width: 32px; height: 32px; border-radius: 9px; }
  .req-pill-btn { padding: 3px 5px; font-size: 10px; }
  .board-grid { padding: 6px; gap: 5px; }
  .tile-label { font-size: 9px; }
  .dock-row { gap: 6px; }
  .dock-row .cartoon-btn { padding: 8px 10px !important; }
}

@media (prefers-reduced-motion: reduce) {
  .animate-pop-in, .animate-merge-squash, .animate-float-up { animation: none !important; }
  .cartoon-btn { transition: none !important; }
}
