* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #14190f;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif;
  color: #fff; user-select: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
.hidden { display: none !important; }

/* 세로 화면 틀 — 가로로 넓은 화면에서는 가운데 세로 기둥으로 표시 */
#frame {
  position: fixed; top: 0; bottom: 0; left: 50%; transform: translateX(-50%);
  width: min(100vw, calc(100vh * 0.62)); width: min(100vw, calc(100dvh * 0.62));
  overflow: hidden; background: #4b7f33;
}
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#vignette {
  position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .35s;
  box-shadow: inset 0 0 90px 30px rgba(220, 30, 20, .75);
}
#vignette.on { opacity: 1; transition: opacity .05s; }

/* ── 상단 정보 ── */
#hud { position: absolute; left: 0; right: 0; top: 0; padding: calc(env(safe-area-inset-top, 0px) + 10px) 10px 0; pointer-events: none; }
.hud-row { display: flex; align-items: flex-start; gap: 8px; }
.crest {
  width: 50px; height: 50px; flex: none; border-radius: 10px; padding: 6px;
  background: linear-gradient(#5a4028, #33241a); border: 2px solid #c9a55a; box-shadow: 0 3px 8px rgba(0,0,0,.4);
}
.crest svg { width: 100%; height: 100%; display: block; }
.hud-col { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 0; }
.pills { display: flex; gap: 5px; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 5px; height: 25px; padding: 0 10px 0 5px;
  background: rgba(38, 27, 18, .82); border: 1px solid rgba(201,165,90,.55); border-radius: 13px;
  font-size: 13px; font-variant-numeric: tabular-nums; box-shadow: 0 2px 5px rgba(0,0,0,.3); white-space: nowrap;
}
.pill b { font-weight: 700; }
.pill span { font-size: 11px; opacity: .7; }
.pill.gold { align-self: flex-start; background: rgba(74, 44, 30, .9); font-size: 15px; height: 28px; }
.pill.gold b { color: #ffe08a; }
.pill.bump { animation: bump .25s; }
.pill.warn { animation: warn .4s; }
@keyframes bump { 40% { transform: scale(1.14); } }
@keyframes warn { 30% { background: #b32417; transform: scale(1.12); } }
.ic { width: 17px; height: 17px; display: inline-block; background: center/contain no-repeat; flex: none; }
.ic-coin { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Ccircle cx='10' cy='10' r='9' fill='%23f4c542' stroke='%23a8741a' stroke-width='2'/%3E%3Ccircle cx='10' cy='10' r='4.5' fill='none' stroke='%23a8741a' stroke-width='1.6'/%3E%3C/svg%3E"); }
.ic-heart { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M10 17.5C4 13 2 10 2 7a4 4 0 0 1 8-1 4 4 0 0 1 8 1c0 3-2 6-8 10.500z' fill='%23e8483a' stroke='%237d1c14' stroke-width='1.4'/%3E%3C/svg%3E"); }
.ic-flag { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5 2v16' stroke='%23e9dcc0' stroke-width='2' stroke-linecap='round'/%3E%3Cpath d='M6 3h10l-3 3.500 3 3.500H6z' fill='%234a8fe8'/%3E%3C/svg%3E"); }
.ic-helm { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M3 12a7 7 0 0 1 14 0v5h-5v-5H8v5H3z' fill='%23d94a3d' stroke='%237d1c14' stroke-width='1.4'/%3E%3C/svg%3E"); }

.hud-btns { display: flex; gap: 6px; pointer-events: auto; }
.rbtn {
  width: 38px; height: 38px; border-radius: 50%; font-size: 14px; font-weight: 700;
  background: rgba(38, 27, 18, .82); border: 1px solid rgba(201,165,90,.55); box-shadow: 0 2px 5px rgba(0,0,0,.3);
}
.rbtn:active { transform: scale(.92); }
.rbtn.on { background: #c9872a; }
.rbtn.off { opacity: .5; }

#banner {
  margin: 14px auto 0; width: fit-content; max-width: 90%; padding: 8px 20px; border-radius: 20px;
  background: rgba(20, 14, 9, .78); border: 1px solid rgba(201,165,90,.6);
  font-size: 17px; font-weight: 800; letter-spacing: .5px; text-align: center;
  opacity: 0; transform: translateY(-8px); transition: opacity .3s, transform .3s;
}
#banner.show { opacity: 1; transform: none; }
#banner small { display: block; font-size: 12px; font-weight: 500; opacity: .8; letter-spacing: 0; }

/* ── 하단 조작 ── */
#bottom {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; align-items: flex-end;
  padding: 0 12px calc(env(safe-area-inset-bottom, 0px) + 14px); pointer-events: none;
}
.skill {
  pointer-events: auto; position: relative; width: 64px; height: 64px; border-radius: 50%; padding: 0;
  background: radial-gradient(circle at 35% 30%, #4a8fe8, #1d3f86); border: 3px solid #e9dcc0; box-shadow: 0 4px 10px rgba(0,0,0,.45);
}
.skill svg { width: 38px; height: 38px; display: block; margin: 6px auto 0; }
.skill em { position: absolute; left: 50%; bottom: -3px; transform: translateX(-50%); font-style: normal; font-size: 10px; font-weight: 700;
  background: #261b12; border: 1px solid #c9a55a; border-radius: 8px; padding: 1px 7px; white-space: nowrap; }
.skill #skillCd { position: absolute; inset: -3px; border-radius: 50%; display: none; align-items: center; justify-content: center;
  background: rgba(15,15,20,.72); font-size: 20px; font-weight: 800; }
.skill.cd #skillCd { display: flex; }
.skill.arm { border-color: #ffe08a; box-shadow: 0 0 0 4px rgba(255,224,138,.5), 0 4px 10px rgba(0,0,0,.45); animation: pulse 1s infinite; }
.skill:active { transform: scale(.94); }
@keyframes pulse { 50% { transform: scale(1.07); } }
.next {
  pointer-events: auto; min-width: 132px; padding: 10px 18px; border-radius: 16px; text-align: center;
  background: linear-gradient(#f0a53a, #c8721c); border: 2px solid #ffe2a6; box-shadow: 0 4px 0 #7d430f, 0 6px 12px rgba(0,0,0,.4);
}
.next b { display: block; font-size: 16px; font-weight: 800; text-shadow: 0 1px 0 rgba(0,0,0,.3); }
.next small { display: block; font-size: 11px; opacity: .92; min-height: 0; }
.next:active { transform: translateY(3px); box-shadow: 0 1px 0 #7d430f; }
.next.hide { visibility: hidden; }

#hint {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 96px); transform: translateX(-50%);
  background: rgba(20,14,9,.82); border: 1px solid rgba(201,165,90,.6); border-radius: 16px; padding: 7px 16px;
  font-size: 13px; font-weight: 600; white-space: nowrap; pointer-events: none;
}

/* ── 건설 / 강화 창 ── */
#sheet {
  position: absolute; left: 8px; right: 8px; bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  background: linear-gradient(#4a3423, #2c1f15); border: 2px solid #c9a55a; border-radius: 18px;
  padding: 10px 12px 12px; box-shadow: 0 -4px 24px rgba(0,0,0,.5); animation: up .18s ease-out;
}
#sheet.top { bottom: auto; top: calc(env(safe-area-inset-top, 0px) + 112px); animation-name: down; }
@keyframes down { from { transform: translateY(-30px); opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-head b { font-size: 16px; }
.sheet-head button { width: 32px; height: 32px; border-radius: 50%; background: rgba(0,0,0,.3); font-size: 14px; }
.cards { display: flex; gap: 8px; }
.card {
  flex: 1; min-width: 0; padding: 9px 6px 8px; border-radius: 12px; text-align: center;
  background: #e9dcc0; color: #2c1f15; border: 2px solid #fff3d6; box-shadow: 0 3px 0 #8a7650;
}
.card:active { transform: translateY(2px); box-shadow: 0 1px 0 #8a7650; }
.card.no { filter: grayscale(.8); opacity: .6; }
.card .nm { font-size: 14px; font-weight: 800; }
.card .ds { font-size: 10.5px; line-height: 1.3; margin: 3px 0 6px; min-height: 27px; opacity: .8; word-break: keep-all; }
.card .cost { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; font-size: 14px; background: #2c1f15; color: #ffe08a; border-radius: 10px; padding: 2px 9px 2px 5px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px; }
.stat { background: rgba(0,0,0,.28); border-radius: 10px; padding: 6px 4px; text-align: center; }
.stat span { display: block; font-size: 10.5px; opacity: .7; }
.stat b { font-size: 14px; }
.stat i { font-style: normal; color: #8fe07a; font-size: 11px; margin-left: 2px; }
.actions { display: flex; gap: 8px; }
.act { flex: 1; padding: 10px 6px; border-radius: 12px; font-weight: 800; font-size: 14px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.act.up { background: linear-gradient(#69b84a, #3f8a26); border: 2px solid #c8f0b4; box-shadow: 0 3px 0 #23540f; flex: 1.6; }
.act.sell { background: linear-gradient(#b9573f, #8a3320); border: 2px solid #f0c0b0; box-shadow: 0 3px 0 #561a0c; }
.act.no { filter: grayscale(.8); opacity: .6; }
.act:active { transform: translateY(2px); }
.act .ic { width: 15px; height: 15px; }

/* ── 전체 화면 창 ── */
.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(circle at 50% 35%, rgba(30,45,20,.55), rgba(8,10,6,.9));
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.title-card { width: 100%; max-width: 330px; text-align: center; }
.title-card.small { background: linear-gradient(#4a3423, #2c1f15); border: 2px solid #c9a55a; border-radius: 20px; padding: 22px 20px; }
.logo { width: 92px; margin: 0 auto 8px; filter: drop-shadow(0 6px 10px rgba(0,0,0,.5)); }
h1 { margin: 0; font-size: 40px; font-weight: 900; letter-spacing: 2px; color: #ffe9b0; text-shadow: 0 3px 0 #6b3d10, 0 6px 14px rgba(0,0,0,.6); }
h2 { margin: 0 0 14px; font-size: 22px; color: #ffe9b0; }
.sub { margin: 6px 0 22px; font-size: 14px; opacity: .85; }
#loadWrap { height: 10px; border-radius: 5px; background: rgba(0,0,0,.5); border: 1px solid rgba(201,165,90,.6); overflow: hidden; }
#loadBar { height: 100%; width: 0; background: linear-gradient(90deg, #f0a53a, #ffe08a); transition: width .2s; }
#loadTxt { font-size: 12px; opacity: .7; margin: 8px 0 0; }
.big {
  display: block; width: 100%; margin-top: 10px; padding: 14px; border-radius: 16px; font-size: 19px; font-weight: 900;
  background: linear-gradient(#f0a53a, #c8721c); border: 2px solid #ffe2a6; box-shadow: 0 5px 0 #7d430f, 0 8px 16px rgba(0,0,0,.4);
  text-shadow: 0 1px 0 rgba(0,0,0,.3);
}
.big:active { transform: translateY(4px); box-shadow: 0 1px 0 #7d430f; }
.big.ghost { background: rgba(0,0,0,.3); border-color: rgba(201,165,90,.6); box-shadow: none; font-size: 15px; font-weight: 700; }
.best { font-size: 13px; color: #ffe08a; min-height: 18px; margin: 14px 0 0; }
.howto { list-style: none; padding: 12px 14px; margin: 16px 0 0; text-align: left; font-size: 12.5px; line-height: 1.75;
  background: rgba(0,0,0,.35); border-radius: 14px; }
.howto b { color: #ffe08a; }
.result { display: flex; justify-content: space-between; margin: 6px 0; padding: 8px 12px; background: rgba(0,0,0,.28); border-radius: 10px; font-size: 14px; }
.result b { color: #ffe08a; font-size: 16px; }
#fatalMsg { font-size: 13px; line-height: 1.6; opacity: .85; }
