* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2f7fa3; color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  -webkit-user-select: none; user-select: none; overscroll-behavior: none; }
#game { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; }
#hud { position: fixed; inset: 0; pointer-events: none; display: none; }
body.playing #hud { display: block; }
#hud > * { pointer-events: auto; }
#top { position: absolute; top: calc(env(safe-area-inset-top) + 10px); left: 10px; right: 10px; display: flex; gap: 8px; align-items: center; }
.chip { background: rgba(16, 28, 36, .78); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); border-radius: 999px; padding: 8px 12px;
  font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 6px; border: 0; color: #fff; white-space: nowrap; }
.chip .dot { width: 12px; height: 12px; border-radius: 50%; background: #e0892f; box-shadow: 0 0 0 2px rgba(255,255,255,.8); }
#turnChip { margin-left: auto; }
.chip.ember svg { width: 18px; height: 18px; }
.chip.ember small { color: #ffd38a; font-weight: 600; }
.chip.icon { width: 36px; height: 36px; justify-content: center; padding: 0; font-size: 16px; cursor: pointer; }
#toast { position: absolute; top: calc(env(safe-area-inset-top) + 60px); left: 50%; transform: translateX(-50%); pointer-events: none;
  background: rgba(16, 28, 36, .85); padding: 9px 16px; border-radius: 12px; font-weight: 700; font-size: 15px; opacity: 0; transition: opacity .25s; white-space: nowrap; }
#toast.show { opacity: 1; }
#previews { position: absolute; inset: 0; pointer-events: none; }
.pv { position: absolute; transform: translate(-50%, -100%); background: #ff4b3e; color: #fff; font-weight: 800; font-size: 13px; padding: 2px 7px; border-radius: 8px; white-space: nowrap; box-shadow: 0 2px 6px rgba(0,0,0,.25); }
.pv.kill { background: #1d2a33; border: 2px solid #ff4b3e; }
#bottom { position: absolute; left: 10px; right: 10px; bottom: calc(env(safe-area-inset-bottom) + 10px); display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; gap: 8px; pointer-events: none; }
#bottom > * { pointer-events: auto; }
#nextBtn { grid-column: 1 / 3; justify-self: start; }
#panel { background: rgba(16, 28, 36, .86); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-radius: 18px; padding: 12px 14px; min-height: 64px; }
#panel .hint { color: #b9c6cf; font-size: 14px; padding: 8px 2px; }
#panel .row { display: flex; align-items: center; gap: 8px; }
#panel .title { font-size: 17px; font-weight: 800; }
#panel .owner { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
#panel .stats { font-size: 13px; color: #c9d4db; margin-top: 4px; display: flex; gap: 10px; flex-wrap: wrap; }
#panel .stats b { color: #fff; }
#panel .note { font-size: 12.5px; color: #ffd38a; margin-top: 6px; }
#panel .acts { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.act { border: 0; border-radius: 12px; padding: 9px 12px; font-size: 14px; font-weight: 800; background: #fff; color: #1d2a33; cursor: pointer; display: flex; gap: 6px; align-items: center; }
.act small { font-weight: 700; color: #b5651d; }
.act:disabled { opacity: .38; }
.act.hot { background: #ffd84a; }
#endBtn { align-self: end; height: 64px; border: 0; border-radius: 18px; padding: 0 18px; min-width: 92px; font-size: 16px; font-weight: 900; background: #ffd84a; color: #1d2a33; cursor: pointer; box-shadow: 0 4px 0 #c9a520; }
#endBtn:disabled { background: #6b7780; color: #cfd6db; box-shadow: none; }
#endBtn.pulse { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { transform: scale(1.05); } }
button.ghost { background: rgba(16, 28, 36, .7); color: #fff; border: 1px solid rgba(255,255,255,.25); border-radius: 999px; padding: 8px 14px; font-weight: 700; font-size: 13px; cursor: pointer; }
.pop { position: absolute; transform: translate(-50%, -50%); font-weight: 900; font-size: 22px; pointer-events: none; text-shadow: 0 2px 0 rgba(0,0,0,.35); animation: rise 1.2s ease-out forwards; white-space: nowrap; }
.pop.dmg { color: #ff5a4a; }
.pop.heal { color: #7dff9a; }
.pop.vet { color: #ffd84a; font-size: 18px; }
.pop.info { color: #fff; font-size: 16px; }
@keyframes rise { from { opacity: 1; margin-top: 0; } to { opacity: 0; margin-top: -46px; } }
.overlay { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(10, 30, 40, .55); padding: 20px; z-index: 5; }
.overlay.show { display: flex; }
.card { width: min(420px, 100%); background: #f7f1e3; color: #1d2a33; border-radius: 24px; padding: 26px 20px 18px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.35); max-height: 92vh; overflow: auto; }
.card.left { text-align: left; }
.logo { font-size: 46px; font-weight: 900; letter-spacing: 8px; color: #7a4513; }
.tag { color: #6b5a44; font-weight: 700; margin: 4px 0 18px; }
.tribes { display: grid; gap: 10px; margin-bottom: 16px; }
.tribe { display: flex; gap: 12px; align-items: center; text-align: left; padding: 12px; border-radius: 16px; background: #fff; border: 3px solid transparent; cursor: pointer; }
.tribe.sel { border-color: var(--c); }
.tribe.locked { opacity: .5; cursor: default; }
.tribe .sw { width: 38px; height: 38px; border-radius: 12px; background: var(--c); flex: none; display: grid; place-items: center; color: #fff; font-weight: 900; }
.tribe .tn { font-weight: 900; font-size: 16px; }
.tribe .tn small { font-weight: 700; color: #8a7a64; margin-left: 4px; }
.tribe .tp { font-size: 12.5px; color: #5b5045; margin-top: 2px; }
button.primary { width: 100%; border: 0; border-radius: 16px; padding: 15px; font-size: 18px; font-weight: 900; background: #e0892f; color: #fff; cursor: pointer; box-shadow: 0 4px 0 #9b5a1c; }
button.wide { width: 100%; margin-top: 10px; color: #1d2a33; background: transparent; border-color: rgba(0,0,0,.2); padding: 12px; font-size: 15px; }
.foot { font-size: 12px; color: #8a7a64; margin-top: 14px; }
.result { font-size: 40px; font-weight: 900; }
.sub { color: #6b5a44; font-weight: 700; margin: 4px 0 14px; }
.endstats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.endstats div { background: #fff; border-radius: 12px; padding: 10px; font-size: 13px; color: #6b5a44; }
.endstats b { display: block; font-size: 22px; color: #1d2a33; }
.teaser { font-size: 13px; color: #7a4513; background: #fde7c8; border-radius: 12px; padding: 10px; margin-bottom: 14px; }
.h { font-size: 22px; font-weight: 900; margin-bottom: 8px; }
.card ul { padding-left: 18px; margin: 0 0 16px; font-size: 14px; line-height: 1.5; color: #3b3a36; }
.card li { margin-bottom: 6px; }

/* ---- M2/M3 ---- */
.chip.tech { cursor: pointer; padding: 8px 12px; }
.chip.tech.has { background: #ffd84a; color: #1d2a33; }
@media (max-width: 400px) { #tribeChip .name { display: none; } .chip { padding: 8px 10px; font-size: 13px; } }
#banner { position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%) scale(.9); pointer-events: none; opacity: 0; transition: opacity .3s, transform .3s;
  background: rgba(16, 28, 36, .9); border-radius: 18px; padding: 14px 22px; text-align: center; font-weight: 900; font-size: 20px; white-space: nowrap; }
#banner small { display: block; font-size: 13px; color: #c9d4db; font-weight: 700; margin-top: 4px; white-space: normal; }
#banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.card.home { padding: 18px 16px 16px; }
.card.home .logo { font-size: 38px; letter-spacing: 7px; }
.card.home .tag { margin: 0 0 6px; }
#homeCanvas { width: 100%; height: 190px; display: block; border-radius: 18px; background: linear-gradient(#bfe6ef, #e9f5f2); }
.homestats { display: flex; justify-content: center; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.homestats span { background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 800; color: #5b5045; }
.homestats b { color: #1d2a33; }
.cont { width: 100%; border: 0; border-radius: 14px; padding: 12px; margin-bottom: 10px; font-size: 16px; font-weight: 900; background: #2c9fb3; color: #fff; cursor: pointer; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: #ebe2cf; border-radius: 14px; padding: 4px; margin-bottom: 12px; }
.tabs button { border: 0; background: transparent; border-radius: 10px; padding: 9px 0; font-weight: 800; font-size: 14px; color: #6b5a44; cursor: pointer; }
.tabs button.on { background: #fff; color: #1d2a33; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.sec { text-align: left; font-size: 13px; font-weight: 900; color: #8a7a64; margin: 12px 2px 6px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1; min-width: 56px; border: 2px solid transparent; background: #fff; border-radius: 12px; padding: 10px 6px; font-weight: 800; font-size: 14px; color: #1d2a33; cursor: pointer; }
.seg button.on { border-color: #e0892f; background: #fff6ea; }
.seg button:disabled { opacity: .4; }
.segdesc { text-align: left; font-size: 12.5px; color: #6b5a44; margin: 6px 2px 0; }
.tribe .lockbar { height: 6px; border-radius: 3px; background: #eadfca; margin-top: 6px; overflow: hidden; }
.tribe .lockbar i { display: block; height: 100%; background: var(--c); }
.list { display: grid; gap: 8px; text-align: left; }
.item { background: #fff; border-radius: 14px; padding: 11px 12px; display: flex; gap: 10px; align-items: center; }
.item .t { font-weight: 900; font-size: 15px; }
.item .d { font-size: 12.5px; color: #5b5045; margin-top: 2px; }
.item .r { margin-left: auto; }
.item.off { opacity: .45; }
.item button { border: 0; border-radius: 10px; padding: 8px 12px; font-weight: 900; background: #e0892f; color: #fff; cursor: pointer; white-space: nowrap; }
.item button:disabled { background: #cfc4b1; }
.pill { font-size: 12px; font-weight: 800; padding: 3px 8px; border-radius: 999px; background: #e7f3e3; color: #2f6a2a; white-space: nowrap; }
.go { margin-top: 14px; }
.rewards { text-align: left; background: #fff; border-radius: 14px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.rewards .ln { display: flex; justify-content: space-between; padding: 3px 0; color: #5b5045; }
.rewards .ln b { color: #1d2a33; }
.rewards .tot { border-top: 1px dashed #d9cdb6; margin-top: 6px; padding-top: 6px; font-weight: 900; color: #1d2a33; }
.unlock { background: #fde7c8; color: #7a4513; border-radius: 12px; padding: 9px 12px; margin-bottom: 8px; font-weight: 800; font-size: 14px; text-align: left; }
.techrow { margin-bottom: 12px; }
.techrow .lbl { font-size: 12px; font-weight: 900; color: #8a7a64; margin: 0 2px 6px; }
.techgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tc { background: #fff; border-radius: 14px; padding: 10px; border: 2px solid transparent; text-align: left; cursor: pointer; font: inherit; color: inherit; }
.tc .n { font-weight: 900; font-size: 15px; }
.tc .d { font-size: 12px; color: #5b5045; margin: 3px 0 6px; min-height: 30px; }
.tc .c { font-size: 12.5px; font-weight: 900; color: #b5651d; }
.tc.own { background: #e7f3e3; cursor: default; }
.tc.own .c { color: #2f6a2a; }
.tc.lock { opacity: .5; cursor: default; }
.tc.can { border-color: #e0892f; }
.tc.poor { cursor: default; }
.h small { font-size: 14px; color: #b5651d; margin-left: 6px; }
.act.unit { flex-direction: column; gap: 0; padding: 7px 10px; min-width: 64px; }
.act.unit small { font-size: 11px; }

.go { position: sticky; bottom: 0; box-shadow: 0 4px 0 #9b5a1c, 0 -10px 16px #f7f1e3; }

/* UX pass */
#bottom { max-width: 720px; margin: 0 auto; }
#panel .acts { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; scrollbar-width: none; }
#panel .acts::-webkit-scrollbar { display: none; }
#panel .acts .act { flex: none; }
.act { min-height: 44px; }
