:root{
  --bg:#0f1115;
  --text:#e7ecf5;
  --muted:#a6b0c3;
  --border:#2a3242;
  --shadow: 0 10px 30px rgba(0,0,0,.45);

  --cardW: 150px;
  --radius: 14px;

  --discardW: 260px;
  --discardH: 220px;
  --discardPad: 10px;
  --magnetPx: 60px;
  --stackOffsetPx: 8px;

  --dashPad: 12px;
  --dashGap: 10px;

  --slotW: 170px;
  --slotH: 220px;

  --charW: 350px;
  --charH: 500px;
}

*{ box-sizing:border-box; }
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 20% 10%, #1a2230 0%, var(--bg) 45%, #0b0d12 100%);
  color:var(--text);
  overflow:hidden;
}

.app{ height:100vh; display:grid; grid-template-rows: auto 1fr; }

header{
  position:relative;
  display:flex;
  align-items:center;
  gap:12px;
  padding:12px 14px;
  border-bottom:1px solid var(--border);
  background: linear-gradient(180deg, rgba(21,25,34,.92) 0%, rgba(16,20,28,.92) 100%);
  backdrop-filter: blur(6px);
}
header .title{ font-weight:700; letter-spacing:.2px; }
header .meta{
  display:flex;
  gap:10px;
  align-items:center;
  font-size:12px;
  color:var(--muted);
  white-space:nowrap;
  margin-left: 12px;
}
.pill{
  padding:6px 10px;
  border:1px solid var(--border);
  border-radius:999px;
  background: rgba(0,0,0,.18);
}

.centerControls{
  position:absolute;
  left:50%;
  transform: translateX(-50%);
  display:flex;
  align-items:center;
  justify-content:center;
  pointer-events:auto;
}

.rightControls{
  margin-left:auto;
  display:flex;
  align-items:center;
  gap:10px;
}

button{
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  color:var(--text);
  padding:8px 10px;
  border-radius:10px;
  cursor:pointer;
}
button:hover{ background: rgba(255,255,255,.07); }

.toggle{
  display:flex;
  align-items:center;
  gap:10px;
  font-size:12px;
  color: var(--text);
  user-select:none;
}
.toggle input{ display:none; }
.toggle .track{
  width:44px;
  height:24px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.16);
  background: rgba(0,0,0,.30);
  position:relative;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.25);
}
.toggle .track::after{
  content:'';
  position:absolute;
  top:2px;
  left:2px;
  width:20px;
  height:20px;
  border-radius:999px;
  background: rgba(231,236,245,.92);
  transition: transform .15s ease;
}
.toggle input:checked + .track{
  background: rgba(255,255,255,.10);
  border-color: rgba(255,255,255,.26);
}
.toggle input:checked + .track::after{
  transform: translateX(20px);
}
.toggle .labelText{
  padding:6px 10px;
  border:1px solid var(--border);
  border-radius:999px;
  background: rgba(0,0,0,.18);
  color: var(--muted);
}

.main{
  display:grid;
  grid-template-columns: 360px 1fr;
  height:100%;
  min-height:0;
}

.left{
  border-right:1px solid var(--border);
  background: rgba(16,20,28,.75);
  padding:14px;
  display:flex;
  flex-direction:column;
  gap:12px;
  min-height:0;
}

.tabs{
  display:flex;
  gap:8px;
}
.tab{
  flex:1;
  padding:10px 10px;
  border-radius: 12px;
  border:1px solid var(--border);
  background: rgba(0,0,0,.18);
  color: var(--muted);
}
.tab.active{
  background: rgba(255,255,255,.07);
  color: var(--text);
  border-color: rgba(255,255,255,.18);
}

.deckWrap{
  border:1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(0,0,0,.18);
  padding:12px;
  box-shadow: var(--shadow);
}
.deckLabel{
  display:flex;
  justify-content:space-between;
  align-items:center;
  margin-bottom:10px;
  color:var(--muted);
  font-size:12px;
}
.deckStage{
  position:relative;
  width:100%;
  min-height: 320px;
  display:flex;
  align-items:center;
  justify-content:center;
  user-select:none;
  touch-action:none;
  padding: 10px 0 14px 0;
}
.deckStage.hidden{ display:none; }

.deckBase{
  position:absolute;
  width: var(--cardW);
  height: 220px;
  border-radius: 14px;
  background:
    linear-gradient(135deg, rgba(255,255,255,.06) 0%, rgba(255,255,255,.02) 40%, rgba(0,0,0,.18) 100%);
  border:1px dashed rgba(255,255,255,.16);
  transform: translate(10px, 10px);
  pointer-events:none;
}

.deckFooter{
  display:flex;
  justify-content:flex-end;
  gap:8px;
  margin-top:10px;
}
.hidden{ display:none !important; }

.card{
  width: var(--cardW);
  height: auto;
  border-radius: 14px;
  border:1px solid rgba(255,255,255,.18);
  background: rgba(0,0,0,.25);
  box-shadow: var(--shadow);
  overflow:hidden;
  position:absolute;
  display:flex;
  align-items:center;
  justify-content:center;
  touch-action:none;
  user-select:none;
  cursor:grab;
}
.card:active{ cursor:grabbing; }
.card img{
  width:100%;
  height:auto;
  display:block;
  object-fit:contain;
  background: rgba(0,0,0,.35);
  pointer-events:none;
  user-select:none;
}

.cardActions{
  position:absolute;
  right:6px;
  top:6px;
  display:flex;
  gap:6px;
  z-index: 6;
}

/* Supplies face-down card back */
.cardBack{
  width: var(--cardW);
  height: 220px;
  border-radius: 14px;
  border:1px solid rgba(255,255,255,.18);
  background:
    linear-gradient(135deg, rgba(255,255,255,.08) 0%, rgba(255,255,255,.02) 45%, rgba(0,0,0,.25) 100%),
    repeating-linear-gradient(45deg, rgba(255,255,255,.08) 0 10px, rgba(255,255,255,0) 10px 20px);
  box-shadow: var(--shadow);
  display:flex;
  align-items:center;
  justify-content:center;
  position:absolute;
  user-select:none;
  cursor:pointer;
  touch-action:none;
}

.cardBackInner{
  width: calc(100% - 18px);
  height: calc(100% - 18px);
  border-radius: 12px;
  border:1px dashed rgba(255,255,255,.22);
  display:flex;
  align-items:center;
  justify-content:center;
  flex-direction:column;
  gap:6px;
  background: rgba(0,0,0,.18);
  color: rgba(231,236,245,.92);
  font-size: 14px;
  letter-spacing: .8px;
  text-transform: uppercase;
}

.cardBackHint{
  font-size: 11px;
  color: rgba(166,176,195,.95);
  letter-spacing: .2px;
  text-transform:none;
}

.cardBack.fading{
  opacity: .50;
  transition: opacity .22s ease;
}


.actionBtn{
  width:28px;
  height:28px;
  border-radius:10px;
  border:1px solid rgba(255,255,255,.16);
  background: rgba(0,0,0,.45);
  color: rgba(231,236,245,.95);
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:14px;
  cursor:pointer;
  user-select:none;
}
.actionBtn:hover{ background: rgba(0,0,0,.60); }
.actionBtn.danger{ color: rgba(255,220,220,.95); }
.actionBtn.disabled{
  opacity:.45;
  cursor:not-allowed;
}

.help{
  border:1px solid var(--border);
  border-radius: var(--radius);
  padding:10px 12px;
  background: rgba(0,0,0,.18);
  color:var(--muted);
  font-size:12px;
  line-height:1.45;
}

.right{
  position:relative;
  min-height:0;
  overflow:hidden;
}
.table{
  position:absolute;
  inset:0;
  background:
    radial-gradient(900px 500px at 70% 20%, rgba(46,110,255,.12) 0%, rgba(0,0,0,0) 55%),
    radial-gradient(900px 500px at 20% 80%, rgba(60,200,140,.10) 0%, rgba(0,0,0,0) 55%);
}
.tableGrid{
  position:absolute;
  inset:0;
  background-image:
    linear-gradient(rgba(255,255,255,.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.06) 1px, transparent 1px);
  background-size: 48px 48px;
  opacity:.28;
  pointer-events:none;
}
.playedLayer{
  position:absolute;
  inset:0;
}

.dashboard{
  position:absolute;
  left: 14px;
  top: 14px;
  border:1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.20);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: var(--dashPad);
  display:grid;
  /*
    Canonical dashboard grid (table equivalent):
      Row 1: [Head] [Character (colspan=2)] [Body]
      Row 2: [Hand1] [Character (colspan=2)] [Hand2] (+ dynamic packs start col 5)
      Row 3: [Pack1] [Pack2] [Pack3] [Pack4] (+ dynamic packs start col 5)

    The grid can expand horizontally with extra pack columns (added inline via JS).
  */
  grid-template-columns: var(--slotW) var(--slotW) var(--slotW) var(--slotW);
  grid-template-rows: var(--slotH) var(--slotH) var(--slotH);
  grid-auto-columns: var(--slotW);
  gap: var(--dashGap);
  z-index: 5;
}

/* Fixed slot placement to match the canonical grid */
.dashboard .slot[data-slot="head"]{ grid-column: 1; grid-row: 1; }
.dashboard .slot[data-slot="character"]{ grid-column: 2 / span 2; grid-row: 1 / span 2; }
.dashboard .slot[data-slot="body"]{ grid-column: 4; grid-row: 1; }
.dashboard .slot[data-slot="hand1"]{ grid-column: 1; grid-row: 2; }
.dashboard .slot[data-slot="hand2"]{ grid-column: 4; grid-row: 2; }
.dashboard .slot[data-slot="pack1"]{ grid-column: 1; grid-row: 3; }
.dashboard .slot[data-slot="pack2"]{ grid-column: 2; grid-row: 3; }
.dashboard .slot[data-slot="pack3"]{ grid-column: 3; grid-row: 3; }
.dashboard .slot[data-slot="pack4"]{ grid-column: 4; grid-row: 3; }

.slot{
  position:relative;
  border-radius: 16px;
  border:2px dashed rgba(255,255,255,.18);
  background: rgba(0,0,0,.16);
  overflow:hidden;
}

/* Keep layout space but make slot unusable/invisible when a character has < 2 hands */
.slot.disabled{
  visibility: hidden;
  pointer-events: none;
}
.slot.active{
  border-color: rgba(255,255,255,.44);
  background: rgba(0,0,0,.24);
}
.slot.occupied{
  border-style: solid;
  border-color: rgba(255,255,255,.20);
}
.slotLabel{
  position:absolute;
  left:8px;
  top:8px;
  font-size:12px;
  color: rgba(231,236,245,.90);
  background: rgba(0,0,0,.40);
  border:1px solid rgba(255,255,255,.14);
  border-radius: 999px;
  padding: 5px 9px;
  z-index: 7;
  pointer-events:none;
  user-select:none;
  max-width: calc(100% - 16px);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.slotInner{
  position:absolute;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 10px;
}

.slotCard{
  width: 100%;
  height: 100%;
  border-radius: 14px;
  border:1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.25);
  overflow:hidden;
  position:relative;
  user-select:none;
}
.slotCard img{
  width:100%;
  height:100%;
  object-fit:contain;
  display:block;
  background: rgba(0,0,0,.35);
  pointer-events:none;
  user-select:none;
}

.attachBadge{
  position:absolute;
  right:4px;
  bottom:4px;
  font-size:12px;
  line-height:1;
  padding:3px 6px;
  border-radius: 12px;
  background: rgba(144, 238, 144, .88);
  color: rgba(0,0,0,.92);
  display:flex;
  align-items:center;
  justify-content:center;
  pointer-events:none;
  box-shadow: 0 2px 10px rgba(0,0,0,.4);
  z-index: 5;
}

.slotCard.attachHover{
  outline: 2px solid rgba(130, 200, 255, .85);
  outline-offset: 2px;
}

.attachSection{
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,.12);
}
.attachTitle{
  font-size: 12px;
  color: rgba(166,176,195,.95);
  margin-bottom: 8px;
}
.attachList{
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.attachItem{
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 8px;
  align-items: center;
  padding: 6px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(0,0,0,.18);
  cursor: pointer;
}
.attachItem:hover{
  background: rgba(0,0,0,.28);
}
.attachThumb{
  width: 36px;
  height: 50px;
  object-fit: contain;
  background: rgba(0,0,0,.25);
  border-radius: 8px;
}
.attachName{
  font-size: 12px;
  color: rgba(230,235,245,.95);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.characterSlot{
  grid-column: 2;
  grid-row: 1 / span 2;
  min-height: var(--charH);
}
.characterPlaceholder{
  width:100%;
  height:100%;
  border-radius: 16px;
  border:1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.20);
  display:flex;
  align-items:center;
  justify-content:center;
  color: rgba(166,176,195,.90);
  font-size: 12px;
  text-align:center;
  padding: 10px;
  user-select:none;
}

.discardZone{
  position:absolute;
  right: 14px;
  bottom: 14px;
  width: var(--discardW);
  height: var(--discardH);
  border-radius: 16px;
  border: 2px dashed rgba(255,255,255,.22);
  background: rgba(0,0,0,.22);
  box-shadow: var(--shadow);
  display:flex;
  flex-direction:column;
  padding: 10px 12px;
  gap:6px;
  z-index: 4;
}
.discardZone .hdr{
  display:flex;
  align-items:center;
  justify-content:space-between;
  color: var(--muted);
  font-size:12px;
  user-select:none;
  pointer-events:none;
}
.discardZone .hint{
  color: rgba(166,176,195,.85);
  font-size:12px;
  line-height:1.35;
  pointer-events:none;
  user-select:none;
}
.discardZone.active{
  border-color: rgba(255,255,255,.44);
  background: rgba(0,0,0,.30);
}

.toast{
  position:absolute;
  left:14px;
  bottom:14px;
  background: rgba(0,0,0,.55);
  border:1px solid rgba(255,255,255,.14);
  color:var(--muted);
  border-radius: 12px;
  padding:10px 12px;
  font-size:12px;
  max-width: 520px;
  box-shadow: var(--shadow);
  pointer-events:none;
  opacity:0;
  transform: translateY(8px);
  transition: opacity .18s ease, transform .18s ease;
  z-index: 10;
}
.toast.show{ opacity:1; transform: translateY(0); }

.zoomOverlay{
  position:fixed;
  inset:0;
  background: rgba(0,0,0,.70);
  display:none;
  align-items:center;
  justify-content:center;
  z-index: 9999;
  padding: 18px;
}
.zoomOverlay.show{ display:flex; }
.zoomStage{
  /* Allow the zoom strip to use most of the viewport width so host + attachments
     don't leave a large dead area between panes on wide screens. */
  max-width: 96vw;
  max-height: 92vh;
}

.zoomStrip{
  display:flex;
  gap: 6px;
  align-items: flex-start;
  max-height: 92vh;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 6px;
}

.zoomPane,
.zoomAttachPane{
  display:flex;
  flex-direction: row;
  gap: 10px;  
  max-width: 860px;
}

.zoomPane .zoomCard,
.zoomAttachPane .zoomCard{
  max-width: 420px !important;
  max-height: 64vh !important;
}

.zoomPane .zoomCard img,
.zoomAttachPane .zoomCard img{
  max-height: 64vh !important;
}

.zoomPane .zoomInfo,
.zoomAttachPane .zoomInfo{
  width: 420px !important;
  max-height: 64vh;
  overflow: auto;
}

.zoomAttachOverlay{
  position:absolute;
  left: 8px;
  top: 8px;
  right: 8px;
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 10px;
  pointer-events:none;
  z-index: 6;
}
.zoomAttachLabel{
  pointer-events:none;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 12px;
  border:1px solid rgba(255,255,255,.18);
  background: rgba(0,0,0,.40);
  box-shadow: var(--shadow);
  overflow:hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 310px;
}
.zoomAttachRemove{
  border:0;
  cursor:pointer;
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: rgba(255,60,60,.78) !important;
  color: rgba(255,255,255,.95);
  display:flex;
  align-items:center;
  justify-content:center;
  pointer-events:auto;
}
.zoomAttachRemove:hover{
  background: rgba(255,60,60,.38) !important;
}
.zoomCard{
  max-width: min(62vw, 820px);
  max-height: 92vh;
  border-radius: 16px;
  overflow:hidden;
  border:1px solid rgba(255,255,255,.18);
  background: rgba(0,0,0,.35);
  box-shadow: var(--shadow);
  position: relative;
}

/* Overlay controls for attachment panes (title + detach button) */
.zoomAttachOverlay{
  position:absolute;
  top:8px;
  left:8px;
  right:8px;
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 10px;
  pointer-events:none;
  z-index: 6;
}
.zoomAttachLabel{
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(0,0,0,.55);
  border: 1px solid rgba(255,255,255,.16);
  box-shadow: 0 2px 10px rgba(0,0,0,.35);
  max-width: 320px;
  overflow:hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.zoomAttachRemove{
  pointer-events:auto;
  border:0;
  cursor:pointer;
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: rgba(255,60,60,.18);
  color: rgba(255,255,255,.95);
  display:flex;
  align-items:center;
  justify-content:center;
}
.zoomAttachRemove:hover{ background: rgba(255,60,60,.28); }
.zoomCard img{
  display:block;
  width:100%;
  height:auto;
  max-height: 92vh;
  object-fit:contain;
  background: rgba(0,0,0,.45);
}

.zoomInfo{
  width: min(34vw, 420px);
  max-height: 92vh;
  overflow: auto;
  border-radius: 16px;
  border:1px solid rgba(255,255,255,.18);
  background: rgba(0,0,0,.35);
  box-shadow: var(--shadow);
  padding: 10px;
  font-size: 12px;
}

.zoomInfo table{
  width: 100%;
  border-collapse: collapse;
}
.zoomInfo td, .zoomInfo th{
  border-bottom: 1px solid rgba(255,255,255,.12);
  padding: 6px 6px;
  vertical-align: top;
}
.zoomInfo th{
  text-align: left;
  font-weight: 700;
  opacity: 0.95;
}
.zoomInfo .zKey{ width: 1%; white-space: nowrap; opacity: 0.85; }
.zoomInfo .zVal{ }
.zoomInfo .zRuleName{ width: 1%; white-space: nowrap; font-weight: 700; }

@media (max-width: 1000px){
  .zoomStrip{ flex-direction: column; overflow-x: hidden; overflow-y: auto; max-height: 92vh; }
  .zoomPane, .zoomAttachPane{ min-width: 92vw; max-width: 92vw; }
  .zoomPane .zoomCard, .zoomAttachPane .zoomCard{ max-width: 92vw; }
  .zoomPane .zoomInfo, .zoomAttachPane .zoomInfo{ width: 92vw; max-height: none; }
}

@media (max-width: 900px){
  .main{ grid-template-columns: 1fr; }
  .left{ border-right:none; border-bottom:1px solid var(--border); }
  body{ overflow:auto; }
  .right{ height: calc(100vh - 430px); overflow:auto; }
  .dashboard{ position:relative; left:auto; top:auto; margin: 12px; }
  .discardZone{ position:relative; right:auto; bottom:auto; margin: 12px; }
  header{ flex-wrap:wrap; }
  .centerControls{ position:relative; left:auto; transform:none; order: 3; width:100%; justify-content:center; margin-top:8px; }
}
