/* ─── RiftBot Playmat ─── */
:root {
  --card-w: 92px;
  --card-h: 129px;
  --hand-card-w: 108px;
  --hand-card-h: 151px;
  --bg: #0E1C2F;
  --panel: #16283E;
  --panel2: #1E3A52;
  --border: #2A3F56;
  --gold: #E6A63C;
  --blue: #93E1FF;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: 'BeaufortHeavyItalic', Arial, sans-serif;
  background: radial-gradient(ellipse at 50% 30%, #14283f 0%, var(--bg) 70%);
  color: #F2F2F2;
  margin: 0; padding: 0;
  height: 100dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* ─── Top bar ─── */
#pm-topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  flex-wrap: wrap;
  z-index: 20;
}
.pm-back {
  color: #66CCFF; text-decoration: none; font-size: .8rem;
  padding: 4px 10px; background: var(--panel2); border-radius: 5px;
  white-space: nowrap;
}
.pm-back:hover { background: #2A4F6E; }
.pm-deck-name {
  font-family: 'BeaufortBold'; color: var(--gold); font-size: 1rem;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pm-counters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pm-counter {
  display: flex; align-items: center; gap: 4px;
  background: var(--panel2); border-radius: 6px; padding: 2px 6px;
  font-size: .78rem; color: var(--blue);
}
.pm-counter b { color: #fff; min-width: 18px; text-align: center; font-size: .9rem; }
.pm-counter button {
  background: #0E1C2F; color: var(--blue); border: 1px solid var(--border);
  border-radius: 4px; width: 20px; height: 20px; line-height: 1;
  cursor: pointer; font-size: .8rem; padding: 0;
}
.pm-counter button:hover { background: #2A4F6E; color: #fff; }
.pm-actions { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.pm-actions button {
  background: var(--panel2); color: #F2F2F2; border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 10px; cursor: pointer; font-size: .75rem;
  font-family: inherit;
}
.pm-actions button:hover { background: #2A4F6E; border-color: var(--gold); }
#pm-btn-reset:hover { border-color: #FF6B6B; }

/* ─── Main layout ─── */
#pm-main {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 120px 1fr 260px;
  gap: 8px;
  padding: 8px;
  min-height: 0;
  overflow: hidden;
}

/* Left rail */
#pm-left-rail {
  display: flex; flex-direction: column; gap: 4px;
  align-items: center;
}
.pm-slot-label, .pm-zone-label {
  font-size: .65rem; color: #6d8aa5; text-transform: uppercase; letter-spacing: 1px;
}
.pm-slot {
  width: calc(var(--card-w) + 12px); height: calc(var(--card-h) + 12px);
  border: 1px dashed var(--border); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 8px;
  background: rgba(255,255,255,0.02);
}

/* Center */
#pm-center { display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; }
#pm-battlefields {
  display: flex; gap: 10px; justify-content: center;
  flex: 0 0 auto;
}
.pm-bf-slot {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  min-width: 210px;
}
.pm-bf-card {
  width: 200px; height: 144px;
  border-radius: 8px; overflow: hidden; position: relative;
  border: 1px solid var(--border);
  background: var(--panel);
  cursor: pointer;
  transition: box-shadow .15s, transform .15s;
  flex: 0 0 auto;
}
.pm-bf-card:hover { box-shadow: 0 0 10px rgba(230,166,60,.5); }
.pm-bf-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pm-bf-card.bf-portrait img {
  width: 144px; height: 200px;
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%,-50%) rotate(90deg);
  object-fit: cover;
}
.pm-bf-card.tapped { transform: rotate(6deg); box-shadow: 0 0 8px rgba(147,225,255,.4); filter: brightness(.65); }
.pm-bf-units {
  min-height: calc(var(--card-h) * 0.72 + 10px);
  display: flex; gap: 4px; flex-wrap: wrap; justify-content: center;
  border: 1px dashed rgba(42,63,86,.7); border-radius: 8px;
  padding: 4px; width: 100%;
  background: rgba(255,255,255,0.015);
}
.pm-bf-units .pm-card { width: calc(var(--card-w) * 0.72); height: calc(var(--card-h) * 0.72); }

#pm-base-wrap {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column;
  border: 1px dashed var(--border); border-radius: 10px;
  padding: 4px 8px 8px;
  background: rgba(255,255,255,0.02);
}
#zone-base {
  flex: 1 1 auto;
  display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start;
  overflow-y: auto;
  padding-top: 4px;
}

/* Right rail */
#pm-right-rail {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto 1fr;
  gap: 6px;
  align-content: start;
}
.pm-pile {
  position: relative;
  width: 100%;
  height: calc(var(--card-h) + 26px);
  border: 1px dashed var(--border); border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding: 4px;
  cursor: pointer;
  background: rgba(255,255,255,0.02);
}
.pm-pile:hover { border-color: var(--gold); }
.pm-pile-label { font-size: .62rem; color: #6d8aa5; text-transform: uppercase; letter-spacing: 1px; margin-top: 2px; }
.pm-pile-count {
  position: absolute; top: 4px; right: 6px;
  background: var(--gold); color: #0E1C2F; font-family: 'BeaufortBold';
  border-radius: 10px; padding: 1px 7px; font-size: .75rem;
  z-index: 2;
}
.pm-pile-top { width: var(--card-w); height: var(--card-h); border-radius: 6px; overflow: hidden; background: var(--panel); }
.pm-pile-top img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pm-runepool-wrap {
  grid-column: 1 / -1;
  border: 1px dashed var(--border); border-radius: 8px;
  padding: 4px 6px; min-height: 90px;
  background: rgba(255,255,255,0.02);
}
#zone-runePool { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
#zone-runePool .pm-card { width: calc(var(--card-w) * 0.62); height: calc(var(--card-h) * 0.62); }

/* Card backs */
.pm-cardback {
  width: var(--card-w); height: var(--card-h);
  border-radius: 6px;
  background: linear-gradient(135deg, #1E3A52 0%, #0E1C2F 55%, #1E3A52 100%);
  border: 2px solid var(--gold);
  position: relative;
}
.pm-cardback::after {
  content: 'R'; font-family: 'BeaufortBold';
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: rgba(230,166,60,.55); font-size: 2rem;
}
.pm-cardback-rune { border-color: #93E1FF; }
.pm-cardback-rune::after { content: '\2726'; color: rgba(147,225,255,.55); }

/* ─── Cards ─── */
.pm-card {
  width: var(--card-w); height: var(--card-h);
  position: relative;
  flex: 0 0 auto;
  cursor: grab;
  touch-action: none;
}
.pm-card-inner {
  width: 100%; height: 100%;
  border-radius: 6px; overflow: hidden;
  transition: transform .18s;
  box-shadow: 0 2px 6px rgba(0,0,0,.5);
  background: var(--panel);
}
.pm-card-inner img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.pm-card.tapped .pm-card-inner { transform: rotate(90deg) scale(.82); filter: brightness(.7); }
.pm-card.dragging-src { opacity: .3; }
.pm-card .pm-fd {
  width: 100%; height: 100%;
  background: linear-gradient(135deg, #1E3A52 0%, #0E1C2F 55%, #1E3A52 100%);
  border: 2px solid var(--gold); border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: rgba(230,166,60,.55); font-family: 'BeaufortBold'; font-size: 1.4rem;
}
.pm-badge {
  position: absolute; z-index: 3;
  min-width: 20px; height: 20px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'BeaufortBold'; font-size: .72rem; color: #fff;
  padding: 0 4px;
  pointer-events: none;
}
.pm-badge-damage { top: -6px; right: -6px; background: #C0392B; border: 1px solid #ff8878; }
.pm-badge-buff { bottom: -6px; right: -6px; background: #1E8449; border: 1px solid #7ce8a8; }
.pm-recycle-btn {
  position: absolute; top: -7px; right: -7px; z-index: 4;
  width: 20px; height: 20px; border-radius: 50%;
  background: #16283E; color: #93E1FF; border: 1px solid #93E1FF;
  font-size: .8rem; line-height: 1; cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.pm-recycle-btn:hover { background: #93E1FF; color: #0E1C2F; }
.pb-token-name { font-size: .62rem; color: #93E1FF; margin-top: 2px; line-height: 1.2; }
.pm-card.mulligan-selected .pm-card-inner { outline: 3px solid #FF9800; filter: brightness(.75); }
.pm-card .pm-mull-badge {
  position: absolute; top: 4px; left: 4px; z-index: 3;
  background: #FF9800; color: #000; font-size: .6rem; font-family: 'BeaufortBold';
  border-radius: 4px; padding: 1px 5px; pointer-events: none;
}

/* Drop highlight */
[data-zone].pm-drop-ok { outline: 2px solid var(--gold); outline-offset: -2px; border-radius: 8px; }

/* Drag clone */
#pm-drag-clone {
  position: fixed; z-index: 999; pointer-events: none;
  width: var(--card-w); height: var(--card-h);
  transform: translate(-50%,-50%) rotate(3deg) scale(1.05);
  filter: drop-shadow(0 8px 16px rgba(0,0,0,.7));
}
#pm-drag-clone img, #pm-drag-clone .pm-fd { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }

/* ─── Hand ─── */
#pm-hand-wrap {
  flex: 0 0 auto;
  padding: 2px 12px 8px;
  background: linear-gradient(180deg, rgba(22,40,62,0) 0%, rgba(22,40,62,.85) 40%);
  border-top: 1px solid var(--border);
}
.pm-hand-label { margin-bottom: 2px; }
#zone-hand {
  display: flex; gap: 6px;
  min-height: calc(var(--hand-card-h) + 24px);
  align-items: flex-end;
  overflow-x: auto; overflow-y: hidden;
  padding-top: 24px;
}
#zone-hand .pm-card { width: var(--hand-card-w); height: var(--hand-card-h); }
#zone-hand.crowded .pm-card { margin-right: -34px; }
#zone-hand.crowded .pm-card:last-child { margin-right: 0; }
#zone-hand .pm-card:hover { z-index: 5; }
#zone-hand .pm-card:hover .pm-card-inner { transform: translateY(-18px); }
#zone-hand .pm-card.mulligan-selected:hover .pm-card-inner { transform: translateY(-18px); }

/* ─── Mulligan bar ─── */
#pm-mulligan-bar {
  position: fixed; left: 50%; bottom: 200px; transform: translateX(-50%);
  background: var(--panel2); border: 1px solid var(--gold);
  border-radius: 10px; padding: 10px 16px;
  display: flex; gap: 14px; align-items: center;
  z-index: 50;
  box-shadow: 0 6px 24px rgba(0,0,0,.6);
  font-size: .85rem;
}
#pm-mulligan-bar button {
  background: var(--gold); color: #0E1C2F; font-family: 'BeaufortBold';
  border: none; border-radius: 6px; padding: 7px 16px; cursor: pointer; font-size: .8rem;
}
#pm-mulligan-bar button:hover { background: #f5bc5a; }

/* ─── Deck picker ─── */
#deck-picker {
  position: fixed; inset: 0; z-index: 60;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.dp-panel {
  max-width: 560px; width: 100%;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 28px; text-align: center;
}
.dp-panel h1 { font-family: 'BeaufortBold'; color: var(--gold); margin: 0 0 8px; }
.dp-panel p { color: var(--blue); font-size: .85rem; }
.dp-input-row { display: flex; gap: 8px; margin: 16px 0 6px; }
.dp-input-row input {
  flex: 1; background: #0E1C2F; border: 1px solid var(--border); border-radius: 6px;
  color: #fff; padding: 9px 12px; font-family: inherit; font-size: .85rem;
}
.dp-input-row button {
  background: var(--gold); color: #0E1C2F; font-family: 'BeaufortBold';
  border: none; border-radius: 6px; padding: 9px 20px; cursor: pointer;
}
.dp-error { color: #FF6B6B; font-size: .8rem; min-height: 18px; }
#dp-my-decks { display: flex; flex-direction: column; gap: 5px; margin-top: 10px; max-height: 260px; overflow-y: auto; }
.dp-deck-btn {
  background: var(--panel2); border: 1px solid var(--border); border-radius: 6px;
  color: #F2F2F2; padding: 8px 12px; cursor: pointer; text-align: left; font-family: inherit;
  font-size: .82rem; display: flex; justify-content: space-between; gap: 8px;
}
.dp-deck-btn:hover { border-color: var(--gold); }
.dp-deck-btn .dp-deck-legend { color: var(--blue); font-size: .72rem; }
.dp-links a { color: #66CCFF; }

/* ─── Pile browser ─── */
#pile-browser {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(5,12,20,.8);
  display: flex; align-items: center; justify-content: center;
}
.pb-panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  max-width: 760px; width: 92%; max-height: 80vh;
  display: flex; flex-direction: column;
}
.pb-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  font-family: 'BeaufortBold'; color: var(--gold);
}
.pb-close { background: none; border: none; color: #fff; font-size: 1.4rem; cursor: pointer; }
#pb-cards {
  display: flex; flex-wrap: wrap; gap: 10px;
  padding: 14px; overflow-y: auto;
}
.pb-card { width: var(--card-w); text-align: center; }
.pb-card img { width: 100%; border-radius: 6px; display: block; }
.pb-card-actions { display: flex; gap: 3px; justify-content: center; margin-top: 3px; flex-wrap: wrap; }
.pb-card-actions button {
  background: var(--panel2); color: var(--blue); border: 1px solid var(--border);
  border-radius: 4px; font-size: .6rem; padding: 2px 5px; cursor: pointer; font-family: inherit;
}
.pb-card-actions button:hover { border-color: var(--gold); color: #fff; }
.pb-empty { color: #6d8aa5; padding: 10px; }

/* ─── Context menu ─── */
#pmContextMenu {
  position: fixed; z-index: 90;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  min-width: 160px; padding: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,.7);
}
#pmContextMenu button {
  display: block; width: 100%; text-align: left;
  background: none; border: none; color: #F2F2F2;
  padding: 6px 10px; cursor: pointer; font-size: .78rem; font-family: inherit;
  border-radius: 5px;
}
#pmContextMenu button:hover { background: #2A4F6E; color: var(--gold); }
#pmContextMenu .cm-sep { border-top: 1px solid var(--border); margin: 3px 0; }

/* ─── Hover preview ─── */
.pm-preview {
  position: fixed; z-index: 80; pointer-events: none;
  width: 300px;
  background: var(--panel); border: 1px solid var(--gold); border-radius: 10px;
  overflow: hidden;
  opacity: 0; transition: opacity .12s;
}
.pm-preview.visible { opacity: 1; }
.pm-preview img { width: 100%; display: block; }
.pm-preview.landscape { width: 460px; }
.pm-preview.landscape .pm-preview-img-wrap {
  width: 460px; height: 330px; position: relative; overflow: hidden;
}
.pm-preview.landscape .pm-preview-img-wrap img {
  width: 330px; position: absolute; left: 50%; top: 50%;
  transform: translate(-50%,-50%) rotate(90deg);
}
.pm-preview-info { padding: 8px 10px; }
.pm-preview-name { font-family: 'BeaufortBold'; font-size: .9rem; color: var(--gold); margin-bottom: 3px; }
.pm-preview-meta { font-size: .7rem; color: var(--blue); margin-bottom: 2px; }
.pm-preview-text { font-size: .7rem; color: #ccc; margin-top: 4px; line-height: 1.3; max-height: 90px; overflow-y: auto; }
.pm-preview-text img.rune-icon { height: 12px; vertical-align: middle; }

/* Tour help button: default bottom-left sits on the hand — move to bottom-right */
.tour-help-btn {
  bottom: 10px !important;
  left: auto !important;
  right: 10px !important;
  width: 34px !important;
  height: 34px !important;
}

/* ─── Mobile notice ─── */
#mobile-notice {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5,12,20,.94);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.mn-panel {
  background: var(--panel); border: 1px solid var(--gold); border-radius: 12px;
  padding: 26px; max-width: 380px; text-align: center;
}
.mn-panel h2 { font-family: 'BeaufortBold'; color: var(--gold); margin: 0 0 8px; }
.mn-panel p { color: var(--blue); font-size: .85rem; }
.mn-panel button {
  background: var(--gold); color: #0E1C2F; font-family: 'BeaufortBold';
  border: none; border-radius: 6px; padding: 10px 18px; cursor: pointer; margin: 10px 0 6px;
  display: block; width: 100%;
}
.mn-panel a { color: #66CCFF; font-size: .8rem; }

/* ─── Responsive degradation ─── */
@media (max-width: 1100px) {
  :root { --card-w: 76px; --card-h: 106px; --hand-card-w: 92px; --hand-card-h: 129px; }
  .pm-bf-card { width: 160px; height: 115px; }
  .pm-bf-card.bf-portrait img { width: 115px; height: 160px; }
  .pm-bf-slot { min-width: 168px; }
  #pm-main { grid-template-columns: 104px 1fr 210px; }
}
@media (max-width: 900px) {
  body { overflow-y: auto; height: auto; min-height: 100dvh; }
  #pm-main { display: flex; flex-direction: column; overflow: visible; }
  #pm-left-rail { flex-direction: row; justify-content: center; }
  #pm-right-rail { grid-template-columns: repeat(4, 1fr); }
  .pm-runepool-wrap { grid-column: 1 / -1; }
  #pm-battlefields { flex-wrap: wrap; }
}
