* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", "Malgun Gothic", sans-serif;
  background: radial-gradient(ellipse at 50% 30%, #3a3f4b 0%, #23262e 70%, #191b21 100%);
  touch-action: none;
}

#view { position: fixed; inset: 0; display: block; touch-action: none; }

#topbars {
  position: fixed;
  top: 8px; left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  z-index: 10;
  width: calc(100vw - 10px);
  pointer-events: none; /* 빈 영역은 3D 조작을 막지 않게 */
}
#topbars > * { pointer-events: auto; }

#toolbar {
  display: flex; gap: 6px; align-items: center;
  flex-wrap: wrap; justify-content: center;
  padding: 8px 10px;
  background: rgba(20, 22, 28, 0.78);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  backdrop-filter: blur(8px);
  max-width: 100%;
}

#toolbar button {
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 9px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.07);
  color: #e8eaf0;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}
#toolbar button:hover { background: rgba(255,255,255,0.16); }
#toolbar button.active { background: #4f7cff; border-color: #6f95ff; }
#toolbar button:disabled { opacity: .35; cursor: default; }
#toolbar .sep { width: 1px; height: 22px; background: rgba(255,255,255,0.15); margin: 0 3px; }
.gone { display: none !important; }

/* ◫ 분할 화면: 오른쪽 절반에 같은 앱을 iframe으로 */
#splitPane {
  position: fixed;
  top: 0; right: 0;
  width: 50vw; height: 100vh;
  z-index: 5;
  border-left: 1px solid rgba(255,255,255,0.18);
  background: #23262e;
}
#splitPane.hidden { display: none; }
#splitPane iframe { width: 100%; height: 100%; border: 0; display: block; }
body.split #topbars { width: calc(50vw - 10px); left: 25%; }
body.split .panel { left: 25%; }
body.split #hint { left: 25%; }

#paperBar {
  display: flex; gap: 6px;
  flex-wrap: wrap; justify-content: center;
  padding: 6px 8px;
  background: rgba(20, 22, 28, 0.6);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  max-width: 100%;
}
#paperBar.hidden { display: none; }
#paperBar button {
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.07);
  color: #e8eaf0;
  cursor: pointer;
}
#paperBar button.active { background: #4f7cff; border-color: #6f95ff; }
#paperBar button.openBtn { background: rgba(255, 186, 73, 0.14); border-color: rgba(255, 186, 73, 0.45); }
#paperBar button.openBtn.hidden { display: none; }
#paperBar button.locked { display: none; }

.panel {
  position: fixed;
  bottom: 56px; left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 8px;
  padding: 10px 12px;
  background: rgba(20, 22, 28, 0.85);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 14px;
  backdrop-filter: blur(8px);
  z-index: 10;
}
.panel.hidden { display: none; }
.panel button {
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.07);
  color: #e8eaf0;
  cursor: pointer;
}
.panel .dir.active { background: #4f7cff; border-color: #6f95ff; }

#overlayPanel { align-items: center; flex-wrap: wrap; max-width: calc(100vw - 24px); }
#overlaySrcs { display: flex; gap: 5px; flex-wrap: wrap; }
#overlaySrcs button { font-size: 13px; padding: 6px 10px; }
#overlaySrcs button.active { background: #4f7cff; border-color: #6f95ff; }
#ovMirror.active { background: #4f7cff; border-color: #6f95ff; }
#ovScale { width: 110px; accent-color: #4f7cff; }

#hint {
  position: fixed;
  bottom: 14px; left: 50%;
  transform: translateX(-50%);
  padding: 7px 14px;
  background: rgba(20, 22, 28, 0.6);
  border-radius: 20px;
  color: #aeb4c2;
  font-size: 13px;
  z-index: 9;
  white-space: nowrap;
  max-width: calc(100vw - 20px);
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 🧩 작업대: 자료를 끌어다 늘어놓고 맞춰 보기 */
#board {
  position: fixed; left: 0; top: 0; bottom: 0; right: 36vw; z-index: 8; overflow: hidden;
  border-right: 2px solid rgba(255,255,255,.18);
  background: #2b2a27 repeating-linear-gradient(90deg, rgba(255,255,255,.018) 0 2px, transparent 2px 6px);
  touch-action: none; cursor: grab;
}
#board.hidden { display: none; }
#board.drop { box-shadow: inset 0 0 0 4px #4f7cff; }
#boardWorld { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#boardEmpty {
  position: absolute; left: 50%; top: 55%; transform: translate(-50%, -50%);
  color: #9a978f; text-align: center; font-size: 16px; line-height: 1.7; pointer-events: none;
}
.bcard { position: absolute; transform-origin: 50% 50%; cursor: move; user-select: none; }
.bcard { perspective: 1600px; }
.bflip { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; }
.bcard.snap .bflip { transition: transform .35s ease; }
.bfront, .bback { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: #f4f1ea; box-shadow: 0 6px 18px rgba(0,0,0,.45); }
.bback { transform: rotateY(180deg); }
.bfront img, .bback img { display: block; width: 100%; height: 100%; pointer-events: none; }
.bcard.sel .bfront, .bcard.sel .bback { outline: 3px solid #4f7cff; outline-offset: 2px; }
#cardTools {
  position: absolute; display: flex; gap: 4px; padding: 5px;
  background: rgba(20,22,28,.9); border: 1px solid rgba(255,255,255,.14); border-radius: 10px; z-index: 2;
}
#cardTools.hidden { display: none; }
#cardTools button, #boardClear {
  font-size: 14px; min-width: 34px; padding: 6px 8px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.08); color: #e8eaf0; cursor: pointer;
}
#cardTools button.on { background: #4f7cff; }
#boardClear { position: absolute; right: 14px; bottom: 14px; }
.chipGhost {
  position: fixed; z-index: 30; pointer-events: none; padding: 5px 12px; border-radius: 8px;
  background: #4f7cff; color: #fff; font-size: 13px; transform: translate(-50%, -50%); opacity: .9;
}
.chipGhost:has(img) { padding: 0; background: none; opacity: .8; }
.chipGhost img { display: block; width: 160px; box-shadow: 0 8px 24px rgba(0,0,0,.5); }
/* 작업대 펴면: 왼쪽 = 작업대, 오른쪽 36vw = 자료 탭 + 자료 보기 */
body.boardOn #view { left: auto; right: 0; }
body.boardOn #topbars { left: 82vw; width: calc(36vw - 10px); }
body.boardOn .panel, body.boardOn #hint { left: 82vw; max-width: calc(36vw - 16px); }
body.boardOn #btnSplit { display: none; }
@media (max-width: 759px) { /* 좁은 화면: 위 = 작업대, 아래 45% = 자료 */
  #board { right: 0; bottom: 45vh; border-right: 0; border-bottom: 2px solid rgba(255,255,255,.18); }
  body.boardOn #view { top: auto; bottom: 0; }
  body.boardOn #topbars { left: 50%; width: calc(100vw - 10px); top: calc(55vh + 6px); }
  body.boardOn .panel, body.boardOn #hint { left: 50%; max-width: calc(100vw - 16px); }
}
#toolbar button#btnBoard.active { background: #4f7cff; border-color: #6f95ff; }
#boardHelp {
  position: absolute; left: 14px; bottom: 14px; right: 150px; color: #a9a59c; font-size: 12.5px;
  background: rgba(20,22,28,.55); padding: 6px 10px; border-radius: 8px; pointer-events: none;
}
