/* 마둑 프로토타입 — 아트는 이후 단계다. 도형과 숫자로만 만든다 (§11).
   단, 등급이 외형으로 구분되는 것과 이름이 한글로 보이는 것은 여기서도 지킨다. */

:root {
  --bg: #14161a;
  --panel: #1c2027;
  --panel-2: #232830;
  --line: #333a45;
  --ink: #e8eaee;
  --dim: #8d94a1;
  /* 판 위의 돌·판과 같은 색. board-view.js 의 COLORS 와 config 의 ui.board 를 따른다 */
  --stone-me: #0b0e13;
  --stone-opp: #f8fafc;
  --board-bg: #8d7658;
  --gold: #e5b567;
  --me: #eceff4;
  --hit: #6fd18a;
  --warn: #e2705f;
  --accent: #7aa2f7;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; cursor: pointer; }

#app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
  padding: 10px;
  max-width: 1180px;
  margin: 0 auto;
}

/* ───────────────────────────────────────── HUD
   이번 목표가 이 화면에서 가장 큰 글씨다. "이번에 뭘 해야 하는가"를 먼저 읽게 한다. */

#hud {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 10px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.goal { flex: 1; min-width: 0; }
.goal-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.stage-tag {
  display: inline-flex; align-items: baseline; gap: 5px; flex: none;
  padding: 3px 9px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line);
}
.stage-tag b { font-size: 14px; }
.stage-tag small { font-size: 10px; color: var(--dim); }
.goal-label { font-size: 12px; color: var(--dim); }
.goal-target { font-size: 30px; line-height: 1.05; font-variant-numeric: tabular-nums; color: var(--ink); }
.goal-unit { font-size: 14px; color: var(--dim); }
.goal-foot {
  display: flex; align-items: baseline; gap: 8px; margin-top: 4px;
  font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums;
}

.bar { height: 7px; margin-top: 6px; background: #2b313a; border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .28s ease; }
.bar.done i { background: var(--hit); }

.hud-right { display: flex; gap: 8px; }
.stat {
  min-width: 58px; padding: 5px 8px; text-align: center;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
}
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat small { font-size: 9px; color: var(--dim); }
.stat.gold b { color: var(--gold); }
.stat.streak.on { border-color: var(--hit); }
.stat.streak.on b { color: var(--hit); }

/* 남은 수 — 지고 나서 "왜 진 거지?"가 나오지 않게 크게 보여준다.
   여유(기본) → 조심(4 이하) → 위험(2 이하) 세 단계로 색이 바뀐다. */
.stat.moves { min-width: 78px; }
.stat.moves b { font-size: 24px; }
.stat.moves.warn { border-color: var(--gold); }
.stat.moves.warn b { color: var(--gold); }
.stat.moves.danger { border-color: var(--warn); }
.stat.moves.danger b { color: var(--warn); }

/* 목표까지 남은 점수 — 진행바만으로는 "얼마나 모자란지"가 안 읽힌다 */
.remain { margin-left: auto; font-variant-numeric: tabular-nums; }
.remain.warn { color: var(--gold); }
.remain.danger { color: var(--warn); font-weight: 700; }
.remain.done { color: var(--hit); font-weight: 700; }

/* ───────────────────────────────────────── 판 */

#table { display: grid; grid-template-columns: 1fr 300px; gap: 10px; min-height: 0; }

/* 판과 패는 한 열이다 — 패는 언제나 판 바로 아래에 붙어 있다 */
#playCol { display: flex; flex-direction: column; gap: 10px; min-height: 0; min-width: 0; }

#boardWrap {
  flex: 1 1 auto;            /* 판이 남은 세로를 다 쓴다 — 패는 그 아래에 붙는다 */
  position: relative; min-height: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
#board { display: block; touch-action: manipulation; }

#floaters { position: absolute; inset: 0; pointer-events: none; }

/* 판 위 알림 — 새 전장이 열릴 때, 마지막 수일 때 */
.banner {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  padding: 7px 16px; border-radius: 999px; pointer-events: none;
  background: rgba(20,22,26,.92); border: 1px solid var(--line);
  font-size: 13px; font-weight: 600; white-space: nowrap;
  animation: dropIn .25s ease-out;
}
.banner.hidden { display: none; }
.banner.danger { border-color: var(--warn); color: var(--warn); }
.banner.chapter { border-color: var(--accent); color: var(--accent); }
/* 투명도는 건드리지 않는다 — display:none 이었다가 나타나는 경우 애니메이션이
   끝 상태로 넘어가지 못해 계속 투명하게 남는 일이 생긴다. 이동만 준다. */
@keyframes dropIn {
  from { transform: translate(-50%, -10px); }
  to   { transform: translate(-50%, 0); }
}
.floater {
  position: absolute; transform: translate(-50%, -50%);
  font-weight: 800; font-variant-numeric: tabular-nums;
  color: var(--hit); text-shadow: 0 2px 10px rgba(0,0,0,.8);
  animation: rise 1s ease-out forwards; white-space: nowrap;
}
.floater.loss { color: var(--warn); }

/* 능력의 대상을 고르는 동안 판 아래에 붙는다 (D-6).
   판 위 알림(banner)은 위쪽이므로 겹치지 않는다. */
.target-bar {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  padding: 7px 9px 7px 15px; border-radius: 999px; max-width: calc(100% - 20px);
  background: rgba(20,22,26,.94); border: 1px solid var(--accent);
  font-size: 13px; font-weight: 600; color: var(--accent);
  animation: dropIn .2s ease-out;
}
.target-bar.hidden { display: none; }
.target-bar span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.target-bar button {
  flex: none; padding: 4px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; color: var(--dim);
  background: transparent; border: 1px solid var(--line);
}
.target-bar button:hover { color: var(--ink); border-color: var(--dim); }
@keyframes rise {
  0%   { opacity: 0; transform: translate(-50%,-50%) scale(.7); }
  18%  { opacity: 1; transform: translate(-50%,-90%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%,-220%) scale(1); }
}

/* ───────────────────────────────────────── 옆 패널 */

#side {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 0;
}
#side h3 { margin: 0; font-size: 12px; letter-spacing: .04em; color: var(--dim); font-weight: 600; }
#side h3 small { font-weight: 400; opacity: .7; margin-left: 4px; }

.traits { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.traits li {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; min-height: 40px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  cursor: grab; user-select: none;
}
.traits li.empty { border-style: dashed; opacity: .45; cursor: default; }
.traits li.dragging { opacity: .4; }
.traits li.over { border-color: var(--accent); }
.traits li.mul { border-color: #6a5a3a; background: #262117; }
.traits .slot-no { font-size: 10px; color: var(--dim); width: 12px; flex: none; }
.traits .t-name { font-weight: 700; font-size: 13px; flex: none; }
.traits .t-desc { font-size: 10px; color: var(--dim); line-height: 1.3; }
.traits .t-stack { margin-left: auto; font-size: 10px; color: var(--hit); flex: none; }
/* 눌러서 자세히 볼 수 있다는 표시 — 손가락에는 title 속성이 보이지 않는다 */
.traits .t-more {
  margin-left: auto; flex: none; align-self: flex-start;
  font-size: 9px; color: var(--dim); border: 1px solid var(--line);
  border-radius: 999px; padding: 2px 6px; white-space: nowrap;
}
.traits li.clickable:hover .t-more { color: var(--accent); border-color: var(--accent); }
/* 상점에서 버릴 칸을 고를 때 */
.traits li.removable:hover { border-color: var(--warn); }
.traits li.removable .t-more { color: var(--warn); border-color: var(--warn); }
/* 상점 안의 특성 목록은 드래그 대상이 아니다 */
.sheet .traits li { cursor: pointer; }

.note { color: var(--dim); font-size: 11px; text-align: center; }

/* 등급 범례 — 판 위의 테두리 색이 무슨 뜻인지 늘 보이는 곳에 둔다 */
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.legend li { display: flex; align-items: center; gap: 7px; font-size: 11px; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.legend .g-name { font-weight: 700; }
.legend .g-loot { margin-left: auto; color: var(--dim); font-variant-numeric: tabular-nums; }

.side-foot { margin-top: auto; display: flex; align-items: center; gap: 8px; }
#deckInfo { flex: 1; min-width: 0; font-size: 10px; color: var(--dim); line-height: 1.5; }
button.ghost {
  flex: none; padding: 6px 12px; font-size: 11px;
  background: transparent; border: 1px solid var(--line); border-radius: 6px; color: var(--dim);
}
button.ghost:hover { color: var(--ink); border-color: var(--dim); }

/* ───────────────────────────────────────── 손에 있는 패
   판 바로 아래. 기본으로 골라진 패는 없다 — 골라야만 판이 눌린다. */

#handBar {
  flex: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px;
}
#handBar.shake { animation: shake .32s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.hand-head {
  display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px;
  font-size: 12px; color: var(--dim); font-weight: 600; letter-spacing: .03em;
}

/* 편 범례 — "검은 돌이 나"를 말해주는 곳. 이게 없으면 첫 수에서 알 방법이 없다.
   범례를 **판과 같은 바닥색** 위에 올린다. 어두운 패널에 올리면 검은 돌 표시가
   테두리만 보여 오히려 흰 돌처럼 읽힌다 — 판에서 보이는 그대로여야 한다. */
.sides {
  margin-left: auto; flex: none;
  display: flex; align-items: center; gap: 11px;
  padding: 3px 9px; border-radius: 999px;
  background: var(--board-bg);
}
.sides b { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; }
.sides i { width: 13px; height: 13px; border-radius: 50%; flex: none; }
.sides .me { color: #12151a; font-weight: 800; }
.sides .me i { background: var(--stone-me); box-shadow: 0 0 0 1px #000; }
.sides .opp { color: #3c434d; font-weight: 600; }
.sides .opp i { background: var(--stone-opp); box-shadow: 0 0 0 1px #98a1ae; }

.hand { display: flex; gap: 8px; }
.card {
  --g: var(--me);
  position: relative; flex: 1 1 0; min-width: 0;
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px 10px; text-align: left;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
.card:hover { transform: translateY(-3px); }
/* 고른 패 — 판 위 유령 돌의 점선과 같은 파랑으로 묶어준다 */
.card.sel {
  border-color: var(--accent); background: #1b2333;
  transform: translateY(-5px); box-shadow: 0 6px 18px rgba(0,0,0,.45);
}
/* 카드 위의 돌 — 판에 놓일 그 돌이다. 검은 돌이 내 돌이라는 걸 손에서 먼저 본다 */
.card .c-stone {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  background: var(--stone-me);
  box-shadow: 0 0 0 1px #000, 0 0 0 2px rgba(255,255,255,.14), 0 2px 5px rgba(0,0,0,.5);
  display: grid; place-items: center;
}
.card .c-stone.graded::after {
  content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--g);
}
.card .c-text { min-width: 0; }
.card .c-top { display: flex; align-items: baseline; gap: 6px; margin-bottom: 3px; }
.card .c-name { font-weight: 800; font-size: 15px; color: var(--g); }
.card .c-grade { font-size: 10px; font-weight: 700; color: var(--dim); }
.card .c-desc { display: block; font-size: 11px; color: var(--dim); line-height: 1.35; }

/* ───────────────────────────────────────── 오버레이 */

.overlay {
  position: fixed; inset: 0; background: rgba(10,12,15,.86);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 20;
  backdrop-filter: blur(3px);
}
.overlay.hidden { display: none; }
.sheet {
  width: min(680px, 100%); max-height: 88vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px;
}
.sheet h2 { margin: 0 0 4px; font-size: 22px; }
.sheet .sub { color: var(--dim); font-size: 12px; margin-bottom: 16px; }
.sheet h4 { margin: 18px 0 8px; font-size: 12px; color: var(--dim); font-weight: 600; letter-spacing: .04em; }

.ledger { width: 100%; border-collapse: collapse; font-size: 13px; }
.ledger td { padding: 6px 0; border-bottom: 1px solid var(--line); }
.ledger td:last-child { text-align: right; font-variant-numeric: tabular-nums; color: var(--gold); }
.ledger tr.total td { border-bottom: none; font-weight: 700; font-size: 15px; padding-top: 10px; }

.shelf { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; }
.buy {
  text-align: left; padding: 11px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
}
.buy:disabled { opacity: .4; cursor: default; }
.buy.sold { opacity: .3; }
.buy.mul { border-color: #6a5a3a; }
.buy .b-top { display: flex; align-items: baseline; gap: 6px; }
.buy .b-name { font-weight: 700; font-size: 14px; }
.buy .b-price { margin-left: auto; color: var(--gold); font-variant-numeric: tabular-nums; }
.buy .b-desc { font-size: 10px; color: var(--dim); margin-top: 4px; line-height: 1.35; }

.actions { display: flex; gap: 8px; margin-top: 20px; }
.actions button {
  flex: 1; padding: 11px; border-radius: 9px; font-size: 13px; font-weight: 600;
  background: var(--panel-2); border: 1px solid var(--line);
}
.actions button.primary { background: var(--accent); border-color: var(--accent); color: #0f1420; }
.actions button:disabled { opacity: .4; cursor: default; }

.msg { margin-top: 10px; font-size: 12px; color: var(--warn); min-height: 16px; }

/* ───────────────────────────────────────── 상세 보기 / 도감
   "이 특성이 정확히 뭘 하는지"와 "순서를 어떻게 짜야 하는지"를 볼 구멍. */

.overlay.detail { z-index: 30; }        /* 상점 위에서도 열린다 */

.axis {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 10px; font-weight: 700; vertical-align: middle; margin-left: 6px;
}
.axis.loot { background: #1e2b3f; color: var(--accent); }
.axis.add  { background: #1e2b3f; color: var(--accent); }
.axis.mul  { background: #2f2716; color: var(--gold); }
.axis.gold { background: #2f2716; color: var(--gold); }

.d-head { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.d-head h2 { margin: 0; }
.d-effect { margin: 10px 0 14px; font-size: 15px; line-height: 1.5; }
.d-rows { width: 100%; border-collapse: collapse; font-size: 13px; }
.d-rows td { padding: 7px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.d-rows td:first-child { color: var(--dim); width: 88px; white-space: nowrap; }
.d-tip {
  margin-top: 14px; padding: 10px 12px; border-radius: 8px;
  background: var(--panel-2); border-left: 3px solid var(--accent);
  font-size: 12px; line-height: 1.6; color: var(--ink);
}
.d-tip b { color: var(--accent); }

/* 특성 칸은 눌러서 상세를 본다 */
.traits li { position: relative; }
.traits li.clickable { cursor: pointer; }

/* 좁은 화면 — 판이 세로 공간을 빼앗기지 않게 한다.
   #table을 display:contents로 풀어 "판+패" 열과 옆 패널을 #app 그리드에 직접 올린다.
   패는 #playCol 안에 있으므로 좁은 화면에서도 언제나 판 바로 아래에 붙어 있다. */
@media (max-width: 900px) {
  html, body { height: auto; min-height: 100%; }
  /* 어떤 요소도 판을 화면 밖으로 밀어내지 못하게 한다.
     이게 없으면 HUD 한 줄이 548px를 강제해 390px 폰에서 판이 잘려 나간다. */
  body { overflow-x: hidden; }
  #app {
    height: auto; min-height: 100%;
    width: 100%; max-width: 100%;
    grid-template-rows: auto auto auto;
    gap: 8px; padding: 8px;
  }
  #app > * { min-width: 0; }
  #table { display: contents; }
  #playCol { gap: 8px; }

  /* 판은 정사각으로 화면 폭을 꽉 채운다. 세로가 짧은 창에서만 상한이 걸린다. */
  #boardWrap { width: 100%; aspect-ratio: 1 / 1; max-height: 52vh; }

  /* HUD를 두 줄로 접는다 — 목표 줄 / 숫자 줄 */
  #hud { flex-wrap: wrap; padding: 8px 10px; gap: 8px; }
  .goal { flex: 1 1 100%; min-width: 0; }
  .goal-target { font-size: 26px; }
  .hud-right { flex: 1 1 100%; gap: 6px; }
  .hud-right .stat { flex: 1 1 0; min-width: 0; padding: 4px 2px; }
  .stat b { font-size: 16px; }
  .stat.moves { min-width: 0; }
  .stat.moves b { font-size: 22px; }

  #handBar { padding: 8px; }
  .hand { gap: 6px; }
  .card { padding: 7px 8px; gap: 6px; }
  .card .c-stone { width: 20px; height: 20px; }
  .card .c-stone.graded::after { width: 6px; height: 6px; }
  .card .c-top { gap: 4px; margin-bottom: 2px; }
  .card .c-name { font-size: 13px; }
  .card .c-grade { font-size: 9px; }
  .card .c-desc { font-size: 10px; }
  /* 편 범례는 좁은 화면에서 줄바꿈해 카드 위에 한 줄로 남는다 */
  .hand-head { flex-wrap: wrap; row-gap: 4px; }
  .sides { gap: 10px; }

  #side { flex-direction: column; padding: 8px; gap: 6px; min-width: 0; }
  #side h3 { font-size: 11px; }
  /* 특성은 좁은 화면에서도 세로로 쌓는다. 가로 띠로 만들면 설명이 잘려
     "특성을 정할 때 한 번 보고 다시는 못 보는" 상태가 된다. 3칸뿐이라 세로로 넣어도 짧다 */
  .traits li { min-height: 38px; padding: 6px 8px; }
  .legend { flex-direction: row; flex-wrap: wrap; gap: 4px 10px; }
  .legend li { gap: 5px; }
  .legend .g-loot { margin-left: 2px; }

  .side-foot { gap: 8px; }

  .sheet { padding: 16px; border-radius: 12px; }
  .shelf { grid-template-columns: 1fr; }
}
