/* Cozy Patch World — Paper Craft Stylesheet (?v=1.2.0) */
:root {
  --paper-cream: #fdf8ee;
  --paper-warm: #f5e8cf;
  --paper-card: #fffdf8;
  --paper-edge: #e4d4b7;
  --ink-dark: #2c241b;
  --ink-muted: #5a4b3c;
  --accent-moss: #4d7c3f;
  --accent-moss-dark: #345929;
  --accent-berry: #c94a4a;
  --accent-amber: #d9822b;
  --accent-sky: #3b7ea1;
  --border-craft: #bfa886;
  --shadow-cut:
    0 2px 0 #e6d8be,
    0 5px 0 rgba(44, 36, 27, 0.22),
    0 12px 24px rgba(44, 36, 27, 0.18);
  --shadow-btn: 0 4px 0 #28451f, 0 7px 12px rgba(44, 36, 27, 0.2);
  --font-display: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #cbe0b5;
  color: var(--ink-dark);
  font-family: var(--font-body);
  touch-action: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#world-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: pointer;
}

/* Layered paper-cut card with subtle fiber grain & inner deckle rim */
.paper-panel {
  background: var(--paper-card);
  background-image:
    radial-gradient(rgba(148, 118, 78, 0.08) 1px, transparent 0),
    radial-gradient(rgba(96, 128, 74, 0.05) 1px, transparent 0);
  background-size: 14px 14px, 23px 23px;
  background-position: 0 0, 7px 9px;
  border: 3px solid var(--border-craft);
  outline: 2px dashed rgba(176, 148, 110, 0.45);
  outline-offset: -7px;
  border-radius: 24px;
  box-shadow: var(--shadow-cut);
  color: var(--ink-dark);
}

/* Top HUD */
#hud-top {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
  z-index: 20;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
  flex-wrap: wrap;
}

.hud-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: linear-gradient(180deg, #fffef9 0%, #f7edd9 100%);
  border: 2.5px solid var(--border-craft);
  border-radius: 999px;
  box-shadow: 0 3px 0 rgba(44, 36, 27, 0.2), inset 0 1px 0 #ffffff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  color: var(--ink-dark);
  cursor: pointer;
  min-height: 44px;
}

.hud-pill:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(44, 36, 27, 0.18);
}

.hud-pill.static {
  cursor: default;
}

.hud-pill.static:active {
  transform: none;
}

/* Buttons */
.craft-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  min-height: 48px;
  border-radius: 18px;
  border: 2.5px solid #28451f;
  background: linear-gradient(180deg, #5d914d 0%, var(--accent-moss) 100%);
  color: #ffffff;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-btn), inset 0 2px 0 rgba(255, 255, 255, 0.28);
  transition: transform 0.08s ease;
}

.craft-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #28451f;
}

.craft-btn.secondary {
  background: linear-gradient(180deg, #fcf5e6 0%, var(--paper-warm) 100%);
  color: var(--ink-dark);
  border-color: var(--border-craft);
  box-shadow: 0 4px 0 #a38d6f, inset 0 2px 0 #ffffff;
}

.craft-btn.secondary:active {
  box-shadow: 0 1px 0 #a38d6f;
}

.craft-btn.amber {
  background: linear-gradient(180deg, #e8963c 0%, var(--accent-amber) 100%);
  border-color: #965110;
  box-shadow: 0 4px 0 #965110, inset 0 2px 0 rgba(255, 255, 255, 0.3);
}

.craft-btn.amber:active {
  box-shadow: 0 1px 0 #965110;
}

.craft-btn.small {
  padding: 8px 14px;
  min-height: 40px;
  font-size: 15px;
  border-radius: 13px;
}

/* Floating Action Prompt near Player */
#context-bar {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 18;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(92vw, 450px);
  pointer-events: none;
}

#speech-banner {
  pointer-events: auto;
  width: 100%;
  padding: 13px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 16px;
  line-height: 1.38;
  font-weight: 600;
}

#speech-banner.hidden,
.hidden {
  display: none !important;
}

#action-prompts {
  pointer-events: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

/* Modal Overlays */
.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(34, 28, 20, 0.54);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  z-index: 40;
}

.modal-card {
  width: min(96vw, 680px);
  max-height: 92vh;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Splash Screen */
#splash-overlay {
  z-index: 60;
  background: rgba(32, 46, 28, 0.68);
}

#splash-card {
  width: min(95vw, 580px);
  padding: 20px;
  text-align: center;
}

#splash-demo-canvas {
  width: 100%;
  height: 190px;
  border-radius: 18px;
  border: 3px solid var(--border-craft);
  box-shadow: inset 0 2px 6px rgba(44, 36, 27, 0.14);
  background: #e5f3d8;
  display: block;
}

.splash-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 4px 0;
}

.splash-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #d5c7b2;
  border: 2px solid #9c8970;
}

.splash-dot.active {
  background: var(--accent-moss);
  border-color: #2d4b23;
  transform: scale(1.2);
}

/* Activity Stage */
#activity-overlay {
  z-index: 50;
}

#activity-card {
  width: min(97vw, 760px);
  max-height: 94vh;
  padding: 16px 18px;
}

.activity-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.progress-pips {
  display: flex;
  gap: 6px;
  align-items: center;
}

.pip {
  width: 22px;
  height: 12px;
  border-radius: 999px;
  background: #e3d6c1;
  border: 2px solid #b5a184;
}

.pip.done-first {
  background: #5ca146;
  border-color: #356626;
}

.pip.done-hint {
  background: #e5a93b;
  border-color: #9c6b14;
}

.pip.done-shown {
  background: #7aa6c2;
  border-color: #3f6a85;
}

.pip.current {
  border-color: var(--ink-dark);
  transform: scale(1.12);
}

.task-prompt-box {
  background: var(--paper-warm);
  border: 2.5px solid var(--border-craft);
  border-radius: 16px;
  padding: 12px 15px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--ink-dark);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.hint-box {
  background: #fff4d9;
  border: 2.5px solid #d99b26;
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 16px;
  font-weight: 600;
  color: #4d3508;
}

#activity-board {
  min-height: 260px;
  background: #f1e6d0;
  background-image: radial-gradient(rgba(148, 118, 78, 0.09) 1px, transparent 0);
  background-size: 12px 12px;
  border: 2.5px solid var(--border-craft);
  border-radius: 18px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  position: relative;
  box-shadow: inset 0 2px 6px rgba(44, 36, 27, 0.1);
}

.activity-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

/* Interactive tokens & drop zones */
.token-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  align-items: center;
}

.craft-token {
  min-width: 58px;
  min-height: 58px;
  padding: 8px 14px;
  border-radius: 16px;
  background: linear-gradient(180deg, #fffefb 0%, #f8efe0 100%);
  border: 3px solid #9e8768;
  box-shadow: 0 4px 0 rgba(44, 36, 27, 0.22), inset 0 1px 0 #ffffff;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 800;
  color: var(--ink-dark);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  touch-action: none;
  transition: transform 0.1s ease, border-color 0.1s ease;
}

.craft-token.selected {
  border-color: var(--accent-moss);
  background: #eaf7e4;
  transform: translateY(-4px) scale(1.05);
}

.craft-token.glow-hint {
  border-color: #e09119;
  box-shadow: 0 0 0 4px rgba(224, 145, 25, 0.35);
}

.craft-token:disabled,
.craft-token.used {
  opacity: 0.38;
  pointer-events: none;
}

.drop-zone-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 10px;
}

.drop-zone {
  min-height: 98px;
  padding: 10px;
  border-radius: 18px;
  border: 3px dashed #8c775b;
  background: rgba(255, 253, 248, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  box-shadow: inset 0 2px 4px rgba(44, 36, 27, 0.08);
}

.drop-zone.drag-over {
  border-style: solid;
  border-color: var(--accent-moss);
  background: #e3f5dc;
}

/* Drag ghost */
#drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 100;
  transform: translate(-50%, -50%) scale(1.08);
  opacity: 0.94;
}

/* Backpack Drawer */
#backpack-drawer {
  position: absolute;
  bottom: 10px;
  left: 10px;
  right: 10px;
  z-index: 30;
  padding: 14px 16px;
  max-height: 44vh;
  overflow-y: auto;
}

.backpack-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.deco-chip {
  padding: 8px 12px;
  border-radius: 14px;
  border: 2.5px solid var(--border-craft);
  background: var(--paper-warm);
  font-weight: 700;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  min-height: 44px;
  box-shadow: 0 2px 0 rgba(44, 36, 27, 0.15);
}

.deco-chip.placed {
  background: #e5f3de;
  border-color: var(--accent-moss);
}

/* Fallback error panel */
#canvas-fallback {
  position: absolute;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e7decb;
  padding: 20px;
}

/* Phone responsiveness (390x844 and narrow viewports) */
@media (max-width: 480px) {
  .hud-pill {
    padding: 6px 10px;
    font-size: 14px;
    min-height: 40px;
  }
  .craft-btn {
    padding: 10px 14px;
    font-size: 15px;
    min-height: 44px;
  }
  .task-prompt-box {
    font-size: 16px;
    padding: 10px 12px;
  }
  .craft-token {
    min-width: 50px;
    min-height: 50px;
    font-size: 18px;
    padding: 6px 10px;
  }
  .drop-zone-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  #splash-demo-canvas {
    height: 155px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
