@font-face { font-family: Galmuri11; src: url(../fonts/Galmuri11-ksc.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: Galmuri11; src: url(../fonts/Galmuri11-Bold-ksc.woff2) format('woff2'); font-weight: bold; font-display: swap; }
:root {
  --ink: #2a1d14; --paper: #f4e9d2; --paper2: #e8d8b5; --wood: #6b4423; --wood2: #3a2414; --gold: #ffd54f;
  --font: Galmuri11, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #111; font-family: var(--font); color: var(--ink); -webkit-tap-highlight-color: transparent; }
canvas#world { position: fixed; inset: 0; display: block; image-rendering: pixelated; touch-action: none; }
button { font-family: var(--font); cursor: pointer; }
.hidden { display: none !important; }
#loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; color: #ffe9a8; font-size: 16px; background: #14110d; z-index: 50; }

/* 나무 액자 느낌 패널 */
.card, #modal .box, #hud .me, #hud .right .btns button, #log {
  background: var(--paper); border: 3px solid var(--wood2); box-shadow: inset 0 0 0 2px var(--paper2), 0 4px 0 rgba(0, 0, 0, 0.35);
}

/* 로그인 */
#login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(12, 10, 8, 0.35); z-index: 20; overflow-y: auto; }
#login .card { width: min(560px, 100%); padding: 22px 22px 16px; border-radius: 6px; margin: auto; }
.logo { text-align: center; line-height: 1; margin: 4px 0 6px; }
.logo span { display: inline-block; font-weight: bold; font-size: 40px; letter-spacing: 2px; text-shadow: 0 4px 0 #2a1d14; -webkit-text-stroke: 1.5px #2a1d14; paint-order: stroke fill; }
.logo .l1 { color: #ffd54f; } .logo .l2 { color: #ff8a65; margin-left: 8px; }
.tag { text-align: center; margin: 4px 0 14px; color: #6b4423; font-size: 13px; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab { flex: 1; padding: 9px 0; border: 2px solid var(--wood2); background: var(--paper2); color: var(--ink); font-size: 14px; border-radius: 4px; }
.tab.on { background: var(--wood); color: #fff3c4; }
form label { display: block; font-size: 13px; margin: 0 0 9px; }
form label small { color: #8a6d4d; font-size: 11px; }
form input { display: block; width: 100%; margin-top: 4px; padding: 9px 10px; font: 15px var(--font); border: 2px solid var(--wood2); border-radius: 4px; background: #fffaf0; color: var(--ink); }
form input:focus { outline: 3px solid var(--gold); }
button.primary { width: 100%; padding: 11px 0; margin-top: 4px; font-size: 16px; font-weight: bold; color: #fff3c4; background: #b5462e; border: 3px solid var(--wood2); border-radius: 4px; box-shadow: 0 3px 0 var(--wood2); }
button.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--wood2); }
button:disabled { opacity: 0.5; cursor: default; }
.two { display: flex; gap: 16px; }
.two .col { flex: 1; min-width: 0; }
.look { text-align: center; }
#pv { image-rendering: pixelated; background: radial-gradient(#7fb069, #4f7f3f); border: 2px solid var(--wood2); border-radius: 6px; }
.swl { font-size: 11px; color: #6b4423; margin: 6px 0 3px; }
.sws { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.sw { width: 22px; height: 22px; border: 2px solid var(--wood2); border-radius: 4px; padding: 0; font-size: 11px; }
#sw-style .sw { width: auto; padding: 2px 7px; background: var(--paper2); }
.sw.on { outline: 3px solid var(--gold); }
#sw-style .sw.on { background: var(--wood); color: #fff3c4; }
#login-err { color: #c62828; min-height: 18px; margin: 8px 0 0; font-size: 13px; text-align: center; }
#mode-note { margin: 6px 0 0; font-size: 11px; color: #7a6248; text-align: center; }
@media (max-width: 560px) { .two { flex-direction: column-reverse; gap: 4px; } .logo span { font-size: 32px; } }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud .me { position: absolute; left: 10px; top: 10px; padding: 8px 10px; border-radius: 5px; min-width: 210px; pointer-events: auto; font-size: 13px; }
#hud .row1 { display: flex; align-items: center; gap: 6px; }
#hud .row1 b { font-size: 15px; }
.rank { font-size: 11px; padding: 2px 6px; border-radius: 3px; border: 2px solid var(--wood2); color: #2a1d14; font-weight: bold; }
#hud .row2 { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
#hud .row2 .lab { color: #7a5a3a; font-size: 12px; }
#hud .row2 b { color: #b5462e; font-size: 16px; }
.hp { margin-left: auto; display: inline-flex; gap: 2px; }
.heart { width: 14px; height: 12px; display: inline-block; background: #e53935; clip-path: polygon(50% 100%, 0 40%, 0 15%, 15% 0, 35% 0, 50% 15%, 65% 0, 85% 0, 100% 15%, 100% 40%); }
.heart.empty { background: #9e8f7a; opacity: 0.6; }
.next { position: relative; height: 14px; margin-top: 6px; background: #d8c8a6; border: 2px solid var(--wood2); border-radius: 3px; overflow: hidden; }
.next i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(#ffd54f, #f0a500); }
.next span { position: relative; display: block; text-align: center; font-size: 10px; line-height: 10px; color: #3a2414; }
#hud .right { position: absolute; right: 10px; top: 10px; text-align: right; }
#h-map { display: inline-block; color: #ffe9a8; font-size: 14px; text-shadow: 2px 2px 0 #000, -1px -1px 0 #000; margin-bottom: 4px; }
#online { color: #b9f6ca; font-size: 12px; text-shadow: 1px 1px 0 #000; min-height: 14px; }
#hud .btns { display: flex; gap: 5px; justify-content: flex-end; margin-top: 4px; flex-wrap: wrap; }
#hud .btns button { pointer-events: auto; padding: 6px 9px; font-size: 12px; border-radius: 4px; color: var(--ink); }
#log { position: absolute; left: 10px; bottom: 10px; width: min(420px, calc(100% - 20px)); padding: 6px 9px; border-radius: 5px; font-size: 12px; line-height: 1.5; background: rgba(20, 14, 10, 0.72); color: #f3e5c8; border-color: rgba(0,0,0,0.6); box-shadow: none; }
#log:empty { display: none; }
#log .win { color: #ffe082; } #log .lose { color: #ff8a80; } #log .sys { color: #b3e5fc; }

/* 터치 */
#touch { position: fixed; inset: auto 0 0 0; height: 0; z-index: 6; }
#touch .pad { position: fixed; left: 14px; bottom: 96px; width: 150px; height: 150px; }
#touch .pad button, #touch-a { position: absolute; width: 52px; height: 52px; border-radius: 10px; border: 3px solid rgba(0,0,0,0.55); background: rgba(244, 233, 210, 0.78); font-size: 18px; color: #3a2414; touch-action: none; user-select: none; -webkit-user-select: none; }
#touch .pad button.on { background: #ffd54f; }
#touch .u { left: 49px; top: 0; } #touch .d { left: 49px; bottom: 0; } #touch .l { left: 0; top: 49px; } #touch .r { right: 0; top: 49px; }
#touch-a { position: fixed !important; right: 22px; bottom: 120px; width: 66px !important; height: 66px !important; border-radius: 50% !important; font-weight: bold; font-size: 22px !important; background: rgba(255, 138, 101, 0.85) !important; }
@media (max-width: 640px) {
  #hud .right { left: 10px; right: 10px; top: 92px; text-align: left; }
  #hud .btns { justify-content: flex-start; }
  #h-map { position: fixed; right: 10px; top: 10px; max-width: 34vw; font-size: 12px; text-align: right; }
  #online { position: fixed; right: 10px; top: 30px; }
}
@media (max-width: 820px) {
  #hud .me { min-width: 0; padding: 6px 8px; }
  #hud .btns button { padding: 5px 6px; font-size: 11px; }
  #log { bottom: 8px; font-size: 11px; width: calc(100% - 20px); }
}

/* 대화창 */
#modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.45); z-index: 30; padding: 14px; }
#modal .box { width: min(560px, 100%); max-height: 86vh; display: flex; flex-direction: column; border-radius: 6px; padding: 14px 16px 12px; }
#modal h3 { margin: 0 0 8px; padding-bottom: 6px; border-bottom: 2px dashed #b89b72; font-size: 17px; color: #6b2f1a; }
#modal-body { overflow-y: auto; font-size: 13.5px; line-height: 1.65; }
#modal-body p { margin: 0 0 8px; }
#modal-body h4 { margin: 10px 0 4px; font-size: 14px; }
#modal-body ul { margin: 0 0 6px; padding-left: 18px; }
.dim { color: #7a6248; font-size: 12px; }
#modal-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
#modal-btns button { padding: 8px 16px; font-size: 14px; border: 3px solid var(--wood2); border-radius: 4px; background: var(--paper2); color: var(--ink); }
#modal-btns button.primary { width: auto; margin: 0; background: #b5462e; color: #fff3c4; }
.pbar { position: relative; height: 18px; background: #d8c8a6; border: 2px solid var(--wood2); border-radius: 3px; overflow: hidden; margin: 3px 0 8px; }
.pbar i { position: absolute; inset: 0 auto 0 0; }
.pbar span { position: relative; display: block; text-align: center; font-size: 11px; line-height: 14px; color: #fff; text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000; }
.row.small { display: grid; grid-template-columns: 110px 1fr; gap: 8px; align-items: center; font-size: 12px; }
.row.small .pbar { margin: 2px 0; height: 16px; }
.sub { padding-left: 6px; }
.mon-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.mon-chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px 3px 3px; border: 2px solid #b89b72; border-radius: 4px; background: #fffaf0; font-size: 12px; }
.mon-chip canvas { image-rendering: pixelated; }
.rank-row { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 4px; margin-bottom: 3px; }
.rank-row.me { background: #fff3c4; outline: 2px solid #f0a500; }
.badge { width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; border: 2px solid var(--wood2); border-radius: 50%; font-size: 12px; font-weight: bold; }
table.rank { width: 100%; border-collapse: collapse; font-size: 13px; }
table.rank th { text-align: left; border-bottom: 2px solid #b89b72; padding: 4px; font-size: 12px; }
table.rank td { padding: 5px 4px; border-bottom: 1px dashed #d1bd98; }
table.rank .n { text-align: right; }
table.rank tr.me td { background: #fff3c4; }
table.rank td:nth-child(3) { text-shadow: 1px 1px 0 #3a2414; font-size: 12px; }
button.link { background: none; border: none; color: #1565c0; text-decoration: underline; font-size: 12px; padding: 0; }

/* 토스트 */
#toast { position: fixed; left: 50%; top: 18%; transform: translate(-50%, -10px); padding: 10px 18px; border-radius: 6px; font-size: 16px; color: #fff3c4; background: rgba(40, 24, 12, 0.92); border: 3px solid #ffd54f; opacity: 0; transition: all .25s; pointer-events: none; z-index: 60; white-space: nowrap; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.rank { font-size: 22px; font-weight: bold; color: #ffd54f; padding: 14px 26px; box-shadow: 0 0 30px rgba(255, 213, 79, 0.6); }
#toast.bad { border-color: #ff8a80; }

/* 전투 */
#battle { position: fixed; inset: 0; z-index: 40; background: rgba(10, 8, 6, 0.95); display: flex; padding: 10px; }
.bt-wrap { flex: 1; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, 1fr); gap: 10px; min-height: 0; max-width: 1400px; margin: 0 auto; width: 100%; }
.bt-q { display: flex; flex-direction: column; min-height: 0; background: #fff; border: 3px solid var(--wood2); border-radius: 6px; overflow: hidden; }
.bt-qhead { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--paper2); border-bottom: 2px solid var(--wood2); font-size: 12px; }
.bt-src { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #5a3a20; }
.bt-zoom { padding: 4px 10px; font-size: 12px; border: 2px solid var(--wood2); background: var(--paper); border-radius: 4px; }
.bt-qbody { flex: 1; overflow: auto; display: flex; justify-content: center; align-items: flex-start; padding: 10px; background: #fff; -webkit-overflow-scrolling: touch; }
.bt-img { width: 100%; max-width: none; height: auto; display: block; cursor: zoom-in; }
.bt-img.zoom { width: 160%; max-width: none; cursor: zoom-out; }
.bt-side { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.bt-arena { position: relative; flex: 1 1 auto; min-height: 170px; max-height: 360px; border: 3px solid var(--wood2); border-radius: 6px; overflow: hidden; background: #222; }
.bt-cv { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
.bt-plate { position: absolute; padding: 5px 8px; background: var(--paper); border: 3px solid var(--wood2); border-radius: 5px; font-size: 12px; min-width: 150px; }
.bt-plate.mon { left: 8px; top: 8px; }
.bt-plate.me { right: 8px; bottom: 8px; }
.bt-name { font-weight: bold; margin-bottom: 4px; white-space: nowrap; }
.hpbar { height: 9px; background: #5d4037; border: 2px solid var(--wood2); border-radius: 3px; overflow: hidden; }
.hpbar i { display: block; height: 100%; width: 100%; background: linear-gradient(#81c784, #43a047); transition: width .6s ease-out; }
.bt-hearts { display: flex; gap: 3px; }
.bt-msg { min-height: 52px; padding: 8px 12px; font-size: 14px; line-height: 1.5; color: var(--ink); background: var(--paper); border: 3px solid var(--wood2); border-radius: 6px; }
.bt-choices { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.bt-ch { padding: 12px 0; font-size: 24px; border: 3px solid var(--wood2); border-radius: 6px; background: #fffaf0; color: var(--ink); box-shadow: 0 3px 0 var(--wood2); }
.bt-ch:hover:not(:disabled) { background: #fff3c4; }
.bt-ch.sel { background: #ffd54f; transform: translateY(-2px); }
.bt-ch.ok { background: #66bb6a; color: #fff; }
.bt-ch.bad { background: #e57373; color: #fff; }
.bt-actions { display: flex; gap: 6px; }
.bt-actions button:disabled { opacity: 1; filter: grayscale(0.7) brightness(0.85); }
.bt-actions button { flex: 1; padding: 11px 0; font-size: 16px; font-weight: bold; border: 3px solid var(--wood2); border-radius: 6px; box-shadow: 0 3px 0 var(--wood2); }
.bt-attack { background: #b5462e; color: #fff3c4; }
.bt-run { flex: 0 0 34% !important; background: var(--paper2); color: var(--ink); font-size: 14px !important; }
.bt-next { background: #2e7d32; color: #fff; }
@media (max-width: 860px), (orientation: portrait) {
  #battle { padding: 6px; }
  .bt-wrap { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; gap: 6px; }
  .bt-side { gap: 6px; }
  .bt-arena { flex: 0 0 auto; height: 22vh; min-height: 120px; }
  .bt-plate { font-size: 11px; min-width: 120px; padding: 3px 6px; }
  .bt-msg { min-height: 40px; font-size: 13px; padding: 6px 9px; }
  .bt-ch { padding: 8px 0; font-size: 20px; }
  .bt-actions button { padding: 9px 0; }
}

/* 서버 고르기 */
#sv-pick { margin: 2px 0 10px; }
#sv-pick .swl { text-align: left; font-size: 13px; margin-bottom: 5px; }
#sv-pick small { color: #8a6d4d; font-size: 11px; }
#sv-list { display: flex; gap: 8px; }
.sv { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; border: 2px solid var(--wood2); border-radius: 5px; background: var(--paper2); color: var(--ink); font-size: 14px; }
.sv span { font-size: 11px; color: #6b4423; }
.sv.on { background: var(--wood); color: #fff3c4; outline: 3px solid var(--gold); }
.sv.on span { color: #ffe9a8; }
.sv.busy span { color: #c62828; }
.sv.on.busy span { color: #ffab91; }
/* 자리 비움 · 연결 경고 */
#away { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; background: rgba(10, 8, 6, 0.72); padding: 16px; }
#away .box { width: min(380px, 100%); text-align: center; padding: 18px 20px; border-radius: 6px; background: var(--paper); border: 3px solid var(--wood2); box-shadow: inset 0 0 0 2px var(--paper2), 0 4px 0 rgba(0,0,0,0.35); }
#away h3 { margin: 0 0 8px; color: #6b2f1a; }
#away p { margin: 0 0 14px; font-size: 14px; line-height: 1.6; }
#netwarn { position: fixed; left: 50%; top: 70px; transform: translateX(-50%); z-index: 65; width: min(520px, calc(100% - 20px)); padding: 9px 14px; border-radius: 6px; background: #5a1f14; color: #ffe0d6; border: 3px solid #ff8a65; font-size: 13px; line-height: 1.5; text-align: center; }
