* { box-sizing: border-box; }

:root {
  --tile: 46px;
  --cols: 16;
  --rows: 11;
}

html, body {
  width: 100%; height: 100%;
  margin: 0; padding: 0;
  font-family: 'Segoe UI', 'Malgun Gothic', sans-serif;
  background: linear-gradient(180deg, #e8f5e9 0%, #f1f8e9 100%);
  color: #2c3e2d;
  overscroll-behavior: none;
}
img { image-rendering: pixelated; user-select: none; -webkit-user-drag: none; }

#app {
  max-width: 1280px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 10px 14px 80px;
}

/* ===== Top bar / tracker ===== */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px;
  background: #2e7d32; color: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.topbar .title { font-weight: 700; font-size: 18px; }
.topbar .status { display: flex; gap: 8px; }
.badge {
  background: rgba(255,255,255,0.18);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
}
.badge span { font-weight: 700; }

.phase-tracker { display: flex; gap: 4px; margin: 10px 0; }
.step {
  flex: 1; padding: 8px; text-align: center;
  background: #fff; border-radius: 8px; font-size: 13px;
  color: #999; border: 2px solid transparent;
  transition: all 0.2s;
}
.step span {
  display: inline-block;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #ddd; color: #fff;
  font-weight: 700;
  margin-right: 4px;
  line-height: 20px;
}
.step.active { color: #2e7d32; border-color: #2e7d32; background: #f1f8e9; }
.step.active span { background: #2e7d32; }
.step.done { color: #66bb6a; }
.step.done span { background: #66bb6a; }

/* ===== Main layout ===== */
main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 12px;
  min-height: 560px;
}

/* ===== Tile-grid map ===== */
#map-stage {
  position: relative;
  width: calc(var(--cols) * var(--tile));
  height: calc(var(--rows) * var(--tile));
  border: 4px solid #6d4c41;
  border-radius: 14px;
  background: #8bc34a;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  overflow: hidden;
  outline: none;
  justify-self: center;
  align-self: start;
}
#map-stage:focus { box-shadow: 0 0 0 3px #66bb6a, 0 2px 12px rgba(0,0,0,0.18); }

#ground-layer, #obj-layer, #fx-layer {
  position: absolute; inset: 0;
}
#fx-layer { pointer-events: none; }

.tile, .map-obj, .zone-card, .char, .fx, .zone-water-outside, .zone-desc-chip, .item-fx {
  position: absolute;
  left: calc(var(--col) * var(--tile));
  top:  calc(var(--row) * var(--tile));
  width: calc(var(--w, 1) * var(--tile));
  height: calc(var(--h, 1) * var(--tile));
}

.tile.grass {
  background-image: url('./assets/images/tiles/grass/1.png');
  background-size: var(--tile) var(--tile);
  background-repeat: repeat;
}

/* Solid props - 더 크게 보이도록 */
.map-obj { display: flex; flex-direction: column; align-items: center; }
.map-obj img {
  width: 100%; height: 100%;
  object-fit: contain;
  filter: drop-shadow(2px 3px 2px rgba(0,0,0,0.15));
}
.map-obj.building img,
.map-obj.shop img,
.map-obj.weed img {
  transform: scale(1.08);
  transform-origin: bottom center;
}
.map-obj.tree {
  overflow: visible;
  z-index: 4;
}
.map-obj.tree img {
  transform: scale(1.35);
  transform-origin: bottom center;
}
.map-obj .lbl {
  position: absolute;
  bottom: -2px; left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  background: rgba(255,255,255,0.9);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid #8d6e63;
  color: #3e2723;
  font-weight: 700;
  white-space: nowrap;
  z-index: 3;
}
.map-obj.shop .lbl { background: #fff59d; border-color: #f9a825; }

/* Zone cards (2x2 그리드, 더 작게) */
.zone-card {
  background-image: url('./assets/images/tiles/soil/5.png');
  background-size: var(--tile) var(--tile);
  background-repeat: repeat;
  border: 2px solid #5d4037;
  border-radius: 6px;
  cursor: pointer;
  overflow: visible;
  z-index: 2;
}
.zone-card .z-tag {
  position: absolute;
  top: -10px; left: -4px;
  background: #2e7d32; color: #fff;
  font-weight: 900; font-size: 13px;
  padding: 2px 7px;
  border-radius: 6px;
  z-index: 4;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.zone-card.adjacent  { box-shadow: 0 0 0 3px #1976d2 inset; }
.zone-card.menu-open { box-shadow: 0 0 0 3px #d84315 inset; }
.zone-card.watered   { animation: waterPulse 0.6s; }
@keyframes waterPulse {
  0%   { box-shadow: 0 0 0 0 rgba(33,150,243,0.7) inset; }
  100% { box-shadow: 0 0 0 12px rgba(33,150,243,0) inset; }
}

/* Pots inside zone (작물 이미지를 크게) */
.zone-card .z-pots {
  position: absolute;
  inset: 6px 4px 6px 4px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  align-content: center;
  justify-content: center;
  gap: 2px;
  pointer-events: none;
}
.zone-card .z-pots .gpot {
  width: 100%; aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
}
.zone-card .z-pots .gpot img {
  width: 100%; height: 100%;
  object-fit: contain;
}
/* 완두콩은 조금 더 크게 (이미지에 여백이 있어서) */
.zone-card .z-pots .gpot.pea img { transform: scale(1.45); }

/* Pest overlay (bugs.png) */
.zone-card .z-pest {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: none;
  z-index: 5;
}
.zone-card .z-pest.active { display: flex; align-items: center; justify-content: center; }
.zone-card .z-pest img {
  width: 70%; height: 70%;
  object-fit: contain;
  animation: pestWiggle 0.6s ease-in-out infinite alternate;
  filter: drop-shadow(1px 1px 2px rgba(0,0,0,0.4));
}
@keyframes pestWiggle {
  from { transform: translateY(0) rotate(-6deg); }
  to   { transform: translateY(-3px) rotate(6deg); }
}

/* Boar countdown gauge over zone */
.zone-card .boar-timer {
  position: absolute;
  left: 4px; right: 4px;
  top: 18px;
  height: 6px;
  background: rgba(0,0,0,0.4);
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.6);
  display: none;
  z-index: 6;
}
.zone-card .boar-timer.active { display: block; }
.zone-card .boar-timer .fill {
  height: 100%;
  background: #ef5350;
  width: 100%;
  transition: width 0.2s linear;
}

/* Water bar - now placed BELOW the zone, outside */
.zone-water-outside {
  height: calc(var(--tile) * 0.85);
  pointer-events: none;
  display: flex; flex-direction: column; justify-content: center;
  gap: 2px;
  padding: 1px 2px;
  z-index: 2;
}
.zone-water-outside .planted-line {
  font-size: 11px;
  text-align: center;
  font-weight: 700;
  color: #1b5e20;
  background: rgba(255,255,255,0.95);
  border: 1px solid #66bb6a;
  border-radius: 4px;
  padding: 0 4px;
  line-height: 1.25;
  min-height: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.zone-water-outside .planted-line.empty { display: none; }
.zone-water-outside .water-bar {
  height: 8px;
  background: rgba(0,0,0,0.35);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid #fff;
}
.zone-water-outside .water-bar .fill {
  height: 100%; width: 30%;
  transition: width 0.2s, background 0.2s;
  border-radius: 3px;
}
.zone-water-outside .water-bar .fill.dry  { background: #e53935; }
.zone-water-outside .water-bar .fill.good { background: #43a047; }
.zone-water-outside .water-bar .fill.over { background: #1e88e5; }
.zone-water-outside .water-label {
  font-size: 9px;
  color: #1b3a1c;
  text-align: center;
  font-weight: 700;
  text-shadow: 0 0 3px #fff, 0 0 2px #fff;
  margin-top: 1px;
  line-height: 1;
}

/* Zone description chip (밭에서 위로 떼서 표시) */
.zone-desc-chip {
  height: calc(var(--tile) * 0.42);
  width: calc(var(--w) * var(--tile));
  top: calc((var(--row) - 0.78) * var(--tile));
  font-size: 10px;
  background: rgba(255,255,255,0.92);
  color: #4e342e;
  border-radius: 4px;
  padding: 2px 4px;
  text-align: center;
  font-weight: 600;
  border: 1px solid #8d6e63;
  pointer-events: none;
  z-index: 3;
  display: flex; align-items: center; justify-content: center;
  white-space: nowrap;
}

/* Character - 시각적으로 크게 (1.4x) */
.char {
  z-index: 7;
}
.char img {
  width: 140%; height: 140%;
  margin-left: -20%;
  margin-top: -25%;
  object-fit: contain;
  filter: drop-shadow(2px 3px 2px rgba(0,0,0,0.25));
}
.char.facing-left  img { transform: scaleX(-1); }
.char.action       { animation: bump 0.15s; }
@keyframes bump {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.1); }
}

/* Watering animation */
.char.watering img { visibility: hidden; }
.char.watering::after {
  content: '';
  position: absolute;
  left: -20%; top: -25%;
  width: 140%; height: 140%;
  background-image: url('./assets/images/char/char_ani_water.png');
  background-repeat: no-repeat;
  background-size: 300% 100%;
  background-position: 0 0;
  image-rendering: pixelated;
  animation: waterFrames 0.6s steps(3) 1 forwards;
}
.char.watering.facing-left::after { transform: scaleX(-1); }
@keyframes waterFrames {
  to { background-position: -300% 0; }
}

/* Boar */
.boar {
  position: absolute;
  left: calc(var(--col) * var(--tile));
  top:  calc(var(--row) * var(--tile));
  width: calc(var(--tile) * 1.2);
  height: calc(var(--tile) * 1.2);
  margin-left: calc(var(--tile) * -0.1);
  margin-top: calc(var(--tile) * -0.1);
  background-image: url('./assets/images/animal/animal_ani_run.png');
  background-repeat: no-repeat;
  background-size: 300% 100%;
  background-position: 0 0;
  animation: boarFrames 0.4s steps(3) infinite;
  z-index: 8;
  pointer-events: none;
  filter: drop-shadow(2px 3px 3px rgba(0,0,0,0.3));
}
@keyframes boarFrames { to { background-position: -300% 0; } }
.boar.hit { animation: boarFrames 0.4s steps(3) infinite, boarBump 0.18s; }
@keyframes boarBump {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px) scale(1.15); }
}
.boar::after {
  content: '🐗 ' attr(data-hp);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(198,40,40,0.95);
  color: #fff;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
  font-weight: 700;
}

/* Raindrops */
.raindrop {
  position: absolute;
  top: -20px;
  width: 10px; height: 14px;
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center;
  pointer-events: none;
  animation-name: rainFall;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
  z-index: 4;
  opacity: 0.85;
}
@keyframes rainFall {
  from { transform: translateY(0); }
  to   { transform: translateY(calc(var(--rows) * var(--tile) + 40px)); }
}

/* Info banner */
#map-stage .info-banner {
  position: absolute;
  top: 38px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.78);
  color: #fff;
  font-size: 12px;
  padding: 5px 14px;
  border-radius: 999px;
  font-weight: 700;
  z-index: 11;
  pointer-events: none;
  transition: opacity 0.3s;
  white-space: nowrap;
  max-width: 95%;
  overflow: hidden;
  text-overflow: ellipsis;
}
#map-stage .info-banner.alert { background: rgba(198,40,40,0.92); }
#map-stage .info-banner.good  { background: rgba(46,125,50,0.92); }

/* Rain overlay */
#fx-layer.raining::before {
  content: '';
  position: absolute; inset: 0;
  background-image:
    repeating-linear-gradient(115deg,
      rgba(120,160,200,0.55) 0 1px,
      transparent 1px 8px);
  animation: rainShift 0.6s linear infinite;
  pointer-events: none;
}
@keyframes rainShift {
  0% { background-position: 0 0; }
  100% { background-position: 16px 24px; }
}

/* Weather banner */
.weather-banner {
  position: absolute;
  top: 6px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  color: #fff;
  font-size: 12px;
  padding: 3px 12px;
  border-radius: 999px;
  font-weight: 700;
  z-index: 10;
  pointer-events: none;
}

/* Crop selection menu (Phase 1 popup) */
#crop-menu {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255,255,255,0.98);
  border: 3px solid #2e7d32;
  border-radius: 14px;
  padding: 14px 18px;
  z-index: 30;
  min-width: 320px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  text-align: center;
}
#crop-menu .hd {
  font-weight: 900; font-size: 16px;
  color: #2e7d32; margin-bottom: 8px;
}
#crop-menu .slots {
  display: flex; gap: 8px; justify-content: center;
  margin-bottom: 10px;
}
#crop-menu .slot {
  width: 70px; height: 70px;
  border: 2px dashed #cfd8dc;
  background: #fafafa;
  border-radius: 8px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  font-size: 11px;
}
#crop-menu .slot.empty { color: #aaa; font-style: italic; }
#crop-menu .slot img { width: 36px; height: 36px; }
#crop-menu .opts {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
#crop-menu .opts button {
  background: #fff;
  border: 2px solid #66bb6a;
  border-radius: 8px;
  padding: 6px 8px;
  display: flex; align-items: center; gap: 4px;
  cursor: pointer;
  font-size: 13px;
  justify-content: center;
}
#crop-menu .opts button:hover { background: #f1f8e9; }
#crop-menu .opts button .num {
  display: inline-block;
  background: #2e7d32; color: #fff;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
  font-weight: 700;
}
#crop-menu .opts button img { width: 22px; height: 22px; }

/* Item-use floating effect over zone */
.item-fx {
  pointer-events: none;
  z-index: 20;
  display: flex; align-items: center; justify-content: center;
}
.item-fx .bubble {
  background: rgba(255,255,255,0.96);
  border: 2px solid #66bb6a;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 14px;
  font-weight: 700;
  color: #2e7d32;
  display: flex; align-items: center; gap: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  animation: itemFxUp 1.1s ease-out forwards;
}
.item-fx .bubble span { font-size: 12px; }
@keyframes itemFxUp {
  0%   { transform: translateY(0) scale(0.7); opacity: 0; }
  20%  { transform: translateY(-10px) scale(1.05); opacity: 1; }
  100% { transform: translateY(-60px) scale(1); opacity: 0; }
}

/* ===== Side panel ===== */
#side-panel {
  background: #fff;
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  overflow: auto;
  max-height: 560px;
}
#side-panel.flash { animation: flashPanel 0.4s; }
@keyframes flashPanel {
  0%, 100% { background: #fff; }
  50%      { background: #fff59d; }
}
#side-panel h2 { margin: 0 0 4px; font-size: 16px; color: #2e7d32; }
#side-panel .sub { font-size: 12px; color: #666; margin: 0 0 10px; }

.controls-card {
  background: #fffde7;
  border: 1px dashed #f9a825;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 11px;
  color: #5d4037;
  margin-bottom: 8px;
  line-height: 1.6;
}
.kbd {
  display: inline-block;
  background: #fff;
  border: 1px solid #aaa;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
  font-family: monospace;
  font-size: 10px;
  margin: 0 1px;
}

/* Phase 1: zone summary */
.zone-summary-list { display: flex; flex-direction: column; gap: 4px; }
.zone-summary {
  display: grid;
  grid-template-columns: 36px 1fr auto auto;
  gap: 6px;
  align-items: center;
  background: #fafafa;
  border: 1px solid #c8e6c9;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
}
.zsum-tag {
  background: #2e7d32; color: #fff;
  border-radius: 4px;
  padding: 2px 0;
  font-weight: 900;
  text-align: center;
  font-size: 12px;
}
.zsum-desc { font-size: 11px; color: #555; }
.zsum-icons { display: flex; gap: 2px; }
.zsum-icons img { width: 18px; height: 18px; }
.zsum-name {
  font-size: 11px;
  background: #fff; color: #333;
  border: 1px solid #cfd8dc;
  border-radius: 4px;
  padding: 1px 6px;
  font-weight: 700;
}

/* Phase 2: growing */
.week-display {
  text-align: center;
  font-size: 26px; font-weight: 900;
  color: #2e7d32;
  margin: 4px 0;
}
.week-display .week-remain {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 14px;
  font-weight: 700;
  color: #ef6c00;
  background: #fff3e0;
  border: 1px solid #ffb74d;
  border-radius: 999px;
  vertical-align: middle;
}
.progress-bar {
  width: 100%; height: 14px;
  background: #e0e0e0;
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #aed581, #2e7d32);
  width: 0%;
  transition: width 0.2s linear;
}
.progress-marks {
  display: flex; justify-content: space-between;
  font-size: 10px; color: #777;
  padding: 0 2px; margin-top: 2px;
}
.weather-card {
  background: #fff3e0;
  border-left: 5px solid #ff9800;
  padding: 6px 10px;
  border-radius: 8px;
  margin: 8px 0;
}
.weather-card.rain { background: #e1f5fe; border-left-color: #0288d1; }
.weather-card .wkey  { font-size: 11px; color: #ef6c00; font-weight: 700; }
.weather-card .wname { font-size: 14px; font-weight: 700; margin: 2px 0; }
.weather-card .wdesc { font-size: 11px; color: #555; }
.weather-card.next {
  background: #f5f5f5;
  border-left-color: #9e9e9e;
  border-left-style: dashed;
  opacity: 0.85;
  margin-top: 4px;
}
.weather-card.next.rain { background: #eceff1; border-left-color: #607d8b; }
.weather-card.next .wkey { color: #616161; }

/* Item bar (보유 아이템 + 단축키) */
#item-bar {
  margin-top: 6px;
}
.item-bar-title {
  font-size: 11px; font-weight: 700;
  color: #555; margin-bottom: 4px;
}
.item-bar-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
}
.item-slot {
  border: 2px solid #66bb6a;
  background: #fff;
  border-radius: 6px;
  padding: 4px 2px;
  text-align: center;
  font-size: 9px;
  position: relative;
}
.item-slot.empty { opacity: 0.4; border-color: #ccc; }
.item-slot .hk {
  position: absolute;
  top: -6px; left: -4px;
  background: #d84315; color: #fff;
  font-size: 10px;
  border-radius: 4px;
  padding: 0 4px;
  font-weight: 700;
}
.item-slot .ic { font-size: 18px; display: block; }
.item-slot .nm { display: block; font-size: 9px; }
.item-slot .ct { font-weight: 700; color: #2e7d32; }

.zone-status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  font-size: 10px;
  margin-top: 6px;
}
.zsg {
  background: #f1f8e9;
  border: 1px solid #c8e6c9;
  border-radius: 4px;
  padding: 3px 4px;
  text-align: center;
}
.zsg b { color: #2e7d32; }

/* Phase 3: results */
.result-list { display: flex; flex-direction: column; gap: 4px; }
.result-row {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 6px; align-items: center;
  background: #fafafa;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12px;
}
.result-row img { width: 22px; height: 22px; }
.result-row .meta { font-size: 10px; color: #666; }
.grade {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 10px;
  color: #fff;
}
.grade.S { background: #ff6d00; }
.grade.A { background: #2e7d32; }
.grade.B { background: #689f38; }
.grade.C { background: #fbc02d; color: #333; }
.grade.D { background: #c62828; }
.summary-box {
  background: #f1f8e9;
  border-radius: 10px;
  padding: 10px;
  margin-top: 10px;
  text-align: center;
}
.summary-box .big {
  font-size: 22px; font-weight: 900; color: #2e7d32;
}

/* Phase 4: shop */
.shop-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.shop-item {
  background: #fff;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  padding: 6px;
  font-size: 11px;
  text-align: center;
  position: relative;
}
.shop-item .ico {
  font-size: 22px;
  position: relative;
}
.shop-item .ico .hk {
  position: absolute;
  top: 0; right: 0;
  background: #d84315; color: #fff;
  font-size: 10px;
  border-radius: 4px;
  padding: 0 4px;
  font-weight: 700;
}
.shop-item .name { font-weight: 700; font-size: 12px; }
.shop-item .desc { font-size: 10px; color: #666; min-height: 28px; }
.shop-item .price { color: #2e7d32; font-weight: 700; margin: 2px 0; }
.shop-item button {
  width: 100%; padding: 3px;
  background: #66bb6a; color: #fff;
  border: none; border-radius: 6px;
  cursor: pointer; font-size: 11px;
}
.shop-item button:disabled { background: #bdbdbd; cursor: not-allowed; }
.inventory {
  background: #fff3e0;
  border-radius: 8px;
  padding: 6px 10px;
  margin-top: 8px;
  font-size: 11px;
}
.inv-item {
  display: inline-block;
  background: #fff;
  border-radius: 6px;
  padding: 1px 6px;
  margin: 2px 2px;
  border: 1px solid #ffcc80;
}

/* ===== Footer ===== */
.footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-top: 1px solid #e0e0e0;
  padding: 10px 16px;
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px;
  z-index: 10;
}
.footer .hint { font-size: 12px; color: #666; flex: 1; text-align: center; }
.btn {
  padding: 10px 22px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
}
.btn.primary { background: #2e7d32; color: #fff; }
.btn.primary:disabled { background: #bdbdbd; cursor: not-allowed; }
.btn.ghost { background: #f5f5f5; color: #555; }
.btn.ghost:disabled { opacity: 0.5; cursor: not-allowed; }

@media (max-width: 1100px) {
  main { grid-template-columns: 1fr; }
  #map-stage { justify-self: center; }
  #side-panel { max-height: none; }
}

/* ============================================================
 *  Screen system (title / login / mode / survey / done)
 * ============================================================ */
.screen { display: none; }
body[data-screen="title"]            #screen-title,
body[data-screen="login"]            #screen-login,
body[data-screen="mode"]             #screen-mode,
body[data-screen="endgame"]          #screen-endgame,
body[data-screen="rank"]             #screen-rank,
body[data-screen="survey"]           #screen-survey,
body[data-screen="done"]             #screen-done,
body[data-screen="multi-menu"]       #screen-multi-menu,
body[data-screen="multi-create"]     #screen-multi-create,
body[data-screen="multi-join"]       #screen-multi-join,
body[data-screen="multi-customize"]  #screen-multi-customize,
body[data-screen="multi-lobby"]      #screen-multi-lobby,
body[data-screen="multi-end"]        #screen-multi-end {
  display: flex;
}
body[data-screen="multi-game"] #screen-multi-game {
  display: flex; flex-direction: column;
}
body[data-screen="game"] #app {
  display: flex;
}
body:not([data-screen="game"]) #app { display: none; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center; justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #c5e1a5 0%, #aed581 50%, #81c784 100%);
  overflow: auto;
}

.card {
  background: #fff;
  border-radius: 18px;
  padding: 28px 32px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
  max-width: 520px;
  width: 100%;
  text-align: center;
}
.card h1 { margin: 0; }
.card h2 { margin: 0 0 8px; color: #2e7d32; font-size: 22px; }
.card .sub-title { font-size: 13px; color: #666; margin: 4px 0 16px; }
.card .title-hint { font-size: 11px; color: #888; margin-top: 14px; }
.card .title-emoji { font-size: 42px; margin-bottom: 6px; }
.big-title {
  font-size: 36px;
  font-weight: 900;
  color: #1b5e20;
  letter-spacing: -1px;
  margin: 4px 0 6px;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.06);
}
.big-btn {
  padding: 14px 28px;
  font-size: 16px;
  margin-top: 10px;
  min-width: 180px;
}

/* Login form */
.login-card form {
  display: flex; flex-direction: column;
  gap: 10px;
  text-align: left;
  margin-top: 10px;
}
.login-card label {
  display: flex; flex-direction: column;
  font-size: 13px; color: #555;
  font-weight: 700;
}
.login-card input {
  margin-top: 4px;
  padding: 10px 12px;
  border: 2px solid #c8e6c9;
  border-radius: 8px;
  font-size: 14px;
  background: #fafafa;
}
.login-card input:focus {
  border-color: #2e7d32;
  outline: none;
  background: #fff;
}
.form-actions {
  display: flex; gap: 8px;
  justify-content: center;
  margin-top: 12px;
}
.form-msg {
  font-size: 12px;
  color: #c62828;
  margin-top: 8px;
  min-height: 16px;
  text-align: center;
}

/* Mode select */
.mode-card .mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0;
}
.mode-card .mode-grid.three {
  grid-template-columns: 1fr 1fr 1fr;
}
.mode-btn {
  background: #fff;
  border: 3px solid #66bb6a;
  border-radius: 14px;
  padding: 24px 14px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.mode-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(46,125,50,0.2);
  background: #f1f8e9;
}
.mode-btn.coming {
  border-color: #bdbdbd;
  color: #999;
  cursor: not-allowed;
  opacity: 0.7;
}
.mode-btn.coming:hover { transform: none; box-shadow: none; background: #fff; }
.mode-btn .mode-emoji { font-size: 36px; }
.mode-btn .mode-name {
  font-weight: 900; font-size: 16px;
  color: #2e7d32; margin: 6px 0 4px;
}
.mode-btn.coming .mode-name { color: #757575; }
.mode-btn .mode-desc {
  font-size: 11px; color: #666;
  line-height: 1.4;
}

/* Survey */
.survey-card {
  max-width: 680px;
  text-align: left;
  max-height: 92vh;
  overflow-y: auto;
}
.survey-card h2 { text-align: center; }
.survey-card .sub-title { text-align: center; }
.survey-userinfo {
  background: #f1f8e9;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: #2e7d32;
  font-weight: 700;
  text-align: center;
  margin: 8px 0 16px;
}
.survey-card .q { margin-bottom: 16px; }
.q-label {
  display: block;
  font-weight: 700; font-size: 14px;
  color: #2c3e2d; margin-bottom: 6px;
}
.q-label .req { color: #c62828; }
.q-label .hint-text { font-size: 11px; color: #777; font-weight: 500; }
.zone-radio {
  display: flex; flex-wrap: wrap;
  gap: 6px;
}
.zone-radio label {
  display: inline-flex; align-items: center;
  gap: 4px;
  padding: 8px 14px;
  border: 2px solid #c8e6c9;
  border-radius: 8px;
  background: #fafafa;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}
.zone-radio label:has(input:checked) {
  border-color: #2e7d32; background: #2e7d32; color: #fff;
}
.zone-radio input { accent-color: #2e7d32; }
.survey-card textarea {
  width: 100%;
  border: 2px solid #c8e6c9;
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
  background: #fafafa;
}
.survey-card textarea:focus {
  border-color: #2e7d32;
  outline: none;
  background: #fff;
}
.char-count {
  text-align: right;
  font-size: 11px;
  color: #888;
  margin-top: 2px;
}

/* Done */
.done-card .title-emoji {
  font-size: 56px; color: #2e7d32;
}
.done-card h2 { color: #2e7d32; }

/* End-of-game screen */
.endgame-card { max-width: 460px; }
.endgame-card .title-emoji { font-size: 50px; }
.endgame-card h2 { color: #2e7d32; font-size: 24px; }
.endgame-money {
  font-size: 36px;
  font-weight: 900;
  color: #ff6d00;
  margin: 10px 0 4px;
}
.endgame-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}
.endgame-actions .btn {
  width: 100%;
}

/* Rank screen */
.rank-card { max-width: 640px; text-align: left; max-height: 90vh; overflow-y: auto; }
.rank-card h2 { text-align: center; }
.rank-card .sub-title { text-align: center; }
.rank-filter {
  display: flex; justify-content: center;
  gap: 6px;
  margin: 8px 0 12px;
}
.rank-filter label {
  display: inline-flex; align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border: 2px solid #c8e6c9;
  border-radius: 999px;
  background: #fafafa;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.rank-filter label.active {
  background: #2e7d32;
  color: #fff;
  border-color: #2e7d32;
}
.rank-filter input { display: none; }
.rank-list {
  background: #f9fbe7;
  border: 1px solid #c8e6c9;
  border-radius: 8px;
  padding: 6px;
  margin-bottom: 12px;
  min-height: 100px;
}
.rank-loading, .rank-empty {
  text-align: center; padding: 32px;
  color: #888; font-size: 13px;
}
.rank-note {
  font-size: 11px;
  color: #c62828;
  background: #fff3e0;
  padding: 4px 8px;
  border-radius: 4px;
  margin-bottom: 6px;
  text-align: center;
}
.rank-row {
  display: grid;
  grid-template-columns: 36px 1fr 56px 56px 100px;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
  align-items: center;
}
.rank-row + .rank-row { margin-top: 2px; }
.rank-row.head {
  font-weight: 900;
  font-size: 11px;
  color: #555;
  background: transparent;
  border-bottom: 2px solid #c8e6c9;
  border-radius: 0;
  padding-bottom: 4px;
}
.rank-row:not(.head) { background: #fff; }
.rank-row.top1 { background: linear-gradient(90deg, #fff8e1, #fff); }
.rank-row.top1 .rk::before { content: '🥇 '; }
.rank-row.me { outline: 2px solid #2e7d32; background: #f1f8e9; }
.rank-row .rk { font-weight: 900; color: #2e7d32; text-align: center; }
.rank-row .mn { text-align: right; font-weight: 900; color: #ff6d00; }
.rank-row .cl, .rank-row .sn { text-align: center; }

/* Topbar user badge + round chip + greeting */
.user-badge { background: rgba(255,255,255,0.32); font-weight: 700; }
.round-chip {
  display: inline-block;
  background: #ff8f00; color: #fff;
  font-size: 11px;
  border-radius: 999px;
  padding: 2px 8px;
  vertical-align: middle;
  margin-left: 4px;
}

@media (max-width: 720px) {
  .mode-card .mode-grid { grid-template-columns: 1fr; }
  .card { padding: 20px; }
  .big-title { font-size: 28px; }
}

/* ============================================================
 *  Multiplayer
 * ============================================================ */

/* --- Rooms list (Join) --- */
.rooms-list {
  background: #f9fbe7;
  border: 1px solid #c8e6c9;
  border-radius: 8px;
  padding: 6px;
  max-height: 320px;
  overflow-y: auto;
  margin: 8px 0 12px;
}
.room-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  background: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  border: 1px solid #e0e0e0;
  margin-bottom: 4px;
}
.room-row .room-name { font-weight: 700; }
.room-row .room-meta { font-size: 11px; color: #666; }
.room-row .btn.small { padding: 6px 12px; font-size: 12px; }

/* --- Customize --- */
.customize-row {
  display: flex; align-items: center;
  gap: 12px;
  margin: 10px 0;
  text-align: left;
}
.customize-label {
  font-weight: 700;
  width: 50px;
  flex-shrink: 0;
}
.customize-options {
  display: flex; gap: 6px; flex-wrap: wrap;
}
.customize-options .opt {
  border: 2px solid #c8e6c9;
  background: #fafafa;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 16px;
  cursor: pointer;
  font-family: inherit;
}
.customize-options .opt.selected {
  border-color: #2e7d32; background: #2e7d32; color: #fff;
}
.color-opt[data-color="green"]  { background: #66bb6a; color: #fff; }
.color-opt[data-color="red"]    { background: #ef5350; color: #fff; }
.color-opt[data-color="blue"]   { background: #42a5f5; color: #fff; }
.color-opt[data-color="yellow"] { background: #fdd835; color: #333; }
.color-opt.selected { outline: 3px solid #1b5e20; }
.char-preview {
  position: relative;
  width: 80px; height: 100px;
  margin: 14px auto 8px;
  display: flex; align-items: center; justify-content: center;
}
.char-preview img {
  width: 80px; height: 80px;
  image-rendering: pixelated;
  object-fit: contain;
}
.char-preview .hat {
  position: absolute;
  top: -8px;
  font-size: 36px;
  z-index: 2;
}
.char-preview.color-red    img { filter: hue-rotate(-50deg) saturate(2); }
.char-preview.color-blue   img { filter: hue-rotate(180deg) saturate(1.5); }
.char-preview.color-yellow img { filter: hue-rotate(50deg)  saturate(1.8); }
.char-preview.color-green  img { /* default */ }

/* --- Lobby --- */
.lobby-players {
  display: flex; flex-direction: column; gap: 6px;
  margin: 10px 0;
}
.lobby-player {
  display: grid;
  grid-template-columns: 24px 28px 1fr auto auto auto;
  gap: 6px;
  align-items: center;
  background: #fafafa;
  border: 2px solid #c8e6c9;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}
.lobby-player.me { border-color: #2e7d32; background: #f1f8e9; }
.lobby-player.host { box-shadow: 0 0 0 2px #ff8f00 inset; }
.badge-color {
  width: 18px; height: 18px;
  border-radius: 50%;
  display: inline-block;
}
.badge-color.color-green  { background: #66bb6a; }
.badge-color.color-red    { background: #ef5350; }
.badge-color.color-blue   { background: #42a5f5; }
.badge-color.color-yellow { background: #fdd835; }
.badge-hat { font-size: 20px; text-align: center; }
.lp-name { font-weight: 700; }
.lp-meta { font-size: 11px; color: #666; }
.lp-tag {
  font-size: 10px; font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  background: #ff8f00;
  color: #fff;
}
.lp-tag.me-tag { background: #2e7d32; }

/* --- Game --- */
#screen-multi-game {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: linear-gradient(180deg, #aed581, #81c784);
  align-items: center;
  padding: 14px;
  overflow: auto;
}
.multi-topbar {
  width: 100%;
  max-width: 800px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  padding: 10px 18px;
  background: rgba(46,125,50,0.94);
  color: #fff;
  border-radius: 12px;
  align-items: center;
  font-weight: 900;
  box-shadow: 0 3px 10px rgba(0,0,0,0.2);
}
.multi-topbar .m-side { font-size: 14px; }
.multi-topbar .m-left { text-align: left; }
.multi-topbar .m-right { text-align: right; position: relative; }
.multi-topbar .m-center {
  font-size: 26px;
  text-align: center;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.m-money-fx {
  display: inline-block;
  margin-left: 4px;
  color: #fff176;
  font-size: 16px;
  font-weight: 900;
  opacity: 0;
  transform: translateY(0);
}
.m-money-fx.fx-pop {
  animation: moneyPop 1.1s ease-out forwards;
}
@keyframes moneyPop {
  0%   { opacity: 0; transform: translateY(0); }
  20%  { opacity: 1; transform: translateY(-4px); }
  100% { opacity: 0; transform: translateY(-24px); }
}

.multi-stage-wrap { margin: 14px 0; display: flex; justify-content: center; }
#multi-stage {
  position: relative;
  border: 4px solid #6d4c41;
  border-radius: 14px;
  background: #8bc34a;
  box-shadow: 0 4px 14px rgba(0,0,0,0.15);
  overflow: hidden;
  outline: none;
}
#multi-stage:focus { box-shadow: 0 0 0 3px #66bb6a, 0 4px 14px rgba(0,0,0,0.2); }
#multi-ground, #multi-obj, #multi-fx {
  position: absolute; inset: 0;
}
#multi-fx { pointer-events: none; }
.m-tile, .m-plot, .m-shop, .m-player, .m-lettuce, .m-wet, .m-boar {
  position: absolute;
  left: calc(var(--col) * 44px);
  top: calc(var(--row) * 44px);
  width: calc(var(--w, 1) * 44px);
  height: calc(var(--h, 1) * 44px);
}
.m-tile.grass {
  background-image: url('./assets/images/tiles/grass/1.png');
  background-size: 44px 44px;
  background-repeat: repeat;
}
.m-plot {
  background-image: url('./assets/images/tiles/soil/5.png');
  background-size: 44px 44px;
  background-repeat: repeat;
  border: 2px solid #5d4037;
  border-radius: 4px;
}
.m-shop {
  display: flex; flex-direction: column; align-items: center;
}
.m-shop img {
  width: 100%; height: 100%;
  object-fit: contain;
  filter: drop-shadow(2px 3px 2px rgba(0,0,0,0.18));
}
.m-shop .lbl {
  position: absolute; bottom: -2px; left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  background: #fff59d;
  border: 1px solid #f9a825;
  border-radius: 4px;
  padding: 0 5px;
  font-weight: 700;
}
.m-wet {
  background: rgba(33,150,243,0.28);
  pointer-events: none;
  z-index: 1;
}

.m-player {
  z-index: 6;
}
.m-player img {
  width: 130%; height: 130%;
  margin-left: -15%; margin-top: -20%;
  image-rendering: pixelated;
  filter: drop-shadow(2px 3px 2px rgba(0,0,0,0.2));
}
.m-player.color-red    img { filter: hue-rotate(-50deg) saturate(2)  drop-shadow(2px 3px 2px rgba(0,0,0,0.2)); }
.m-player.color-blue   img { filter: hue-rotate(180deg) saturate(1.5) drop-shadow(2px 3px 2px rgba(0,0,0,0.2)); }
.m-player.color-yellow img { filter: hue-rotate(50deg)  saturate(1.8) drop-shadow(2px 3px 2px rgba(0,0,0,0.2)); }
.m-player.facing-left img { transform: scaleX(-1); }
.m-player .hat {
  position: absolute;
  top: -14px; left: 50%;
  transform: translateX(-50%);
  font-size: 18px;
  z-index: 7;
}
.m-player .name-tag {
  position: absolute;
  bottom: -10px; left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  padding: 1px 6px;
  border-radius: 999px;
  white-space: nowrap;
  font-weight: 700;
  z-index: 7;
}
.m-player.me .name-tag {
  background: #2e7d32;
}

.m-lettuce {
  z-index: 3;
  display: flex; align-items: center; justify-content: center;
}
.m-lettuce img {
  width: 80%; height: 80%;
  object-fit: contain;
  image-rendering: pixelated;
}
.m-lettuce.withered img { opacity: 0.65; filter: grayscale(0.4); }
.m-lettuce.harvestable img { animation: lettucePop 0.6s ease-in-out infinite alternate; }
@keyframes lettucePop {
  from { transform: translateY(0); }
  to   { transform: translateY(-4px) scale(1.05); }
}
.harvest-banner {
  position: absolute;
  bottom: 100%; left: 50%;
  transform: translateX(-50%);
  background: #2e7d32; color: #fff;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 700;
  white-space: nowrap;
  margin-bottom: 2px;
  z-index: 8;
}
.harvest-banner.withered { background: #c62828; }

.m-boar {
  z-index: 9;
  background-image: url('./assets/images/animal/animal_ani_run.png');
  background-repeat: no-repeat;
  background-size: 300% 100%;
  background-position: 0 0;
  animation: mBoarFrames 0.4s steps(3) infinite;
  width: calc(1.4 * 44px);
  height: calc(1.4 * 44px);
  margin-left: calc(-0.2 * 44px);
  margin-top: calc(-0.2 * 44px);
  pointer-events: none;
}
@keyframes mBoarFrames { to { background-position: -300% 0; } }
.m-boar-hp {
  position: absolute;
  bottom: 100%; left: 50%;
  transform: translateX(-50%);
  background: rgba(198,40,40,0.95);
  color: #fff; font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 700;
  white-space: nowrap;
}
.m-boar-timer {
  position: absolute;
  top: 4px; left: 4px; right: 4px;
  height: 5px;
  background: rgba(0,0,0,0.4);
  border-radius: 3px;
  overflow: hidden;
}
.m-boar-timer .fill {
  height: 100%; background: #ef5350;
  transition: width 0.2s;
}

.multi-bottom {
  width: 100%;
  max-width: 800px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}
.multi-log {
  background: rgba(255,255,255,0.92);
  border-radius: 8px;
  padding: 6px 10px;
  max-height: 110px;
  overflow-y: auto;
  font-size: 12px;
  border: 1px solid #c8e6c9;
}
.m-log-row { padding: 2px 0; border-bottom: 1px dashed #e0e0e0; }
.m-log-row:last-child { border-bottom: none; }
.multi-hud {
  background: rgba(255,255,255,0.94);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  display: flex; flex-direction: column; gap: 4px;
}

/* --- End screen --- */
.multi-end-list {
  display: flex; flex-direction: column; gap: 4px;
  margin: 10px 0;
}
.end-row {
  display: grid;
  grid-template-columns: 32px 1fr 50px 50px 100px;
  gap: 6px;
  background: #fafafa;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  align-items: center;
}
.end-row .rk { font-weight: 900; color: #2e7d32; text-align: center; }
.end-row .mn { text-align: right; font-weight: 900; color: #ff6d00; }
.end-row .cl, .end-row .sn { text-align: center; color: #666; }

/* --- Rank: multi rows --- */
.rank-row.multi {
  grid-template-columns: 36px 1fr 2fr 110px;
}
.rank-row.multi .rm { font-weight: 700; }
.rank-row.multi .pl { font-size: 11px; color: #555; }
