*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  font-family: 'Jua', 'Malgun Gothic', system-ui, sans-serif;
  background: radial-gradient(120% 90% at 50% 0%, #c8ecff 0%, #8bcef3 55%, #63b3e3 100%);
  color: #33405c;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ---------- HUD ---------- */
#hud { display: flex; gap: 6px; }

.userLine {
  align-self: flex-start;
  margin: 0;
  max-width: 100%;
  padding: 4px 12px;
  border: 2px solid #c2905a;
  border-radius: 99px;
  background: linear-gradient(#fffdf6, #ffeccd);
  color: #8a5a34;
  font-size: 13px;
  box-shadow: 0 2px 0 #a5754a;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border: 3px solid #c2905a;
  border-radius: 15px;
  background: linear-gradient(#fffdf6, #ffeed8);
  box-shadow: 0 3px 0 #a5754a;
}

.stat .ico { font-size: 17px; line-height: 1; }
.stat .col { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.stat b { font-size: 13px; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.bar { height: 8px; border-radius: 99px; background: #e6d3b2; overflow: hidden; }
.fill { display: block; height: 100%; width: 0%; border-radius: 99px; transition: width .18s ease; }
.fill.money { background: linear-gradient(90deg, #ffd166, #ffab21); }
.fill.wood { background: linear-gradient(90deg, #c98b4f, #8a5a34); }
.fill.axe { background: linear-gradient(90deg, #8ee06f, #45a838); }
.fill.axe.low { background: linear-gradient(90deg, #ff9a5c, #e04b3c); }

/* ---------- 무대 ---------- */
#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  display: block;
  border: 4px solid #c2905a;
  border-radius: 20px;
  background: #bfeaff;
  box-shadow: 0 6px 0 #a5754a;
  image-rendering: pixelated;
  cursor: crosshair;
  touch-action: manipulation;
}

/* ---------- 패널 ---------- */
.panelWrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 10px;
  border-radius: 20px;
  background: linear-gradient(to bottom, rgba(16, 26, 44, 0), rgba(16, 26, 44, .35) 26%, rgba(16, 26, 44, .62) 100%);
  animation: fadeIn .16s ease;
}
.panelWrap.center { align-items: center; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { transform: translateY(10px) scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }

.panel {
  width: 100%;
  max-width: 470px;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  border: 3px solid #c2905a;
  border-radius: 20px;
  background: #fffdf6;
  box-shadow: 0 6px 0 #a5754a;
  overflow: hidden;
  animation: pop .2s ease;
}
.panel.result { max-width: 340px; padding-bottom: 14px; text-align: center; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.panel.result h2 { margin: 8px 0 4px; font-size: 20px; font-weight: 400; }
.panel.result .hint { padding: 0 16px; }

.panelHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px 7px 14px;
  background: linear-gradient(#ffdd93, #ffbe4d);
  border-bottom: 3px solid #c2905a;
}
.panelHead h2 { margin: 0; font-size: 17px; font-weight: 400; }

.closeBtn {
  width: 30px; height: 30px;
  border: none; border-radius: 10px;
  background: rgba(255, 255, 255, .75);
  color: #8a5a34;
  font-family: inherit; font-size: 15px;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(138, 90, 52, .35);
}
.closeBtn:active { transform: translateY(2px); box-shadow: none; }

.sellRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  background: #fff5df;
  border-bottom: 2px solid #f0e0c2;
  font-size: 15px;
}

.sellBtn {
  font-family: inherit; font-size: 15px;
  padding: 6px 14px;
  border: none; border-radius: 12px;
  background: linear-gradient(#ffc76b, #ff9f2e);
  color: #fff; cursor: pointer;
  box-shadow: 0 3px 0 #d47c14;
}
.sellBtn em { font-style: normal; font-size: 13px; opacity: .95; }
.sellBtn:disabled { background: #ddd3c4; box-shadow: 0 3px 0 #b9ae9d; cursor: default; }
.sellBtn:not(:disabled):active { transform: translateY(2px); box-shadow: 0 1px 0 #d47c14; }

.list { overflow-y: auto; padding: 8px 10px 14px; -webkit-overflow-scrolling: touch; }
.list h3 { margin: 6px 4px; font-size: 14px; font-weight: 400; color: #b07c44; }

.shopItem {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  margin-bottom: 6px;
  border: 2px solid #f0e0c2;
  border-radius: 14px;
  background: #fffaf0;
}
.shopItem.owned { background: #f2f8ee; border-color: #cfe6c2; }
.siIcon { font-size: 20px; }
.siInfo { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.siInfo b { font-size: 15px; font-weight: 400; }
.siInfo em { font-style: normal; font-size: 12px; color: #95a0b5; }
.tag {
  display: inline-block;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 99px;
  background: #8ee06f;
  color: #fff;
  font-size: 11px;
  vertical-align: 2px;
}

.buyBtn {
  flex: 0 0 auto;
  font-family: inherit; font-size: 14px;
  padding: 7px 13px;
  border: none; border-radius: 12px;
  background: linear-gradient(#8ee06f, #57c445);
  color: #fff; cursor: pointer;
  box-shadow: 0 3px 0 #3f9c31;
  white-space: nowrap;
}
.buyBtn:disabled { background: #ddd3c4; box-shadow: 0 3px 0 #b9ae9d; cursor: default; }
.buyBtn:not(:disabled):active { transform: translateY(2px); box-shadow: 0 1px 0 #3f9c31; }

/* ---------- 기부 ---------- */
.hint { margin: 10px 14px 4px; font-size: 14px; color: #7c88a0; line-height: 1.35; white-space: pre-line; }

#donateList { padding: 8px 12px 4px; overflow-y: auto; }

.dCard {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding: 9px 11px;
  border: 3px solid #f0e0c2;
  border-radius: 16px;
  background: #fffaf0;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
}
.dCard.selected { border-color: #ffb02e; background: #fff4d8; transform: translateY(-2px); }
.dIcon { font-size: 26px; }
.dBody { display: flex; flex-direction: column; gap: 2px; }
.dBody b { font-size: 16px; font-weight: 400; }
.dBody em { font-style: normal; font-size: 12.5px; color: #8e9ab1; }

.bigBtn {
  margin: 10px 14px 14px;
  padding: 11px;
  border: none;
  border-radius: 16px;
  background: linear-gradient(#ff9aa2, #f2607a);
  color: #fff;
  font-family: inherit;
  font-size: 17px;
  cursor: pointer;
  box-shadow: 0 4px 0 #cf4460;
}
.bigBtn:disabled { background: #ddd3c4; box-shadow: 0 4px 0 #b9ae9d; cursor: default; }
.bigBtn:not(:disabled):active { transform: translateY(2px); box-shadow: 0 2px 0 #cf4460; }

.bigIcon { font-size: 46px; margin-top: 18px; }
.resultStat { margin: 8px 16px 0; font-size: 14px; color: #8e9ab1; line-height: 1.55; white-space: pre-line; }

.donateTotals {
  margin: 10px 16px 0;
  padding: 8px 11px;
  border: 2px solid #f0e0c2;
  border-radius: 14px;
  background: #fffaf0;
  text-align: left;
}
.totalRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 0;
  font-size: 13.5px;
  color: #6c7995;
}
.totalRow b { font-weight: 400; color: #b07c44; }

.rankStatus {
  margin: 10px 16px 0;
  font-size: 13px;
  color: #4a6b3f;
  line-height: 1.4;
  word-break: keep-all;
}

.tierBadge {
  margin: 10px 16px 0;
  padding: 7px 11px;
  border-radius: 14px;
  background: linear-gradient(#ffe6a6, #ffc65c);
  color: #7a4a12;
  font-size: 13.5px;
  line-height: 1.4;
}

.tierLine {
  margin: 2px 14px 4px;
  padding: 6px 11px;
  border-radius: 12px;
  background: #fff4d8;
  color: #b07c44;
  font-size: 13px;
  line-height: 1.4;
}

@media (max-height: 470px) {
  .panel.result .bigIcon { font-size: 30px; margin-top: 10px; }
  .panel.result h2 { font-size: 17px; margin: 6px 0 2px; }
  .panel.result .hint { font-size: 13px; }
  .donateTotals, .tierBadge { margin-top: 7px; }
}

/* ---------- 하단 탭 ---------- */
#bar { display: flex; gap: 6px; }

.tab {
  flex: 1 1 0;
  padding: 9px 4px;
  border: 3px solid #c2905a;
  border-radius: 15px;
  background: linear-gradient(#fffdf6, #ffeccd);
  color: #8a5a34;
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
  box-shadow: 0 3px 0 #a5754a;
}
.tab:active { transform: translateY(2px); box-shadow: 0 1px 0 #a5754a; }
.tab.active { background: linear-gradient(#ffe08f, #ffbe4d); color: #7a4a12; }
.tab.ready { animation: glow 1s ease-in-out infinite; border-color: #f2607a; }

.tab.resetTab { flex: 0 0 auto; padding: 9px 12px; font-size: 16px; }
.tab.resetTab.armed { background: linear-gradient(#ff9aa2, #f2607a); color: #fff; border-color: #cf4460; }

@keyframes glow {
  0%, 100% { background: linear-gradient(#ffe08f, #ffbe4d); }
  50% { background: linear-gradient(#ffd0d8, #ff9aa2); }
}

/* ---------- 창 여는 중 ---------- */
#sceneLoading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 14px;
  border-radius: 20px;
  background: linear-gradient(to bottom, rgba(16, 26, 44, 0) 38%, rgba(16, 26, 44, .42));
  pointer-events: none;
  animation: fadeIn .16s ease;
}

.loadCard {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 99px;
  background: rgba(28, 38, 58, .9);
  color: #fff;
  font-size: 14px;
}
.loadCard b { font-weight: 400; }
.loadCard i {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .3);
  border-top-color: #ffd166;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 토스트 ---------- */
#toast {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translate(-50%, 12px);
  max-width: 88%;
  padding: 8px 16px;
  border-radius: 99px;
  background: rgba(28, 38, 58, .92);
  color: #fff;
  font-size: 14.5px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 420px) {
  .stat b { font-size: 12px; }
  .tab { font-size: 14px; padding: 8px 2px; }
  .dBody em { display: none; }
}
