* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --ink: #241a14;
  --panel: #3a2c20;
  --panel-edge: #8a6a4a;
  --gold: #ffcf7d;
  --text: #fdf1dc;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--ink);
  font-family: 'Press Start 2P', monospace;
  user-select: none;
}

#game {
  display: block;
  width: 100vw; height: 100vh;
}

#vignette {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 3;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(30, 18, 8, .38) 100%);
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: 14px; left: 14px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 5;
  pointer-events: none;
}
.hud-pill {
  background: rgba(42, 30, 20, .82);
  border: 2px solid var(--panel-edge);
  border-radius: 8px;
  color: var(--text);
  font-size: 9px;
  padding: 8px 12px;
  width: fit-content;
  letter-spacing: 1px;
}
#sparks { color: var(--gold); }
#mute {
  pointer-events: auto;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  padding: 6px 10px;
}
#mute:hover { border-color: var(--gold); }

/* ---------- Area toast ---------- */
#toast {
  position: fixed;
  top: 48px; left: 50%;
  transform: translateX(-50%);
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255, 207, 125, .7), 2px 2px 0 #241206;
  font-size: 16px;
  letter-spacing: 3px;
  opacity: 0;
  transition: opacity .5s;
  z-index: 6;
  pointer-events: none;
  text-align: center;
}
#toast.show { opacity: 1; }

/* ---------- Speech bubble ---------- */
#bubble {
  position: fixed;
  transform: translate(-50%, -100%);
  width: max-content;
  max-width: min(340px, 80vw);
  background: #fff8ec;
  border: 3px solid #6a4a2c;
  border-radius: 14px;
  padding: 10px 14px 11px;
  z-index: 10;
  box-shadow: 0 6px 24px rgba(30, 15, 5, .35);
  pointer-events: none;
}
#bubble::after, #bubble::before {
  content: '';
  position: absolute;
  left: 50%; top: 100%;
  transform: translateX(-50%);
  border: solid transparent;
}
#bubble::after { border-width: 11px; border-top-color: #6a4a2c; }
#bubble::before { border-width: 8px; border-top-color: #fff8ec; margin-top: -4px; z-index: 1; }
#bubble-name {
  color: #c2578a;
  font-size: 8px;
  margin-bottom: 6px;
  letter-spacing: 1px;
}
#bubble-text {
  color: #4a3826;
  font-size: 9px;
  line-height: 1.9;
}
#bubble-hint {
  text-align: right;
  color: #b3987a;
  font-size: 7px;
  margin-top: 6px;
  animation: bounce 1s infinite;
}
@keyframes bounce { 50% { transform: translateY(3px); } }

/* ---------- Minigame / popup modal ---------- */
#modal {
  position: fixed; inset: 0;
  background: rgba(25, 14, 5, .72);
  display: flex; align-items: center; justify-content: center;
  z-index: 20;
}
#modal-card {
  position: relative;
  background: linear-gradient(180deg, #4e3c2a, #302217);
  border: 3px solid var(--panel-edge);
  border-radius: 14px;
  padding: 26px;
  min-width: 380px;
  max-width: 92vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 60px rgba(15,8,2,.8);
}
#modal-title {
  color: var(--gold);
  font-size: 13px;
  text-align: center;
  margin-bottom: 18px;
  letter-spacing: 2px;
}
#modal-body { color: var(--text); font-size: 10px; text-align: center; }
#modal-close {
  position: absolute;
  top: 10px; right: 10px;
  background: none;
  border: 2px solid var(--panel-edge);
  border-radius: 6px;
  color: #d8bc93;
  font-family: inherit;
  font-size: 10px;
  padding: 5px 8px;
  cursor: pointer;
}
#modal-close:hover { color: #fff; border-color: #fff; }

.mg-status { margin-top: 16px; font-size: 10px; min-height: 16px; color: #e5cba0; line-height: 1.7; }
.mg-row { display: flex; justify-content: center; gap: 14px; margin: 10px 0; }

/* ---------- Town map ---------- */
#map-overlay {
  position: fixed; inset: 0;
  z-index: 18;
  background: rgba(25, 14, 5, .7);
  display: flex; align-items: center; justify-content: center;
}
#map-card {
  background: linear-gradient(180deg, #4e3c2a, #302217);
  border: 3px solid var(--panel-edge);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 10px 60px rgba(15,8,2,.8);
}
#map-title { color: var(--gold); font-size: 12px; text-align: center; margin-bottom: 12px; letter-spacing: 2px; }
#map-canvas {
  display: block;
  border: 2px solid var(--panel-edge);
  border-radius: 8px;
  max-width: 80vw; max-height: 70vh;
  height: auto;
}
#map-hint { color: #c2a37c; font-size: 8px; text-align: center; margin-top: 10px; }

/* ---------- Title screen ---------- */
#title {
  position: fixed; inset: 0;
  z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: #ef9dc4;
  overflow: hidden;
}
#title-bg {
  position: absolute; inset: 0;
  background-image: url('assets/background.png');
  background-size: cover;
  background-position: center;
}
#title-content {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  gap: 48px;
}
#title-heading {
  margin: 0;
  font-family: 'Petemoss', 'Baloo 2', cursive;
  font-weight: 400;
  font-size: 108px;
  line-height: 1.15;
  color: #F0A8A8;
  text-align: center;
  text-shadow: 0 6px 18px rgba(0, 0, 0, .25);
}
.title-line {
  display: block;
  opacity: 0;
  animation: titleFadeIn .4s ease forwards;
}
#line-1 { animation-delay: .1s; }
#line-2 { animation-delay: .5s; }
@keyframes titleFadeIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
#btn-go {
  position: relative;
  overflow: hidden;
  font-family: 'Baloo 2', 'Arial Rounded MT Bold', 'Comic Sans MS', sans-serif;
  font-weight: 800;
  font-size: 28px;
  color: #F0A8A8;
  background: #F7EBEB;
  border: 5px solid #942a5c;
  border-radius: 999px;
  padding: 10px 40px 14px;
  cursor: pointer;
  box-shadow: 0 9px 0 rgba(140, 38, 86, .38);
  opacity: 0;
  transform: scale(0);
  animation: btnZoomIn .5s cubic-bezier(.34, 1.56, .64, 1) .9s forwards;
  --load: 0%;
}
#btn-go:disabled { cursor: default; }
#btn-go-fill {
  position: absolute;
  inset: 0;
  width: var(--load);
  background: #F0A8A8;
  transition: width .2s ease;
}
#btn-go-label {
  position: relative;
  z-index: 1;
  mix-blend-mode: difference;
}
#btn-go:hover:not(:disabled) { transform: translateY(-3px) scale(1.03); filter: brightness(1.04); box-shadow: 0 12px 0 rgba(140, 38, 86, .38); }
#btn-go:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 3px 0 rgba(140, 38, 86, .38); }
@keyframes btnZoomIn {
  from { opacity: 0; transform: scale(0); }
  to   { opacity: 1; transform: scale(1); }
}

/* ---------- Letter ---------- */
.letter {
  background: linear-gradient(180deg, #f8f0dc, #efe2c4);
  color: #4a3826;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 15px;
  line-height: 1.8;
  text-align: left;
  padding: 28px 10px 28px 32px;
  border-radius: 6px;
  width: 470px;
  max-width: 100%;
  box-shadow: inset 0 0 40px rgba(120,90,40,.18), 0 6px 24px rgba(0,0,0,.4);
}
.letter-scroll {
  max-height: min(52vh, 480px);
  overflow-y: auto;
  padding-right: 22px;
}
.letter-scroll::-webkit-scrollbar { width: 8px; }
.letter-scroll::-webkit-scrollbar-track { background: rgba(120,90,40,.12); border-radius: 4px; }
.letter-scroll::-webkit-scrollbar-thumb { background: rgba(120,90,40,.4); border-radius: 4px; }
.letter-scroll::-webkit-scrollbar-thumb:hover { background: rgba(120,90,40,.6); }
.letter p { margin-bottom: 14px; }
.letter p:last-child { margin-bottom: 0; }
.letter-sign { text-align: right; font-style: italic; margin-top: 18px; }

/* ---------- Photo wall ---------- */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px 16px;
  max-width: 560px;
  padding: 10px 4px;
}
.polaroid {
  background: #fdfdf8;
  padding: 7px 7px 18px;
  box-shadow: 0 5px 14px rgba(0,0,0,.45);
  transition: transform .15s;
}
.polaroid img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.polaroid .cap {
  font-family: Georgia, serif;
  font-style: italic;
  color: #7a6a55;
  font-size: 11px;
  margin-top: 6px;
  text-align: center;
}
.r0 { transform: rotate(-3deg); }
.r1 { transform: rotate(2.5deg); }
.r2 { transform: rotate(-2deg); }
.r3 { transform: rotate(3.5deg); }
.r4 { transform: rotate(-3.5deg); }
.polaroid:hover { transform: rotate(0) scale(1.08); position: relative; z-index: 2; }

/* ---------- Flower drawing pad ---------- */
.draw-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; }
#draw-pad {
  background: #fdf9ef;
  border: 2px solid var(--panel-edge);
  border-radius: 10px;
  cursor: crosshair;
  touch-action: none;
}
.draw-tools { display: flex; gap: 8px; align-items: center; }
.swatch {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 3px solid #241206;
  cursor: pointer;
}
.swatch.on { border-color: #fff; transform: scale(1.15); }
#draw-clear {
  font-family: inherit;
  font-size: 10px;
  background: #5a4630;
  color: #d8bc93;
  border: 2px solid var(--panel-edge);
  border-radius: 6px;
  padding: 6px 9px;
  cursor: pointer;
}
#plant-btn {
  font-family: inherit;
  font-size: 11px;
  background: var(--gold);
  color: #3a2412;
  border: none;
  border-radius: 8px;
  padding: 12px 18px;
  cursor: pointer;
  letter-spacing: 1px;
}
#plant-btn:hover { filter: brightness(1.15); }

/* ---------- Race car picker ---------- */
.car-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 560px;
  margin: 0 auto 14px;
}
.car-opt {
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: #43331f;
  border: 3px solid var(--panel-edge);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
}
.car-opt:last-child { grid-column: 1 / -1; max-width: 270px; width: 100%; justify-self: center; }
.car-opt img { width: 100%; max-width: 220px; image-rendering: pixelated; pointer-events: none; }
.car-opt:hover { filter: brightness(1.12); }
.car-opt.on { border-color: var(--gold); background: #574327; }
.car-name { font-size: 9px; color: var(--gold); letter-spacing: 1px; }
#car-go {
  font-family: inherit;
  font-size: 11px;
  background: var(--gold);
  color: #3a2412;
  border: none;
  border-radius: 8px;
  padding: 12px 22px;
  cursor: pointer;
  letter-spacing: 1px;
}
#car-go:hover { filter: brightness(1.15); }

/* ---------- Workbench ---------- */
.wb-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  max-width: 560px;
}
.wb-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #43331f;
  border: 2px solid var(--panel-edge);
  border-radius: 10px;
  padding: 12px;
  text-align: left;
}
.wb-icon { font-size: 26px; }
.wb-info { flex: 1; min-width: 0; }
.wb-name { color: var(--gold); font-size: 9px; margin-bottom: 6px; }
.wb-desc { font-size: 8px; color: #e5cba0; line-height: 1.6; }
.wb-take {
  font-family: inherit;
  font-size: 8px;
  color: #3a2412;
  background: var(--gold);
  border: none;
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
}
.wb-take:hover:not(:disabled) { filter: brightness(1.15); }
.wb-take:disabled { background: #6a563e; color: #cbb090; cursor: default; }

/* ---------- grand prix ---------- */
#race-canvas {
  display: block;
  border: 3px solid var(--panel-edge);
  border-radius: 12px;
  background: #1c2650;
  max-width: 86vw;
  height: auto;
}
