* { box-sizing: border-box; }

body {
  margin: 0;
  overflow: hidden;
  font-family: "Fredoka", "Trebuchet MS", sans-serif;
  background: #5fb8e6;
  color: #4a3b49;
}

#world {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
  cursor: pointer;
}

button {
  font: inherit;
  font-weight: 600;
  color: #4a3b49;
  padding: 7px 13px;
  border: 3px solid #5b4659;
  border-radius: 14px;
  background: #fff8ef;
  cursor: pointer;
  box-shadow: 0 3px 0 #5b4659;
}
button:active { transform: translateY(3px); box-shadow: none; }
button.danger { background: #ffd9d6; }

.hidden { display: none !important; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.hint { text-align: center; opacity: 0.75; font-size: 14px; margin: 10px 16px; }

/* ---------- Top bar ---------- */
#topbar {
  position: fixed;
  top: 12px; left: 16px; right: 16px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
#town-name {
  margin: 0;
  padding: 4px 16px;
  font-size: 26px;
  background: #fff8ef;
  border: 3px solid #5b4659;
  border-radius: 16px;
  box-shadow: 0 3px 0 #5b4659;
  outline: none;
}

/* ---------- Toolbar ---------- */
.toolbar {
  position: fixed;
  bottom: 12px; left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  max-height: 40vh;
  display: flex;
  flex-wrap: wrap;            /* buttons go onto a new row instead of scrolling */
  justify-content: center;
  gap: 4px;
  padding: 8px;
  overflow-y: auto;           /* only scrolls if even the rows don't fit */
  background: #fff8ef;
  border: 3px solid #5b4659;
  border-radius: 20px;
  box-shadow: 0 4px 0 #5b4659;
}
.toolbar button {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 58px;
  padding: 4px 6px;
  font-size: 11px;
  box-shadow: none;
  border-width: 2px;
  border-color: transparent;
  background: transparent;
}
.toolbar button span { font-size: 24px; line-height: 1.2; }
.toolbar button:hover { background: #fdecd8; }
.toolbar button.active { background: #ffe08a; border-color: #5b4659; }

/* Second layer: the different styles of the chosen tool */
.subbar {
  position: fixed;
  bottom: 104px; left: 50%;   /* moved above the toolbar by the code */
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  max-height: 34vh;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  overflow-y: auto;
  background: #fff8ef;
  border: 3px solid #5b4659;
  border-radius: 18px;
  box-shadow: 0 4px 0 #5b4659;
}
.subbar button {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 78px;
  padding: 4px;
  font-size: 11px;
  box-shadow: none;
  border-width: 2px;
  border-color: transparent;
  background: transparent;
}
.subbar button img { width: 56px; height: 56px; }
.subbar button:hover { background: #fdecd8; }
.subbar button.active { background: #ffe08a; border-color: #5b4659; }

.tip {
  position: fixed;
  top: 72px; left: 50%;
  transform: translateX(-50%);
  background: rgba(91, 70, 89, 0.85);
  color: #fff;
  padding: 6px 14px;
  border-radius: 12px;
  font-size: 14px;
  text-align: center;
  pointer-events: none;
  max-width: calc(100% - 32px);
}

/* ---------- House editor card ---------- */
.card {
  position: fixed;
  top: 80px; right: 16px;
  width: 260px;
  max-width: calc(100% - 32px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: #fff8ef;
  border: 3px solid #5b4659;
  border-radius: 20px;
  box-shadow: 0 4px 0 #5b4659;
  z-index: 5;
}
#preview { width: 100%; height: auto; background: #bfe6f7; border-radius: 12px; }
.card label { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.card input[type="text"] { font: inherit; width: 140px; padding: 4px 8px; border: 2px solid #5b4659; border-radius: 8px; }
input[type="color"] { width: 50px; height: 34px; border: 2px solid #5b4659; border-radius: 8px; padding: 2px; background: #fff; cursor: pointer; }

/* ---------- Interior (3D cutaway room) ---------- */
#interior {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: radial-gradient(circle at 50% 40%, #f4eff8, #d9d2e6);
}
#room-canvas { position: absolute; inset: 0; display: block; touch-action: none; cursor: pointer; }
#interior-top {
  position: absolute;
  top: 12px; left: 16px; right: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}
#interior-top > * { pointer-events: auto; }
#interior-title {
  margin: 0;
  padding: 4px 14px;
  font-size: 22px;
  background: #fff8ef;
  border: 3px solid #5b4659;
  border-radius: 14px;
  box-shadow: 0 3px 0 #5b4659;
}
#room-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
#room-tabs button { padding: 4px 12px; font-size: 15px; }
#room-tabs button.active { background: #ffe08a; }
#room-size { display: flex; align-items: center; gap: 6px; margin-left: auto; }
#room-size label { font-weight: 600; }
#room-size select { font: inherit; font-weight: 600; color: #4a3b49; padding: 4px 8px; border: 3px solid #5b4659; border-radius: 12px; background: #fff8ef; cursor: pointer; }
#play-btn { background: #c9f2d2; }
#play-btn.playing { background: #ffe08a; }

/* Room buttons (zoom into a room) and the furniture menu */
#room-chips {
  position: absolute;
  top: 66px; left: 16px; right: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  pointer-events: none;
}
#room-chips button { pointer-events: auto; padding: 4px 12px; font-size: 14px; }
#room-chips button.active { background: #ffe08a; }
#iactions {
  position: absolute;
  top: 156px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: #fff8ef;
  border: 3px solid #5b4659;
  border-radius: 16px;
  box-shadow: 0 3px 0 #5b4659;
  max-width: calc(100% - 32px);
  flex-wrap: wrap;
  justify-content: center;
}
#iactions b { padding: 0 6px; }
#iactions button { padding: 4px 10px; font-size: 14px; box-shadow: 0 2px 0 #5b4659; }
#interior .tip { top: 108px; }

/* Wallpaper colors */
.swatches {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(7, 26px);
  gap: 6px;
  align-content: center;
  padding: 0 6px;
}
.swatches .swatch { width: 26px; height: 26px; padding: 0; border-radius: 50%; border: 2px solid #5b4659; box-shadow: none; }
.swatches .swatch.active { outline: 3px solid #ff5fa2; outline-offset: 1px; }
.swatches .wheel { grid-column: span 7; display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.swatches .wheel input { width: 34px; height: 26px; }
#iactions input[type="color"] { width: 36px; height: 30px; }

/* ---------- Money mode ---------- */
#money-bar { display: flex; align-items: center; gap: 8px; }
#coins {
  font-size: 20px; font-weight: 600;
  padding: 4px 14px;
  background: #fff3c4;
  border: 3px solid #5b4659; border-radius: 16px;
  box-shadow: 0 3px 0 #5b4659;
  min-width: 96px; text-align: center;
}
#coins.bump { animation: bump 0.35s ease; }
#coins.drop { animation: drop 0.35s ease; }
#coins.shake { animation: shake 0.4s ease; }
@keyframes bump { 50% { transform: scale(1.15); background: #ffe58a; } }
@keyframes drop { 50% { transform: scale(0.9); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); background: #ffd9d6; } 40%, 80% { transform: translateX(6px); background: #ffd9d6; } }
.subbar .price { display: block; font-size: 10px; color: #a0701a; }
#earn-info { font-size: 13px; font-weight: 600; color: #a0701a; text-align: center; }
#adopt-btn { background: #c9f2d2; }

/* Pop-up windows (choosing a town, adopting) */
.overlay {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: rgba(60, 45, 80, 0.45);
  padding: 16px;
}
.overlay-box {
  background: #fff8ef;
  border: 3px solid #5b4659; border-radius: 22px;
  box-shadow: 0 5px 0 #5b4659;
  padding: 20px;
  max-width: 560px; width: 100%;
  text-align: center;
}
.overlay-box h2 { margin: 0 0 12px; }
.mode-cards { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; }
.mode-card {
  flex: 1 1 200px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 16px;
  font-size: 16px;
}
.mode-card span { font-size: 44px; }
.mode-card small { font-weight: 400; opacity: 0.8; }
.mode-card.current { background: #ffe08a; }
#adopt-list { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 12px 0; }
.adopt-card { display: flex; flex-direction: column; align-items: center; width: 92px; padding: 8px; }
.adopt-card .adopt-icon { font-size: 34px; }
.adopt-card em { font-size: 11px; font-style: normal; color: #3f9a6e; }
.adopt-card:disabled { opacity: 0.45; cursor: not-allowed; }

.overlay-box.small { max-width: 400px; }
.btn-row.center { justify-content: center; }
.subbar .price.free { color: #3f9a6e; }

/* Tasks */
#tasks-btn { position: relative; }
#tasks-btn.has-news::after {
  content: ""; position: absolute; top: -4px; right: -4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: #ff5f8f; border: 2px solid #5b4659;
}
.tasks-box { max-height: calc(100vh - 32px); overflow-y: auto; text-align: left; }
.tasks-box h2, .tasks-box > button { display: block; margin-left: auto; margin-right: auto; text-align: center; }
.tasks-box h3 { margin: 14px 0 6px; font-size: 16px; }
.tasks-box h3 small { font-weight: 400; opacity: 0.7; }
.task { background: #fff; border: 2px solid #e8dccb; border-radius: 12px; padding: 8px 10px; margin-bottom: 6px; }
.task.done { background: #eafbe9; border-color: #b9e3c3; }
.task-top { display: flex; justify-content: space-between; gap: 8px; }
.task-top b { color: #a0701a; white-space: nowrap; }
.task small { opacity: 0.7; }
.bar { height: 8px; background: #f1e8dc; border-radius: 6px; overflow: hidden; margin: 5px 0 2px; }
.bar div { height: 100%; background: linear-gradient(90deg, #ffd93d, #f2a65a); }
.task .care span { opacity: 0.3; font-size: 18px; margin-right: 4px; }
.task .care span.got { opacity: 1; }

/* Daily gift */
#gift-days { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; margin: 8px 0; }
#gift-days span { font-size: 11px; padding: 4px 6px; border-radius: 8px; background: #f1e8dc; opacity: 0.6; }
#gift-days span.got { background: #ffe08a; opacity: 1; font-weight: 600; }

/* Stage 3 */
#level-btn { background: #e3f4ff; }
#upgrade-btn { background: #fff3c4; }
#upgrade-btn:disabled { opacity: 0.7; cursor: default; }
#earn-info small { font-weight: 400; opacity: 0.8; }
.big-emoji { font-size: 48px; }

/* Shop */
#shop-btn { background: #ffe3ec; }
.shop-box { max-width: 680px; }
.bundle { background: #fff; border: 2px solid #e8dccb; border-radius: 14px; padding: 10px; margin-bottom: 10px; }
.bundle.owned { background: #eafbe9; border-color: #b9e3c3; }
.bundle-top { display: flex; align-items: center; gap: 10px; }
.bundle-top b { font-size: 17px; }
.bundle-top .season { display: block; color: #e07a5f; font-weight: 600; }
.bundle-icon { font-size: 32px; }
.bundle-items { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.bundle-items span { display: flex; flex-direction: column; align-items: center; width: 64px; }
.bundle-items img { width: 44px; height: 44px; }
.bundle-items small { font-size: 9px; text-align: center; line-height: 1.1; }
.bundle button { width: 100%; }
.subbar button.locked img { opacity: 0.45; filter: grayscale(0.6); }
.subbar .price.locked { color: #8d8497; }

/* Sleeping town and busy bonus */
#sleep-banner {
  position: fixed; top: 110px; left: 50%; transform: translateX(-50%);
  z-index: 20; pointer-events: none;
  background: #e3e8ff; color: #4a3b49; font-weight: 600;
  padding: 8px 16px; border: 3px solid #5b4659; border-radius: 16px; box-shadow: 0 3px 0 #5b4659;
  max-width: calc(100% - 32px); text-align: center;
  animation: snooze 2s ease-in-out infinite;
}
@keyframes snooze { 50% { transform: translateX(-50%) translateY(3px); } }
#busy-badge {
  font-weight: 600; padding: 4px 10px;
  background: #fff3a0; border: 3px solid #5b4659; border-radius: 14px; box-shadow: 0 3px 0 #5b4659;
}

.backups { margin-top: 16px; padding-top: 12px; border-top: 2px dashed #e8dccb; }
.backups h3 { margin: 0 0 4px; }
.backups button { font-size: 14px; padding: 6px 10px; }
/* The account part of the Towns window looks like the Backups part */
#account-box { margin-top: 16px; padding-top: 12px; border-top: 2px dashed #e8dccb; }
#account-box h3 { margin: 0 0 4px; }
#account-box button { font-size: 14px; padding: 6px 10px; }
#account-box input:not([type="checkbox"]) { font: inherit; width: 220px; max-width: 100%; padding: 4px 8px; border: 2px solid #5b4659; border-radius: 8px; }
#account-box label { display: block; text-align: center; margin: 8px 0; }
#account-box .account-who { text-align: center; font-weight: 600; margin: 6px 0; }
#acc-error { color: #c0392b; opacity: 1; }
#acc-error:empty { display: none; }

/* ---------- Beta ---------- */
#version-btn {
  position: fixed; left: 12px; bottom: 12px; z-index: 4;
  font-size: 12px; padding: 4px 10px; background: #ffe3ec; box-shadow: 0 2px 0 #5b4659;
}
#feedback-btn { background: #c9f2d2; }
#feedback-details { font-size: 12px; background: #f6efe6; border-radius: 10px; padding: 8px; word-break: break-word; }
#news-list ul { margin: 4px 0 12px; padding-left: 20px; }
#news-list li { margin: 4px 0; }
#tutorial-panel { z-index: 40; }
#tutorial-text { min-height: 64px; }
#tutorial-dots { display: flex; justify-content: center; gap: 6px; margin: 8px 0 14px; }
#tutorial-dots span { width: 9px; height: 9px; border-radius: 50%; background: #e8dccb; }
#tutorial-dots span.on { background: #f2a65a; }
#tutorial-skip { background: transparent; box-shadow: none; border-color: transparent; text-decoration: underline; }

/* ---------- Small screens (phones) ---------- */
.phone-only { display: none; }
.overlay-box { max-height: calc(100vh - 32px); overflow-y: auto; }
@media (max-width: 640px) {
  .phone-only { display: inline-block; }
  #topbar { top: 8px; left: 8px; right: 8px; gap: 6px; }
  #town-name { font-size: 17px; padding: 3px 10px; max-width: 46vw; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  #topbar button, #money-bar button { font-size: 13px; padding: 4px 8px; }
  #coins { font-size: 15px; padding: 3px 8px; min-width: 0; }
  #busy-badge { font-size: 12px; padding: 3px 6px; }
  #menu-btn { margin-left: auto; font-size: 18px; padding: 2px 10px; }
  #top-buttons { display: none; }
  #top-buttons.open {
    display: flex; flex-direction: column; align-items: stretch;
    position: absolute; top: 44px; right: 0; z-index: 25;
    background: #fff8ef; border: 3px solid #5b4659; border-radius: 16px; padding: 8px; box-shadow: 0 4px 0 #5b4659;
  }
  #money-bar { order: 3; width: 100%; flex-wrap: wrap; }
  #version-btn { display: none; }
  .toolbar { flex-wrap: nowrap; overflow-x: auto; max-height: none; bottom: 8px; padding: 6px; gap: 2px; justify-content: flex-start; }
  .toolbar button { min-width: 50px; font-size: 10px; padding: 3px 4px; }
  .toolbar button span { font-size: 20px; }
  .subbar { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; }
  .subbar button { width: 66px; }
  .subbar button img { width: 46px; height: 46px; }
  .card { top: auto; bottom: 150px; right: 8px; left: 8px; width: auto; max-height: 55vh; overflow-y: auto; }
  #preview { display: none; }
  .tip { top: 96px; font-size: 13px; }
  #interior-top { top: 8px; left: 8px; right: 8px; gap: 6px; }
  #interior-title { font-size: 16px; padding: 3px 10px; }
  #interior-top button, #room-size select { font-size: 13px; padding: 3px 8px; }
  #room-chips { top: 96px; left: 8px; right: 8px; }
}

.mode-card.locked { opacity: 0.6; cursor: not-allowed; background: #f1e8dc; }
.mode-card.locked small { color: #8d7a88; font-weight: 600; }
