:root {
  --ink: #3d302b; --ink-soft: #7a6a62; --paper: rgba(255, 251, 246, 0.9); --accent: #f08f86;
  --font: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  --shadow: 0 8px 24px rgba(60, 40, 30, 0.16);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #f4b197; color: var(--ink); font-family: var(--font); }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }

.loading { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; background: linear-gradient(#f6d7c8, #f2b9a0); z-index: 50; transition: opacity .8s; }
.loading p { margin: 0; color: var(--ink-soft); }
.loading .dot { width: 44px; height: 44px; border-radius: 50%; background: radial-gradient(circle at 40% 40%, #fff6c8, #ffc070 60%, #f39a7a); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.82); opacity: .6; } }
.loading.done { opacity: 0; pointer-events: none; }

.hud { position: fixed; left: 0; right: 0; top: 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding: calc(12px + var(--safe-t)) 14px 0; pointer-events: none; z-index: 10; flex-wrap: wrap; }
.hud > * { pointer-events: auto; }
.hud-left { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px; border-radius: 999px; background: var(--paper); box-shadow: var(--shadow); border: 0; text-decoration: none; color: var(--ink); font-size: 14.5px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); cursor: pointer; }
.chip.back { font-weight: 700; }
.chip.title { cursor: default; }
.chip.title span { color: var(--ink-soft); font-size: 12.5px; }
.seg { display: inline-flex; padding: 4px; border-radius: 999px; background: var(--paper); box-shadow: var(--shadow); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.seg button { border: 0; background: transparent; min-height: 34px; min-width: 50px; padding: 0 12px; border-radius: 999px; font-size: 14px; font-weight: 600; color: var(--ink-soft); cursor: pointer; transition: background .25s, color .25s; }
.clock-line { position: fixed; left: 50%; top: calc(58px + var(--safe-t)); transform: translateX(-50%); margin: 0; font-size: 11.5px; color: rgba(255, 255, 255, .95); text-shadow: 0 1px 3px rgba(40, 28, 24, .6), 0 0 8px rgba(40, 28, 24, .3); white-space: nowrap; pointer-events: none; z-index: 9; }
.seg button[aria-checked="true"] { background: #fff; color: var(--ink); box-shadow: 0 2px 8px rgba(60, 40, 30, .15); }

.bottom { position: fixed; left: 0; right: 0; bottom: calc(18px + var(--safe-b)); display: flex; justify-content: center; align-items: center; gap: 10px; pointer-events: none; z-index: 10; }
.bottom > * { pointer-events: auto; }
.mine { display: inline-flex; align-items: center; gap: 8px; min-height: 50px; padding: 0 22px; border: 0; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 700; font-size: 15.5px; box-shadow: 0 10px 26px rgba(200, 90, 80, .35); cursor: pointer; }
.mine svg { width: 20px; height: 20px; fill: #fff; }
.mine:active { transform: scale(.97); }
.scarf i { width: 16px; height: 16px; border-radius: 50%; background: var(--scarf, #eea3a8); box-shadow: inset 0 0 0 2px rgba(255,255,255,.7); }
.count { position: absolute; right: 14px; bottom: 6px; font-size: 12px; color: rgba(255,255,255,.9); text-shadow: 0 1px 3px rgba(0,0,0,.35); pointer-events: none; }
.scarf-pop { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + var(--safe-b)); display: flex; gap: 8px; padding: 8px; border-radius: 999px; background: var(--paper); box-shadow: var(--shadow); z-index: 12; }
.scarf-pop button { width: 36px; height: 36px; border-radius: 50%; border: 3px solid #fff; cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.scarf-pop button[aria-pressed="true"] { outline: 2px solid var(--ink); }

.hint { position: fixed; left: 50%; bottom: calc(82px + var(--safe-b)); transform: translateX(-50%); padding: 8px 14px; border-radius: 999px; background: rgba(40, 28, 24, .42); color: #fff; font-size: 13px; white-space: nowrap; pointer-events: none; transition: opacity 1s; z-index: 9; }
.hint.off { opacity: 0; }
.toast { position: fixed; left: 50%; top: calc(70px + var(--safe-t)); transform: translateX(-50%); padding: 10px 16px; border-radius: 16px; background: var(--paper); box-shadow: var(--shadow); font-weight: 600; font-size: 14px; opacity: 0; transition: opacity .3s; pointer-events: none; z-index: 30; }
.toast.on { opacity: 1; }

.joy { position: fixed; width: 120px; height: 120px; border-radius: 50%; background: rgba(255, 255, 255, .16); box-shadow: inset 0 0 0 2px rgba(255,255,255,.5); pointer-events: none; z-index: 8; transition: background .2s;
  left: calc(22px + env(safe-area-inset-left, 0px)); bottom: calc(22px + var(--safe-b)); }
.joy.on { background: rgba(255, 255, 255, .26); }
.joy i { position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; margin: -25px 0 0 -25px; border-radius: 50%; background: rgba(255, 251, 246, .85); box-shadow: var(--shadow); }
.rotate-hint { display: none; }

.sheet { position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translateX(-50%); width: min(420px, calc(100vw - 24px)); padding: 16px 16px 14px; border-radius: 22px; background: rgba(255, 251, 246, .96); box-shadow: 0 18px 50px rgba(60, 40, 30, .28); z-index: 20; animation: up .28s ease-out; }
@keyframes up { from { opacity: 0; transform: translate(-50%, 16px); } }
.sheet .x { position: absolute; right: 8px; top: 8px; width: 36px; height: 36px; border: 0; border-radius: 50%; background: transparent; font-size: 22px; color: var(--ink-soft); cursor: pointer; }
.sh-row { display: flex; gap: 14px; align-items: center; }
#shPhoto { width: 96px; height: 96px; border-radius: 14px; flex: none; box-shadow: 0 0 0 4px #fff, 0 4px 12px rgba(60,40,30,.2); }
.sh-tag { display: inline-block; margin: 0 0 4px; padding: 2px 8px; border-radius: 999px; background: rgba(240,143,134,.14); color: #c0645c; font-size: 12px; font-weight: 700; }
.sheet h2 { margin: 0; font-size: 21px; }
.sh-dates { margin: 2px 0 0; font-size: 14px; color: var(--ink-soft); }
.sh-where { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-soft); }
.sh-text { margin: 12px 0 4px; font-size: 15px; line-height: 1.65; word-break: keep-all; }
.sh-owner { margin: 0; text-align: right; font-size: 13px; color: #a07c6c; font-weight: 600; }

@media (max-width: 640px) {
  .chip.title span { display: none; }
  .seg button { min-width: 0; padding: 0 10px; }
  .hud { padding-left: 10px; padding-right: 10px; }
  .hint { display: none; }
  .count { right: auto; left: 50%; transform: translateX(-50%); bottom: 60px; white-space: nowrap; }
  .sheet { bottom: calc(80px + var(--safe-b)); }
}

/* 휴대폰: 가로로 쥐는 것이 기본. 조이스틱(왼쪽 아래 164px 정사각)을 비워 둔다. */
body.touch .bottom { left: calc(170px + env(safe-area-inset-left, 0px)); right: calc(14px + env(safe-area-inset-right, 0px)); }
body.touch .count { left: auto; right: 14px; transform: none; bottom: 4px; }
body.touch .hint { display: block; left: calc(50% + 70px); bottom: calc(80px + var(--safe-b)); }
@media (orientation: landscape) and (max-height: 500px) {
  body.touch .hud { padding-top: calc(8px + var(--safe-t)); padding-left: calc(12px + env(safe-area-inset-left, 0px)); padding-right: calc(12px + env(safe-area-inset-right, 0px)); }
  body.touch .bottom { bottom: calc(12px + var(--safe-b)); justify-content: flex-end; }
  body.touch .sheet { bottom: calc(12px + var(--safe-b)); left: auto; right: calc(14px + env(safe-area-inset-right, 0px)); transform: none; width: min(400px, calc(100vw - 200px)); max-height: calc(100vh - 70px); overflow: auto; animation: none; }
  body.touch .scarf-pop { left: auto; right: 14px; transform: none; bottom: calc(72px + var(--safe-b)); }
  body.touch .hint { bottom: calc(76px + var(--safe-b)); }
  body.touch .count { bottom: calc(70px + var(--safe-b)); right: calc(16px + env(safe-area-inset-right, 0px)); }
  body.touch .clock-line { top: calc(52px + var(--safe-t)); }
}
@media (orientation: portrait) {
  body.touch .rotate-hint { display: block; position: fixed; left: 50%; top: calc(64px + var(--safe-t)); transform: translateX(-50%); padding: 5px 12px; border-radius: 999px; background: rgba(40, 28, 24, .45); color: #fff; font-size: 12.5px; white-space: nowrap; pointer-events: none; z-index: 9; }
  body.touch .bottom { left: 0; right: 0; bottom: calc(160px + var(--safe-b)); }
  body.touch .sheet { bottom: calc(160px + var(--safe-b)); }
  body.touch .scarf-pop { bottom: calc(220px + var(--safe-b)); }
  body.touch .hint { display: none; }
  body.touch .count { bottom: calc(140px + var(--safe-b)); }
}
.bottom > [hidden] { display: none !important; }
