:root {
  --bg: #fff6f1;
  --ink: #3b2a33;
  --muted: #8a7480;
  --card: #ffffff;
  --line: #f0dfe4;
  --pink: #ff7aa2;
  --pink-dark: #e0507d;
  --mess: #ff9a62;
  --tid: #4fb6c2;
  --love: #ff5d8f;
  --good: #2e9e6a;
  --bad: #d9534f;
  --wall: #5a4636;
  --shadow: 0 6px 24px rgba(120, 60, 80, .12);
  --emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
.emoji-font, .emoji { font-family: var(--emoji); }

#app {
  height: 100dvh;
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}

/* ---------- header ---------- */
.top { display: flex; align-items: center; gap: 12px; }
.brand { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -.02em; flex: 1; white-space: nowrap; }
.brand span { color: var(--pink); font-style: italic; }
.day { font-weight: 700; background: var(--card); border: 1px solid var(--line); border-radius: 99px; padding: 3px 12px; white-space: nowrap; }
.ap { display: flex; gap: 4px; }
.pip { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #f2b84b; background: transparent; }
.pip.full { background: #ffc94d; box-shadow: 0 0 6px rgba(255, 190, 60, .7); }
.icon-btn {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); font-weight: 800; flex: none;
}

/* ---------- meters ---------- */
.meters { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.meter { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px; }
.meter-label { display: flex; justify-content: space-between; font-size: 13px; white-space: nowrap; gap: 6px; }
.meter-label span { overflow: hidden; text-overflow: ellipsis; }
.bar { height: 8px; background: #f4e8ec; border-radius: 99px; overflow: hidden; margin-top: 4px; }
.bar div { height: 100%; border-radius: 99px; transition: width .6s ease; }
.meter-love .bar div { background: var(--love); }
.meter-mess .bar div { background: var(--mess); }
.meter-tid .bar div { background: var(--tid); }
.meter-tidy .bar div { background: #8bc34a; }
.meter.low { border-color: #f3a9a7; animation: lowPulse 1.6s ease-in-out infinite; }
.meter.low b { color: var(--bad); }
@keyframes lowPulse { 50% { box-shadow: 0 0 0 3px rgba(217, 83, 79, .18); } }

/* ---------- stage ---------- */
.stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
#apt { width: 100%; height: 100%; max-height: 100%; border-radius: 14px; filter: drop-shadow(var(--shadow)); user-select: none; }
.wall { fill: none; stroke: var(--wall); stroke-width: 8; }
.outer-wall { fill: none; stroke: var(--wall); stroke-width: 6; rx: 10; }
.door { fill: #e8dccb; }
.front-door { fill: #b5835a; }
.rug { fill: #f6c7a9; opacity: .75; }
.rug-inner { fill: none; stroke: #fff; stroke-width: 3; stroke-dasharray: 8 6; opacity: .7; }
.room-label { font-size: 13px; font-weight: 700; fill: rgba(59, 42, 51, .35); letter-spacing: .04em; text-transform: uppercase; pointer-events: none; }
.furniture rect { stroke: rgba(0, 0, 0, .18); stroke-width: 2; }
.emoji { text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.night { fill: #2a2f6b; opacity: 0; transition: opacity 1s ease; }

.item { cursor: pointer; outline: none; }
.item-inner { animation: bob 2.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.item .hit { fill: rgba(255, 255, 255, .7); stroke: rgba(224, 80, 125, .55); stroke-width: 2; stroke-dasharray: 4 3; transition: all .2s; }
.item:hover .hit, .item:focus-visible .hit { fill: #fff; stroke: var(--pink-dark); stroke-dasharray: none; }
.item.selected .hit { fill: #fff; stroke: var(--pink-dark); stroke-width: 4; stroke-dasharray: none; }
.item.selected .item-inner { animation: wiggle .5s ease-in-out infinite; }
.item .heavy { font-size: 13px; font-weight: 900; fill: var(--bad); }
.item.poof .item-inner { animation: poof .45s ease-in forwards; }
@keyframes bob { 50% { transform: translateY(-3px); } }
@keyframes wiggle { 25% { transform: rotate(-8deg) scale(1.12); } 75% { transform: rotate(8deg) scale(1.12); } }
@keyframes poof { to { transform: scale(0); opacity: 0; } }
.sparkle { animation: sparkle 1s ease-out forwards; }
@keyframes sparkle { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-30px); } }

.char { transition: transform 1s ease-in-out; pointer-events: none; }
.char.walking .char-body { animation: walk .25s ease-in-out infinite alternate; }
@keyframes walk { from { transform: translateY(0) rotate(-4deg); } to { transform: translateY(-4px) rotate(4deg); } }
.char .skin { stroke: rgba(0, 0, 0, .35); stroke-width: 2; }
.char-mess .skin { fill: #ffd2b0; }
.char-tid .skin { fill: #f4d6b8; }
.char-mess .hair { fill: #8a4b22; }
.char-tid .hair { fill: #20202e; }
.char .eye { fill: #2b2026; }
.char .glasses { fill: none; stroke: #20202e; stroke-width: 1.6; }
.char .cheek { fill: #ff8fab; opacity: .55; }
.char .mouth { fill: none; stroke: #2b2026; stroke-width: 2.2; stroke-linecap: round; transition: d .4s; }
.name-tag text { font-size: 11px; font-weight: 800; fill: #fff; text-anchor: middle; dominant-baseline: central; }
.char-mess .name-tag rect { fill: var(--mess); }
.char-tid .name-tag rect { fill: var(--tid); }
.bubble { opacity: 0; transition: opacity .25s; }
.bubble.show { opacity: 1; }
.bubble rect, .bubble .tail { fill: #fff; stroke: rgba(0, 0, 0, .2); stroke-width: 1.5; }
.bubble .tail { stroke: none; }
.bubble text { font-size: 13px; font-weight: 600; fill: var(--ink); text-anchor: middle; dominant-baseline: central; }

.toast {
  position: absolute; left: 50%; bottom: 10px; transform: translate(-50%, 20px);
  width: max-content; max-width: min(92%, 560px);
  background: rgba(59, 42, 51, .94); color: #fff; padding: 8px 14px; border-radius: 14px;
  font-size: 14px; opacity: 0; transition: all .3s; pointer-events: none; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast .chip { background: rgba(255, 255, 255, .16); color: #fff; }

/* ---------- panel ---------- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 10px 12px; box-shadow: var(--shadow); }
.hint { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.actions { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.act, .opt {
  text-align: left; background: #fff8fa; border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 10px; display: flex; flex-direction: column; gap: 3px; transition: transform .1s, border-color .2s;
}
.act:not(:disabled):hover, .opt:not(:disabled):hover { border-color: var(--pink); transform: translateY(-1px); }
.act small, .opt small { color: var(--muted); font-size: 12px; line-height: 1.25; }
.act-top, .opt-top { font-weight: 700; display: flex; align-items: center; gap: 5px; }
.cost { margin-left: auto; font-size: 12px; font-weight: 700; color: #b07a00; background: #fff1c9; border-radius: 99px; padding: 1px 7px; white-space: nowrap; }
.end-day {
  margin-top: 8px; width: 100%; padding: 10px; border: 0; border-radius: 12px;
  background: linear-gradient(135deg, #5b5fc7, #8a5cc7); color: #fff; font-weight: 800;
}
.end-day small { font-weight: 500; opacity: .8; }
.end-day.pulse { animation: glow 1.4s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 5px rgba(120, 100, 220, .25); } }

.item-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.item-head .big { font-size: 34px; line-height: 1; }
.item-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.item-head small { color: var(--muted); }
.item-head > div { flex: 1; }
.options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.opt-chips { display: flex; flex-wrap: wrap; gap: 4px; }

.chip { display: inline-block; font-size: 12px; font-weight: 700; border-radius: 99px; padding: 1px 7px; margin: 1px 2px; white-space: nowrap; }
.chip.up { background: #e2f6ea; color: var(--good); }
.chip.down { background: #fde6e6; color: var(--bad); }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(50, 25, 40, .45); display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 10; backdrop-filter: blur(3px); animation: fadeIn .25s;
}
.modal.hidden { display: none; }
.card {
  background: var(--card); border-radius: 20px; padding: 20px 22px; max-width: 520px; width: 100%;
  max-height: calc(100dvh - 32px); overflow-y: auto; box-shadow: 0 20px 60px rgba(60, 20, 40, .3); animation: pop .3s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.92); opacity: 0; } }
.card h2 { margin: 2px 0 8px; font-size: 22px; letter-spacing: -.01em; }
.card p { margin: 6px 0; }
.card hr { border: 0; border-top: 1px dashed var(--line); margin: 12px 0; }
.kicker { color: var(--pink-dark); font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; margin: 0 !important; }
.result { font-size: 17px; }
.chips { margin: 10px 0 0; }
.notes { margin: 8px 0; padding-left: 20px; }
.notes li { margin: 3px 0; }
.modal-buttons { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.modal-buttons.stack { flex-direction: column; }
.modal-buttons button { border-radius: 12px; padding: 10px 16px; font-weight: 700; border: 1px solid transparent; }
.modal-buttons .primary { background: var(--pink); color: #fff; }
.modal-buttons .primary:hover { background: var(--pink-dark); }
.modal-buttons .ghost { background: transparent; border-color: var(--line); }
.modal-buttons .choice { background: #fff8fa; border-color: var(--line); text-align: left; }
.modal-buttons .choice:hover { border-color: var(--pink); background: #fff0f5; }

.title-card { text-align: center; }
.logo { font-size: 46px; }
.logo-title { font-size: 28px !important; margin: 0 !important; }
.tagline { color: var(--muted); }
.cast { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.cast-card { border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.cast-card b { font-size: 15px; }
.cast-card.mess { background: #fff0e6; }
.cast-card.tid { background: #e5f6f8; }
.howto { padding-left: 0; list-style: none; margin: 8px 0 0; font-size: 14px; }
.howto li { margin: 6px 0; }

.ending { text-align: center; }
.ending-emoji { font-size: 64px; animation: pop .6s ease-out; }
.ending.good .ending-emoji { animation: pop .6s ease-out, bob 2s ease-in-out .6s infinite; }
.final-stats { margin-top: 10px; font-weight: 700; font-size: 18px; }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  #app { height: auto; min-height: 100dvh; }
  .stage { flex: none; }
  #apt { height: auto; }
  #app { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); gap: 6px; }
  .brand { font-size: 16px; }
  .pip { width: 9px; height: 9px; }
  .ap { gap: 3px; }
  .meters { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .meter { padding: 4px 8px; }
  .meter-label { font-size: 12px; }
  .actions { grid-template-columns: repeat(2, 1fr); }
  .actions .act:last-child { grid-column: span 2; }
  .act small { display: none; }
  .options { grid-template-columns: 1fr; }
  .opt { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .opt-top { flex: 1 1 100%; }
  .opt small { display: none; }
  .panel { padding: 8px 10px; }
  .hint { font-size: 13px; margin-bottom: 6px; }
}
@media (max-width: 420px) {
  .brand { font-size: 14px; }
  .ap .pip { width: 8px; height: 8px; }
  .day { padding: 2px 8px; font-size: 13px; }
}
