:root {
  --ink: #17324a;
  --muted: #5d7488;
  --accent: #e8573f;
  --gold: #e8a91c;
  --glass: rgba(255, 255, 255, 0.82);
  --line: rgba(23, 50, 74, 0.14);
  --font: 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #cfe3f2;
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

[hidden] { display: none !important; }

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* 화면 위 정보 */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.meter {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--glass);
  font-size: 14px;
}
.meter-label { color: var(--muted); }
.meter b { min-width: 28px; text-align: right; font-variant-numeric: tabular-nums; }

.bar {
  width: min(120px, 26vw);
  height: 8px;
  border-radius: 8px;
  background: var(--line);
  overflow: hidden;
}
.bar i {
  display: block;
  width: 100%;
  height: 100%;
  background: #3fb27f;
  transition: width 0.15s linear, background 0.2s;
}
.bar i.low { background: var(--accent); }
.bar.thin { width: 100%; height: 5px; }
.bar.thin i { background: var(--ink); transition: none; }

#labels {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.tag {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  will-change: transform;
}
.name {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(23, 50, 74, 0.72);
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
}
.tag.me .name { background: var(--accent); }
.bubble {
  position: relative;
  display: none;
  width: max-content;
  max-width: 200px;
  padding: 6px 11px;
  border-radius: 12px;
  background: #fff;
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  text-align: center;
}
.bubble.show { display: block; }
.bubble::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -4px;
  width: 9px;
  height: 9px;
  background: inherit;
  transform: translateX(-50%) rotate(45deg);
}

#top-right {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
#room-button {
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 12px;
  background: var(--glass);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: auto;
}
#room-button:hover { background: #fff; }

#shop-button, #clamp-shop-button {
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 12px;
  background: var(--glass);
  font-size: 14px;
  font-weight: 700;
  pointer-events: auto;
}
#shop-button:hover, #clamp-shop-button:hover { background: #fff; }

/* 행사 예고: 화면 위쪽 가운데, 상단 표시줄 아래 */
#event-banner {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 52px);
  left: 50%;
  z-index: 3;
  max-width: calc(100% - 32px);
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(20, 24, 48, 0.78);
  color: #ffe9a8;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-50%);
}

/* 행사 알림: 화면 가운데에 잠시 떴다가 사라진다 */
#event-popup {
  position: fixed;
  top: 38%;
  left: 50%;
  z-index: 5;
  padding: 16px 26px;
  border-radius: 18px;
  background: rgba(20, 24, 48, 0.82);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 22px;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: event-pop 3s ease forwards;
}
@keyframes event-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.85); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.04); }
  20% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%); }
}

/* 눈싸움장 조준점 */
#crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border: 2px solid rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(30, 40, 50, 0.45), inset 0 0 0 1px rgba(30, 40, 50, 0.45);
  pointer-events: none;
}
#crosshair::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(30, 40, 50, 0.45);
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.tabs button {
  flex: 1;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 15px;
}
.tabs button[aria-selected='true'] {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
  font-weight: 700;
}
.item-list {
  max-height: 50vh;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
  border-top: 1px solid var(--line);
}
.item-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--line);
}
.item-list .secondary { flex: none; margin-left: auto; font-variant-numeric: tabular-nums; }
.item-list .secondary.wearing { border-color: var(--ink); background: var(--ink); color: #fff; opacity: 1; }
.swatch {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.item-name { font-size: 15px; }
.item-kind { display: block; color: var(--muted); font-size: 12px; }
#settings-button {
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 12px;
  background: var(--glass);
  font-size: 14px;
  pointer-events: auto;
}
#settings-button:hover { background: #fff; }

.section {
  margin: 16px 0 8px;
  font-size: 15px;
}
.slider {
  display: grid;
  grid-template-columns: 64px 1fr 40px;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  font-size: 14px;
}
.slider input { width: 100%; accent-color: var(--accent); }
.slider output { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
#language {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
}
.note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.code-row {
  display: flex;
  gap: 8px;
}
.code-row .primary { flex: 1; }
.code-box {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font: 700 18px/1 ui-monospace, 'Consolas', monospace;
  letter-spacing: 0.06em;
  text-align: center;
  outline: none;
}
.code-box:focus { border-color: var(--accent); }
.warning {
  margin: 12px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fdf0ec;
  color: #8a2f1d;
  font-size: 13px;
  line-height: 1.5;
}
#code-message {
  min-height: 18px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 480px) {
  #top-right { gap: 6px; }
  #room-button, #settings-button, #shop-button, #clamp-shop-button { padding: 0 9px; font-size: 13px; }
  #top-right { flex-wrap: wrap; justify-content: flex-end; max-width: calc(100vw - 150px); }
}

#gold-box {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--glass);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
#gold-box.bump { animation: bump 0.3s ease-out; }
.coin-mark {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: inset 0 0 0 2px #c78a0c;
}

@keyframes bump {
  40% { transform: scale(1.14); }
}

#run-info {
  position: absolute;
  top: calc(max(14px, env(safe-area-inset-top)) + 46px);
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 420px;
  margin: 0 auto;
  padding: 6px 12px;
  border-radius: 10px;
  background: var(--glass);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
#timer { flex: none; width: 46px; text-align: right; }

/* 조작 안내 */
#touch-hint {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(26px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.zone {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  color: var(--ink);
  font-size: 22px;
}

#key-hint {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 52px);
  /* 밤하늘이나 어두운 바닥 위에서도 읽히도록 밝은 바탕을 깐다 */
  width: fit-content;
  max-width: calc(100% - 32px);
  margin: 0 auto;
  padding: 2px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font-size: 14px;
  text-align: center;
  pointer-events: none;
}

/* 체력이 0일 때 걷기 안내 위에 띄운다. 버튼은 그만큼 위로 올린다. */
#health-warning {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 74px);
  width: fit-content;
  margin: 0 auto;
  padding: 3px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  color: #d62d20;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  pointer-events: none;
}
body.no-health #actions { bottom: calc(max(14px, env(safe-area-inset-bottom)) + 112px); }

#joystick {
  position: fixed;
  left: 24px;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 62px);
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  touch-action: none;
}
#joystick-knob {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  pointer-events: none;
}

#actions {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 84px);
  z-index: 1;
  display: flex;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
}
#actions button {
  min-height: 50px;
  padding: 0 22px;
  border: 0;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: auto;
}
#action { background: var(--accent); color: #fff; }
#action2 { background: var(--glass); color: var(--ink); }
#actions button:hover { filter: brightness(1.06); }
#action[data-kind='liftCancel'] { background: var(--ink); }
#action[data-kind='eating'] { background: var(--ink); }

@media (pointer: coarse) {
  #actions {
    left: 160px;
    flex-direction: column;
    align-items: flex-end;
  }
  #actions button {
    max-width: 100%;
    padding: 0 16px;
    font-size: 15px;
    white-space: normal;
  }
}

.gauge {
  width: 64px;
  height: 7px;
  border-radius: 7px;
  background: rgba(23, 50, 74, 0.72);
  overflow: hidden;
}
.gauge i {
  display: block;
  width: 0;
  height: 100%;
  background: #f2b925;
}

#menu-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
#menu-tabs button {
  flex: 1;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 15px;
}
#menu-tabs button[aria-selected='true'] {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
  font-weight: 700;
}
#menu-list {
  max-height: 50vh;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
  border-top: 1px solid var(--line);
}
#menu-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--line);
}
.food-name { font-size: 15px; }
.food-heal { margin-left: 6px; color: #2e8b57; font-size: 13px; font-weight: 700; white-space: nowrap; }
#menu-list .secondary { flex: none; font-variant-numeric: tabular-nums; }

#toast {
  position: fixed;
  top: 24%;
  left: 50%;
  transform: translate(-50%, 6px);
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--glass);
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.hit { color: var(--accent); }
#toast.coin { color: #b47a06; }

#flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s;
}
#flash.on { opacity: 1; transition: none; }

/* 선택과 결과 */
.panel-wrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(23, 50, 74, 0.18);
}

.panel {
  width: min(440px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 24px 20px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.94);
}
.panel h1 {
  margin: 0;
  font-size: 23px;
  text-align: center;
}
.panel.wide-panel { width: min(620px, 100%); }

/* 눈싸움장 집게 상점: 집게 그림 카드 */
#clamp-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  max-height: 58vh;
  margin: 14px 0 0;
  padding: 2px;
  overflow: auto;
  list-style: none;
}
@media (max-width: 520px) {
  #clamp-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.clamp-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.clamp-card.held { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.clamp-card img { width: 100%; aspect-ratio: 24 / 17; object-fit: contain; border-radius: 10px; background: #eef3f7; }
.clamp-card b { font-size: 14px; text-align: center; }
.clamp-card .secondary { width: 100%; min-height: 36px; font-variant-numeric: tabular-nums; }
.clamp-card .secondary.wearing { border-color: var(--ink); background: var(--ink); color: #fff; opacity: 1; }
.sub {
  margin: 6px 0 18px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 120px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  text-align: left;
}
.card:hover { border-color: var(--accent); }
.card b { font-size: 19px; }
.card span { color: var(--muted); font-size: 13px; line-height: 1.45; }

.stats {
  margin: 0 0 18px;
  border-top: 1px solid var(--line);
}
.stats div {
  display: flex;
  justify-content: space-between;
  padding: 9px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.stats dt { color: var(--muted); }
.stats dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }

.primary {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}
.primary:hover { filter: brightness(1.06); }

.secondary {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-size: 15px;
  white-space: nowrap;
}
.secondary:hover:not(:disabled) { border-color: var(--accent); }
.secondary:disabled { opacity: 0.45; cursor: default; }
.secondary.wide { width: 100%; margin-top: 10px; }

/* 후원 (Ko-fi) */
.support-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  margin-top: 10px;
  border-radius: 12px;
  background: #ffdd00;
  color: #1f1f1f;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
}
.support-link:hover { filter: brightness(0.96); }
.support-link[hidden] { display: none; }
#settings-support .note { margin-bottom: 0; }

/* 입장 */
#entry-form label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 14px;
}
input {
  -webkit-user-select: text;
  user-select: text;
}
#name {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  outline: none;
}
#name:focus { border-color: var(--accent); }
#name-error {
  min-height: 20px;
  margin: 6px 0 12px;
  color: var(--accent);
  font-size: 13px;
}

/* 방 목록 */
#room-list {
  max-height: 46vh;
  margin: 0 0 14px;
  padding: 0;
  overflow: auto;
  list-style: none;
  border-top: 1px solid var(--line);
}
#room-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
#rooms-close { width: 100%; }

/* 채팅 */
#chat {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 2;
  display: flex;
  gap: 6px;
  max-width: 420px;
  margin: 0 auto;
}
#chat-input {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--glass);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  outline: none;
}
#chat-input:focus { background: #fff; border-color: var(--accent); }

#banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  padding: 7px 16px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  text-align: center;
}

@media (max-width: 380px) {
  .cards { grid-template-columns: 1fr; }
  .card { min-height: 0; }
}

@media (max-width: 480px) {
  .bar:not(.thin) { width: 18vw; }
  .meter { padding: 8px 10px; }
  .meter-label { display: none; }
  #run-info { top: calc(max(14px, env(safe-area-inset-top)) + 46px); }
}
