:root {
  --paper: #fbf6ec;
  --cream: #f6efe3;
  --ink: #33302d;
  --muted: #8a7f73;
  --line: #e6d9c6;
  --sea: #2b8fb0;
  --sea-deep: #17587a;
  --accent: #e98a62;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }

body {
  font-family: Pretendard, "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #d9eef5 0%, #f4ecdc 55%, #efe3cf 100%);
  background-attachment: fixed;
}

button {
  font: inherit;
  font-size: 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 8px 13px;
  border-radius: 12px;
  cursor: pointer;
}
button:hover { border-color: #cfbda5; }
button:disabled { opacity: 0.55; cursor: default; }

/* ---------- 해변 고르기 ---------- */

#lobby { max-width: 1080px; margin: 0 auto; padding: 32px 16px 48px; }
.lobby-top h1 { margin: 0; font-size: 30px; letter-spacing: -0.02em; }
.brand { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 99px; background: var(--sea-deep); color: #fff; }
.tagline { margin: 8px 0 20px; color: var(--muted); }

#notice {
  display: flex; align-items: center; gap: 12px; justify-content: space-between; flex-wrap: wrap;
  background: #fff8ea; border: 1px solid #f0d9b0; border-radius: 14px; padding: 12px 16px; margin-bottom: 16px;
}

.me-row {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: rgba(255, 255, 255, 0.7); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; margin-bottom: 20px;
}
.name-field { display: flex; align-items: center; gap: 8px; }
.name-field label { font-size: 13px; color: var(--muted); }
.name-field input {
  font: inherit; font-size: 14px; width: 130px; padding: 7px 10px; border-radius: 10px; border: 1px solid var(--line); background: #fff;
}
#myStats { font-size: 14px; color: var(--muted); flex: 1; min-width: 200px; }
#myStats b { color: var(--ink); }
.album-btn b { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 99px; background: var(--accent); color: #fff; font-size: 12px; }

#cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.card { background: var(--paper); border-radius: 18px; overflow: hidden; box-shadow: 0 6px 20px rgba(60, 50, 30, 0.12); display: flex; flex-direction: column; }
.card canvas { display: block; width: 100%; aspect-ratio: 16 / 9; }
.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card .region { font-size: 12px; color: var(--muted); }
.card h3 { margin: 0; font-size: 20px; }
.card .blurb { margin: 0; font-size: 13px; color: var(--muted); }
.card .round { margin-top: 6px; font-weight: 600; font-size: 14px; }
.bar { height: 8px; background: #e9dfd0; border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #7fd3c7, var(--sea)); transition: width 0.4s; }
.card .meta { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.card .badges { font-size: 12.5px; color: #b0643f; min-height: 18px; }
.card .badges.has-card { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
.card button { margin-top: auto; background: var(--sea-deep); color: #fff; border: none; padding: 11px; font-weight: 600; }
.card button.rest { background: #5a9a7a; }
.foot { margin-top: 24px; font-size: 12px; color: var(--muted); text-align: center; }

/* ---------- 해변 안 ---------- */

#game { position: fixed; inset: 0; overflow: hidden; background: #1d6f92; touch-action: none; user-select: none; -webkit-user-select: none; }
#world { position: absolute; inset: 0; width: 100%; height: 100%; }

.hud-top {
  position: absolute; left: 12px; right: 12px; top: 12px;
  display: flex; align-items: flex-start; gap: 10px; pointer-events: none;
}
.hud-top > * { pointer-events: auto; }
.round-box {
  flex: 1; max-width: 320px; margin: 0 auto;
  background: rgba(251, 246, 236, 0.92); border-radius: 14px; padding: 9px 14px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
}
#roundTitle { font-weight: 700; font-size: 15px; margin-bottom: 6px; transition: margin 0.25s; }
#remain { font-size: 12.5px; color: var(--muted); margin-top: 5px; font-variant-numeric: tabular-nums; }
/* 누르면 접히고 펼쳐진다. 접히면 제목 막대 자체가 진행 게이지 */
.round-box { cursor: pointer; transition: background 0.3s; }
.round-box .bar, .round-box #remain { max-height: 30px; transition: max-height 0.25s, opacity 0.2s, margin 0.25s; }
.round-box.mini { background: linear-gradient(90deg, rgba(127, 211, 199, 0.85) var(--p, 0%), rgba(251, 246, 236, 0.92) var(--p, 0%)); }
.round-box.mini #roundTitle { margin-bottom: 0; }
.round-box.mini .bar, .round-box.mini #remain { max-height: 0; opacity: 0; margin: 0; overflow: hidden; }
#people, #btnBack { background: rgba(251, 246, 236, 0.92); border-radius: 12px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15); }
#people { padding: 8px 12px; font-size: 13px; white-space: nowrap; }

#restBanner {
  position: absolute; left: 50%; top: 96px; transform: translateX(-50%);
  background: rgba(255, 250, 240, 0.95); padding: 10px 18px; border-radius: 99px; font-size: 14px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); white-space: nowrap; max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis;
}

.hud-bottom {
  position: absolute; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex; align-items: flex-end; gap: 10px; pointer-events: none;
}
.hud-bottom > * { pointer-events: auto; }
.mine-box {
  background: rgba(251, 246, 236, 0.92); border-radius: 99px; padding: 6px 12px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  font-size: 13px; display: flex; align-items: center; gap: 10px; white-space: nowrap;
}
#mine { font-weight: 700; font-size: 13px; }
.counts { display: flex; gap: 8px; }
.bag { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.bagbar { width: 36px; height: 5px; border-radius: 99px; background: #e9dfd0; overflow: hidden; }
.bagbar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.bag.full .bagbar i { background: #d9534f; }
.hint { margin-top: 6px; font-size: 12px; color: var(--muted); }

#emotes { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 auto; justify-content: center; }
#emotes button { background: rgba(251, 246, 236, 0.92); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12); padding: 7px 11px; font-size: 13px; }

.right-box { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
#minimap { width: 220px; height: 138px; border-radius: 12px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2); border: 2px solid rgba(255, 255, 255, 0.85); }
#btnPick {
  width: 76px; height: 76px; border-radius: 50%; font-size: 16px; font-weight: 700;
  background: var(--accent); color: #fff; border: 3px solid #fff; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

/* 소풍 시간: 돗자리 펴기 버튼 / 돗자리를 눌렀을 때 작은 메뉴 / 주운 쓰레기·봉투 숨김 */
#btnMat {
  padding: 10px 14px; border-radius: 99px; font-size: 14px; font-weight: 700;
  background: #fff; color: var(--ink, #3a3330); border: 2px solid var(--accent); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
#btnMat.on { background: var(--accent); color: #fff; }
#btnSound {
  width: 36px; height: 36px; padding: 0; border-radius: 50%; font-size: 17px; line-height: 1;
  background: rgba(255, 255, 255, 0.9); border: 1px solid rgba(0, 0, 0, 0.12); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}
#btnPhoto {
  width: 48px; height: 48px; padding: 0; border-radius: 50%; font-size: 22px;
  background: #fff; border: 2px solid var(--accent); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
#shotFlash { position: fixed; inset: 0; z-index: 50; background: #fff; opacity: 0.85; pointer-events: none; animation: shotFlash 0.35s ease-out forwards; }
@keyframes shotFlash { to { opacity: 0; } }
.photo-preview { width: 100%; border-radius: 12px; display: block; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18); }
#btnTurn {
  padding: 10px 14px; border-radius: 99px; font-size: 14px; font-weight: 700;
  background: #fff; color: #3a3330; border: 2px solid var(--accent); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
#btnTurn.on { background: var(--accent); color: #fff; }
#btnDrop {
  padding: 10px 14px; border-radius: 99px; font-size: 14px; font-weight: 700;
  background: #fff; color: #3a3330; border: 2px solid #8a8378; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
#matMenu {
  position: absolute; z-index: 30; transform: translate(-50%, -110%); display: flex; gap: 6px;
  background: rgba(251, 246, 236, 0.96); padding: 6px; border-radius: 12px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}
#matMenu button { padding: 7px 12px; font-size: 13px; font-weight: 700; border-radius: 9px; }
/* 돗자리 돌리기·완료 / 앉아서 돌기: 화면 위 해당 자리에 뜨는 작은 버튼 */
#matAdjust button, #seatTurn button {
  position: absolute; z-index: 30; transform: translate(-50%, -50%);
  min-width: 40px; height: 40px; padding: 0 10px; border-radius: 99px; font-size: 18px; font-weight: 700;
  background: rgba(255, 255, 255, 0.95); box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
}
#matAdjust .ok { font-size: 14px; background: var(--accent); color: #fff; }
#matAdjust .ok:disabled { background: #c9c3b8; }
.mine-box.picnic #mine, .mine-box.picnic .bag { display: none; }

/* ---------- 알림·창 ---------- */

#toasts {
  position: fixed; left: 50%; top: 150px; transform: translateX(-50%); z-index: 40;
  display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none;
}
.toast {
  background: rgba(51, 48, 45, 0.9); color: #fff; padding: 8px 14px; border-radius: 99px; font-size: 13.5px;
  animation: rise 0.3s ease-out; transition: opacity 0.6s;
}

#modal, #modal2 { position: fixed; inset: 0; z-index: 50; background: rgba(30, 40, 50, 0.45); display: grid; place-items: center; padding: 16px; }
#modal2 { z-index: 55; background: rgba(30, 40, 50, 0.3); } /* 참가 일지 위에 겹쳐 뜨는 엽서 */
.sheet {
  background: var(--paper); border-radius: 20px; padding: 18px; width: min(860px, 100%); max-height: calc(100dvh - 32px); overflow: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35); animation: rise 0.3s ease-out;
}
.sheet h2 { margin: 0 0 4px; font-size: 20px; }
.sheet .sub { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.sheet canvas.postcard { width: 100%; height: auto; border-radius: 10px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12); display: block; }
.sheet .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.sheet .primary { background: var(--sea-deep); color: #fff; border: none; font-weight: 600; }
.album { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.album button { padding: 0; border: none; background: none; border-radius: 10px; overflow: hidden; text-align: left; }
.album canvas { width: 100%; display: block; }
.album .cap { font-size: 12.5px; padding: 6px 2px; color: var(--muted); }
.letter { background: #fffdf6; border: 1px solid var(--line); border-radius: 12px; padding: 16px; font-size: 16px; line-height: 1.6; }
.letter .from { margin-top: 8px; text-align: right; color: var(--muted); font-size: 13px; }
.sheet textarea { width: 100%; min-height: 80px; margin-top: 12px; font: inherit; font-size: 15px; padding: 10px; border-radius: 12px; border: 1px solid var(--line); resize: vertical; }
.empty { color: var(--muted); font-size: 14px; }

#status {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: #fff; padding: 6px 13px; border-radius: 99px; font-size: 13px;
}
#status:empty { display: none; }

@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 720px) {
  #lobby { padding-top: 20px; }
  .lobby-top h1 { font-size: 24px; }
  .hud-top { gap: 6px; }
  #people { display: none; }
  #btnBack { padding: 8px 10px; font-size: 13px; }
  .round-box { padding: 7px 10px; }
  #roundTitle { font-size: 13px; }
  .hud-bottom { flex-wrap: wrap; }
  .hint { display: none; }
  #emotes { order: -1; width: 100%; }
  #emotes .label { display: none; }
  #minimap { width: 140px; height: 88px; }
  #btnPick { width: 64px; height: 64px; }
}

/* ---------- 3D 화면 위 이름표·말풍선 ---------- */

#overlay { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.av-label {
  position: absolute; left: 0; top: 0; white-space: nowrap;
  display: flex; align-items: center; gap: 5px;
  background: rgba(255, 255, 255, 0.9); color: #2f2a27; font-size: 12px; font-weight: 600;
  padding: 2px 8px 2px 6px; border-radius: 99px; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}
.av-label i { width: 8px; height: 8px; border-radius: 50%; }
.av-label.me { font-weight: 800; }
.av-bubble, .ping-label, .lift-label {
  position: absolute; left: 0; top: 0; white-space: nowrap;
  background: rgba(255, 252, 246, 0.97); color: #3a3330; font-size: 13.5px; font-weight: 600;
  padding: 6px 11px; border-radius: 14px; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.18);
}
.ping-label { background: #3a3028; color: #fffaf0; font-size: 13px; }
.lift-label { background: #ffd16a; color: #3a3028; }
.floater {
  position: absolute; transform: translate(-50%, -50%); white-space: nowrap;
  color: #fff; font-weight: 800; font-size: 18px; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  animation: floatUp 1s ease-out forwards;
}
@keyframes floatUp { to { transform: translate(-50%, -150%); opacity: 0; } }

#restBanner { text-align: center; white-space: normal; border-radius: 16px; }
#restBanner .closing { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

#doneCard {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); z-index: 20;
  width: min(440px, calc(100% - 32px)); text-align: center; cursor: pointer;
  background: rgba(251, 246, 236, 0.97); border-radius: 22px; padding: 22px 24px 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3); animation: rise 0.5s ease-out;
}
#doneCard h2 { margin: 0 0 8px; font-size: 20px; }
#doneCard .sum { margin: 0 0 12px; color: var(--ink); }
#doneCard .closing { margin: 0 0 10px; padding: 10px 12px; border-radius: 12px; background: #eaf4ea; color: #2f5a3a; font-weight: 600; }
#doneCard .tap { font-size: 12px; color: var(--muted); }

.closing-line { margin: 12px 0 0; padding: 10px 12px; border-radius: 12px; background: #eaf4ea; color: #2f5a3a; font-weight: 600; text-align: center; }

#emotes button { display: inline-flex; align-items: center; gap: 5px; }
#emotes kbd { font: inherit; font-size: 10.5px; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 0 4px; }
@media (max-width: 720px) {
  #emotes kbd { display: none; }
}

/* 화면 조이스틱 (휴대폰·태블릿) */
#joy {
  position: absolute; left: 22px; bottom: calc(150px + env(safe-area-inset-bottom)); z-index: 4;
  width: 128px; height: 128px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.28); border: 2px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); touch-action: none;
}
#joy .knob {
  position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px;
  border-radius: 50%; background: rgba(251, 246, 236, 0.95); box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
  pointer-events: none; transition: transform 0.05s;
}

.lobby-top h1 .en { font-size: 0.6em; font-weight: 600; color: var(--muted); letter-spacing: 0.02em; }

/* ---------- 캐릭터 고르기 ---------- */

.char-btn { display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; }
.char-btn .pic { width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(#e3f1f6, #f7efe2); overflow: hidden; display: grid; place-items: center; }
.char-btn img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 8%; transform: scale(1.7); transform-origin: 50% 12%; }
.char-tabs { display: flex; gap: 4px; margin-bottom: 12px; background: #efe5d4; padding: 4px; border-radius: 12px; width: fit-content; }
.char-tabs button { border: none; background: transparent; padding: 7px 24px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.char-tabs button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1); }
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.char-card { padding: 6px 6px 8px; border-radius: 14px; border: 2px solid transparent; background: #fff; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.char-card:hover { border-color: #d9c8ae; }
.char-card.on { border-color: var(--sea-deep); background: #eef6f9; }
.char-card .pic { width: 100%; aspect-ratio: 4 / 5; display: grid; place-items: center; background: linear-gradient(#e3f1f6, #f7efe2); border-radius: 10px; overflow: hidden; }
.char-card img { width: 100%; height: 100%; object-fit: contain; }
.char-card .nm { font-size: 13px; }
.spin { width: 22px; height: 22px; border: 3px solid #d8cbb7; border-top-color: var(--sea-deep); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 한강 편의점 ---------- */

.shop-h { margin: 14px 0 8px; font-size: 15px; }
.shop-h small { font-weight: 400; color: var(--muted); font-size: 12.5px; margin-left: 6px; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.shop-item { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left; padding: 10px 12px; border-radius: 14px; position: relative; }
.shop-item .em { font-size: 28px; line-height: 1.1; }
.shop-item b { font-size: 14.5px; }
.shop-item small { font-size: 12px; color: var(--muted); }
.shop-item .price { position: absolute; top: 10px; right: 10px; font-weight: 700; font-size: 13px; color: #b7791f; }
.shop-item:not(:disabled):hover { border-color: var(--sea-deep); background: #f3f9fb; }
#coins { font-weight: 700; font-size: 13px; color: #b7791f; }

/* 창 오른쪽 위 닫기 버튼 (휴대폰에서 누르기 쉽게 크게) */
.sheet { position: relative; }
.sheet h2 { padding-right: 48px; }
.close-x {
  position: sticky; float: right; top: 0; margin: -6px -6px 0 8px; z-index: 2;
  width: 40px; height: 40px; padding: 0; border-radius: 50%;
  display: grid; place-items: center; font-size: 18px; line-height: 1;
  background: #fff; border: 1px solid var(--line); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}
.close-x:hover { background: #f3f0ea; }

/* ---------- 휴대폰 화면 배치 ----------
   위 왼쪽: 목록 버튼 + 대회 제목(게이지) / 그 아래 쓰레기·코인·봉투, 위 오른쪽: 미니맵
   아래: 맨 밑에 동작(이모티콘) 한 줄, 그 위 왼쪽 조이스틱 · 오른쪽 줍기·둘러보기 */
@media (max-width: 720px) {
  /* 왼쪽 위: [← 목록][대회 제목 막대] / 그 아래 같은 너비의 쓰레기·코인·봉투 띠. 오른쪽 맨 위: 미니맵.
     제목 막대를 펼쳐도 목록 버튼은 그대로 */
  .hud-top { top: calc(10px + env(safe-area-inset-top)); left: 10px; right: 158px; align-items: flex-start; gap: 6px; }
  #btnBack { display: flex; align-items: center; justify-content: center; align-self: flex-start; width: 38px; height: 33px; flex: none; padding: 0; font-size: 17px; }
  #btnBack .lbl { display: none; }
  .round-box { flex: 1; max-width: none; min-width: 0; margin: 0; padding: 8px 10px; }
  #roundTitle, #remain { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #remain { font-size: 11px; }

  .mine-box {
    position: fixed; z-index: 3;
    top: calc(85px + env(safe-area-inset-top)); left: 10px; right: 158px;
    margin: 0; padding: 5px 10px; gap: 8px; font-size: 12px;
  }
  /* 대회 상자가 접히면 띠도 위로 붙는다 */
  #game:has(.round-box.mini) .mine-box { top: calc(49px + env(safe-area-inset-top)); }
  #mine, #coins { font-size: 12px; }
  .bag { gap: 4px; flex: 1; }
  .bagbar { flex: 1; width: auto; }
  #minimap {
    position: fixed; z-index: 3;
    top: calc(10px + env(safe-area-inset-top)); right: 10px;
    width: 140px; height: 88px;
  }

  #emotes {
    position: fixed; z-index: 3;
    left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom));
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 0; width: auto;
  }
  #emotes button { justify-content: center; height: 46px; padding: 0; font-size: 22px; border-radius: 12px; }

  .hud-bottom { bottom: calc(64px + env(safe-area-inset-bottom)); justify-content: flex-end; }
  .right-box { flex-direction: row-reverse; align-items: flex-end; gap: 10px; }
  #joy { bottom: calc(70px + env(safe-area-inset-bottom)); left: 16px; }

  #toasts { top: calc(120px + env(safe-area-inset-top)); width: calc(100% - 24px); }
  .toast { text-align: center; }
  #restBanner { top: calc(176px + env(safe-area-inset-top)); white-space: normal; border-radius: 16px; text-align: center; }
}

/* 큰 쓰레기 게이지 */
.lift-label .gauge { display: block; height: 7px; margin-top: 4px; border-radius: 99px; background: rgba(58, 48, 40, 0.18); overflow: hidden; min-width: 120px; }
.lift-label .gauge b { display: block; height: 100%; width: 0; background: #3aa655; border-radius: 99px; transition: width 0.12s linear; }

/* 휴대폰: 줍기·회전 버튼과 조이스틱을 조금 위로 */
@media (max-width: 720px) {
  .hud-bottom { bottom: calc(110px + env(safe-area-inset-bottom)); }
  #joy { bottom: calc(116px + env(safe-area-inset-bottom)); }
}

/* ---------- 로딩 화면 ---------- */
#loading {
  position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(180deg, #d9eef5 0%, #f4ecdc 60%, #efe3cf 100%);
}
.ld-card { text-align: center; max-width: 360px; }
.ld-card h1 { margin: 0 0 22px; font-size: 30px; letter-spacing: -0.02em; }
.ld-card h1 .en { font-size: 0.6em; font-weight: 600; color: var(--muted); }
.ld-spin {
  width: 42px; height: 42px; margin: 0 auto 16px; border-radius: 50%;
  border: 4px solid #d8cbb7; border-top-color: var(--sea-deep); animation: spin 0.9s linear infinite;
}
#ldMsg { margin: 0; font-size: 16px; font-weight: 700; }
#ldSub { margin: 8px 0 0; font-size: 13.5px; line-height: 1.5; color: var(--muted); min-height: 1em; }
#ldRetry { margin-top: 18px; padding: 10px 22px; font-size: 15px; background: var(--sea-deep); color: #fff; border: none; font-weight: 600; }
#loading.error .ld-spin { animation: none; border-color: #e9b4a4; border-top-color: #e9b4a4; position: relative; }
#loading.error .ld-spin::after { content: '!'; position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; color: #d9534f; font-size: 20px; }
#loading.error #ldMsg { color: #b8442f; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 랭킹 ---------- */
.rank-tabs { margin-bottom: 10px; }
.rank-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: min(56vh, 520px); overflow: auto; }
.rank-row { display: grid; grid-template-columns: 38px 40px 1fr auto; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 12px; background: #fff; border: 1px solid var(--line); }
.rank-row .rk { text-align: center; font-weight: 800; font-size: 15px; color: var(--muted); }
.rank-row.top1 .rk, .rank-row.top2 .rk, .rank-row.top3 .rk { font-size: 22px; }
.rank-row .pic { width: 40px; height: 40px; border-radius: 10px; overflow: hidden; background: linear-gradient(#e3f1f6, #f7efe2); }
.rank-row .pic img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 8%; transform: scale(1.7); transform-origin: 50% 12%; }
.rank-row .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row .v { font-weight: 700; color: var(--sea-deep); font-variant-numeric: tabular-nums; }
.rank-row.me { border-color: var(--sea-deep); background: #eef6f9; }
.rank-me { margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: #f3ead9; font-size: 14px; font-weight: 600; text-align: center; }
.rank-tabs { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; }
.rank-tabs button { padding: 8px 6px; white-space: nowrap; }

/* ---------- 프로필 카드 ---------- */
.me-row.profile { display: grid; grid-template-columns: auto 1fr auto; gap: 14px 18px; align-items: center; padding: 14px 16px; }
.pf-top { display: flex; align-items: center; gap: 12px; min-width: 0; }
.pf-pic { position: relative; flex: none; width: 72px; height: 72px; padding: 0; border-radius: 18px; overflow: hidden; border: 2px solid #fff; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12); background: linear-gradient(#e3f1f6, #f7efe2); }
.pf-pic .pic { position: absolute; inset: 0; display: block; }
.pf-pic img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 6%; transform: scale(1.6); transform-origin: 50% 10%; }
.pf-chg { position: absolute; left: 0; right: 0; bottom: 0; font-size: 11px; background: rgba(51, 48, 45, 0.68); color: #fff; padding: 2px 0; }
.pf-name { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pf-label { font-size: 12px; color: var(--muted); padding-left: 6px; }
.pf-name .name-field { gap: 6px; }
.pf-name .name-field input { font-size: 20px; font-weight: 800; border: 1px solid transparent; background: transparent; padding: 4px 6px; width: 180px; max-width: 100%; }
.pf-name .name-field input:hover, .pf-name .name-field input:focus { border-color: var(--line); background: #fff; outline: none; }
.pf-name #nameSave { padding: 6px 12px; background: var(--sea-deep); color: #fff; border: none; font-weight: 600; }
#myStats.pf-stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; color: var(--ink); min-width: 0; }
.pf-stats .tile { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 7px 4px; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.pf-stats .tile .e { font-size: 17px; line-height: 1.2; }
.pf-stats .tile b { font-size: 18px; font-variant-numeric: tabular-nums; }
.pf-stats .tile small { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.pf-actions { display: flex; flex-direction: column; gap: 8px; }
.pf-actions button { white-space: nowrap; font-weight: 600; }
@media (max-width: 720px) {
  .me-row.profile { grid-template-columns: 1fr; }
  #myStats.pf-stats { grid-template-columns: repeat(3, 1fr); }
  .pf-actions { flex-direction: row; }
  .pf-actions button { flex: 1; padding: 10px 8px; }
}

/* ---------- 참가 일지 ---------- */
.recent-cards { display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 8px; margin-bottom: 8px; scroll-snap-type: x mandatory; }
.recent-card { flex: none; width: 168px; padding: 0; border: none; background: none; text-align: left; scroll-snap-align: start; }
.recent-card canvas { width: 100%; display: block; border-radius: 8px; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12); }
.recent-card span { display: block; font-size: 12px; color: var(--muted); padding: 4px 2px 0; }
.stamp-tabs { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; margin: 4px 0 10px; }
.stamp-tabs button { padding: 8px 4px; white-space: nowrap; }
.stamp-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; margin-bottom: 6px; }
.stamp-head .st-badges { font-size: 13px; color: var(--muted); }
.stamp-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.stamp-nav button { width: 40px; height: 34px; padding: 0; }
.stamp-nav .range { font-weight: 700; font-size: 14px; }
.stamp-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; padding: 12px; border-radius: 14px; background: #fffdf6; border: 1px dashed #d9c9ae; }
.stamp-cell {
  position: relative; aspect-ratio: 1; padding: 0; border-radius: 50%; border: 1.5px dashed #ddd0bb; background: transparent;
  font-size: 11px; color: #c4b49b; display: grid; place-items: center; cursor: default;
}
.stamp-cell.future { border-color: #eee5d6; }
.stamp-cell.live { border: 2px solid var(--st); color: var(--st); font-size: 9px; font-weight: 700; animation: pulse 1.6s ease-in-out infinite; }
.stamp-cell.on { cursor: pointer; border: 2.5px solid var(--st); color: var(--st); background: color-mix(in srgb, var(--st) 14%, #fff); transform: rotate(var(--rot, 0deg)); box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 3.5px var(--st); }
.stamp-cell.on .ink { font-weight: 900; font-size: 12px; line-height: 1; letter-spacing: -0.03em; }
.stamp-cell.on .ink small { font-size: 7px; font-weight: 700; }
.stamp-cell.on.top { --st: #c99a1e; background: radial-gradient(circle at 35% 30%, #fff6d1, #f3d36b); box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 3.5px #c99a1e, 0 0 0 2px #f6dc84; }
.stamp-cell .paw { position: absolute; right: -6px; bottom: -6px; font-size: 13px; transform: rotate(calc(-1 * var(--rot, 0deg))); }
.stamp-cell.on.chain::before { content: ''; position: absolute; right: 100%; top: 50%; width: 8px; height: 3px; background: var(--st); opacity: 0.55; border-radius: 2px; transform: rotate(calc(-1 * var(--rot, 0deg))); }
.stamp-cell.on:hover { filter: brightness(1.05); }
.stamp-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.stamp-legend .lg { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: -2px; margin-right: 4px; }
.stamp-legend .lg.st { border: 2px solid #2a9d8f; background: #e3f3f1; }
.stamp-legend .lg.st.top { border-color: #c99a1e; background: #f3d36b; }
.stamp-legend .lg.chain { width: 14px; height: 3px; border-radius: 2px; background: #2a9d8f; vertical-align: 3px; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--st) 25%, transparent); } }
@media (max-width: 720px) {
  .stamp-grid { gap: 4px; padding: 8px; }
  .stamp-cell { font-size: 9px; }
  .stamp-cell.on .ink { font-size: 10px; }
  .stamp-cell.on .ink small { display: none; }
}

/* 복구 코드 */
.pf-code { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 6px; padding-left: 6px; margin-top: 2px; font-size: 12px; color: var(--muted); }
.pf-code b { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; color: var(--ink); letter-spacing: 0.04em; user-select: all; -webkit-user-select: all; }
.pf-code button { padding: 2px 8px; font-size: 11.5px; border-radius: 8px; }
.pf-code button.link { border: none; background: none; padding: 2px 0 2px 4px; color: var(--sea-deep); text-decoration: underline; }
.restore-row { display: flex; gap: 8px; }
.restore-row input { flex: 1; min-width: 0; font: inherit; font-size: 18px; letter-spacing: 0.08em; text-transform: uppercase; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.restore-msg { min-height: 1.4em; margin: 10px 0 0; font-size: 14px; color: #b8442f; }
.restore-confirm { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; color: var(--ink); font-weight: 600; }
.restore-note { font-size: 12.5px; color: var(--muted); margin: 8px 0 0; line-height: 1.5; }

/* 봉투 고르기 */
.pf-bag { grid-column: 1 / -1; display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; }
.pf-bag .pf-label { padding-left: 0; font-weight: 600; color: var(--ink); }
.bag-opts { display: flex; gap: 6px; flex-wrap: wrap; }
.bag-opt { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 6px 12px; border-radius: 12px; border: 1px solid var(--line); background: #fff; text-align: left; }
.bag-opt b { font-size: 13.5px; }
.bag-opt small { font-size: 11.5px; color: var(--muted); }
.bag-opt.on { border-color: var(--sea-deep); background: #e6f3f1; box-shadow: inset 0 0 0 1px var(--sea-deep); }
.bag-opt.locked { opacity: 0.55; cursor: default; }
.bag-note { flex-basis: 100%; font-size: 12px; color: var(--muted); }

/* 쉬는 시간 이야기 자막 */
#story {
  position: absolute; left: 50%; top: 30%; transform: translate(-50%, 8px); z-index: 6;
  max-width: min(92vw, 640px); text-align: center; white-space: pre-line; pointer-events: none;
  font-size: clamp(18px, 3.6vw, 28px); font-weight: 800; line-height: 1.45; color: #fff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.55), 0 0 2px rgba(0, 0, 0, 0.6);
  opacity: 0; transition: opacity 0.9s ease, transform 0.9s ease;
}
#story.on { opacity: 1; transform: translate(-50%, 0); }

/* 대회 목록 맨 아래 소리 출처 */
.credits { margin: 18px 0 8px; text-align: center; font-size: 11px; color: rgba(60, 50, 45, 0.55); }
