:root {
  --sky: #efe7c1;
  --grass: #9bb565;
  --earth: #866141;
  --wood: #6e4b31;
  --wood-dark: #342015;
  --cream: rgba(244, 232, 197, 0.93);
  --accent: #d7b15b;
  --accent-strong: #b95b2d;
  --panel-shadow: rgba(34, 22, 14, 0.28);
  --ink-soft: #604630;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(255, 244, 214, 0.65), transparent 35%),
    linear-gradient(180deg, #d0c68d 0%, #95a15e 100%);
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  color: var(--wood-dark);
}

body { overflow: hidden; }

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

.hidden { display: none !important; }
.hud, .overlay, .screen-panel { position: absolute; inset: 0; }
.hud { pointer-events: none; }

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

.reward-pop {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 10px 14px;
  border-radius: 999px;
  border: 3px solid rgba(58, 34, 19, 0.18);
  font-size: 1rem;
  font-weight: 900;
  box-shadow: 0 8px 0 rgba(49, 26, 13, 0.16);
  animation: reward-rise 1.2s ease-out forwards;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.reward-gold {
  background: linear-gradient(180deg, #fbefba 0%, #d9a83d 100%);
  color: var(--wood-dark);
}

.reward-green {
  background: linear-gradient(180deg, #ddeeb5 0%, #87bc54 100%);
  color: var(--wood-dark);
}

.reward-blue {
  background: linear-gradient(180deg, #dff1fb 0%, #73aeca 100%);
  color: var(--wood-dark);
}

.celebration-banner {
  position: absolute;
  left: 50%;
  top: 20px;
  transform: translateX(-50%);
  padding: 14px 22px;
  border-radius: 18px;
  border: 4px solid var(--wood-dark);
  background: linear-gradient(180deg, #f6efcf 0%, #d9b151 100%);
  box-shadow: 0 12px 0 rgba(47, 28, 16, 0.22);
  font-size: clamp(0.95rem, 1.8vw, 1.2rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--wood-dark);
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 12px;
}

.celebration-pop { animation: celebration-pop 1.8s ease forwards; }

.celebration-check {
  color: #2f8d46;
  font-size: 1.25em;
  line-height: 1;
}

.guide-panel,
.prompt-bubble,
.overlay-card,
.screen-card,
.hotbar-wrap {
  background: var(--cream);
  border: 4px solid var(--wood-dark);
  box-shadow: 0 10px 0 var(--panel-shadow);
}

.guide-panel {
  position: absolute;
  top: 18px;
  left: 18px;
  width: min(420px, calc(100vw - 170px));
  min-height: 88px;
  padding: 10px 12px;
  border-radius: 20px;
  pointer-events: auto;
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 10px;
  align-items: center;
  backdrop-filter: blur(4px);
}

.guide-portrait {
  width: 100%;
  aspect-ratio: 488 / 502;
  object-fit: cover;
  border-radius: 16px;
  border: 3px solid rgba(52, 32, 21, 0.18);
  background: linear-gradient(180deg, #f5dca4 0%, #c78a4c 100%);
}

.guide-name {
  font-size: 1rem;
  font-weight: 900;
  margin-bottom: 4px;
}

.guide-text {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.28;
  font-weight: 700;
  font-size: 0.95rem;
}

.subtle {
  margin: 0;
  color: var(--ink-soft);
}

.quest-panel-eyebrow,
.hotbar-caption {
  font-size: 0.82rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent-strong);
}

.objective-title {
  margin: 0;
  font-size: clamp(1.2rem, 2vw, 1.55rem);
  line-height: 1.1;
}

.objective-detail {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.35;
  font-weight: 700;
}

.quest-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 250px;
  overflow: auto;
}

.future-days {
  display: grid;
  gap: 10px;
}

.debug-panel {
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 2px dashed rgba(52, 32, 21, 0.22);
  background: rgba(255, 244, 214, 0.72);
}

.debug-button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.debug-skip-button {
  padding: 10px 14px;
  border: 3px solid var(--wood-dark);
  border-radius: 14px;
  background: linear-gradient(180deg, #f6df9b 0%, #dca94e 100%);
  color: var(--wood-dark);
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

.future-day-card {
  padding: 12px 14px;
  border-radius: 16px;
  border: 2px solid rgba(52, 32, 21, 0.14);
  background: rgba(255, 248, 229, 0.72);
}

.future-day-title {
  font-weight: 900;
  font-size: 0.9rem;
}

.future-day-copy {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 0.88rem;
  line-height: 1.35;
  font-weight: 700;
}

.quest-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 14px;
  border: 2px solid rgba(52, 32, 21, 0.14);
  background: rgba(255, 247, 221, 0.72);
}

.quest-item.active {
  border-color: rgba(185, 91, 45, 0.5);
  background: linear-gradient(180deg, rgba(255, 234, 180, 0.95) 0%, rgba(228, 194, 109, 0.92) 100%);
  transform: translateY(-1px);
}

.quest-item.done {
  border-color: rgba(84, 128, 60, 0.42);
  background: linear-gradient(180deg, rgba(227, 244, 205, 0.92) 0%, rgba(188, 220, 145, 0.9) 100%);
}

.quest-item-title {
  font-weight: 800;
  font-size: 0.94rem;
}

.quest-item-progress {
  min-width: 42px;
  text-align: center;
  font-weight: 900;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(52, 32, 21, 0.08);
}

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

.resource-pill {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(88, 60, 38, 0.08);
  border: 2px solid rgba(52, 32, 21, 0.1);
  font-size: 0.85rem;
  font-weight: 800;
}

.resource-pill strong {
  font-size: 0.9rem;
}

.hotbar-wrap {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: min(860px, calc(100vw - 24px));
  padding: 10px 12px;
  border-radius: 28px;
  pointer-events: auto;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}

.hotbar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
  min-width: 100%;
}

.hotbar-slot {
  position: relative;
  min-width: 92px;
  min-height: 88px;
  border-radius: 16px;
  border: 3px solid rgba(52, 32, 21, 0.18);
  background: linear-gradient(180deg, rgba(144, 119, 87, 0.2) 0%, rgba(62, 43, 31, 0.28) 100%);
  color: rgba(52, 32, 21, 0.55);
  display: grid;
  grid-template-rows: auto auto auto;
  justify-items: center;
  align-content: center;
  gap: 3px;
  padding: 8px 6px 6px;
  font: inherit;
  cursor: pointer;
  box-shadow: inset 0 -6px 0 rgba(52, 32, 21, 0.08);
}

.hotbar-slot.available {
  background: linear-gradient(180deg, rgba(255, 246, 223, 0.98) 0%, rgba(208, 177, 116, 0.88) 100%);
  color: var(--wood-dark);
}

.hotbar-slot.selected {
  transform: translateY(-5px);
  border-color: #fff0b2;
  box-shadow: 0 0 0 3px rgba(196, 149, 49, 0.65), inset 0 -8px 0 rgba(52, 32, 21, 0.08);
}

.hotbar-slot:disabled {
  cursor: default;
}

.slot-key {
  position: absolute;
  top: 6px;
  left: 8px;
  font-size: 0.75rem;
  font-weight: 900;
  opacity: 0.85;
}

.slot-art {
  width: 34px;
  height: 34px;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  filter: drop-shadow(0 2px 0 rgba(52, 32, 21, 0.18));
}

.slot-name {
  font-size: 0.74rem;
  font-weight: 800;
  text-align: center;
  line-height: 1.1;
}

.slot-detail {
  min-width: 44px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(52, 32, 21, 0.1);
  font-size: 0.66rem;
  font-weight: 900;
  text-align: center;
}

.hud-controls {
  position: absolute;
  right: 16px;
  bottom: 128px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border-radius: 999px;
  background: rgba(244, 232, 197, 0.95);
  border: 3px solid rgba(52, 32, 21, 0.88);
  box-shadow: 0 8px 0 rgba(34, 22, 14, 0.18);
  pointer-events: auto;
}

.zoom-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.zoom-button,
.pause-fab,
.icon-button.small {
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  border-width: 3px;
  border-radius: 999px;
  box-shadow: 0 4px 0 rgba(75, 48, 33, 0.18);
}

.prompt-bubble {
  position: absolute;
  right: 20px;
  bottom: 140px;
  max-width: min(360px, calc(100vw - 40px));
  padding: 14px 16px;
  border-radius: 18px;
  pointer-events: none;
  font-size: 0.98rem;
  line-height: 1.35;
  font-weight: 800;
}

.screen-panel, .overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(81, 60, 39, 0.26);
  backdrop-filter: blur(4px);
}

#startScreen {
  flex-direction: column;
  gap: 20px;
  background: linear-gradient(180deg, rgba(34, 21, 13, 0.68) 0%, rgba(86, 61, 39, 0.26) 55%, rgba(81, 60, 39, 0.18) 100%);
}

.day-night-wash {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 22%, rgba(255, 238, 187, 0.78), transparent 22%),
    linear-gradient(180deg, rgba(35, 53, 102, 0.08) 0%, rgba(14, 24, 54, 0.12) 100%);
  opacity: 0;
  pointer-events: none;
}

.day-night-wash.cycle-active {
  animation: day-night-cycle 4.3s ease-in-out forwards;
}

.screen-card, .overlay-card {
  width: min(700px, 100%);
  max-height: min(92vh, 780px);
  overflow: auto;
  border-radius: 28px;
  padding: 24px;
}

.pause-card {
  width: min(760px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.intro-card {
  width: min(840px, 100%);
  text-align: center;
}

.logo-stage {
  display: grid;
  place-items: center;
  width: min(900px, calc(100vw - 40px));
  min-height: 40vh;
  transition: opacity 520ms ease, transform 520ms ease;
}

.logo-stage.logo-fade {
  opacity: 0;
  transform: scale(1.03);
}

.logo-image {
  width: min(760px, 92vw);
  image-rendering: auto;
  filter: drop-shadow(0 18px 36px rgba(0, 0, 0, 0.32));
}

.intro-dialogue-card {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: minmax(220px, 300px) 1fr;
  gap: 24px;
  align-items: center;
  background: rgba(248, 238, 209, 0.97);
}

.intro-grandpa {
  display: grid;
  place-items: center;
}

.intro-farmer-portrait {
  width: min(280px, 100%);
  aspect-ratio: 488 / 502;
  object-fit: cover;
  border-radius: 22px;
  border: 4px solid rgba(52, 32, 21, 0.22);
  background: linear-gradient(180deg, #f5dca4 0%, #c78a4c 100%);
}

.intro-copy {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.intro-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.intro-title {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.3rem);
  line-height: 1;
}

.character-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 10px;
}

.name-field {
  margin-top: 8px;
  font-weight: 900;
  color: var(--wood-dark);
}

.name-input {
  width: min(360px, 100%);
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: 16px;
  border: 3px solid rgba(52, 32, 21, 0.2);
  background: rgba(255, 248, 229, 0.95);
  color: var(--wood-dark);
  font: inherit;
  font-weight: 700;
}

.character-card {
  border: 4px solid var(--wood-dark);
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(255, 245, 213, 0.98) 0%, rgba(214, 177, 92, 0.92) 100%);
  color: var(--wood-dark);
  font: inherit;
  font-weight: 900;
  font-size: 1.1rem;
  padding: 16px;
  display: grid;
  gap: 10px;
  justify-items: center;
  cursor: pointer;
  box-shadow: 0 10px 0 rgba(47, 28, 16, 0.22);
}

.character-card:hover {
  background: rgba(255, 245, 213, 0.98);
}

.character-card img {
  width: min(220px, 100%);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.character-card.selected {
  transform: translateY(-3px);
  box-shadow: 0 0 0 3px rgba(196, 149, 49, 0.65), 0 10px 0 rgba(47, 28, 16, 0.22);
}

.primary-button, .icon-button, .overlay-action {
  border: 4px solid var(--wood-dark);
  border-radius: 16px;
  background: linear-gradient(180deg, #f0cb75 0%, #d19e3f 100%);
  color: var(--wood-dark);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(75, 48, 33, 0.18);
  padding: 20px;
}

.primary-button {
  margin-top: 20px;
  width: 100%;
}

.primary-button:hover, .icon-button:hover, .overlay-action {
  background: #f0cb75;
}

.icon-button { min-width: 48px; min-height: 48px; }
.icon-button.small { min-width: 42px; min-height: 42px; }

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

.overlay-content { display: flex; flex-direction: column; gap: 16px; margin-top: 18px; }
.mini-grid, .sequence-row, .shape-row, .count-controls { display: flex; flex-wrap: wrap; gap: 12px; }
.mini-slot, .overlay-action { min-height: 64px; padding: 12px 16px; }
.mini-slot {
  display: grid;
  place-items: center;
  min-width: 72px;
  border-radius: 18px;
  border: 4px dashed rgba(75, 48, 33, 0.22);
  background: #fff9ef;
  font-weight: 800;
}

.mini-slot.filled { background: #dcf1c0; border-style: solid; }
.overlay-action.selected { background: #ffd47e; }

.count-display {
  font-size: clamp(2rem, 7vw, 4rem);
  font-weight: 900;
  text-align: center;
  color: var(--accent-strong);
}

.help-text {
  padding: 12px 14px;
  background: #f4e3b0;
  border-radius: 16px;
  font-weight: 700;
}

@keyframes reward-rise {
  0% {
    opacity: 0;
    transform: translate(-50%, -10px) scale(0.85);
  }
  12% {
    opacity: 1;
    transform: translate(-50%, -18px) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -74px) scale(1.04);
  }
}

@keyframes celebration-pop {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(-10px) scale(0.92);
  }
  12% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
  82% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) translateY(-8px) scale(0.98);
  }
}

@keyframes day-night-cycle {
  0% {
    opacity: 0;
    background:
      radial-gradient(circle at 50% 22%, rgba(255, 238, 187, 0.78), transparent 22%),
      linear-gradient(180deg, rgba(35, 53, 102, 0.08) 0%, rgba(14, 24, 54, 0.12) 100%);
  }
  22% {
    opacity: 0.7;
  }
  48% {
    opacity: 0.95;
    background:
      radial-gradient(circle at 70% 18%, rgba(255, 255, 255, 0.2), transparent 18%),
      linear-gradient(180deg, rgba(17, 26, 59, 0.82) 0%, rgba(7, 11, 29, 0.88) 100%);
  }
  76% {
    opacity: 0.88;
    background:
      radial-gradient(circle at 42% 20%, rgba(255, 235, 164, 0.6), transparent 19%),
      linear-gradient(180deg, rgba(236, 190, 128, 0.44) 0%, rgba(132, 180, 110, 0.24) 100%);
  }
  100% {
    opacity: 0;
    background:
      radial-gradient(circle at 50% 22%, rgba(255, 238, 187, 0.78), transparent 22%),
      linear-gradient(180deg, rgba(35, 53, 102, 0.08) 0%, rgba(14, 24, 54, 0.12) 100%);
  }
}

@media (max-width: 980px) {
  .guide-panel {
    width: min(360px, calc(100vw - 140px));
  }
}

@media (max-width: 700px) {
  .intro-dialogue-card {
    grid-template-columns: 1fr;
  }

  .intro-farmer-portrait {
    width: min(220px, 70vw);
  }

  .intro-copy {
    text-align: center;
  }

  .intro-actions {
    justify-content: center;
  }

  .guide-panel {
    top: 12px;
    left: 12px;
    right: 12px;
    bottom: auto;
    width: auto;
    min-height: 76px;
    grid-template-columns: 60px 1fr;
    gap: 8px;
    padding: 8px 10px;
  }

  .guide-name {
    font-size: 0.92rem;
  }

  .guide-text {
    font-size: 0.82rem;
    line-height: 1.2;
  }

  .resource-strip {
    grid-template-columns: 1fr 1fr;
  }

  .hotbar-wrap {
    width: calc(100vw - 12px);
    bottom: 10px;
    padding: 8px 10px;
  }

  .hotbar {
    gap: 8px;
    min-width: max(100%, 560px);
  }

  .hotbar-slot {
    min-width: 72px;
    min-height: 72px;
    padding: 6px 5px;
  }

  .slot-art {
    width: 26px;
    height: 26px;
  }

  .slot-name {
    font-size: 0.62rem;
  }

  .slot-detail {
    font-size: 0.58rem;
    min-width: 36px;
  }

  .hud-controls {
    bottom: 125px;
    right: 12px;
    padding: 5px;
  }

  .zoom-controls {
    gap: 6px;
  }

  .celebration-banner {
    top: 12px;
    width: calc(100vw - 24px);
    text-align: center;
  }

}
