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

body {
  font-family: "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: linear-gradient(#8ed3f7 0%, #bde8fa 35%, #d4f0c0 70%, #b9dd8c 100%);
  background-attachment: fixed;
  min-height: 100vh;
  color: #3a2c1a;
  overflow-x: hidden;
}

/* 天空裝飾 */
.sun {
  position: fixed;
  top: 26px; right: 46px;
  width: 74px; height: 74px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff6c9, #ffd94d 60%, #ffb52e);
  box-shadow: 0 0 44px 14px rgba(255, 216, 77, .55);
  z-index: 0;
  animation: sunpulse 5s ease-in-out infinite;
}
@keyframes sunpulse {
  0%, 100% { box-shadow: 0 0 44px 14px rgba(255,216,77,.55); }
  50% { box-shadow: 0 0 58px 20px rgba(255,216,77,.75); }
}
.cloud {
  position: fixed;
  font-size: 3rem;
  opacity: .85;
  z-index: 0;
  pointer-events: none;
  animation: drift linear infinite;
}
.cloud.c1 { top: 4%;  animation-duration: 65s; }
.cloud.c2 { top: 12%; font-size: 2.2rem; animation-duration: 90s; animation-delay: -30s; }
.cloud.c3 { top: 20%; font-size: 3.6rem; animation-duration: 110s; animation-delay: -70s; opacity: .6; }
@keyframes drift {
  from { left: -8%; }
  to   { left: 105%; }
}

#app {
  max-width: 1760px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: 10px;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  background: linear-gradient(#fffdf2, #fdf3d3);
  border: 3px solid #b5854b;
  border-radius: 14px;
  padding: 8px 16px;
  box-shadow: 0 4px 0 #8a6337, 0 8px 18px rgba(80, 55, 20, .18);
  flex-shrink: 0;
}

#topbar h1 {
  font-size: 1.25rem;
  letter-spacing: 1px;
  text-shadow: 0 2px 0 rgba(255,255,255,.8);
}

#stats { display: flex; align-items: center; gap: 14px; font-size: 1.05rem; }

#exp-bar {
  display: inline-block;
  width: 90px; height: 12px;
  background: #e0d5c0;
  border-radius: 6px;
  overflow: hidden;
  vertical-align: middle;
  margin-right: 6px;
}
#exp-fill {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, #7ec850, #4ca42e);
  transition: width .3s;
}

main {
  display: flex;
  gap: 12px;
  margin-top: 10px;
  flex: 1;
  min-height: 0;
  align-items: stretch;
}

#farm-wrap {
  flex: 1.15;
  min-width: 0;
  display: flex;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(255,255,255,.18), transparent 55%),
    linear-gradient(#95c463, #83b34e);
  border: 3px solid #6f9640;
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 4px 0 #55742f, 0 10px 22px rgba(50, 80, 20, .22);
}

#farm {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 8px;
  min-height: 0;
}

.plot {
  min-height: 0;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,.06) 0 4px, transparent 4px 11px),
    linear-gradient(#b57e50, #96613a);
  border: 3px solid #7d5230;
  box-shadow: inset 0 3px 7px rgba(60, 35, 12, .45), 0 2px 0 rgba(60,35,12,.35);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  font-size: clamp(1.1rem, 3.6vh, 1.8rem);
  user-select: none;
  transition: transform .08s;
}
.plot:hover { transform: scale(1.05); }
.plot.locked {
  background: #999;
  border-color: #777;
  font-size: 1.2rem;
  color: #eee;
}
.plot.watered { background: #7c5233; border-color: #5c3a20; }
.plot .timer {
  position: absolute;
  bottom: 3px;
  font-size: .62rem;
  background: rgba(0,0,0,.55);
  color: #fff;
  padding: 1px 6px;
  border-radius: 8px;
}
.plot .weed-mark {
  position: absolute;
  top: 2px; right: 4px;
  font-size: .95rem;
  animation: shake .6s infinite;
}
.plot .bug-mark {
  position: absolute;
  top: 2px; left: 4px;
  font-size: .95rem;
  animation: shake .4s infinite;
}
.plot.ready { animation: bounce 1s infinite; }
.plot.dead { background: #6e6152; border-color: #55483b; }

/* 左欄：農田＋牧場 */
#left-col {
  flex: 1.15;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#left-col #farm-wrap { flex: 1; min-height: 0; }

#pasture-title {
  margin: 8px 0 6px;
  font-size: 1rem;
  color: #2f4520;
  text-shadow: 0 1px 0 rgba(255,255,255,.4);
  display: flex;
  align-items: center;
  gap: 8px;
}
#pasture-cap { font-size: .78rem; color: #55742f; }
#pasture-cap button {
  font-family: inherit;
  font-size: .72rem;
  border: 2px solid #b5854b;
  background: #fffbe8;
  border-radius: 8px;
  padding: 2px 8px;
  cursor: pointer;
  box-shadow: 0 2px 0 #8a6337;
}
#pasture-cap button:hover { background: #f5efdc; }

/* 牧場：開放草地，動物在裡面散步 */
#pasture {
  position: relative;
  height: 190px;
  flex-shrink: 0;
  border-radius: 12px;
  border: 4px solid #8a5c30;
  box-shadow: inset 0 0 0 3px #c99e5f, inset 0 6px 14px rgba(60, 90, 30, .25);
  background:
    radial-gradient(circle at 18% 30%, rgba(255,255,255,.16) 0 8%, transparent 9%),
    radial-gradient(circle at 72% 60%, rgba(255,255,255,.12) 0 6%, transparent 7%),
    radial-gradient(circle at 45% 80%, rgba(80,110,40,.18) 0 5%, transparent 6%),
    linear-gradient(#a4c876, #8fb35e);
  overflow: hidden;
}
#pasture::before { /* 草叢點綴 */
  content: "🌼 🌱 🌸 🌱";
  position: absolute;
  bottom: 4px; left: 10px;
  font-size: .7rem;
  opacity: .8;
  letter-spacing: 18px;
  pointer-events: none;
}

.roam {
  position: absolute;
  transition: left 3.5s linear, top 3.5s linear;
  cursor: pointer;
  text-align: center;
  z-index: 1;
}
.roam .a-emoji {
  display: block;
  font-size: 1.9rem;
  filter: drop-shadow(0 3px 2px rgba(60, 35, 12, .35));
}
.roam.ready .a-emoji { animation: bounce 1s infinite; }
.roam .a-tag {
  display: inline-block;
  font-size: .58rem;
  background: rgba(255, 252, 240, .92);
  border: 1px solid #c99e5f;
  color: #6b4a22;
  padding: 0 5px;
  border-radius: 7px;
  white-space: nowrap;
}
.roam.ready .a-tag { background: #ffe9a8; border-color: #e89b23; font-weight: bold; }

/* 右欄：開心小鎮（大富翁式街道） */
#town-wrap {
  width: 250px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255,255,255,.2), transparent 55%),
    linear-gradient(#dcd3b8, #cfc4a4);
  border: 3px solid #a3966f;
  border-radius: 14px;
  padding: 8px 10px 10px;
  box-shadow: 0 4px 0 #857a58, 0 10px 22px rgba(80, 70, 40, .2);
  overflow-y: auto;
}
#town-title {
  font-size: 1rem;
  color: #4a4028;
  margin-bottom: 4px;
  text-shadow: 0 1px 0 rgba(255,255,255,.5);
}
#town-house { display: flex; justify-content: center; flex-shrink: 0; }

#town {
  display: grid;
  grid-template-columns: 1fr 26px 1fr;
  gap: 8px 0;
  flex: 1;
}
#town {
  grid-template-columns: 1fr 24px 1fr 24px 1fr;
  grid-template-rows: 26px repeat(3, 1fr) 26px;
  position: relative;
  gap: 8px 0;
}

/* 環狀道路：繞著中排街區一圈 */
#ring-road {
  position: absolute;
  top: 4px; bottom: 4px;
  left: calc((100% - 48px) / 3 + 1px);
  right: calc((100% - 48px) / 3 + 1px);
  border: 22px solid #7c7c74;
  border-radius: 46px;
  z-index: 0;
  pointer-events: none;
}
#ring-road::before { /* 白色虛線中線 */
  content: "";
  position: absolute;
  inset: -12px;
  border: 2px dashed rgba(255, 255, 255, .85);
  border-radius: 38px;
}

/* 路上的車與行人：沿環道繞圈 */
.traffic {
  position: absolute;
  z-index: 1;
  font-size: .95rem;
  pointer-events: none;
  --lane1: calc((100% - 48px) / 3 + 3px);
  --lane2: calc(100% - (100% - 48px) / 3 - 21px);
  animation: patrol linear infinite;
}
.traffic.ped { font-size: .8rem; }
.t1 { animation-duration: 13s; }
.t2 { animation-duration: 17s; animation-delay: -8s; }
.t3 { animation-duration: 21s; animation-delay: -3s; }
.t4 { animation-duration: 42s; animation-direction: reverse; }
.t5 { animation-duration: 50s; animation-delay: -21s; animation-direction: reverse; }
@keyframes patrol {
  0%   { left: var(--lane1); top: 4px; }
  25%  { left: var(--lane2); top: 4px; }
  50%  { left: var(--lane2); top: calc(100% - 26px); }
  75%  { left: var(--lane1); top: calc(100% - 26px); }
  100% { left: var(--lane1); top: 4px; }
}

.lot {
  min-height: 86px;
  background: linear-gradient(#f2e8cd, #e7d9b4);
  border: 3px solid #b5a276;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  position: relative;
  padding: 6px 4px 8px;
  transition: transform .08s;
  user-select: none;
}
.lot:hover { transform: scale(1.04); z-index: 1; }
.lot.forsale { background: linear-gradient(#dcdcd2, #c9c9bd); border-style: dashed; }
.lot.empty-lot { border-style: dashed; }
.lot.open { animation: bounce 1s infinite; border-color: #e89b23; }
.lot .l-emoji { font-size: 1.7rem; line-height: 1.1; }
.lot .l-name { font-size: .68rem; color: #5a4a30; font-weight: bold; }
.lot .l-price {
  font-size: .6rem;
  background: rgba(0,0,0,.5);
  color: #fff;
  padding: 0 6px;
  border-radius: 7px;
  white-space: nowrap;
}
.lot .l-money {
  position: absolute;
  top: 2px; right: 4px;
  font-size: 1rem;
  animation: bounce 1s infinite;
  filter: drop-shadow(0 0 6px rgba(255, 235, 130, .95));
}
.lot .p-bar {
  width: 70%;
  height: 5px;
  background: rgba(60, 35, 12, .25);
  border-radius: 3px;
  overflow: hidden;
}
.lot .p-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #ffd94d, #ff9d2e);
  transition: width 1s linear;
}
.lot.open .p-fill { background: linear-gradient(90deg, #9be15d, #4ca42e); }

.pen {
  aspect-ratio: 1.45;
  background:
    radial-gradient(circle at 30% 18%, rgba(255,255,255,.3), transparent 45%),
    repeating-linear-gradient(45deg, rgba(140,90,30,.08) 0 5px, transparent 5px 11px),
    linear-gradient(#f4d78e, #e2b95e);
  border: 3px solid #a8743f;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  font-size: 1.8rem;
  user-select: none;
  transition: transform .08s;
  box-shadow: inset 0 -8px 12px rgba(140, 90, 30, .28), 0 3px 0 #8a5c30;
}
/* 柵欄木條 */
.pen::before {
  content: "";
  position: absolute;
  top: -9px; left: 8%;
  width: 84%; height: 11px;
  background: repeating-linear-gradient(90deg, #b5854b 0 9px, transparent 9px 20px);
  border-bottom: 3px solid #8a5c30;
  border-radius: 3px 3px 0 0;
  pointer-events: none;
}
.pen:hover { transform: scale(1.05); z-index: 1; }
.pen.locked {
  background: linear-gradient(#a5a5a0, #8d8d88);
  border-color: #777;
  font-size: 1rem;
  color: #eee;
  box-shadow: inset 0 -8px 12px rgba(0,0,0,.2);
}
.pen.locked::before { background: repeating-linear-gradient(90deg, #909088 0 9px, transparent 9px 20px); border-bottom-color: #77776f; }
.pen.empty .animal { opacity: .45; }

.pen .animal {
  font-size: 2.1rem;
  filter: drop-shadow(0 3px 2px rgba(60, 35, 12, .35));
}
.pen.producing .animal { animation: idle 2.4s ease-in-out infinite; }
.pen.has-product .animal { animation: bounce 1s infinite; }
@keyframes idle {
  0%, 100% { transform: translateY(0) rotate(0); }
  25% { transform: translateY(-2px) rotate(-4deg); }
  75% { transform: translateY(-2px) rotate(4deg); }
}

.pen .aname {
  position: absolute;
  top: 3px; left: 5px;
  font-size: .6rem;
  background: rgba(255, 252, 240, .9);
  border: 1px solid #c99e5f;
  color: #6b4a22;
  padding: 0 5px;
  border-radius: 7px;
}

.pen .product {
  position: absolute;
  top: 2px; right: 5px;
  font-size: 1.15rem;
  animation: bounce 1s infinite;
  filter: drop-shadow(0 0 6px rgba(255, 235, 130, .95));
}

.pen .p-bar {
  position: absolute;
  bottom: 16px;
  width: 62%;
  height: 6px;
  background: rgba(60, 35, 12, .3);
  border-radius: 3px;
  overflow: hidden;
}
.pen .p-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #ffd94d, #ff9d2e);
  transition: width 1s linear;
}
.pen.has-product .p-fill { background: linear-gradient(90deg, #9be15d, #4ca42e); }

.pen .timer {
  position: absolute;
  bottom: 2px;
  font-size: .62rem;
  background: rgba(0,0,0,.55);
  color: #fff;
  padding: 1px 6px;
  border-radius: 8px;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
@keyframes shake {
  0%, 100% { transform: rotate(-12deg); }
  50% { transform: rotate(12deg); }
}

#panel {
  width: 258px;
  flex-shrink: 0;
  background: linear-gradient(#fffdf2, #fbf2d6);
  border: 3px solid #b5854b;
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 4px 0 #8a6337, 0 8px 18px rgba(80, 55, 20, .18);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
  margin-bottom: 8px;
}
.tab-btn {
  padding: 6px 1px;
  font-size: .66rem;
  font-family: inherit;
  background: #efe6cb;
  border: 2px solid #d8c49a;
  border-radius: 8px;
  cursor: pointer;
  color: #7a6a50;
  white-space: nowrap;
}
.tab-btn:hover { background: #f7f0dc; }
.tab-btn.active {
  background: #fff;
  border-color: #4ca42e;
  color: #2f4520;
  font-weight: bold;
}
.tab-page { display: none; }
.tab-page.active {
  display: block;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.seed, .tool {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 8px;
  margin-bottom: 5px;
  background: #fff;
  border: 2px solid #d8c49a;
  border-radius: 9px;
  cursor: pointer;
  font-size: .92rem;
  font-family: inherit;
  text-align: left;
  transition: border-color .1s, background .1s;
}
.seed, .tool { box-shadow: 0 2px 0 #d8c49a; }
.seed:hover, .tool:hover { background: #f5efdc; transform: translateY(-1px); }
.seed:active, .tool:active { transform: translateY(1px); box-shadow: none; }
.seed.selected, .tool.selected { border-color: #4ca42e; background: #e8f6dd; }
.seed.cant-afford { opacity: .45; }
.seed .emoji { font-size: 1.25rem; }
.seed .info { flex: 1; line-height: 1.25; }
.seed .info small { color: #7a6a50; display: block; }
.seed.locked-seed { opacity: .45; }

.quest {
  background: #fff;
  border: 2px solid #d8c49a;
  border-radius: 9px;
  padding: 7px 9px;
  margin-bottom: 6px;
  font-size: .85rem;
}
.quest.done-claimed { opacity: .5; }
.quest .q-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.quest .q-reward { color: #8a6337; font-size: .78rem; white-space: nowrap; }
.quest .q-bar {
  height: 8px;
  background: #eee3cc;
  border-radius: 4px;
  overflow: hidden;
  margin-top: 5px;
}
.quest .q-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #f5b942, #e89b23);
  transition: width .3s;
}
.quest .q-progress { font-size: .74rem; color: #7a6a50; margin-top: 3px; }
.quest .q-claim {
  margin-top: 5px;
  width: 100%;
  padding: 4px;
  border: none;
  border-radius: 7px;
  background: #4ca42e;
  color: #fff;
  font-family: inherit;
  font-size: .85rem;
  cursor: pointer;
  animation: bounce 1s infinite;
}
.quest .q-claim:hover { background: #3e8a24; }

#tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tool { margin-bottom: 0; justify-content: center; text-align: center; }

#hint {
  margin: 6px 0 8px;
  font-size: .74rem;
  color: #6b5a3e;
  background: #f3ecd8;
  border-radius: 8px;
  padding: 6px 8px;
  line-height: 1.45;
}

/* ---------- 房子 ---------- */
#house-title {
  margin: 10px 0 4px;
  font-size: 1rem;
  color: #2f4520;
  text-shadow: 0 1px 0 rgba(255,255,255,.4);
}

#house-area {
  flex: 1;
  min-height: 150px;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  background: linear-gradient(rgba(255,255,255,.10), rgba(0,0,0,.05));
  border-radius: 12px;
  overflow: hidden;
}

#house {
  position: relative;
  width: 250px;
  height: 250px;
  transform: scale(.8);
  transform-origin: bottom center;
  margin-bottom: 40px;
}
#town-house {
  height: 200px;
  overflow: hidden;
  align-items: flex-end;
}
#town-house #house {
  transform: scale(.62);
  margin-bottom: 32px;
}
.h-part { display: none; position: absolute; left: 50%; transform: translateX(-50%); }
.h-part.built { display: block; }

/* SVG 房子：各部件用 .built 切換顯示 */
#house-svg { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); }
#house-svg .hp { display: none; }
#house-svg .hp.built { display: inline; }
#house-svg { cursor: pointer; }
#home-label {
  position: absolute;
  bottom: -36px;
  left: 50%;
  transform: translateX(-50%);
  font-size: .85rem;
  font-weight: bold;
  background: rgba(255, 252, 240, .92);
  border: 2px solid #c99e5f;
  color: #6b4a22;
  padding: 2px 12px;
  border-radius: 10px;
  white-space: nowrap;
}
.smoke { opacity: 0; }
#house.complete .smoke { animation: puff 3s ease-out infinite; }
#house.complete .smoke.s2 { animation-delay: 1.5s; }
@keyframes puff {
  0%   { opacity: 0; transform: translate(0, 0) scale(.5); }
  30%  { opacity: .85; }
  100% { opacity: 0; transform: translate(7px, -30px) scale(1.5); }
}

#house-empty {
  position: absolute;
  inset: 20% 12%;
  border: 3px dashed rgba(255,255,255,.65);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #f6ffe8;
  font-size: 1.05rem;
  text-align: center;
  gap: 4px;
  text-shadow: 0 1px 2px rgba(0,0,0,.3);
}
#house-empty small { font-size: .72rem; opacity: .9; }
#house.has-parts #house-empty { display: none; }

.h-foundation {
  bottom: 0;
  width: 210px; height: 18px;
  /* 石磚 */
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,.14) 0 2px, transparent 2px 26px),
    linear-gradient(#b9b9ae, #98988c);
  border: 2px solid #74746a;
  border-radius: 4px;
  box-shadow: inset 0 2px 3px rgba(255,255,255,.35), 0 3px 5px rgba(0,0,0,.25);
}
.h-floor1, .h-floor2 {
  /* 橫向木牆板 */
  background:
    repeating-linear-gradient(0deg, rgba(140,90,30,.12) 0 2px, transparent 2px 12px),
    linear-gradient(#f9e4b8, #eecd90);
  border: 3px solid #b98d55;
  border-radius: 3px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.35), inset -6px 0 10px rgba(140,90,30,.18);
}
.h-floor1 { bottom: 18px; width: 186px; height: 82px; z-index: 2; }
.h-floor2 { bottom: 100px; width: 186px; height: 74px; z-index: 2; }
.h-foundation { z-index: 2; }
/* 樓層間的木飾條 */
.h-floor2::after {
  content: "";
  position: absolute;
  left: -6px; right: -6px; bottom: -6px;
  height: 7px;
  background: linear-gradient(#c99e5f, #a97d43);
  border-radius: 3px;
  box-shadow: 0 2px 3px rgba(0,0,0,.25);
}
/* 立體側面（2.5D）：右側牆與側屋頂 */
.h-side1, .h-side2, .h-found-side {
  left: auto;
  transform: skewY(-25deg);
  transform-origin: left;
  background: linear-gradient(100deg, #dcb87a, #c39a58);
  border: 3px solid #a97d43;
  border-left: none;
  z-index: 0;
}
.h-side1 { left: calc(50% + 90px); width: 26px; height: 82px; bottom: 18px; }
.h-side2 { left: calc(50% + 90px); width: 26px; height: 74px; bottom: 100px; }
.h-found-side {
  left: calc(50% + 102px);
  width: 26px; height: 18px; bottom: 0;
  background: linear-gradient(100deg, #a3a396, #83837a);
  border-color: #6a6a60;
}
.h-roof-side {
  left: 0; top: 0;
  transform: none;
  width: 270px; height: 250px;
  clip-path: polygon(125px 14px, 151px 2px, 267px 54px, 241px 78px);
  background: linear-gradient(115deg, #a84936, #7e2f1f);
  z-index: 1;
}

.h-roof {
  bottom: 172px;
  width: 232px; height: 64px;
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
  /* 平滑屋瓦，不要磚牆感 */
  background: linear-gradient(168deg, #e0705a 0%, #c8503a 55%, #a83e2b 100%);
  filter: drop-shadow(0 3px 4px rgba(0,0,0,.3));
  z-index: 3;
}
/* 屋簷板 */
.h-roof::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 7px;
  background: linear-gradient(#8f3a29, #7a2f20);
}
.h-chimney {
  bottom: 208px;
  margin-left: 58px;
  z-index: 2;
  width: 22px; height: 36px;
  /* 紅磚 */
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,.18) 0 2px, transparent 2px 9px),
    linear-gradient(#a85b4c, #8a473a);
  border: 2px solid #63332a;
  border-radius: 3px 3px 0 0;
}
.h-chimney::before {
  content: "";
  position: absolute;
  top: -5px; left: -4px; right: -4px;
  height: 6px;
  background: #63332a;
  border-radius: 2px;
}
#house.complete .h-chimney::after {
  content: "💨";
  position: absolute;
  top: -22px; left: -4px;
  animation: smoke 2.5s ease-out infinite;
}
@keyframes smoke {
  0%   { opacity: 0; transform: translateY(4px) scale(.7); }
  30%  { opacity: .9; }
  100% { opacity: 0; transform: translateY(-16px) scale(1.25); }
}

.h-door {
  display: none;
  position: absolute;
  left: 50%; transform: translateX(-50%);
  bottom: -3px;
  width: 36px; height: 54px;
  /* 直紋木門 */
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,.14) 0 2px, transparent 2px 9px),
    linear-gradient(#9d6a3e, #7a4c28);
  border: 3px solid #5f3a1d;
  border-radius: 18px 18px 3px 3px;
  box-shadow: inset 0 2px 4px rgba(255,255,255,.25), 0 2px 4px rgba(0,0,0,.3);
}
/* 門上小圓窗 */
.h-door::before {
  content: "";
  position: absolute;
  top: 7px; left: 50%; transform: translateX(-50%);
  width: 16px; height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3c9, #ffd97a);
  border: 2px solid #5f3a1d;
}
.h-door::after {
  content: "";
  position: absolute;
  right: 5px; top: 28px;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #f5d76e;
  box-shadow: 0 0 3px rgba(245,215,110,.9);
}
.h-window {
  display: none;
  position: absolute;
  top: 46%; transform: translateY(-50%);
  width: 32px; height: 32px;
  /* 四格窗＋玻璃反光 */
  background:
    linear-gradient(#fff 0 0) center/3px 100% no-repeat,
    linear-gradient(#fff 0 0) center/100% 3px no-repeat,
    linear-gradient(125deg, #eaf7ff 0%, #bfe3f7 45%, #93cbee 100%);
  border: 3px solid #fff;
  outline: 2px solid #b98d55;
  border-radius: 3px;
  box-shadow: 0 2px 4px rgba(0,0,0,.2);
}
/* 窗台花箱 */
.h-window::after {
  content: "";
  position: absolute;
  left: -5px; right: -5px; bottom: -9px;
  height: 7px;
  background:
    radial-gradient(circle at 20% 0%, #ff8fb0 0 2px, transparent 3px),
    radial-gradient(circle at 50% 0%, #ffd166 0 2px, transparent 3px),
    radial-gradient(circle at 80% 0%, #ff8fb0 0 2px, transparent 3px),
    linear-gradient(#7ba05b, #5d8041);
  border-radius: 2px;
  box-shadow: 0 2px 3px rgba(0,0,0,.25);
}
.h-window.hw-l { left: 16px; }
.h-window.hw-r { right: 16px; }
.h-door.built, .h-window.built { display: block; }
/* 餐廳開張後窗戶亮暖黃燈 */
#house.restaurant .h-window {
  background:
    linear-gradient(#fff 0 0) center/3px 100% no-repeat,
    linear-gradient(#fff 0 0) center/100% 3px no-repeat,
    radial-gradient(circle at 40% 35%, #fff6d0, #ffdd88 75%);
  box-shadow: 0 0 10px rgba(255, 221, 136, .8);
}

/* ---------- 餐廳 ---------- */
.h-sign {
  bottom: 146px;
  padding: 3px 10px;
  background: linear-gradient(#8a5a2b, #6f451e);
  color: #ffe9b8;
  font-size: .82rem;
  font-weight: bold;
  letter-spacing: 1px;
  border: 2px solid #5f3a1d;
  border-radius: 8px;
  white-space: nowrap;
  z-index: 4;
  box-shadow: 0 3px 5px rgba(0,0,0,.35);
}
.h-awning {
  bottom: 76px;
  width: 76px; height: 15px;
  background: repeating-linear-gradient(90deg, #e05548 0 11px, #fff6e8 11px 22px);
  border: 2px solid #b03a2e;
  border-radius: 4px 4px 9px 9px;
  z-index: 4;
}
#house.restaurant { cursor: pointer; }
#rest-money {
  display: none;
  position: absolute;
  top: 4px; right: 16px;
  font-size: 1.7rem;
  animation: bounce 1s infinite;
  filter: drop-shadow(0 0 8px rgba(255, 235, 130, .95));
  z-index: 3;
}
#rest-bar {
  display: none;
  position: absolute;
  bottom: -18px; left: 50%; transform: translateX(-50%);
  width: 176px; height: 9px;
  background: rgba(60, 35, 12, .35);
  border-radius: 5px;
  overflow: hidden;
}
#rest-fill {
  display: block;
  height: 100%; width: 0;
  background: linear-gradient(90deg, #ffd94d, #ff9d2e);
  transition: width 1s linear;
}
#house.rest-ready #rest-fill { background: linear-gradient(90deg, #9be15d, #4ca42e); }
#rest-timer {
  display: none;
  position: absolute;
  bottom: -44px; left: 50%; transform: translateX(-50%);
  font-size: .8rem;
  background: rgba(0,0,0,.55);
  color: #fff;
  padding: 1px 9px;
  border-radius: 9px;
  white-space: nowrap;
}
#house.restaurant #rest-bar, #house.restaurant #rest-timer { display: block; }
#house.rest-ready #rest-money { display: block; }

#house.complete::after {
  content: "✨";
  position: absolute;
  top: 8px; left: 8px;
  font-size: 1.4rem;
  animation: sparkle 1.6s ease-in-out infinite;
}
@keyframes sparkle {
  0%, 100% { opacity: .3; transform: scale(.8) rotate(-10deg); }
  50% { opacity: 1; transform: scale(1.15) rotate(10deg); }
}

.build-item.done, .furn-item.done { opacity: .55; }
.build-item.next { border-color: #e89b23; background: #fdf3dd; }
.build-item .info b { color: #8a6337; }

/* ---------- 室內佈置（整頁視圖） ---------- */
#interior-view {
  flex: 1;
  min-height: 0;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  background: linear-gradient(#fffdf2, #fbf2d6);
  border: 3px solid #b5854b;
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 4px 0 #8a6337, 0 8px 18px rgba(80, 55, 20, .18);
}
#interior-view.hidden, main.hidden { display: none; }

#interior-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  flex-shrink: 0;
}
#interior-head h2 { font-size: 1.15rem; }
#interior-bonus {
  margin-left: auto;
  font-size: .82rem;
  color: #6b5a3e;
  background: #f3ecd8;
  border-radius: 8px;
  padding: 4px 10px;
}
#interior-close {
  border: 2px solid #d8c49a;
  background: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: .85rem;
  font-family: inherit;
  box-shadow: 0 2px 0 #d8c49a;
}
#interior-close:hover { background: #f5efdc; }

#interior-body { display: flex; gap: 12px; min-height: 0; flex: 1; }

#room {
  flex: 1;
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  border: 3px solid #b98d55;
  font-size: clamp(14px, 3.4vh, 26px); /* 傢俱用 em，跟著房間縮放 */
}
.r-wall {
  position: absolute;
  inset: 0 0 30% 0;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.06) 0 3px, transparent 3px 26px),
    linear-gradient(#e8d5b5, #dfc9a2);
}
.r-window {
  position: absolute;
  top: 18%; left: 50%; transform: translateX(-50%);
  width: 84px; height: 74px;
  background:
    linear-gradient(#fff 0 0) center/4px 100% no-repeat,
    linear-gradient(#fff 0 0) center/100% 4px no-repeat,
    linear-gradient(160deg, #cdeafa, #9fd4f2);
  border: 4px solid #fff;
  outline: 3px solid #b98d55;
  border-radius: 4px;
  box-shadow: 0 0 18px rgba(255, 244, 200, .8);
}
.r-floor {
  position: absolute;
  inset: 70% 0 0 0;
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,.08) 0 2px, transparent 2px 34px),
    linear-gradient(#c99e5f, #b3874c);
}
.furn {
  position: absolute;
  filter: drop-shadow(0 3px 3px rgba(60, 35, 12, .35));
  user-select: none;
  touch-action: none;
  cursor: pointer; /* 點傢俱主角會過去互動 */
  transform-origin: center;
}
#room.edit .furn {
  cursor: grab;
  outline: 2px dashed rgba(255, 255, 255, .8);
  outline-offset: 4px;
  border-radius: 8px;
}
#room.edit .furn:active { cursor: grabbing; }

/* ---------- 主角 ---------- */
#player {
  position: absolute;
  left: 46%; top: 55%;
  font-size: 2.4em;
  z-index: 3;
  transition: left 1.1s ease-in-out, top 1.1s ease-in-out;
  filter: drop-shadow(0 3px 3px rgba(60, 35, 12, .35));
  user-select: none;
  pointer-events: none;
}
#player-body {
  display: inline-block;
  transition: transform .4s;
}
#player.walking #player-body { animation: walkbob .35s ease-in-out infinite; }
@keyframes walkbob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
#player.lie #player-body { transform: rotate(-90deg) translateX(.18em); }
#player.sit #player-body { transform: translateY(.12em) scale(.95); }
#player-emote {
  position: absolute;
  top: -.65em; left: 62%;
  font-size: .55em;
  animation: emote-pop 1.6s ease-in-out infinite;
}
@keyframes emote-pop {
  0%, 100% { transform: translateY(0) scale(1); opacity: .85; }
  50% { transform: translateY(-5px) scale(1.18); opacity: 1; }
}
/* 使用中的電器：發光閃爍 */
.furn.fx-on {
  filter: drop-shadow(0 0 10px rgba(140, 220, 255, .95)) brightness(1.15);
  animation: tvflicker 1.1s steps(2) infinite;
}
@keyframes tvflicker {
  50% { filter: drop-shadow(0 0 15px rgba(190, 238, 255, 1)) brightness(1.32); }
}

.furn-del {
  display: none;
  position: absolute;
  top: -13px; right: -13px;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid #c0392b;
  background: #fff;
  color: #c0392b;
  font-size: .62rem;
  line-height: 1;
  cursor: pointer;
  z-index: 5;
  font-family: inherit;
  padding: 0;
}
#room.edit .furn-del { display: block; }
.furn-del:hover { background: #ffe3de; }

.furn-size {
  display: none;
  position: absolute;
  top: -13px; left: -15px;
  z-index: 5;
  gap: 2px;
}
#room.edit .furn-size { display: flex; }
.furn-size button {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid #2e86c1;
  background: #fff;
  color: #2e86c1;
  font-size: .6rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}
.furn-size button:hover { background: #e2f0fb; }

#furn-edit {
  border: 2px solid #d8c49a;
  background: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: .85rem;
  font-family: inherit;
  box-shadow: 0 2px 0 #d8c49a;
}
#furn-edit:hover { background: #f5efdc; }
#furn-edit.editing { border-color: #4ca42e; background: #e8f6dd; }
.furn.rug {
  width: 46%; height: 36px;
  left: 27%; bottom: 5%;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, #f2b9a0 0 40%, #d97b5f 42% 70%, #b95b40 72% 100%);
  box-shadow: inset 0 2px 4px rgba(255,255,255,.35);
  filter: none;
}

.furn-cat {
  font-size: .8rem;
  font-weight: bold;
  color: #6b4a22;
  border-bottom: 2px dashed #e0cda0;
  padding-bottom: 3px;
  margin: 8px 0 6px;
}
.furn-cat:first-child { margin-top: 0; }

#furn-side { width: 200px; display: flex; flex-direction: column; min-height: 0; }
#furn-shop { flex: 1; overflow-y: auto; max-height: 264px; padding-right: 2px; }
#furn-note {
  margin-top: 6px;
  font-size: .72rem;
  color: #8a7a5e;
  background: #f3ecd8;
  border-radius: 8px;
  padding: 5px 8px;
  text-align: center;
}

@media (max-width: 620px) {
  #interior-body { flex-direction: column; }
  #furn-side { width: 100%; }
  #room { height: 220px; }
}

#perks-title {
  font-size: .8rem;
  font-weight: bold;
  color: #6b4a22;
  border-bottom: 2px dashed #e0cda0;
  padding-bottom: 3px;
  margin: 10px 0 6px;
}
.perk {
  font-size: .74rem;
  color: #5a4a30;
  background: #fff;
  border: 2px solid #eee0c0;
  border-radius: 8px;
  padding: 5px 8px;
  margin-bottom: 4px;
  line-height: 1.4;
}
.perk.locked { opacity: .55; }

#save-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#save-note {
  margin-top: 8px;
  font-size: .76rem;
  color: #8a7a5e;
  line-height: 1.5;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(40,30,15,.9);
  color: #fff;
  padding: 9px 18px;
  border-radius: 20px;
  font-size: .95rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 手機版：恢復直向捲動排版 */
@media (max-width: 760px) {
  body { overflow-y: auto; }
  #app { height: auto; }
  main { flex-direction: column; }
  #farm { grid-template-columns: repeat(4, 1fr); grid-template-rows: auto; }
  .plot { aspect-ratio: 1; }
  #left-col { width: 100%; }
  #pasture { height: 170px; }
  #town-wrap { width: 100%; overflow-y: visible; }
  #panel { width: 100%; }
  .tab-page.active { overflow: visible; }
}

/* 大螢幕：中右欄加寬，不要擠成細條 */
@media (min-width: 1400px) {
  #town-wrap { width: 340px; }
  #panel { width: 330px; }
  .lot { min-height: 104px; }
  .lot .l-emoji { font-size: 2.1rem; }
  .lot .l-name { font-size: .78rem; }
  .lot .l-price { font-size: .7rem; }
  #town-house { height: 250px; }
  #town-house #house { transform: scale(.8); margin-bottom: 38px; }
  #pasture { height: 240px; }
  .roam .a-emoji { font-size: 2.3rem; }
  .roam .a-tag { font-size: .68rem; }
  .tab-btn { font-size: .78rem; }
  .seed { font-size: 1rem; }
  #farm { gap: 10px; }
}

#town-note {
  margin-top: 8px;
  font-size: .74rem;
  color: #8a7a5e;
  background: #f3ecd8;
  border-radius: 8px;
  padding: 6px 8px;
  line-height: 1.5;
}
