:root {
  --desk-bg: #1b1814;
  --panel-bg: #26211b;
  --manila: #eadcc0;
  --manila-dark: #d9c59d;
  --manila-border: #8d7a58;
  --ink-text: #221d17;
  --muted: #665947;
  --c-black: #1e1d1b;
  --c-blue: #1e5b94;
  --c-red: #b22a24;
  --c-gold: #c6860e;
  --c-green: #227848;
}

* {
  box-sizing: border-box;
  user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 50% 30%, #2a241d 0%, var(--desk-bg) 80%);
  color: #f4ebd8;
  font-family: "Pretendard", "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
  font-size: 13px;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.desk-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1680px;
  margin: 0 auto;
  padding: 8px 12px;
  gap: 8px;
}

/* 상단 바 */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #221d17;
  border: 1px solid #493e30;
  border-radius: 6px;
  padding: 6px 12px;
  min-height: 46px;
}

.top-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
}

.agency-badge {
  background: var(--c-red);
  color: #fff5e6;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 3px;
  letter-spacing: 0.5px;
  font-size: 12px;
  border: 1px solid #ff988f;
}

.board-title-wrap {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.board-sub {
  font-size: 11px;
  color: #cbbba0;
}

.top-quests {
  display: flex;
  gap: 6px;
  flex: 1;
  justify-content: center;
  overflow: hidden;
}

.quest-chip {
  background: #312a21;
  border: 1px solid #635440;
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 11px;
  white-space: nowrap;
}

.quest-chip.done {
  border-color: #42b86d;
  color: #8df0b2;
  background: #1d3224;
}

.top-stats {
  display: flex;
  gap: 6px;
  align-items: center;
}

.stat-pill {
  background: #171410;
  border: 1px solid #4e4233;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
}

.stat-pill.stability b { color: #8ad6ff; }
.stat-pill.breach b { color: #ff8078; }
.stat-pill.budget b { color: #ffd666; }
.stat-pill.variant b { color: #ff6987; }

.top-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  position: relative;
}

.mini-btn {
  background: #383026;
  color: #f4ebd8;
  border: 1px solid #6a5b47;
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 12px;
}

.mini-btn:hover {
  background: #4b4033;
}

.warn-btn {
  border-color: #c2802d;
  color: #ffd996;
}

.tester-wrap {
  position: relative;
}

.tester-menu {
  position: absolute;
  right: 0;
  top: 32px;
  width: 240px;
  background: #231e17;
  border: 1px solid #8c7758;
  border-radius: 6px;
  padding: 8px;
  z-index: 60;
  box-shadow: 0 10px 26px rgba(0,0,0,0.65);
}

.tester-menu-title {
  font-weight: 700;
  font-size: 11px;
  color: #d7c39f;
  margin-bottom: 6px;
}

.tester-board-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 6px;
}

.tester-board-btn {
  background: #352d23;
  border: 1px solid #63533f;
  color: #efe1c4;
  padding: 4px;
  font-size: 11px;
  border-radius: 3px;
  cursor: pointer;
  text-align: left;
}

.tester-board-btn:hover {
  background: #4a3f30;
}

.full-w { width: 100%; }

/* 3단 본문 */
.desk-main {
  display: grid;
  grid-template-columns: 290px minmax(480px, 1fr) 330px;
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid #493e30;
  border-radius: 6px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.panel-head h2 {
  margin: 0;
  font-size: 14px;
  color: #f3e4c3;
}

.ink-badge {
  background: #17344d;
  border: 1px solid #59a8eb;
  color: #b8e1ff;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
}

.deck-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #c2b296;
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px dashed #4a3f31;
}

/* 좌측 손패 */
.hand-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex: 1;
  overflow-y: auto;
  padding-right: 2px;
}

.stamp-card {
  background: var(--manila);
  color: var(--ink-text);
  border: 2px solid var(--manila-border);
  border-left-width: 7px;
  border-radius: 5px;
  padding: 7px 8px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  position: relative;
}

.stamp-card.color-black { border-left-color: var(--c-black); }
.stamp-card.color-blue { border-left-color: var(--c-blue); }
.stamp-card.color-red { border-left-color: var(--c-red); }
.stamp-card.color-gold { border-left-color: var(--c-gold); }

.stamp-card.selected {
  transform: translateX(4px);
  box-shadow: 0 0 0 2px #ffcb47, 0 4px 12px rgba(0,0,0,0.45);
}

.stamp-card.variant-card {
  background: linear-gradient(135deg, #f3dedd 0%, #ead6be 100%);
  border-color: #c93346;
}

.stamp-card.promoted-card {
  background: linear-gradient(135deg, #f3ebd0 0%, #e1d0a1 100%);
  border-color: #b57e0f;
}

.stamp-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 800;
  font-size: 13px;
  margin-bottom: 3px;
}

.stamp-cost {
  background: #23201b;
  color: #b2e2ff;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 10px;
}

.stamp-meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #4f4333;
  margin-bottom: 2px;
}

.stamp-desc {
  font-size: 11px;
  color: #3c3225;
  line-height: 1.3;
}

.hand-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-top: 8px;
}

.ctrl-btn {
  background: #3a3126;
  color: #f4ebd8;
  border: 1px solid #6c5b45;
  border-radius: 4px;
  padding: 6px 6px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.ctrl-btn:hover:not(:disabled) {
  background: #4e4234;
}

.ctrl-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.convert-panel {
  margin-top: 6px;
  background: #1a1611;
  border: 1px solid #8a6d43;
  border-radius: 5px;
  padding: 6px;
}

.convert-title {
  font-size: 11px;
  color: #f0d7a3;
  margin-bottom: 4px;
}

.convert-pay-row {
  display: flex;
  gap: 10px;
  font-size: 11px;
  margin-bottom: 5px;
}

.convert-colors {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.cbtn {
  border: none;
  border-radius: 3px;
  padding: 4px 2px;
  font-size: 11px;
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.c-black { background: var(--c-black); border: 1px solid #666; }
.c-blue { background: var(--c-blue); }
.c-red { background: var(--c-red); }
.c-gold { background: var(--c-gold); }

/* 중앙 4x4 보드 */
.center-panel {
  background: linear-gradient(180deg, #322b21 0%, #241f18 100%);
  align-items: stretch;
  justify-content: space-between;
  padding: 10px 14px;
}

.center-panel.shake {
  animation: desk-shake 0.18s ease-in-out;
}

@keyframes desk-shake {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-3px, 2px); }
  50% { transform: translate(3px, -2px); }
  75% { transform: translate(-2px, -1px); }
}

.col-headers {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 5px;
}

.col-hdr {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: #b8a586;
  background: #1d1914;
  border-radius: 3px;
  padding: 2px 0;
  border: 1px solid #44392c;
}

.col-hdr.breach-col {
  color: #ff9c94;
  border-color: #7c3530;
}

.col-hdr.shred-col-active {
  color: #ffb86b;
  border-color: #b55b1e;
  background: #331c10;
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 8px;
  flex: 1;
  min-height: 0;
}

.board-cell {
  background: var(--manila);
  color: var(--ink-text);
  border: 2px solid var(--manila-border);
  border-radius: 5px;
  padding: 5px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  overflow: hidden;
  box-shadow: inset 0 0 12px rgba(90, 70, 40, 0.14);
}

.board-cell:hover {
  border-color: #ffd159;
}

.board-cell.breach-edge {
  border-left: 4px solid #a8322c;
}

.board-cell.shredder-cell {
  background: repeating-linear-gradient(
    -45deg,
    #e9d9b9,
    #e9d9b9 8px,
    #dfc79e 8px,
    #dfc79e 16px
  );
  border-right: 4px solid #bf5a1d;
}

.board-cell.sight-lit {
  box-shadow: inset 0 0 0 2px rgba(242, 189, 44, 0.72), inset 0 0 16px rgba(255, 224, 110, 0.35);
}

.board-cell.hover-target {
  outline: 2px dashed #1f74c9;
  outline-offset: -3px;
}

.board-cell.anim-active {
  box-shadow: 0 0 0 3px #ffd000, inset 0 0 22px rgba(255, 210, 0, 0.55);
}

.cell-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  z-index: 2;
}

.cell-num {
  font-weight: 800;
  color: #6b5b43;
}

.terrain-tags {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
}

.t-badge {
  font-size: 9.5px;
  padding: 0 4px;
  border-radius: 3px;
  font-weight: 700;
  background: #30281e;
  color: #f8e8c8;
}

.t-trap { background: #5a3c16; color: #ffd98f; }
.t-cctv { background: #6e1f1f; color: #ffb9b9; }
.t-sludge { background: #262523; color: #a7f0bd; }
.t-noise { background: #8f221b; color: #ffd5d1; }

/* 괴이 서류 카드 */
.enemy-card {
  background: #f9f2e3;
  border: 2px dashed #b92d27;
  border-radius: 4px;
  padding: 4px 5px;
  margin-top: 2px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 2;
}

.enemy-card.vulnerable {
  border: 2px solid #d9910d;
  background: #fff8df;
  box-shadow: 0 0 8px rgba(235, 168, 22, 0.45);
}

.enemy-card.preview-contained {
  border: 2px solid #228b4f;
  background: #e9faef;
}

.enemy-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 800;
}

.enemy-state-pill {
  font-size: 9.5px;
  padding: 0 4px;
  border-radius: 3px;
  font-weight: 800;
}

.pill-unsealed { background: #b22a24; color: #fff; }
.pill-vuln { background: #d68c08; color: #fff; }
.pill-contained { background: #1d7d46; color: #fff; }

.enemy-cond-row {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: #463a2a;
}

.enemy-bar-wrap {
  height: 12px;
  background: #dcd1b8;
  border-radius: 3px;
  position: relative;
  overflow: hidden;
  border: 1px solid #968568;
}

.enemy-bar-fill {
  height: 100%;
  background: #c78b14;
  transition: width 0.15s;
}

.enemy-bar-preview {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(34, 139, 79, 0.58);
}

.enemy-bar-text {
  position: absolute;
  inset: 0;
  font-size: 9.5px;
  font-weight: 800;
  text-align: center;
  line-height: 11px;
  color: #191510;
}

/* 도장 인장 마크 */
.placed-stamp-chip {
  margin-top: 2px;
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 10.5px;
  font-weight: 800;
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 3;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.placed-stamp-chip.slam {
  animation: stamp-slam 0.18s cubic-bezier(0.2, 1.3, 0.4, 1);
}

@keyframes stamp-slam {
  0% { transform: scale(1.75) rotate(-8deg); opacity: 0.4; }
  75% { transform: scale(0.92) rotate(1deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.placed-stamp-chip.bg-black { background: var(--c-black); border: 1px solid #555; }
.placed-stamp-chip.bg-blue { background: var(--c-blue); }
.placed-stamp-chip.bg-red { background: var(--c-red); }
.placed-stamp-chip.bg-gold { background: var(--c-gold); color: #191202; }

.contained-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(25, 100, 58, 0.2);
  pointer-events: none;
  z-index: 5;
}

.contained-rubber {
  border: 3px solid #1a7c45;
  color: #146939;
  background: rgba(255, 252, 232, 0.92);
  font-weight: 900;
  font-size: 13px;
  padding: 2px 8px;
  transform: rotate(-10deg);
  letter-spacing: 1px;
}

.commit-bar {
  margin-top: 8px;
  display: flex;
}

.commit-btn {
  width: 100%;
  background: linear-gradient(180deg, #c9392f 0%, #9b221a 100%);
  color: #fff4df;
  border: 2px solid #f09582;
  border-radius: 5px;
  padding: 9px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.45);
}

.commit-btn:hover:not(:disabled) {
  filter: brightness(1.08);
}

.commit-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.commit-label {
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 1px;
}

.commit-sub {
  font-size: 11px;
  opacity: 0.9;
}

.small-commit {
  width: auto;
  padding: 7px 18px;
  font-size: 13px;
  font-weight: 800;
}

/* 우측 프로토콜 & 프리뷰 */
.staple-pill {
  background: #3d3121;
  border: 1px solid #ba9352;
  color: #ffe2a3;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
}

.protocol-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 8px;
}

.proto-slot {
  background: #1b1713;
  border: 1px solid #4c4031;
  border-radius: 4px;
  padding: 5px 7px;
  font-size: 11px;
}

.proto-slot.stabilized {
  border-color: #d6a438;
  background: #2b2416;
}

.proto-slot.empty {
  color: #7d6f5c;
  text-align: center;
  border-style: dashed;
}

.proto-top {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  color: #f2dfb7;
}

.proto-se {
  color: #ffaaa0;
  font-size: 10.5px;
  margin-top: 2px;
}

.proto-slot.stabilized .proto-se {
  color: #8fe8ad;
}

.preview-box {
  background: #191511;
  border: 1px solid #594b39;
  border-radius: 5px;
  padding: 8px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  overflow-y: auto;
}

.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.preview-head h3 {
  margin: 0;
  font-size: 12.5px;
  color: #e6d2ad;
}

.mult-display {
  font-size: 12px;
  color: #ffcf63;
}

.mult-chips, .laws-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.chip {
  background: #30281f;
  border: 1px solid #6b5841;
  border-radius: 3px;
  padding: 2px 5px;
  font-size: 10.5px;
  color: #f2dec0;
}

.chip.law-active {
  background: #1f3c2c;
  border-color: #46b576;
  color: #a9f5c8;
}

.preview-outcomes {
  font-size: 11.5px;
  line-height: 1.45;
  color: #e2d4bc;
  border-top: 1px dashed #3e3428;
  padding-top: 5px;
}

.preview-steps {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  border-top: 1px dashed #3e3428;
  padding-top: 5px;
}

.step-line {
  background: #251f19;
  padding: 3px 6px;
  border-radius: 3px;
  border-left: 3px solid #6d5c46;
}

.step-line.c-black { border-left-color: #777; }
.step-line.c-blue { border-left-color: #4897e0; }
.step-line.c-red { border-left-color: #e0574d; }
.step-line.c-gold { border-left-color: #ebaf28; }

.hotkey-strip {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 10.5px;
  color: #b7a589;
  margin-top: 6px;
  padding-top: 5px;
  border-top: 1px solid #3f3529;
}

/* 모달 공통 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 10, 8, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-card {
  background: #27211a;
  border: 2px solid #96805e;
  border-radius: 8px;
  padding: 16px;
  max-width: 680px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  color: #f4ebd8;
  box-shadow: 0 18px 48px rgba(0,0,0,0.7);
}

.wide-modal {
  max-width: 860px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #544636;
  padding-bottom: 8px;
  margin-bottom: 12px;
}

.modal-head h2 {
  margin: 0;
  font-size: 17px;
  color: #ffe3a8;
}

.modal-sub {
  font-size: 12px;
  color: #c8b698;
}

.reward-section {
  margin-bottom: 14px;
}

.reward-section h3 {
  margin: 0 0 8px 0;
  font-size: 13.5px;
  color: #f0d7a3;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.choice-card {
  background: var(--manila);
  color: var(--ink-text);
  border: 2px solid #8a7757;
  border-radius: 5px;
  padding: 9px;
  cursor: pointer;
  text-align: left;
}

.choice-card:hover {
  border-color: #ffd057;
}

.choice-card.picked {
  box-shadow: 0 0 0 3px #28a65a;
  background: #eefaea;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #4d4031;
}

.rest-top-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.fusion-preview {
  background: #1a1611;
  border: 1px dashed #a88753;
  border-radius: 5px;
  padding: 8px 10px;
  margin-bottom: 8px;
  font-size: 12.5px;
  color: #ffe3a3;
}

.rest-deck-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.codex-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.codex-card {
  background: #1d1813;
  border: 1px solid #594b38;
  border-radius: 5px;
  padding: 8px;
  font-size: 12px;
}

.codex-checks {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  font-size: 11px;
}

.codex-check {
  padding: 2px 6px;
  border-radius: 3px;
  background: #2f2820;
  color: #8c7b64;
}

.codex-check.ok {
  background: #1f472f;
  color: #9ff5be;
}

.guide-body {
  font-size: 13px;
  line-height: 1.55;
}

.guide-laws {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 10px;
  background: #1a1612;
  padding: 8px;
  border-radius: 5px;
  font-size: 11.5px;
}

.end-summary {
  background: #1a1612;
  border: 1px solid #594b38;
  border-radius: 5px;
  padding: 12px;
  line-height: 1.7;
  font-size: 13px;
}

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1612;
  color: #ffe6a8;
  border: 1px solid #c9993c;
  padding: 7px 16px;
  border-radius: 20px;
  font-weight: 700;
  z-index: 200;
  box-shadow: 0 6px 18px rgba(0,0,0,0.55);
}
