:root {
  --bg: #fff4e0;
  --card: #ffffff;
  --ink: #3b2f2a;
  --sub: #8a7a70;
  --line: #3b2f2a;
  --accent: #ffcf3f;
  --accent-ink: #3b2f2a;
  --pink: #ff9eae;
  --wall-day: #fde9c9;
  --wall-eve: #f6cfb0;
  --wall-night: #4b4466;
  --floor: #e2b98a;
  --floor-night: #6b5a52;
  --bar-full: #ffb44a;
  --bar-mood: #ff8fa3;
  --bar-clean: #6cc6e8;
  --bar-energy: #8fd16a;
  --shadow: 0 3px 0 var(--line);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #2a2420; --card: #3a322c; --ink: #f6eadf; --sub: #b9a99c; --line: #120e0c; }
}
:root[data-theme="dark"] { --bg: #2a2420; --card: #3a322c; --ink: #f6eadf; --sub: #b9a99c; --line: #120e0c; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: "Gowun Dodum", system-ui, sans-serif; }
body { min-height: 100dvh; overscroll-behavior: none; }
body:has(.sheet:not(.hidden)), body:has(.zoom:not(.hidden)) { overflow: hidden; }
.hidden { display: none !important; }
h1, h2, .title, .btn, .name-tag, .bubble { font-family: "Jua", "Gowun Dodum", sans-serif; font-weight: 400; }
#app { max-width: 560px; margin: 0 auto; padding: 0 16px calc(16px + env(safe-area-inset-bottom)); }

.card { background: var(--card); border: 2.5px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
.btn { border: 2.5px solid var(--line); border-radius: 16px; background: var(--card); color: var(--ink); font-size: 17px;
  padding: 10px 12px; box-shadow: 0 3px 0 var(--line); cursor: pointer; transition: transform .08s; }
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--line); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .45; }
.icon-btn { border: none; background: none; font-size: 20px; color: var(--ink); cursor: pointer; padding: 6px 8px; font-family: "Jua"; }

/* 로그인 */
.screen { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { padding: 28px 22px; width: min(340px, 100%); text-align: center; display: grid; gap: 12px; }
.login-card h1 { margin: 0; font-size: 30px; }
.login-card input { min-width: 0; width: 100%; font-size: 18px; padding: 12px; border-radius: 14px; border: 2.5px solid var(--line); background: var(--bg); color: var(--ink); text-align: center; }
.err { color: #d4475c; min-height: 1.2em; margin: 0; }

/* 상단 */
.top { display: flex; flex-wrap: wrap; gap: 4px 8px; justify-content: space-between; align-items: center; padding: calc(10px + env(safe-area-inset-top)) 0 8px; }
.title { font-size: 24px; }
.top-btns { display: flex; align-items: center; }
#clock { font-size: 15px; color: var(--sub); margin-left: 6px; }

/* 방 */
.room { position: relative; height: clamp(360px, 58vh, 430px); min-height: min(430px, 90vw); border: 2.5px solid var(--line); border-radius: 26px; overflow: hidden; box-shadow: var(--shadow); user-select: none; }
.wall { position: absolute; inset: 0 0 34% 0; background: var(--wall-day); transition: background 2s; }
.floor { position: absolute; inset: 66% 0 0 0; background: var(--floor); border-top: 2.5px solid var(--line);
  background-image: repeating-linear-gradient(90deg, transparent 0 58px, rgba(0,0,0,.07) 58px 61px); transition: background-color 2s; }
.room.eve .wall { background: var(--wall-eve); }
.room.night .wall { background: var(--wall-night); }
.room.night .floor { background-color: var(--floor-night); }
.room.lights-off::after { content: ""; position: absolute; inset: 0; background: rgba(20, 16, 40, .45); pointer-events: none; }
.window { position: absolute; left: 7%; top: 12%; width: 26%; aspect-ratio: 1; border: 2.5px solid var(--line); border-radius: 14px; overflow: hidden; background: #fff; }
.window::before, .window::after { content: ""; position: absolute; background: var(--line); z-index: 2; }
.window::before { left: 50%; top: 0; bottom: 0; width: 2.5px; }
.window::after { top: 50%; left: 0; right: 0; height: 2.5px; }
.sky { position: absolute; inset: 0; background: linear-gradient(#8fd3ff, #d9f1ff); transition: background 2s; }
.room.eve .sky { background: linear-gradient(#ff9a6b, #ffd89b); }
.room.night .sky { background: linear-gradient(#141a3a, #2c3566); }
.sun { position: absolute; width: 34%; aspect-ratio: 1; border-radius: 50%; right: 14%; top: 14%; background: #ffd84a; border: 2px solid var(--line); }
.room.night .sun { background: #fff6c8; box-shadow: inset -8px -2px 0 #2c3566; }

/* 확대 액자 (햄확이) */
.frame { position: absolute; padding: 0; color: var(--ink); z-index: 1; right: 7%; top: 9%; width: 30%; max-width: 130px; aspect-ratio: 1; border-radius: 50%; border: 5px solid #8a5a3b;
  box-shadow: 0 0 0 2.5px var(--line), inset 0 0 0 2.5px var(--line); overflow: visible; background: #fff; cursor: pointer; }
.frame img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.frame .bubble { top: calc(100% + 10px); bottom: auto; left: auto; right: 0; width: max-content; max-width: 180px; transform: none; animation: none; }
.frame .bubble::after { display: none; }
.frame::after { content: attr(data-badge); position: absolute; right: 6px; bottom: 4px; font-size: 20px; }
.frame.empty img { opacity: 0; }
.frame.empty::before { content: "찾지 마세요…"; position: absolute; inset: 0; display: grid; place-items: center; font-family: "Jua"; font-size: 14px; }

/* 펫 */
.pets { position: absolute; inset: 0; pointer-events: none; }
.pet { position: absolute; bottom: 5%; width: 42%; max-width: 180px; pointer-events: auto; display: flex; flex-direction: column; align-items: center; cursor: pointer; transition: left 3s ease-in-out; }
.pet .sprite { width: 100%; aspect-ratio: 1; position: relative; }
.pet img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 4px 0 rgba(0,0,0,.12)); transform-origin: 50% 100%; animation: breathe 3.2s ease-in-out infinite; }
.pet.boxed img { border-radius: 22px; border: 2.5px solid var(--line); object-fit: cover; }
.pet.react img { animation: hop .5s ease-out 2; }
.pet.asleep img { animation: breathe 5s ease-in-out infinite; filter: brightness(.85); }
.pet.away { opacity: .9; }
.pet.office .sprite { width: 82%; margin-bottom: 14px; border: 3px solid var(--line); border-radius: 14px; background: #dff1ff; padding: 6%; box-shadow: 0 6px 0 #8a8f99, 0 6px 0 2.5px var(--line); }
.pet.office img { animation: none; filter: none; border: none; border-radius: 6px; }
.pet.office .badge { top: -14px; right: -8px; font-size: 13px; font-family: "Jua"; background: var(--card); border: 2px solid var(--line); border-radius: 99px; padding: 0 8px; animation: none; white-space: nowrap; }
.pet.selected .name-tag { background: var(--accent); color: var(--accent-ink); }
.name-tag { margin-top: -4px; font-size: 14px; background: var(--card); border: 2px solid var(--line); border-radius: 999px; padding: 1px 10px; white-space: nowrap; }
.badge { position: absolute; top: 2%; right: 4%; font-size: 22px; animation: float 2s ease-in-out infinite; }
.bubble { position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%); background: var(--card); border: 2.5px solid var(--line); border-radius: 16px;
  padding: 4px 10px; font-size: 15px; white-space: normal; width: max-content; max-width: 100%; overflow-wrap: anywhere; text-align: center; animation: pop .25s ease-out; z-index: 3; }
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -8px; width: 12px; height: 12px; background: var(--card);
  border-right: 2.5px solid var(--line); border-bottom: 2.5px solid var(--line); transform: translateX(-50%) rotate(45deg); }
.zzz { position: absolute; top: 0; right: 12%; font-family: "Jua"; color: #6a6aa8; font-size: 20px; animation: zzz 2.4s ease-in-out infinite; }
.note { width: 70%; aspect-ratio: 1; display: grid; place-items: center; text-align: center; background: #fffbe6; color: var(--accent-ink); border: 2.5px solid var(--line);
  border-radius: 8px; transform: rotate(-4deg); font-family: "Jua"; font-size: 14px; padding: 8px; margin-bottom: 8px; }
.heart { position: absolute; font-size: 22px; pointer-events: none; animation: heart 1s ease-out forwards; z-index: 4; }

.visitor { position: absolute; left: 50%; top: 8%; transform: translateX(-50%); width: 44%; padding: 8px; text-align: center; z-index: 5; animation: pop .3s ease-out; }
.visitor img { width: 100%; border-radius: 16px; }
.visitor p { margin: 4px 0 0; font-family: "Jua"; font-size: 15px; }

/* 패널 */
.panel { margin-top: 14px; padding: 14px 16px 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.panel-head h2 { margin: 0; font-size: 22px; }
.lv { font-family: "Jua"; color: var(--sub); font-size: 15px; }
.xp { height: 6px; background: rgba(0,0,0,.08); border-radius: 99px; margin: 6px 0 10px; overflow: hidden; }
.xp i { display: block; height: 100%; background: var(--accent); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.stat { font-size: 13px; }
.stat .bar { height: 12px; border: 2px solid var(--line); border-radius: 99px; overflow: hidden; background: rgba(0,0,0,.05); margin-top: 3px; }
.stat .bar i { display: block; height: 100%; transition: width .6s; }
.stat.low .bar { animation: blink 1s steps(2) infinite; }
.state-line { margin: 10px 0 0; color: var(--sub); font-size: 14px; min-height: 1.2em; }
.actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.actions .btn { min-width: 0; word-break: keep-all; padding: 8px 4px; font-size: 15px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.actions .btn:only-child { grid-column: 1 / -1; }
.actions .btn b { font-size: 22px; font-weight: 400; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tabs .btn { flex: 1; min-width: 0; word-break: keep-all; padding: 6px; font-size: 15px; }
.tabs .btn.on { background: var(--accent); color: var(--accent-ink); }

/* 시트 */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet-body { width: min(560px, 100%); max-height: 86dvh; overflow: auto; border-radius: 26px 26px 0 0; padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: -14px; background: var(--card); padding-top: 4px; z-index: 1; }
.sheet-head h2 { margin: 0; font-size: 22px; }
.foods { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.foods .btn { min-width: 0; word-break: keep-all; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 4px; }
.foods .btn b { font-size: 34px; font-weight: 400; }
.foods small { color: var(--sub); font-family: "Gowun Dodum"; font-size: 12px; }
.album-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.album-grid div { aspect-ratio: 1; border-radius: 12px; background: rgba(0,0,0,.05); display: grid; place-items: center; overflow: hidden; font-family: "Jua"; color: var(--sub); }
.album-grid img { width: 100%; height: 100%; object-fit: contain; }
.album-set { gap: 8px; margin: 14px 0 6px; font-family: "Jua"; font-size: 15px; display: flex; justify-content: space-between; }
.album-set span:last-child { flex-shrink: 0; }
@media (max-width: 380px) { .sheet .tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.log-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.log-list li { font-size: 14px; } .log-list time { color: var(--sub); margin-right: 6px; }
.big-img { width: 100%; border-radius: 16px; }

/* 확대 모드 */
.zoom { position: fixed; inset: 0; background: var(--bg); z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; overflow-y: auto; padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)); }
.zoom-view { position: relative; width: min(100%, 420px, max(120px, calc(100dvh - 180px - env(safe-area-inset-top) - env(safe-area-inset-bottom)))); flex-shrink: 0; aspect-ratio: 1; border-radius: 50%; border: 6px solid #8a5a3b; box-shadow: 0 0 0 3px var(--line); overflow: hidden; background: #fff; }
.zoom-view img { width: 100%; height: 100%; object-fit: cover; transition: transform .2s; }
.zoom-view .bubble { bottom: 12%; top: auto; max-width: 80%; }
.zoom-view .bubble::after { display: none; }
#zoom-range { width: min(80vw, 360px); accent-color: #8a5a3b; }
.zoom-hint { margin: 0; text-align: center; flex-shrink: 0; color: var(--sub); font-size: 14px; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 14px; font-family: "Jua"; z-index: 40; max-width: 90vw; text-align: center; animation: pop .2s ease-out; }

@keyframes breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.025, .975); } }
@keyframes hop { 0% { transform: translateY(0); } 40% { transform: translateY(-14%) scale(.97, 1.03); } 100% { transform: translateY(0); } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes pop { from { transform: translateX(-50%) scale(.6); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }
@keyframes zzz { 0% { opacity: 0; transform: translate(0, 0); } 30% { opacity: 1; } 100% { opacity: 0; transform: translate(14px, -26px); } }
@keyframes heart { from { opacity: 1; transform: translateY(0) scale(.8); } to { opacity: 0; transform: translateY(-50px) scale(1.3); } }
@keyframes blink { 50% { opacity: .4; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
