:root { --ink: #3a2e39; --accent: #ff8a65; --accent2: #7e57c2; --card: #fffaf3; --line: #f0dccb; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif; color: var(--ink); background: #bfe3f5; -webkit-user-select: none; user-select: none; touch-action: none; }
#game { position: fixed; inset: 0; }
#game canvas { display: block; width: 100%; height: 100%; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; }

.top { position: fixed; left: 0; right: 0; top: 0; display: flex; align-items: center; justify-content: space-between; padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left)); pointer-events: none; }
.top > * { pointer-events: auto; }
.logo { background: #fff; padding: 8px 14px; border-radius: 999px; font-size: 18px; box-shadow: 0 3px 0 rgba(0,0,0,.12); }
.logo b { color: var(--accent); }
.tools { display: flex; gap: 8px; }
.big { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 64px; min-height: 60px; padding: 6px 10px; border: 0; border-radius: 18px; background: #fff; font-size: 24px; box-shadow: 0 4px 0 rgba(0,0,0,.15); }
.big span { font-size: 12px; font-weight: 700; }
.big:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.15); }
.big.on { background: var(--accent); color: #fff; }

.floors { position: fixed; right: 12px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 10px; }

#turn { position: fixed; left: 50%; top: 84px; transform: translateX(-50%); background: #fff; padding: 8px 12px; border-radius: 16px; font-weight: 700; font-size: 14px; box-shadow: 0 4px 0 rgba(0,0,0,.12); display: flex; gap: 8px; align-items: center; white-space: nowrap; }
#turn button { border: 0; background: #eee; border-radius: 50%; width: 26px; height: 26px; }

#family { position: fixed; left: 50%; bottom: max(10px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; gap: 8px; padding: 8px 10px; background: rgba(255,255,255,.85); border-radius: 22px; max-width: calc(100vw - 20px); overflow-x: auto; box-shadow: 0 4px 0 rgba(0,0,0,.1); }
.person { display: flex; flex-direction: column; align-items: center; gap: 2px; border: 3px solid transparent; background: none; border-radius: 16px; padding: 4px 6px; min-width: 62px; }
.person b { font-size: 12px; max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person.on { border-color: #ffd54f; background: #fff8dc; }
.person.add { font-size: 28px; color: var(--accent2); }
.face { position: relative; width: 42px; height: 42px; border-radius: 50%; background: var(--skin); border: 3px solid var(--top); display: block; overflow: hidden; }
.face .hair { position: absolute; left: -2px; right: -2px; top: -6px; height: 20px; background: var(--hair); border-radius: 50% 50% 40% 40%; }
.face .hair.bald { display: none; }
.face .hair.long { height: 30px; border-radius: 45%; top: -8px; }
.face .hair.spiky { clip-path: polygon(0 100%, 10% 20%, 25% 70%, 40% 0, 55% 70%, 70% 10%, 85% 70%, 100% 20%, 100% 100%); }
.face .eyes::before, .face .eyes::after { content: ""; position: absolute; top: 20px; width: 6px; height: 7px; border-radius: 50%; background: #222; }
.face .eyes::before { left: 11px; } .face .eyes::after { right: 11px; }

#msg { position: fixed; left: 50%; top: 78px; transform: translate(-50%, -10px); background: #fff; padding: 10px 18px; border-radius: 16px; font-weight: 700; box-shadow: 0 4px 0 rgba(0,0,0,.12); opacity: 0; transition: .25s; pointer-events: none; text-align: center; max-width: 90vw; }
#msg.show { opacity: 1; transform: translate(-50%, 0); }

.overlay { position: fixed; inset: 0; background: rgba(58,46,57,.35); display: flex; align-items: center; justify-content: center; padding: 14px; z-index: 20; }
.overlay[hidden], [hidden] { display: none !important; }
.card { background: var(--card); border-radius: 24px; padding: 18px 20px; width: min(560px, 100%); max-height: 92vh; overflow-y: auto; box-shadow: 0 8px 0 rgba(0,0,0,.15); }
.card h2 { margin: 0 0 12px; font-size: 22px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 8px 0; }
.row > span { width: 92px; font-weight: 700; font-size: 14px; }
.row.end { justify-content: flex-end; margin-top: 16px; }
.sw { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line); }
.sw.on { box-shadow: 0 0 0 3px var(--accent); }
.chip { border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font-weight: 700; text-transform: capitalize; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.name { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.name input, .card input[type=text] { font: inherit; font-size: 18px; padding: 8px 12px; border-radius: 12px; border: 2px solid var(--line); -webkit-user-select: text; user-select: text; }
.btn { border: 0; background: var(--accent); color: #fff; font-weight: 700; padding: 10px 18px; border-radius: 14px; box-shadow: 0 3px 0 rgba(0,0,0,.15); }
.btn.ghost { background: #fff; color: var(--ink); border: 2px solid var(--line); }

.upload { display: flex; flex-direction: column; gap: 4px; padding: 16px; border: 3px dashed var(--accent); border-radius: 18px; background: #fff3ec; cursor: pointer; font-size: 22px; }
.upload b { font-size: 18px; } .upload span { font-size: 14px; }
.upload input { font-size: 14px; margin-top: 6px; }
.examples { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 14px 0; }
.examples button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px; background: #fff; border: 2px solid var(--line); border-radius: 18px; font-size: 30px; }
.examples b { font-size: 15px; } .examples span { font-size: 12px; }
.small { font-size: 13px; }
#hp-busy { margin: 10px 0; font-weight: 700; }

#palette { position: fixed; left: 10px; top: 80px; bottom: 120px; width: 170px; overflow-y: auto; background: rgba(255,255,255,.92); border-radius: 18px; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
#palette .tip { font-size: 12px; margin: 2px 4px 6px; }
.pal { display: flex; align-items: center; gap: 8px; border: 2px solid transparent; background: #fff; border-radius: 12px; padding: 6px 8px; text-align: left; font-size: 13px; font-weight: 700; }
.pal span { font-size: 22px; }
.pal.on { border-color: var(--accent); background: #fff3ec; }
#selbar { position: fixed; left: 50%; top: 80px; transform: translateX(-50%); display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px; background: #fff; padding: 8px 10px; border-radius: 18px; box-shadow: 0 4px 0 rgba(0,0,0,.12); max-width: 94vw; }
body.decorating #family { display: none; }

#loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 700; background: #bfe3f5; z-index: 30; }

/* Auto Builder's dialogs (asked while reading an uploaded plan). */
.modal-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.3); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 16px; padding: 18px 20px; width: min(420px, 100%); }
.modal.wide { width: min(820px, 100%); max-height: 90vh; overflow-y: auto; }
.modal .choices { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.modal .thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.modal .thumb { border: 2px solid var(--line); background: #fff; border-radius: 10px; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.modal .thumb img { width: 100%; }
.toast { position: fixed; top: 140px; left: 50%; transform: translateX(-50%); max-width: min(560px, 90vw); text-align: center; background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 12px; font-size: 14px; z-index: 60; transition: opacity .4s; }
.toast.out { opacity: 0; }

@media (max-width: 600px) {
  .logo { font-size: 15px; padding: 6px 10px; }
  .big { min-width: 54px; min-height: 52px; font-size: 20px; }
  #stick { width: 96px; height: 96px; bottom: 104px; }
  #palette { width: 140px; }
}

/* Phones on their side: short screens, so everything a little smaller and tucked to the edges. */
@media (max-height: 500px) {
  .big { min-width: 50px; min-height: 48px; font-size: 19px; padding: 4px 8px; border-radius: 14px; }
  .big span { font-size: 10px; }
  .logo { display: none; }
  .floors { right: max(8px, env(safe-area-inset-right)); gap: 6px; }
  #family { left: max(8px, env(safe-area-inset-left)); transform: none; bottom: 6px; padding: 4px 6px; }
  .face { width: 34px; height: 34px; }
  .person { min-width: 48px; padding: 2px 4px; }
  #msg { top: 66px; }
  #palette { top: 66px; bottom: 8px; }
}
@media (max-width: 600px) { #full span, .tools .big span { font-size: 10px; } }
