:root {
  --ink: #2d2a32;
  --ink-soft: #6a6472;
  --paper: #fffaf2;
  --paper-2: #f5ecdf;
  --line: rgba(45, 42, 50, 0.12);
  --coral: #ff7a59;
  --coral-deep: #e2583a;
  --mint: #3fbf9f;
  --sky: #5aa9e6;
  --sun: #ffd166;
  --sky-top: #54c1ec;
  --sky-bottom: #d3f2fb;
  --radius: 22px;
  --shadow: 0 10px 30px rgba(35, 30, 50, 0.18), 0 2px 0 rgba(255, 255, 255, 0.6) inset;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  font-family: var(--font); color: var(--ink);
  background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom));
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
  user-select: none; -webkit-user-select: none;
}
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }
button:disabled { opacity: 0.4; cursor: default; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 22px; border-radius: 999px;
  font-weight: 600; font-size: 17px;
  transition: transform 0.12s var(--ease), box-shadow 0.12s var(--ease);
}
.btn.primary {
  width: 100%; color: #fff; background: var(--coral);
  box-shadow: 0 5px 0 var(--coral-deep), 0 12px 24px rgba(226, 88, 58, 0.3);
}
.btn.primary:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--coral-deep); }
.btn.big { min-height: 60px; font-size: 24px; font-weight: 700; }
.btn.ghost { width: 100%; background: var(--paper-2); border: 2px solid var(--line); }
.btn.ghost:active { background: #efe3d2; }
.btn.small { min-height: 42px; font-size: 15px; padding: 0 16px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--paper); box-shadow: var(--shadow); color: var(--ink);
}
.icon-btn.small { width: 34px; height: 34px; }
.icon-btn:active { transform: scale(0.94); }
.pill {
  height: 40px; padding: 0 16px; border-radius: 999px; font-weight: 600; font-size: 15px;
  background: var(--paper); box-shadow: var(--shadow);
}
.pill.accent { background: var(--mint); color: #fff; }
.pill:active { transform: scale(0.96); }

/* ------------------------------------------------------------ screens */

.screen { position: fixed; inset: 0; z-index: 5; display: grid; place-items: center; padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b)); pointer-events: none; }
.screen > * { pointer-events: auto; }
.screen.dim { background: rgba(30, 26, 40, 0.42); pointer-events: auto; z-index: 20; animation: fade 0.2s ease both; }
@keyframes fade { from { opacity: 0; } }

.menu-card {
  width: min(100%, 360px);
  padding: 26px 24px 22px; border-radius: 32px;
  background: var(--paper); box-shadow: 0 24px 60px rgba(35, 30, 50, 0.28), 0 3px 0 rgba(255, 255, 255, 0.7) inset;
  display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
  animation: rise 0.4s var(--ease) both;
}
.menu-card.small { width: min(100%, 320px); }
.menu .menu-card { margin-top: 18vh; }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
.logo { margin: -6px 0 -4px; }
.title { font-size: 48px; font-weight: 700; line-height: 1; letter-spacing: -0.01em; }
.title.small { font-size: 30px; }
.tag { color: var(--ink-soft); font-size: 16px; line-height: 1.35; margin-bottom: 4px; }
.row { display: flex; gap: 10px; width: 100%; }
.row .btn { flex: 1; }

/* ------------------------------------------------------------ creator */

.creator { place-items: stretch; grid-template-rows: auto auto 1fr; padding: 0; }
.cr-head { display: flex; align-items: center; gap: 12px; padding: calc(14px + var(--safe-t)) 16px 6px; }
.cr-head h2 { font-size: 22px; font-weight: 700; background: var(--paper); padding: 8px 16px; border-radius: 999px; box-shadow: var(--shadow); }
.spacer { flex: 1; }
.cr-tabs { display: flex; gap: 8px; padding: 6px 16px; justify-content: flex-start; }
.cr-tab {
  display: flex; align-items: center; gap: 6px; padding: 4px 12px 4px 4px; border-radius: 999px;
  background: rgba(255, 250, 242, 0.75); box-shadow: var(--shadow); font-weight: 600; font-size: 14px;
  border: 2px solid transparent;
}
.cr-tab img { width: 36px; height: 36px; border-radius: 50%; background: #ffe9d6; object-fit: cover; }
.cr-tab.on { background: var(--paper); border-color: var(--coral); }
.cr-panel {
  align-self: end; justify-self: end;
  width: min(420px, 100%); max-height: calc(100vh - 140px); overflow-y: auto;
  margin: 0 16px calc(16px + var(--safe-b)); padding: 16px; border-radius: 28px;
  background: var(--paper); box-shadow: 0 20px 50px rgba(35, 30, 50, 0.25);
  display: flex; flex-direction: column; gap: 12px;
  animation: rise 0.35s var(--ease) both;
}
.cr-panel > * { flex-shrink: 0; }
.cr-name { display: flex; gap: 10px; align-items: end; }
.field { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.08em; }
.field input {
  height: 44px; border-radius: 14px; border: 2px solid var(--line); background: #fff; padding: 0 12px;
  font: 600 18px var(--font); color: var(--ink); text-transform: none; letter-spacing: 0; user-select: text; -webkit-user-select: text;
}
.cr-name .btn { width: auto; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 38px; padding: 0 14px; border-radius: 999px; font-weight: 600; font-size: 15px;
  background: var(--paper-2); color: var(--ink-soft);
}
.chip.on { background: var(--ink); color: #fff; }
.opts { display: flex; flex-direction: column; gap: 12px; }
.opt-title { font-size: 12px; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }
.opt-row { display: flex; flex-wrap: wrap; gap: 6px; }
.opt { min-height: 38px; padding: 0 13px; border-radius: 12px; background: #fff; border: 2px solid var(--line); font-weight: 500; font-size: 15px; }
.opt.on { border-color: var(--coral); background: #fff1ea; font-weight: 600; }
.opt-note { color: var(--ink-soft); font-size: 14px; }
.swatch-row { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line); flex: none; }
.swatch.on { box-shadow: 0 0 0 3px var(--coral); transform: scale(1.08); }
.swatch.shemagh { background: repeating-linear-gradient(0deg, #c23b3b 0 3px, transparent 3px 8px), repeating-linear-gradient(90deg, #c23b3b 0 3px, #f7f3ec 3px 8px); }

/* ------------------------------------------------------------ towns */

.town { place-items: start center; }
.town-head { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.town-title { font-size: 13px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: #fff; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); }
.town-switch { display: flex; align-items: center; gap: 10px; }
.town-name { background: var(--paper); border-radius: 22px; padding: 10px 20px; box-shadow: var(--shadow); text-align: center; min-width: 220px; max-width: 70vw; }
.town-name h2 { font-size: 26px; font-weight: 700; line-height: 1.1; }
.town-name p { font-size: 14px; color: var(--ink-soft); }
.pins { position: fixed; inset: 0; pointer-events: none; }
.pin {
  position: absolute; left: 0; top: 0; pointer-events: auto;
  padding: 7px 12px; border-radius: 14px; font-weight: 600; font-size: 14px; white-space: nowrap;
  background: var(--paper); box-shadow: var(--shadow);
}
.pin::after { content: ""; position: absolute; left: 50%; bottom: -7px; margin-left: -7px; border: 7px solid transparent; border-bottom: 0; border-top-color: var(--paper); }
.pin.empty { background: #f2f7ef; }
.pin.home { background: var(--coral); color: #fff; }
.pin.home::after { border-top-color: var(--coral); }
.pin.picked { outline: 3px solid var(--sky); }
.pin.edge { opacity: 0.94; font-size: 13px; padding: 6px 10px; }
.pin.edge::after { display: none; }
.lot-card {
  position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%);
  width: min(360px, calc(100% - 32px)); padding: 18px; border-radius: 26px;
  background: var(--paper); box-shadow: 0 18px 50px rgba(35, 30, 50, 0.3);
  display: flex; flex-direction: column; gap: 8px; text-align: center;
  animation: rise 0.3s var(--ease) both;
}
.lot-card h3 { font-size: 24px; font-weight: 700; }
.lot-card p { color: var(--ink-soft); font-size: 15px; margin-bottom: 4px; }
.lot-card .icon-btn { position: absolute; right: 10px; top: 10px; box-shadow: none; background: var(--paper-2); }
.back-home { position: fixed; left: 16px; top: calc(16px + var(--safe-t)); width: auto; }

/* ------------------------------------------------------------ HUD */

.hud { position: fixed; inset: 0; z-index: 4; pointer-events: none; }
.hud > *, .hud .live-bar > *, .hud .build-bar, .hud .hold-bar, .hud .build-top { pointer-events: auto; }
.clock {
  position: absolute; left: 12px; top: calc(12px + var(--safe-t));
  background: var(--paper); border-radius: 20px; box-shadow: var(--shadow); padding: 8px 10px 8px 14px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; max-width: calc(100vw - 150px);
}
.clock-read { display: flex; flex-direction: column; line-height: 1.05; }
.clock-read span { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.clock-read b { font-size: 18px; font-variant-numeric: tabular-nums; }
.speeds { display: flex; gap: 2px; background: var(--paper-2); border-radius: 999px; padding: 3px; }
.speeds button { width: 36px; height: 30px; border-radius: 999px; display: grid; place-items: center; color: var(--ink-soft); }
.speeds button.on { background: var(--ink); color: #fff; }
.ffwd { width: 100%; font-size: 12px; font-weight: 600; color: #6b5bd6; }
.top-right { position: absolute; right: 12px; top: calc(12px + var(--safe-t)); display: flex; gap: 8px; align-items: center; }
.hud.building .top-right, .hud.building .clock { display: none; }
.cam { position: absolute; right: 12px; top: calc(70px + var(--safe-t)); display: flex; flex-direction: column; gap: 8px; }
.cam .icon-btn { width: 40px; height: 40px; }

.live-bar {
  position: absolute; left: 12px; right: 12px; bottom: calc(12px + var(--safe-b));
  display: flex; align-items: flex-end; gap: 10px; pointer-events: none;
}
.people { display: flex; gap: 6px; background: var(--paper); border-radius: 22px; box-shadow: var(--shadow); padding: 6px; }
.face { position: relative; width: 58px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 2px; border-radius: 16px; }
.face img { width: 50px; height: 50px; border-radius: 50%; background: #ffe9d6; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line); object-fit: cover; }
.face span { font-size: 12px; font-weight: 600; max-width: 56px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.face.on img { box-shadow: 0 0 0 3px var(--mint); }
.face .mood { position: absolute; right: 4px; top: 4px; width: 13px; height: 13px; border-radius: 50%; border: 2px solid #fff; background: #3fbf7f; }
.needs-card {
  flex: 1; max-width: 360px; background: var(--paper); border-radius: 22px; box-shadow: var(--shadow); padding: 10px 14px 12px;
}
.need-head { display: flex; align-items: center; gap: 8px; }
.need-head b { font-size: 18px; }
.mood-tag { --m: #3fbf7f; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; color: #fff; background: var(--m); }
.need-doing { font-size: 13px; color: var(--ink-soft); margin: 1px 0 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bars { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.bar { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--ink-soft); }
.bar svg { width: 16px; height: 16px; }
.bar i { display: block; width: 100%; height: 8px; border-radius: 99px; background: var(--paper-2); overflow: hidden; }
.bar b { display: block; height: 100%; width: 100%; border-radius: 99px; background: var(--c); transform-origin: left center; transition: transform 0.4s var(--ease); }
.bar.low { color: #e2583a; }
.bar.low b { animation: blink 1s ease-in-out infinite; }
@keyframes blink { 50% { opacity: 0.45; } }
.mode-btn {
  margin-left: auto; width: 72px; height: 72px; border-radius: 24px; background: var(--coral); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-weight: 600; font-size: 13px;
  box-shadow: 0 5px 0 var(--coral-deep), 0 12px 24px rgba(226, 88, 58, 0.3);
}
.mode-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--coral-deep); }

/* build */
.build-top {
  position: absolute; left: 50%; top: calc(12px + var(--safe-t)); transform: translateX(-50%);
  display: flex; gap: 8px; align-items: center; max-width: calc(100vw - 24px);
}
.hint { background: rgba(45, 42, 50, 0.82); color: #fff; font-size: 14px; font-weight: 500; padding: 9px 14px; border-radius: 999px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.build-bar {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 12px calc(12px + var(--safe-b));
  background: var(--paper); border-radius: 26px 26px 0 0; box-shadow: 0 -10px 30px rgba(35, 30, 50, 0.16);
  display: flex; flex-direction: column; gap: 8px;
}
.tabs { margin: 0 auto; max-width: 100%; }
.tray { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 2px 4px; }
.tray::-webkit-scrollbar { display: none; }
.tool, .card {
  flex: none; width: 84px; height: 92px; border-radius: 18px; background: var(--paper-2); border: 2px solid transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 4px;
  font-size: 12px; font-weight: 600; line-height: 1.1; text-align: center; color: var(--ink);
}
.tool.on, .card.on { border-color: var(--coral); background: #fff1ea; }
.tool .tex { width: 44px; height: 44px; border-radius: 12px; display: block; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.8) inset, 0 2px 6px rgba(0, 0, 0, 0.12); }
.tool.paint { width: 56px; height: 56px; }
.tool.paint .tex { width: 38px; height: 38px; border-radius: 50%; }
.card img { width: 62px; height: 62px; object-fit: contain; }
.card span { max-height: 2.2em; overflow: hidden; }
.tray-swatches { justify-content: center; }
.hold-bar {
  position: absolute; left: 50%; bottom: calc(196px + var(--safe-b)); transform: translateX(-50%);
  display: flex; gap: 6px; align-items: center; padding: 6px 6px 6px 14px; border-radius: 999px;
  background: rgba(255, 250, 242, 0.96); box-shadow: var(--shadow); max-width: calc(100vw - 16px);
}
.hold-bar b { font-size: 14px; white-space: nowrap; max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
.hold-bar .pill { height: 36px; padding: 0 12px; font-size: 14px; box-shadow: none; background: var(--paper-2); }
.hold-bar .pill.accent { background: var(--mint); }

/* ------------------------------------------------------------ floating bits */

.pie {
  position: fixed; z-index: 12; min-width: 180px; max-width: 260px; padding: 8px;
  background: var(--paper); border-radius: 20px; box-shadow: 0 16px 40px rgba(35, 30, 50, 0.3);
  display: flex; flex-direction: column; gap: 4px; animation: rise 0.18s var(--ease) both;
}
.pie-title { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-soft); padding: 4px 10px 2px; }
.pie button { text-align: left; padding: 10px 12px; border-radius: 12px; font-weight: 600; font-size: 16px; }
.pie button:hover, .pie button:active { background: var(--paper-2); }

#labels { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
.bubble {
  position: absolute; left: 0; top: 0; padding: 6px 10px; border-radius: 16px; font-size: 22px; line-height: 1;
  background: #fff; box-shadow: 0 6px 14px rgba(35, 30, 50, 0.2); animation: pop 0.25s var(--ease) both;
}
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -8px; margin-left: -6px; border: 8px solid transparent; border-bottom: 0; border-top-color: #fff; border-left-width: 6px; border-right-width: 6px; }
.bubble.think { background: #f4efff; }
.bubble.think::after { border: 0; width: 9px; height: 9px; border-radius: 50%; background: #f4efff; bottom: -12px; margin-left: -4px; }
@keyframes pop { from { opacity: 0; transform: scale(0.6); } }

.toast {
  position: fixed; z-index: 15; left: 50%; bottom: calc(150px + var(--safe-b)); transform: translateX(-50%);
  width: max-content; max-width: min(92vw, 440px); text-align: center;
  padding: 11px 16px; border-radius: 16px; background: rgba(45, 42, 50, 0.9); color: #fff; font-size: 15px; font-weight: 500; line-height: 1.35;
}
.toast.in { animation: toastIn 0.25s var(--ease) both; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } }

.news-card { width: min(100%, 420px); text-align: left; align-items: stretch; }
.news-card .title { text-align: center; }
.news-list { max-height: 50vh; overflow-y: auto; }
.news-list h3 { font-size: 18px; margin-bottom: 6px; }
.news-list h3 small { font-size: 13px; color: var(--ink-soft); font-weight: 500; margin-left: 6px; }
.news-list ul { padding-left: 18px; display: flex; flex-direction: column; gap: 6px; font-size: 15px; line-height: 1.35; color: var(--ink); }

/* ------------------------------------------------------------ loader */

#loader { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: linear-gradient(180deg, #54c1ec, #d3f2fb); transition: opacity 0.5s ease; }
#loader.done { opacity: 0; pointer-events: none; }
.loader-inner { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.loader-house { width: 64px; height: 56px; background: var(--paper); clip-path: polygon(50% 0, 100% 42%, 100% 100%, 0 100%, 0 42%); animation: hop 1.1s ease-in-out infinite; box-shadow: 0 0 0 4px var(--coral) inset; }
@keyframes hop { 50% { transform: translateY(-8px); } }
.loader-title { font-size: 32px; font-weight: 700; color: #fff; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.18); }
.loader-sub { color: #fff; font-weight: 500; }

/* ------------------------------------------------------------ small screens */

@media (max-width: 720px) {
  .live-bar { flex-wrap: wrap; left: 8px; right: 8px; bottom: calc(8px + var(--safe-b)); gap: 8px; }
  .needs-card { order: -1; flex-basis: 100%; max-width: none; padding: 8px 12px 10px; }
  .need-doing { display: none; }
  .face { width: 52px; }
  .face img { width: 44px; height: 44px; }
  .mode-btn { width: 64px; height: 64px; }
  .clock { padding: 6px 8px 6px 12px; gap: 8px; }
  .speeds button { width: 32px; }
  .menu .menu-card { margin-top: 26vh; }
  .title { font-size: 42px; }
  .creator .cr-panel { justify-self: stretch; width: auto; max-height: 46vh; margin: 0 8px calc(8px + var(--safe-b)); padding: 12px; border-radius: 24px; gap: 10px; }
  .cr-head h2 { font-size: 18px; }
  .tool, .card { width: 76px; height: 86px; }
  .card img { width: 54px; height: 54px; }
  .hold-bar { bottom: calc(186px + var(--safe-b)); }
  .toast { bottom: calc(210px + var(--safe-b)); }
}
@media (max-height: 560px) {
  .menu .menu-card { margin-top: 0; }
  .cr-panel { max-height: calc(100vh - 110px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01s !important; transition-duration: 0.01s !important; }
}
