:root {
  --bg: #F6F4EF;
  --ink: #1F2933;
  --muted: #6B7280;
  --line: #E5E1D8;
  --primary: #2563EB;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;   /* 아이폰 두 번 톡 확대 막기 */
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
[hidden] { display: none !important; }

/* ---------- 엄마 화면 ---------- */
#mom { min-height: 100vh; padding-bottom: 170px; }
.sticky { position: sticky; top: 0; z-index: 5; background: var(--bg); padding-top: env(safe-area-inset-top); }
.top { display: flex; align-items: center; gap: 8px; padding: 12px 14px 8px; }
.top h1 { font-size: 21px; margin: 0; flex: 1; letter-spacing: -0.5px; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; background: #fff; font-size: 20px; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.pill { height: 44px; padding: 0 16px; border-radius: 12px; background: var(--ink); color: #fff; font-weight: 700; font-size: 15px; }
.searchbar { padding: 0 14px 8px; }
#search { width: 100%; height: 44px; border-radius: 12px; border: 1px solid var(--line); padding: 0 14px; font-size: 16px; background: #fff; color: var(--ink); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 14px 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 38px; padding: 0 15px; border-radius: 19px; background: #fff; border: 1px solid var(--line); font-size: 15px; white-space: nowrap; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 700; }

.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; padding: 4px 14px; }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } }
.card { position: relative; background: #fff; border-radius: 14px; padding: 6px 6px 8px; box-shadow: 0 1px 3px rgba(0,0,0,.08); border: 3px solid transparent; text-align: center; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: pointer; }
.card img { width: 100%; aspect-ratio: 1 / 1; object-fit: contain; display: block; border-radius: 8px; pointer-events: none; }
.card .name { display: block; font-size: 14px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card.on { border-color: var(--primary); }
.badge { position: absolute; top: 6px; left: 6px; min-width: 28px; height: 28px; padding: 0 6px; border-radius: 14px; background: var(--primary); color: #fff; font-weight: 800; display: grid; place-items: center; font-size: 15px; }
.more { position: absolute; top: 4px; right: 4px; width: 34px; height: 34px; border-radius: 17px; background: rgba(255,255,255,.95); font-size: 18px; font-weight: 800; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.mine { position: absolute; bottom: 30px; right: 8px; font-size: 11px; background: #FFF4CC; color: #7A5B00; border-radius: 6px; padding: 1px 5px; }
.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 40px 0; }

#tray { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: #fff; box-shadow: 0 -2px 14px rgba(0,0,0,.08); border-radius: 18px 18px 0 0; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); }
.tray-list { display: flex; gap: 8px; overflow-x: auto; min-height: 58px; align-items: center; scrollbar-width: none; }
.tray-list::-webkit-scrollbar { display: none; }
.tray-list .hint { color: var(--muted); font-size: 15px; }
.tthumb { position: relative; flex: none; width: 58px; height: 58px; border-radius: 10px; overflow: hidden; border: 2px solid var(--primary); background: #fff; }
.tthumb img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.tthumb span { position: absolute; left: 2px; top: 2px; background: var(--primary); color: #fff; font-size: 11px; font-weight: 800; border-radius: 8px; padding: 0 5px; }
.tray-actions { display: flex; gap: 8px; margin-top: 8px; }
.ghost { height: 52px; padding: 0 18px; border-radius: 14px; background: #F1EFEA; font-weight: 700; }
.primary { flex: 1; height: 52px; border-radius: 14px; background: var(--primary); color: #fff; font-weight: 800; font-size: 17px; }
.primary:disabled { background: #C9CED6; cursor: default; }
.danger { height: 52px; padding: 0 18px; border-radius: 14px; background: #FDECEC; color: #C62828; font-weight: 700; }

/* ---------- 아이 화면 ---------- */
#child { position: fixed; inset: 0; z-index: 30; background: #fff; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#board { position: absolute; inset: 0; display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 16px; padding: 16px; touch-action: none; }
.tile { position: relative; width: var(--tile); display: flex; flex-direction: column; align-items: center; transition: transform .18s ease-out; will-change: transform; }
.tile img { width: var(--tile); height: var(--tile); object-fit: contain; border-radius: 16px; background: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.14); pointer-events: none; -webkit-user-drag: none; }
.tile .label { height: 44px; line-height: 44px; font-size: clamp(18px, calc(var(--tile) * 0.11), 30px); font-weight: 800; white-space: nowrap; pointer-events: none; }
.tile.lift { z-index: 5; transition: none; }

#big { position: absolute; inset: 0; z-index: 10; background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); touch-action: none; }
.big-img-wrap { flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; }
#bigImg { max-width: 100%; max-height: 100%; object-fit: contain; pointer-events: none; transition: transform .18s ease-out; -webkit-user-drag: none; }
#bigImg.lift { transition: none; }
#bigName { font-size: clamp(36px, 9vmin, 72px); font-weight: 900; letter-spacing: -1px; }
.back { height: 64px; padding: 0 34px; border-radius: 32px; background: #F1EFEA; font-size: 22px; font-weight: 800; }

#lockBtn { position: absolute; top: calc(8px + env(safe-area-inset-top)); right: 8px; z-index: 20; width: 48px; height: 48px; border-radius: 24px; overflow: hidden; background: rgba(0,0,0,.05); opacity: .45; touch-action: none; }
#lockBtn .ico { position: relative; font-size: 20px; }
#lockBtn .fill { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: rgba(37,99,235,.55); }
#lockBtn.holding { opacity: 1; }
#lockBtn.holding .fill { height: 100%; transition: height 2s linear; }

/* ---------- 사진 넣기 창 ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; }
.sheet-card { background: #fff; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); }
.sheet-card h2 { margin: 0 0 6px; font-size: 19px; }
.row { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid #F0EDE6; }
.row img { width: 76px; height: 76px; object-fit: contain; border-radius: 10px; background: var(--bg); flex: none; }
.fields { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fields input, .fields select { height: 42px; font-size: 16px; border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; background: #fff; width: 100%; color: var(--ink); }
.fields input.bad { border-color: #E53935; background: #FFF6F6; }
.row .x { width: 36px; height: 36px; font-size: 18px; color: var(--muted); flex: none; }
.sheet-actions { display: flex; gap: 8px; margin-top: 14px; }

#toast { position: fixed; left: 50%; bottom: 180px; transform: translateX(-50%); z-index: 60; max-width: 90vw; background: rgba(31,41,51,.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 15px; text-align: center; }
