/* ============================================================
   흑선행 — 다크 판타지 무협 테마 (어두운 화면 / 밝은 화면)
   색은 아래 두 블록의 값만 바꾸면 전체 분위기가 바뀝니다.
   ============================================================ */

/* ---------- 어두운 화면 (기본) ---------- */
/* ---------- 어두운 화면: 쪽빛 밤 ---------- */
:root {
  --bg: #0b1322;
  --bg-glow-1: rgba(70, 120, 200, 0.14);
  --bg-glow-2: rgba(200, 60, 50, 0.06);
  --panel: #101a2c;
  --panel-2: #142136;
  --card-bg: rgba(12, 20, 36, 0.6);
  --input-bg: #0c1424;
  --topbar-bg: rgba(12, 19, 33, 0.9);
  --line: #2b3d5c;
  --line-soft: #1f2d45;
  --text: #e1e7f1;
  --text-story: #c8d3e4;
  --text-desc: #b9c6da;
  --dim: #8496b3;
  --faint: #56688a;
  --blood: #9c2f28;
  --blood-hi: #d0463b;
  --gold: #8fb4e8;
  --jade: #7fc0b0;
  --hp: #c9483e;
  --hp-dark: #6e1c17;
  --ap: #5d93d8;
  --ap-dark: #24487c;
  --enemy-bar: #6b5a9a;
  --enemy-text: #d7a3a3;
  --crit: #f0c76a;
  --lvl: #f0d69a;
  --btn-main-1: #2c5aa0;
  --btn-main-2: #1f4580;
  --btn-main-text: #f2f6fc;
  --overlay: rgba(4, 8, 16, 0.78);
  --modal-1: #15223a;
  --modal-2: #0e1729;
  --map-bg: #0c1424;
  --shadow: rgba(0, 0, 0, 0.55);
  --seal: #c8392f;

  /* 배경 장식(찢긴 종이) 색 */
  --tear-1: #1a3358; --tear-2: #24467a; --tear-3: #345d97; --tear-4: #142844;
  --sun: #b8362c; --grain: transparent; --decor-opacity: .55;

  --fog-bg: #0f1828;  --fog-fg: #26354f;
  --tC-bg: #2f2a1c;   --tC-fg: #e6c27a;
  --tE-bg: #2a2a22;   --tE-fg: #d2b06e;
  --tF-bg: #13261f;   --tF-fg: #77a88a;
  --tR-bg: #262230;   --tR-fg: #a9a0c0;
  --tM-bg: #1f2a24;   --tM-fg: #97a87a;
  --tP-bg: #1a2433;   --tP-fg: #8ea3c2;
  --tW-bg: #10243f;   --tW-fg: #6ea2dc;
  --tT-bg: #241c33;   --tT-fg: #ab92c8;
  --tB-bg: #2c1b20;   --tB-fg: #c08a86;
  --tO-bg: #33141a;   --tO-fg: #e0645a;
  --tX-bg: #0a0508;   --tX-fg: #ff5244;
  --tV-bg: #0a1d38;   --tV-fg: #3f7fd0;
  --tK-bg: #1b1d24;   --tK-fg: #7d8597;
  --tQ-bg: #13263f;   --tQ-fg: #c9a356;
  --tZ-bg: #23242c;   --tZ-fg: #c9a356;
  --tQo-bg: #3a2f1c;  --tQo-fg: #f0cf86;
  --tZo-bg: #2f2c35;  --tZo-fg: #f0cf86;

  --font-body: "IBM Plex Sans KR", sans-serif;
  --font-title: "Song Myung", serif;   /* 제목과 한자 인장 */
  --font-brush: "Nanum Brush Script", "Song Myung", serif;
}

/* ---------- 밝은 화면: 한지 위 쪽빛 ---------- */
:root[data-theme="light"] {
  --bg: #ece7dc;
  --bg-glow-1: rgba(60, 100, 170, 0.07);
  --bg-glow-2: rgba(200, 60, 50, 0.04);
  --panel: #f3efe6;
  --panel-2: #faf8f2;
  --card-bg: rgba(255, 254, 250, 0.78);
  --input-bg: #fffefa;
  --topbar-bg: rgba(247, 244, 237, 0.93);
  --line: #c7c3b8;
  --line-soft: #e0dbcf;
  --text: #1c2433;
  --text-story: #33405a;
  --text-desc: #3e4a60;
  --dim: #66708a;
  --faint: #9aa0ae;
  --blood: #a3342b;
  --blood-hi: #bf3a2f;
  --gold: #2c5aa0;
  --jade: #2f6d74;
  --hp: #bf3a2f;
  --hp-dark: #e39a91;
  --ap: #2f62ad;
  --ap-dark: #9dbbe4;
  --enemy-bar: #7a68a8;
  --enemy-text: #8a3b3b;
  --crit: #a8650a;
  --lvl: #8a5a10;
  --btn-main-1: #284f8e;
  --btn-main-2: #1c3d72;
  --btn-main-text: #fbfaf6;
  --overlay: rgba(40, 50, 70, 0.4);
  --modal-1: #fcfaf5;
  --modal-2: #f2eee4;
  --map-bg: #e6e1d5;
  --shadow: rgba(40, 50, 80, 0.2);
  --seal: #c8392f;

  --tear-1: #2a4a7c; --tear-2: #4d74ad; --tear-3: #8fa9cf; --tear-4: #1d355f;
  --sun: #c8392f; --grain: transparent; --decor-opacity: 1;

  --fog-bg: #e2ddd0;  --fog-fg: #bbb5a6;
  --tC-bg: #ecdcb6;   --tC-fg: #7a5512;
  --tE-bg: #e7e0c9;   --tE-fg: #6a5428;
  --tF-bg: #d3e2d6;   --tF-fg: #2d5a3e;
  --tR-bg: #e2dccf;   --tR-fg: #5e5340;
  --tM-bg: #dde0c6;   --tM-fg: #565c26;
  --tP-bg: #d6dce6;   --tP-fg: #384a64;
  --tW-bg: #c7d7ec;   --tW-fg: #1f4c86;
  --tT-bg: #ddd5e6;   --tT-fg: #54406b;
  --tB-bg: #e8d4cf;   --tB-fg: #7a3b2e;
  --tO-bg: #efcbc5;   --tO-fg: #8f2318;
  --tX-bg: #1a1f2e;   --tX-fg: #ff5544;
  --tV-bg: #4d7fc2;   --tV-fg: #e9f1fc;
  --tK-bg: #6b6f7a;   --tK-fg: #eceae4;
  --tQ-bg: #a9c3e6;   --tQ-fg: #6b4a12;
  --tZ-bg: #b4b6bd;   --tZ-fg: #5a3f12;
  --tQo-bg: #e8cf96;  --tQo-fg: #5a3c06;
  --tZo-bg: #ded3b8;  --tZo-fg: #5a3c06;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(ellipse at 20% 0%, var(--bg-glow-1), transparent 55%),
    radial-gradient(ellipse at 90% 100%, var(--bg-glow-2), transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  transition: background-color .3s, color .3s;
}
.hidden { display: none !important; }
button { font-family: inherit; }

/* ---------- 버튼 ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 16px;
  cursor: pointer;
  font-size: 14px;
  letter-spacing: 0.05em;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover:not(:disabled) { border-color: var(--gold); }
.btn:disabled { opacity: .38; cursor: not-allowed; }
.btn-main { background: linear-gradient(var(--btn-main-1), var(--btn-main-2)); border-color: var(--blood-hi); color: var(--btn-main-text); }
.btn-main:hover:not(:disabled) { filter: brightness(1.12); border-color: var(--blood-hi); }
.btn-ghost { background: transparent; }
.btn-small { padding: 5px 10px; font-size: 13px; }
.btn small { color: var(--dim); margin-left: 4px; font-size: 11px; }
.btn-main small { color: inherit; opacity: .75; }

.theme-btn {
  width: 34px; height: 34px; border: 1px solid var(--line); background: transparent;
  color: var(--gold); cursor: pointer; font-size: 16px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.theme-btn:hover { border-color: var(--gold); }
.theme-btn::before { content: "☀"; }
:root[data-theme="light"] .theme-btn::before { content: "☾"; }
.theme-btn-float { position: fixed; top: 14px; right: 14px; z-index: 5; }
body.has-update .theme-btn-float { top: calc(var(--ub, 46px) + 14px); }

/* ---------- 입문 화면 ---------- */
.screen { min-height: 100vh; }
#authScreen { display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-box {
  width: 100%; max-width: 400px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  outline: 1px solid var(--line-soft); outline-offset: 5px;
  padding: 36px 28px 28px;
  text-align: center;
}
.auth-seal {
  width: 64px; height: 64px; margin: 0 auto 12px;
  border: 2px solid var(--blood-hi); color: var(--blood-hi);
  font-family: var(--font-title); font-size: 22px; line-height: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transform: rotate(-4deg);
  background: rgba(142,36,32,.08);
}
.auth-title { font-family: var(--font-title); font-size: 40px; margin: 0; letter-spacing: .25em; font-weight: 400; }
.auth-sub { margin: 2px 0 14px; color: var(--dim); font-size: 13px; letter-spacing: .1em; }
.auth-lore { color: var(--text-story); font-size: 14px; margin: 0 0 20px; }
.auth-tabs { display: flex; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.auth-tab {
  flex: 1; background: none; border: none; color: var(--dim);
  padding: 8px; cursor: pointer; font-size: 15px; letter-spacing: .2em;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.auth-tab.active { color: var(--text); border-bottom-color: var(--blood-hi); }
#authForm { display: flex; flex-direction: column; gap: 10px; text-align: left; }
#authForm label { font-size: 13px; color: var(--dim); display: flex; flex-direction: column; gap: 4px; }
input, select, textarea {
  background: var(--input-bg); border: 1px solid var(--line); color: var(--text);
  padding: 9px 11px; font-family: inherit; font-size: 15px; outline: none; border-radius: 0;
}
input:focus, select:focus { border-color: var(--gold); }
#authForm .btn-main { margin-top: 6px; padding: 11px; font-size: 15px; letter-spacing: .3em; }
.auth-msg { min-height: 1.4em; color: var(--blood-hi); font-size: 13px; margin: 10px 0 0; }
.auth-msg.ok { color: var(--jade); }
.auth-divider { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 12px; margin: 10px 0 12px; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
#localBtn { width: 100%; }
.auth-note { color: var(--faint); font-size: 12px; margin: 8px 0 0; }

/* ---------- 상단 바 ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  backdrop-filter: blur(4px);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-seal {
  width: 30px; height: 30px; border: 1.5px solid var(--blood-hi); color: var(--blood-hi);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-title); font-size: 17px; transform: rotate(-4deg);
}
.brand-name { font-family: var(--font-title); font-size: 20px; letter-spacing: .2em; }
.stats { display: flex; align-items: center; gap: 18px; flex: 1; flex-wrap: wrap; }
.stat-name { font-weight: 700; color: var(--gold); letter-spacing: .05em; }
.stat { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.stat-label { color: var(--dim); font-size: 12px; letter-spacing: .1em; }
.stat-num { font-size: 13px; min-width: 56px; }
.bar { width: 90px; height: 7px; background: var(--input-bg); border: 1px solid var(--line); }
.bar-fill { height: 100%; transition: width .3s; }
.bar-fill.hp { background: linear-gradient(90deg, var(--hp-dark), var(--hp)); }
.bar-fill.ap { background: linear-gradient(90deg, var(--ap-dark), var(--ap)); }
.top-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }


/* ============================================================
   화면 배치
   넓은 화면: [지도+지금 있는 곳] [행낭·공방·임무·교환·전공록] [전도+행적]
   → 한 화면에 모두 들어오고, 페이지는 스크롤되지 않는다 (넘치는 칸만 안에서 스크롤)
   좁은 화면·휴대폰: 위에서 아래로 쌓인다
   ============================================================ */
:root { --mapsize: min(560px, calc(100vw - 46px)); --side-w: 320px; }
.layout { display: flex; flex-direction: column; gap: 12px; padding: 12px; max-width: 900px; margin: 0 auto; }
.map-col, .center-col, .side-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; min-height: 0; }
.center-col { gap: 0; }
.minimap-panel { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px; }

@media (min-width: 1100px) {
  /* 지도 크기: 화면 높이에 맞춰 자동 (지형 정보 칸 자리 270px 남김) */
  :root { --mapsize: max(230px, min(440px, calc(100vh - 380px))); --side-w: clamp(260px, 21vw, 340px); }
  body:has(#gameScreen:not(.hidden)) { overflow: hidden; }
  #gameScreen:not(.hidden) { height: 100vh; display: flex; flex-direction: column; }
  body.has-update #gameScreen:not(.hidden) { height: calc(100vh - var(--ub, 46px)); }
  .layout {
    flex: 1; min-height: 0; max-width: 1760px; width: 100%;
    display: grid; grid-template-columns: calc(var(--mapsize) + 22px) minmax(0, 1fr) var(--side-w);
    gap: 12px; padding: 12px 16px; align-items: stretch;
  }
  .map-col #tilePanel { flex: 1; min-height: 0; overflow-y: auto; }
  .center-col .tab-panel { flex: 1; min-height: 0; overflow-y: auto; }
  .side-col .log-panel { flex: 1; min-height: 0; }
  .side-col .log { max-height: none; min-height: 0; }
  .layout .map-frame { margin: 0; outline: none; flex-shrink: 0; }
  body:has(.topbar .chips) .layout { padding-top: 10px; }
}
@media (min-width: 1100px) and (max-width: 1440px) {
  :root { --mapsize: max(220px, min(400px, calc(100vh - 430px))); }
}

.panel {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  padding: 16px;
}
.panel-title {
  font-family: var(--font-body); font-weight: 500; font-size: 17px; letter-spacing: .15em;
  margin: 0 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line-soft);
}
.panel-title small { color: var(--faint); font-size: 12px; margin-left: 4px; }
.side-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.minimap-panel { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px; }

/* ---------- 지도 ---------- */
.map-frame {
  border: 1px solid var(--line); outline: 1px solid var(--line-soft); outline-offset: 4px;
  padding: 10px; background: var(--map-bg);
  width: calc(var(--mapsize) + 22px); margin: 0 auto;
}
.map { display: grid; grid-template-columns: repeat(9, 1fr); gap: 3px; }
.tile {
  aspect-ratio: 1; position: relative;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-title); font-size: calc(var(--mapsize) / 13);
  border: 1px solid rgba(128,128,128,.08);
  user-select: none; transition: filter .15s, transform .1s;
}
.tile.fog { background: var(--fog-bg); color: var(--fog-fg); }
.tile.fog::after { content: "霧"; font-size: .75em; }
.tile.fog.rumor::after { content: "塔"; color: var(--blood); opacity: .55; font-size: .85em; }
.tile.near { cursor: pointer; }
.tile.near::before {
  content: ""; position: absolute; inset: 0;
  border: 1px dashed var(--gold); opacity: .6;
  pointer-events: none;
}
.tile.near:hover { filter: brightness(1.15); transform: scale(1.04); z-index: 2; }
.tile.fog.near { color: var(--dim); }
.tile.fog.near::after { content: "？"; }
.tile.here {
  outline: 2px solid var(--blood-hi); outline-offset: -2px;
  box-shadow: 0 0 14px rgba(196,56,47,.55), inset 0 0 12px rgba(196,56,47,.3);
  z-index: 3;
}
.tile.here::after {
  content: ""; position: absolute; bottom: 3px; left: 50%; transform: translateX(-50%);
  width: 6px; height: 6px; background: var(--blood-hi); border-radius: 50%;
}
.t-C { background: var(--tC-bg); color: var(--tC-fg); }
.t-E { background: var(--tE-bg); color: var(--tE-fg); }
.t-F { background: var(--tF-bg); color: var(--tF-fg); }
.t-R { background: var(--tR-bg); color: var(--tR-fg); }
.t-M { background: var(--tM-bg); color: var(--tM-fg); }
.t-P { background: var(--tP-bg); color: var(--tP-fg); }
.t-W { background: var(--tW-bg); color: var(--tW-fg); }
.t-T { background: var(--tT-bg); color: var(--tT-fg); }
.t-B { background: var(--tB-bg); color: var(--tB-fg); }
.t-O { background: var(--tO-bg); color: var(--tO-fg); }
.t-V { background: var(--tV-bg); color: var(--tV-fg); }
.t-K { background: var(--tK-bg); color: var(--tK-fg); }
.t-Q, .t-Z { background: var(--tQ-bg); color: var(--tQ-fg); outline: 1.5px dashed var(--tQ-fg); outline-offset: -5px; }
.t-Z { background: var(--tZ-bg); color: var(--tZ-fg); outline-color: var(--tZ-fg); }
.t-Qo { background: var(--tQo-bg); color: var(--tQo-fg); box-shadow: inset 0 0 0 2px var(--tQo-fg); }
.t-Zo { background: var(--tZo-bg); color: var(--tZo-fg); box-shadow: inset 0 0 0 2px var(--tZo-fg); }
.mm.t-Q, .mm.t-Z { outline: none; background: var(--tQ-fg); }
.mm.t-Qo, .mm.t-Zo { box-shadow: none; background: var(--tQo-fg); }
.t-X { background: var(--tX-bg); color: var(--tX-fg); text-shadow: 0 0 10px rgba(255,60,40,.8); }
.tile.t-X { animation: towerPulse 3s ease-in-out infinite; }
@keyframes towerPulse { 50% { box-shadow: inset 0 0 18px rgba(196,56,47,.55); } }
.map-hint { text-align: center; color: var(--faint); font-size: 12px; margin: 8px 0 0; }

/* 전도(미니맵) */
.minimap-label { font-size: 13px; color: var(--dim); letter-spacing: .1em; }
.minimap-label small { color: var(--faint); }
.minimap-label span { margin-left: 6px; letter-spacing: 0; }
.minimap { display: grid; gap: 1px; padding: 4px; background: var(--map-bg); border: 1px solid var(--line); }
.mm { width: 8px; height: 8px; }
.mm.view { outline: 1px solid var(--gold); outline-offset: -1px; }
.mm.fog { background: var(--fog-bg); }
.mm.here { background: var(--blood-hi) !important; box-shadow: 0 0 4px var(--blood-hi); }
.mm.rumor { background: var(--blood); opacity: .7; }
.minimap-legend { display: flex; gap: 12px; font-size: 11.5px; color: var(--faint); flex-wrap: wrap; justify-content: center; }
.lg { display: inline-block; width: 8px; height: 8px; margin-right: 4px; vertical-align: middle; }
.lg-here { background: var(--blood-hi); }
.lg-view { outline: 1px solid var(--gold); outline-offset: -1px; }
.lg-camp { background: var(--tC-fg); }
.lg-tower { background: var(--blood); opacity: .7; }

/* ---------- 지형 정보 ---------- */
.tile-head { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.tile-seal {
  width: 46px; height: 46px; flex-shrink: 0;
  border: 1.5px solid currentColor; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-title); font-size: 26px;
}
.tile-name { font-family: var(--font-body); font-weight: 500; font-size: 20px; letter-spacing: .12em; }
.danger { font-size: 12px; color: var(--dim); }
.danger b { color: var(--blood-hi); font-weight: 400; letter-spacing: 2px; }
.tile-desc { color: var(--text-desc); font-size: 14px; margin: 6px 0 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn { flex: 1 1 auto; }
.buff-line { margin-top: 10px; font-size: 13px; color: var(--jade); }

/* ---------- 행적(로그) ---------- */
.log-panel { display: flex; flex-direction: column; min-height: 200px; }
.log { flex: 1; overflow-y: auto; max-height: 300px; padding-right: 6px; font-size: 13px; }
.log p { margin: 0 0 7px; padding-left: 10px; border-left: 2px solid transparent; animation: inkIn .35s ease-out; }
@keyframes inkIn { from { opacity: 0; filter: blur(2px); } to { opacity: 1; filter: none; } }
.log .story { color: var(--text-story); border-left-color: var(--line); }
.log .gain { color: var(--gold); }
.log .bad { color: var(--blood-hi); }
.log .sys { color: var(--faint); font-size: 13px; }
.log .quest { color: var(--jade); }
.log .lvl { color: var(--lvl); border-left-color: var(--gold); }
.log::-webkit-scrollbar, .battle-log::-webkit-scrollbar { width: 6px; }
.log::-webkit-scrollbar-thumb, .battle-log::-webkit-scrollbar-thumb { background: var(--line); }

/* ---------- 하단 탭 ---------- */
.tabs { display: flex; }
.tab {
  flex: 1; background: var(--panel); border: 1px solid var(--line); border-bottom: none;
  color: var(--dim); padding: 10px 6px; cursor: pointer; font-size: 15px; letter-spacing: .1em;
  position: relative;
}
.tab + .tab { border-left: none; }
.tab small { font-size: 11px; color: var(--faint); }
.tab.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 2px 0 var(--blood-hi); }
.tab-dot { position: absolute; top: 8px; right: 10px; width: 7px; height: 7px; border-radius: 50%; background: var(--blood-hi); }
.tab-panel { border-top: none; min-height: 200px; }

.grid-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.card {
  border: 1px solid var(--line-soft); background: var(--card-bg); padding: 10px 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.card-name { font-weight: 700; }
.card-name.rare { color: var(--gold); }
.card-count { color: var(--dim); font-size: 13px; }
.card-desc { color: var(--dim); font-size: 12.5px; }
.card-eff { color: var(--jade); font-size: 12.5px; }
.card .btn { align-self: flex-start; margin-top: 4px; }
.section-label { color: var(--dim); font-size: 13px; letter-spacing: .15em; margin: 16px 0 8px; }
.section-label:first-child { margin-top: 0; }
.equip-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.empty { color: var(--faint); font-size: 14px; padding: 6px 0; }
.stat-sheet { display: flex; gap: 16px; flex-wrap: wrap; font-size: 14px; color: var(--dim); margin-bottom: 4px; }
.stat-sheet b { color: var(--text); font-weight: 500; }

.need { font-size: 13px; }
.need .ok { color: var(--text); }
.need .no { color: var(--blood-hi); }
.notice { border: 1px dashed var(--line); padding: 10px 12px; color: var(--dim); font-size: 14px; margin-bottom: 12px; }

/* ---------- 임무 ---------- */
.quest-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.quest { border: 1px solid var(--line-soft); background: var(--card-bg); padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.quest.done { border-color: var(--gold); }
.quest.claimed { opacity: .55; }
.quest-title { font-weight: 700; }
.quest-sub { font-size: 13px; color: var(--dim); }
.quest-bar { height: 6px; background: var(--input-bg); border: 1px solid var(--line); }
.quest-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--ap-dark), var(--gold)); transition: width .3s; }
.quest-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; }
.quest-foot .btn, .commune-row .btn { white-space: nowrap; flex-shrink: 0; }
.quest-reward { color: var(--jade); font-size: 12.5px; }
.commune { border: 1px solid var(--blood); background: var(--card-bg); padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.commune-title { font-weight: 700; font-size: 16px; color: var(--blood-hi); letter-spacing: .05em; }
.commune .quest-bar { height: 9px; }
.commune-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.commune-row input { width: 80px; padding: 5px 8px; font-size: 14px; }

.mission-list { display: flex; flex-direction: column; gap: 10px; }
.commune.done { border-color: var(--gold); }
.commune.claimed { opacity: .6; }

/* ---------- 교환 ---------- */
.trade-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 18px; }
.trade-form { display: flex; flex-direction: column; gap: 10px; }
.trade-form label { font-size: 13px; color: var(--dim); display: flex; flex-direction: column; gap: 4px; }
.trade-row { display: grid; grid-template-columns: 1fr 90px; gap: 8px; }
.gift-list { display: flex; flex-direction: column; gap: 6px; }
.gift { border-left: 2px solid var(--gold); padding: 4px 10px; font-size: 13.5px; }
.gift .who { color: var(--gold); font-weight: 500; }
.gift .when { color: var(--faint); font-size: 12px; margin-left: 6px; }
.gift .note { color: var(--text-story); display: block; }

/* ---------- 전공록 ---------- */
.rank-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.rank-table th { color: var(--dim); font-weight: 400; text-align: left; border-bottom: 1px solid var(--line); padding: 6px 8px; font-size: 13px; }
.rank-table td { border-bottom: 1px solid var(--line-soft); padding: 7px 8px; }
.rank-table tr.me td { color: var(--gold); font-weight: 500; }
.rank-num { width: 48px; white-space: nowrap; }
.rank-table th { white-space: nowrap; }

/* ---------- 토벌 창 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: var(--overlay); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-box {
  width: 100%; max-width: 640px; max-height: calc(100vh - 32px); overflow-y: auto;
  background: linear-gradient(180deg, var(--modal-1), var(--modal-2));
  border: 1px solid var(--blood); outline: 1px solid var(--line-soft); outline-offset: 5px;
  padding: 20px; box-shadow: 0 10px 40px var(--shadow);
}
.battle-title { font-family: var(--font-body); font-weight: 500; text-align: center; margin: 0 0 14px; letter-spacing: .2em; }
.battle-sides { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; margin-bottom: 12px; }
.versus { font-family: var(--font-title); font-size: 26px; color: var(--blood-hi); }
.side-units { display: flex; flex-direction: column; gap: 6px; }
.unit { font-size: 13px; }
.unit.dead { opacity: .35; text-decoration: line-through; }
.unit .bar { width: 100%; height: 6px; margin-top: 2px; }
.unit .bar-fill { background: var(--hp); }
#battleEnemies .bar-fill { background: var(--enemy-bar); }
.battle-log { height: 240px; overflow-y: auto; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 10px 4px; font-size: 14px; }
.battle-log p { margin: 0 0 5px; animation: inkIn .25s ease-out; }
.battle-log .a { color: var(--text); }
.battle-log .e { color: var(--enemy-text); }
.battle-log .crit { color: var(--crit); }
.battle-log .miss { color: var(--faint); }
.battle-log .end { color: var(--gold); text-align: center; margin-top: 8px; letter-spacing: .1em; }
.battle-log .end.lose { color: var(--blood-hi); }
.battle-log .loot { color: var(--jade); }
.battle-foot { display: flex; justify-content: space-between; margin-top: 12px; gap: 8px; }

/* ---------- 새 버전 알림 띠 ---------- */
.update-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 90;
  min-height: 46px; padding: 8px 48px 8px 16px;
  display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap;
  background: linear-gradient(90deg, #16305a, #23477e 50%, #16305a);
  color: #f4e6d2;
  border-bottom: 1px solid #5d8fd6;
  box-shadow: 0 4px 18px var(--shadow);
  font-size: 14px; text-align: center;
  animation: barIn .4s ease-out;
}
@keyframes barIn { from { transform: translateY(-100%); } to { transform: none; } }
.update-text b { color: #f1d69b; font-weight: 700; margin-right: 4px; }
.update-close {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: #c9b7a0; font-size: 22px; cursor: pointer; padding: 4px 8px;
}
.update-close:hover { color: #fff; }
body.has-update { padding-top: var(--ub, 46px); }
body.has-update .topbar { top: var(--ub, 46px); }

/* ---------- 알림 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: var(--modal-1); border: 1px solid var(--gold); color: var(--text);
  padding: 9px 18px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; z-index: 80; max-width: calc(100% - 32px); text-align: center;
  box-shadow: 0 6px 20px var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }


/* ---------- 상단 바: 두상 · 이름 · 능력치 칩 ---------- */
.topbar { gap: 14px; padding: 8px 20px; flex-wrap: nowrap; }
.who {
  display: flex; align-items: center; gap: 10px; background: none; border: 1px solid transparent;
  color: var(--text); cursor: pointer; padding: 4px 10px 4px 4px; text-align: left; min-width: 0;
}
.who:hover { border-color: var(--line); background: var(--panel-2); }
.who-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.who-name { display: flex; align-items: center; gap: 4px; font-size: 16px; }
.who-name b { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.caret { color: var(--dim); font-size: 11px; }
.who-sub { font-size: 12px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }

.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  border-radius: 50%; overflow: hidden; background: var(--panel-2);
  border: 1.5px solid var(--gold); color: var(--gold);
  font-family: var(--font-title);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-sm { width: 30px; height: 30px; font-size: 14px; border-width: 1px; }
.avatar-md { width: 44px; height: 44px; font-size: 20px; }
.avatar-lg { width: 112px; height: 112px; font-size: 46px; border-width: 2px; }

.chips { display: flex; gap: 6px; flex: 1; justify-content: flex-end; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px;
  background: var(--panel-2); border: 1px solid var(--line-soft); font-size: 13px; white-space: nowrap;
}
.chip b { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.chip-lb { color: var(--dim); font-size: 12px; }
.chip-ic {
  width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-title); font-size: 13px; color: var(--dim);
  border: 1px solid var(--line); border-radius: 50%;
}
.chip-ic.ic-hp { color: var(--hp); border-color: var(--hp); }
.chip-ic.ic-ap { color: var(--ap); border-color: var(--ap); }
.chip-ic.ic-gold { color: var(--gold); border-color: var(--gold); }
.chip .bar { width: 64px; height: 6px; display: inline-block; }
.chip .bar-fill { display: block; }
.icon-btn {
  width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text); cursor: pointer; font-size: 16px;
}
.icon-btn:hover { border-color: var(--gold); color: var(--gold); }

/* ---------- 우편함 ---------- */
.icon-btn { position: relative; }
.badge {
  position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--seal); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}
.mail-box { max-width: 560px; border-color: var(--line); }
.mail-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.mail {
  border: 1px solid var(--line-soft); background: var(--card-bg); padding: 12px 14px;
  border-left: 3px solid var(--btn-main-1); display: flex; flex-direction: column; gap: 6px;
}
.mail-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.mail-title { font-weight: 700; }
.mail-meta { color: var(--faint); font-size: 12px; white-space: nowrap; }
.mail-body { color: var(--text-story); font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.mail-items { color: var(--jade); font-size: 13px; }
.mail-foot { display: flex; justify-content: flex-end; }
.mail.old { border-left-color: var(--line); opacity: .7; }

/* ---------- 내 정보(프로필) 창 ---------- */
.profile-box { max-width: 560px; border-color: var(--line); }
.pf-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.pf-title { margin: 0; font-size: 22px; font-weight: 700; }
.pf-sub { color: var(--dim); font-size: 13px; margin-top: 2px; }
.pf-tabs { display: flex; gap: 4px; margin: 14px 0 16px; border-bottom: 1px solid var(--line); }
.pf-tab {
  background: none; border: none; color: var(--dim); padding: 8px 14px; cursor: pointer; font-size: 14px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.pf-tab.active { color: var(--btn-main-text); background: var(--btn-main-1); border-bottom-color: var(--blood-hi); }

.pf-card { display: flex; gap: 18px; align-items: center; padding: 16px; border: 1px solid var(--line-soft); background: var(--card-bg); }
.pf-card-main { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.pf-card-name { font-size: 20px; font-weight: 700; }
.pf-card-sub { color: var(--dim); font-size: 13px; }
.pf-card-intro { color: var(--text-story); font-size: 14px; margin-top: 4px; white-space: pre-wrap; word-break: break-word; }
.pf-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px; }
.pf-stat { border: 1px solid var(--line-soft); background: var(--card-bg); padding: 8px 10px; text-align: center; }
.pf-stat span { display: block; color: var(--dim); font-size: 12px; }
.pf-stat b { font-size: 16px; }
.pf-credit { color: var(--faint); font-size: 12px; margin-top: 10px; }

.pf-row { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 16px; }
.pf-row-body { display: flex; flex-direction: column; gap: 8px; min-width: 0; flex: 1; }
.pf-help { color: var(--dim); font-size: 12.5px; line-height: 1.55; }
.pf-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 13px; color: var(--dim); }
.pf-field small { color: var(--faint); }
.pf-field input, .pf-field textarea { width: 100%; font-size: 14px; resize: vertical; }
.pf-inline { display: flex; gap: 8px; align-items: center; }
.pf-inline input { flex: 1; min-width: 0; }
.pf-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.cropper { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px; border: 1px dashed var(--line); margin-bottom: 16px; }
.crop-stage {
  width: 240px; height: 240px; border-radius: 50%; overflow: hidden; position: relative;
  background: repeating-conic-gradient(var(--line-soft) 0 25%, transparent 0 50%) 0 0 / 16px 16px;
  cursor: grab; touch-action: none; box-shadow: 0 0 0 2px var(--gold);
}
.crop-stage:active { cursor: grabbing; }
.crop-stage canvas { width: 240px; height: 240px; display: block; }
.crop-zoom { display: flex; align-items: center; gap: 8px; width: 240px; font-size: 13px; color: var(--dim); }
.crop-zoom input { flex: 1; padding: 0; accent-color: var(--blood-hi); }

/* 전공록 두상 */
.rank-table tr.clickable { cursor: pointer; }
.rank-table tr.clickable:hover td { background: var(--card-bg); }
.rank-who { display: flex; align-items: center; gap: 8px; }
.rank-aff { color: var(--faint); font-size: 12px; }

@media (max-width: 1440px) {
  .topbar { flex-wrap: wrap; }
  .chips { order: 3; flex-basis: 100%; justify-content: flex-start; }
}
@media (max-width: 600px) {
  .topbar { padding: 8px 12px; gap: 8px; }
  .brand { display: none; }
  .chip { height: 30px; padding: 0 7px; gap: 4px; }
  .chip-lb { display: none; }
  .chip .bar { width: 40px; }
  .pf-stats { grid-template-columns: repeat(2, 1fr); }
  .pf-row { flex-direction: column; align-items: center; }
}


/* ============================================================
   풍운집결 장식: 찢긴 종이 산수, 붉은 해, 한지 결
   ============================================================ */
.decor { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; opacity: var(--decor-opacity); }
.screen, .tabs, .tab-panel, .layout { position: relative; z-index: 1; }
.d-tear { position: absolute; }
.d-l1 { left: -40px; top: -20px; width: 300px; height: 110vh; background: var(--tear-2);
  clip-path: polygon(0 0,100% 0,80% 7%,94% 16%,66% 27%,86% 38%,58% 51%,78% 63%,52% 75%,70% 87%,46% 100%,0 100%); }
.d-l2 { left: -40px; top: 18vh; width: 210px; height: 90vh; background: var(--tear-1);
  clip-path: polygon(0 0,66% 5%,100% 18%,62% 32%,88% 47%,56% 62%,82% 78%,38% 100%,0 100%); }
.d-l3 { left: 120px; bottom: -30px; width: 160px; height: 38vh; background: var(--tear-3);
  clip-path: polygon(20% 0,60% 12%,48% 30%,82% 46%,64% 64%,100% 100%,0 100%,10% 60%,0 30%); opacity: .8; }
.d-r1 { right: -40px; top: 34vh; width: 260px; height: 80vh; background: var(--tear-3);
  clip-path: polygon(40% 0,100% 0,100% 100%,0 100%,28% 86%,6% 72%,34% 54%,12% 36%,42% 18%); }
.d-r2 { right: -40px; top: 52vh; width: 180px; height: 60vh; background: var(--tear-4);
  clip-path: polygon(60% 0,100% 0,100% 100%,0 100%,18% 78%,4% 58%,32% 38%,20% 18%); }
.d-r3 { right: -20px; top: -20px; width: 110px; height: 22vh; background: var(--tear-2);
  clip-path: polygon(0 0,100% 0,90% 30%,100% 60%,70% 100%,50% 70%,20% 90%,30% 50%); opacity: .7; }
.d-sun { position: absolute; z-index: 1; right: 3.5vw; top: 13vh; width: 140px; height: 140px; border-radius: 50%; background: var(--sun); opacity: .9; }
.d-moon { position: absolute; z-index: 1; right: 2vw; top: 8vh; width: 26px; height: 26px; border-radius: 50%; box-shadow: -7px 5px 0 0 #c9a356; }
.d-grain { position: absolute; inset: 0; background-image: radial-gradient(var(--grain) 1px, transparent 1.2px); background-size: 4px 4px; }
.d-tear { filter: drop-shadow(1px 0 0 rgba(255,255,255,.18)); }

/* 한지 결: hanji.png를 모든 화면 위에 "곱하기"로 겹친다 (색은 그대로, 섬유 결만 보임) */
.paper {
  position: fixed; inset: 0; z-index: 100; pointer-events: none;
  background: url("hanji.png") repeat; background-size: 540px 360px;
  mix-blend-mode: multiply; opacity: .45;   /* 결이 너무 진하면 숫자를 낮추세요 (0~1) */
}
:root[data-theme="dark"] .paper { filter: invert(1); mix-blend-mode: screen; opacity: .22; }

/* 패널에 한지 결 */
.panel, .auth-box, .modal-box, .tab {
  background-image: radial-gradient(var(--grain) 1px, transparent 1.2px), linear-gradient(180deg, var(--panel-2), var(--panel));
  background-size: 4px 4px, auto;
}
.tab.active { background-image: radial-gradient(var(--grain) 1px, transparent 1.2px); background-size: 4px 4px; }

/* 상단 바 낙관 */
.brand-seal {
  width: 38px; height: 38px; border: 2px solid var(--seal); color: var(--seal); background: rgba(200,57,47,.06);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-family: var(--font-title); font-size: 11px; line-height: 1; letter-spacing: 1px; transform: rotate(-5deg);
}

/* 입문 화면 */
#authScreen { gap: 40px; }
.auth-wrap { display: flex; align-items: center; gap: 48px; }
.auth-title-block { position: relative; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.auth-hanja { font-family: var(--font-title); font-size: 76px; line-height: 1.1; letter-spacing: .05em; color: var(--text); text-align: center; text-shadow: 0 2px 0 rgba(0,0,0,.08); }
.auth-hangul { font-family: var(--font-brush); font-size: 40px; color: var(--gold); line-height: 1; }
.auth-stamp {
  position: absolute; right: -26px; top: 46%; width: 46px; height: 46px; border: 2px solid var(--seal); color: var(--seal);
  font-family: var(--font-title); font-size: 13px; line-height: 1.05; display: flex; flex-direction: column; align-items: center; justify-content: center;
  transform: rotate(-8deg); background: rgba(200,57,47,.05);
}
.auth-box { border-top: 3px solid var(--btn-main-1); }
.auth-title { font-family: var(--font-title); }
@media (max-width: 860px) {
  .auth-wrap { flex-direction: column; gap: 18px; }
  .auth-hanja { font-size: 52px; }
  .auth-hangul { font-size: 30px; }
  .auth-stamp { right: -40px; }
  .d-l1, .d-r1 { width: 140px; } .d-l2, .d-r2 { width: 100px; } .d-l3, .d-r3 { display: none; }
  .d-sun { width: 80px; height: 80px; right: 4vw; top: 4vh; opacity: .55; }
  .decor { opacity: calc(var(--decor-opacity) * .5); }
}


/* ============================================================
   촘촘하게: 글씨와 여백을 줄여 한 화면에 담는다
   ============================================================ */
.panel { padding: 12px; }
.panel-title { font-size: 15px; margin-bottom: 8px; }
.tile-head { margin-bottom: 4px; gap: 10px; }
.tile-seal { width: 38px; height: 38px; font-size: 21px; }
.tile-name { font-size: 17px; }
.tile-desc { font-size: 13px; line-height: 1.55; margin: 4px 0 8px; }
.actions { gap: 6px; }
.actions .btn { padding: 6px 10px; font-size: 13px; }
.buff-line { margin-top: 6px; font-size: 12px; }
.map-frame { padding: 8px; }
.map-hint { font-size: 11px; margin-top: 6px; }
.minimap-label { font-size: 12px; }
.minimap-legend { gap: 8px; font-size: 11px; }
.mm { width: 7px; height: 7px; }
.log p { margin-bottom: 5px; }

.tab { padding: 8px 4px; font-size: 14px; }
.tab small { font-size: 10px; }
.tab-panel { padding: 12px 14px; font-size: 13px; }
.section-label { font-size: 12px; margin: 12px 0 6px; }
.grid-list { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 6px; }
.card { padding: 7px 9px; gap: 2px; }
.card-name { font-size: 13px; }
.card-count { font-size: 12px; }
.card-desc, .card-eff, .need { font-size: 11.5px; line-height: 1.45; }
.card .btn { margin-top: 3px; }
.equip-row { gap: 6px; }
.empty { font-size: 12.5px; padding: 3px 0; }
.notice { font-size: 12.5px; padding: 7px 10px; margin-bottom: 8px; }
.quest-grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 6px; }
.quest, .commune { padding: 8px 10px; gap: 4px; }
.quest-title { font-size: 13.5px; }
.commune-title { font-size: 14px; }
.quest-sub, .quest-foot, .quest-reward { font-size: 11.5px; }
.mission-list { gap: 6px; }
.trade-grid { gap: 14px; }
.trade-form { gap: 7px; }
.trade-form label { font-size: 12px; }
.trade-form input, .trade-form select { padding: 6px 9px; font-size: 13px; }
.gift { font-size: 12.5px; }
.rank-table { font-size: 13px; }
.rank-table td { padding: 5px 8px; }
.btn-small { padding: 4px 9px; font-size: 12px; }

/* ---------- 모바일 ---------- */
@media (max-width: 900px) {
  :root { --mapsize: min(calc(100vw - 24px - 22px), 560px); }
  .topbar { padding: 8px 12px; gap: 8px; }
  .stats { gap: 10px; }
  .bar { width: 64px; }
  .tabs { padding: 0 12px; margin-top: 14px; }
  .tab { font-size: 13.5px; letter-spacing: 0; padding: 10px 2px; }
  .tab small { display: none; }
  .tab-dot { top: 5px; right: 5px; }
  .tab-panel { width: calc(100% - 24px); }
  .trade-grid { grid-template-columns: 1fr; }
  .equip-row { grid-template-columns: 1fr; }
  .log { max-height: 240px; }
  .mm { width: 7px; height: 7px; }
}
