/*  DBTS main.css — board geometry, card/hand mechanics, spectator rules and dev tooling.
   All presentation chrome (boot, home hub, HUD, popups, zones skin) lives in theme.css (V 0.327+).  */

    :root {
      --bg: #090606;
      --panel: rgba(18, 18, 22, 0.92);
      --line: rgba(245, 238, 224, 0.88);
      --p1: #ff2323;
      --p2: #1597ff;
      --text: #f5f5f5;
      --muted: #b8b8b8;
      --gold: #ffd76a;
      --card-w: 82px;
      --card-h: 114px;
      --hand-card-w: 126px;
      --hand-card-h: 176px;
      --hand-dock-reveal: 54px;
      --hand-dock-bottom-pad: 14px;
      --hand-dock-card-clearance: 24px;
      --dbts-game-bottom-overscan: 0px;
    }

    * { box-sizing: border-box; }

    html, body {
      width: 100%;
      height: 100%;
      margin: 0;
      overflow: hidden;
      background: #080505;
      color: var(--text);
      font-family: Arial, Helvetica, sans-serif;
      user-select: none;
    }

    button, input, select, textarea { font-family: inherit; }

    #app {
      position: fixed;
      inset: 0;
      display: block;
      background: #080505;
    }

    #viewport {
      position: absolute;
      inset: 0;
      overflow: hidden;
      cursor: default;
    }

    #viewport.dragging-camera { cursor: move; }

    #table {
      position: absolute;
      left: 50%;
      top: 50%;
      width: var(--table-w, 1520px);
      height: var(--table-h, 980px);
      transform-origin: center center;
      background:
        linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px),
        linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px),
        #080505;
      background-size: 40px 40px, 40px 40px, 100% 100%;
      border: 2px solid rgba(255,255,255,0.12);
      box-shadow: 0 0 80px rgba(0,0,0,0.8);
    }

    .zone {
      position: absolute;
      border: 2px solid var(--line);
      background: rgba(0,0,0,0.1);
      box-shadow: inset 0 0 16px rgba(255,255,255,0.035);
      min-width: 48px;
      min-height: 48px;
      overflow: visible;
    }
    .zone[data-id*="union"] { isolation: isolate; }
    .zone.hand-zone, .zone.hand-zone.dev { display: none !important; }

    .zone.dev {
      display: block;
      cursor: move;
      outline: 1px dashed rgba(255, 215, 106, 0.8);
      background: rgba(255, 215, 106, 0.06);
    }

    .zone .resize-handle {
      display: none;
      position: absolute;
      width: 13px;
      height: 13px;
      right: -7px;
      bottom: -7px;
      border: 2px solid #111;
      background: var(--gold);
      cursor: nwse-resize;
      z-index: 20;
    }

    .zone.dev .resize-handle { display: block; }
    .zone.dev.selected-zone {
      box-shadow: 0 0 0 3px rgba(255, 214, 107, 0.95), 0 0 24px rgba(255, 214, 107, 0.55);
      border-color: #ffd66b;
    }

    .card {
      position: absolute;
      width: var(--card-w);
      height: var(--card-h);
      border-radius: 7px;
      border: 1px solid rgba(0,0,0,0.95);
      cursor: grab;
      transform-origin: center center;
      overflow: visible;
      z-index: 100;
    }

    .card.dragging {
      cursor: grabbing;
      z-index: 9999;
      box-shadow: 0 6px 14px rgba(0,0,0,0.6);
    }

    .card.stack-top {
      box-shadow: none;
    }

    /* Only Life cards receive hover feedback. The modest brightness and glow
       identify the exact exposed card without changing its stack order. */
    .card.life-card:hover:not(.dragging) {
      filter: brightness(1.16) drop-shadow(0 0 5px rgba(255,255,255,0.48));
    }

    .card.tapped { filter: none; }

    .card .front, .card .back,
    .hand-card .front, .hand-card .back {
      position: absolute;
      inset: 0;
      display: grid;
      place-items: center;
      text-align: center;
      padding: 8px;
      font-weight: 900;
      line-height: 1.15;
      overflow: hidden;
      border-radius: inherit;
    }

    .card .front { font-size: 11px; }
    .hand-card .front { font-size: 13px; padding: 10px; }

    .card .front, .hand-card .front {
      background: #07070a;
      color: #ccc;
    }

    .card .back, .hand-card .back {
      background:
        radial-gradient(circle, rgba(255,255,255,0.08), transparent 35%),
        repeating-linear-gradient(45deg, #111, #111 8px, #1c0b0b 8px, #1c0b0b 16px);
      color: white;
      letter-spacing: 1px;
    }

    .card img, .hand-card img {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      object-fit: cover;
      pointer-events: none;
      z-index: 2;
      image-rendering: high-quality;
      -webkit-image-rendering: -webkit-optimize-contrast;
    }

    /* Let the browser composite cards naturally — transform-style: preserve-3d
       forces a flattening pass that often blurs sub-pixel rendered images */
    .card {
      -webkit-font-smoothing: antialiased;
    }

    .fallback-name {
      position: relative;
      z-index: 1;
      padding: 4px;
      word-break: break-word;
    }

    .card-art-retry-label {
      position: absolute;
      inset: 0;
      display: grid;
      place-items: center;
      padding: 8px;
      background: linear-gradient(180deg, rgba(5,8,18,.94), rgba(8,12,28,.98));
      color: rgba(255,255,255,.78);
      font-size: 9px;
      line-height: 1.25;
      text-align: center;
      text-transform: uppercase;
      pointer-events: none;
    }

    .pile-count {
      display: none;
    }

    /* Stack count tooltip */
    #stackTooltip {
      position: fixed;
      z-index: 99990;
      pointer-events: none;
      background: rgba(8,8,14,0.92);
      border: 1px solid rgba(255,255,255,0.2);
      border-radius: 7px;
      padding: 4px 9px;
      font-size: 12px;
      font-weight: 900;
      color: #fff;
      white-space: nowrap;
      display: none;
      backdrop-filter: blur(8px);
      box-shadow: 0 4px 14px rgba(0,0,0,0.6);
    }

    /* V 0.324 — independent browser-bottom hand layer. It uses authored
       2048px coordinates and the same uniform game scale, but its bottom edge
       is the REAL browser viewport instead of the letterboxed game stage. */
    #handBrowserOverlay {
      position: fixed;
      left: 50%;
      bottom: 0;
      width: 2048px;
      height: calc(var(--hand-card-h) + var(--hand-dock-card-clearance) + var(--hand-dock-bottom-pad));
      transform: translateX(-50%) scale(var(--dbts-game-scale));
      transform-origin: center bottom;
      overflow: visible;
      pointer-events: none;
      z-index: 9400;
    }

    #handDock {
      position: absolute;
      left: var(--game-left-gutter, 0px);
      right: var(--game-right-gutter, 0px);
      bottom: 0;
      height: calc(var(--hand-card-h) + var(--hand-dock-card-clearance) + var(--hand-dock-bottom-pad));
      /* Large hands may extend into the left UI gutter. Keep the cards above
         Match Chat and Game History so they remain visible and selectable. */
      z-index: 9400;
      pointer-events: none;
      display: flex;
      justify-content: center;
      align-items: flex-end;
      padding: 0 28px var(--hand-dock-bottom-pad);
      background: transparent;
      overflow: visible;
      transform: translateY(calc(var(--hand-card-h) + var(--hand-dock-card-clearance) - var(--hand-dock-reveal)));
      transition: transform 0.38s cubic-bezier(0.22, 1.3, 0.36, 1);
    }

    #handDock.hand-open,
    #handDock.hand-drop-open {
      transform: translateY(0);
    }

    /* A card leaving the hand retracts the hand immediately. If that card
       later returns to a valid hand drop, hand-drop-open wins and raises it. */
    #handDock.hand-drag-out {
      transform: translateY(calc(var(--hand-card-h) + var(--hand-dock-card-clearance) - var(--hand-dock-reveal)));
    }
    #handDock.hand-drag-out.hand-drop-open { transform: translateY(0); }

    /* No hover effect while collapsed */
    #handDock:not(.hand-open):not(.hand-drop-open) .hand-card:hover {
      scale: 1 !important;
      --hand-shift-x: 0px !important;
      --hand-shift-y: 0px !important;
      box-shadow: 0 12px 26px rgba(0,0,0,0.7) !important;
    }

    #handFan {
      position: relative;
      height: calc(var(--hand-card-h) + var(--hand-dock-card-clearance));
      width: min(100%, 980px);
      pointer-events: none;
      overflow: visible;
    }

    .hand-card {
      pointer-events: auto;
      position: absolute;
      width: var(--hand-card-w);
      height: var(--hand-card-h);
      bottom: 0;
      left: 50%;
      border-radius: 10px;
      border: 1px solid rgba(0,0,0,0.95);
      cursor: grab;
      overflow: hidden;
      transform-origin: center bottom;
      scale: 1;
      translate: var(--hand-shift-x, 0px) var(--hand-shift-y, 0px);
      /* Lift animates independently from the JS-set row position. */
      transition: scale 0.22s cubic-bezier(0.34, 1.1, 0.64, 1),
                  translate 0.18s cubic-bezier(0.34, 1.1, 0.64, 1),
                  box-shadow 0.18s ease;
    }

    .hand-card:hover,
    .hand-card.hand-hover {
      scale: 1;
      --hand-shift-y: -24px;
      box-shadow: 0 14px 32px rgba(0,0,0,0.86), 0 0 16px rgba(255,215,106,0.16);
    }

    @keyframes stackSearchPulse {
      0%, 100% { filter: brightness(1); box-shadow: 0 0 8px rgba(255,211,88,0.35); }
      50% { filter: brightness(1.3); box-shadow: 0 0 18px 5px rgba(255,211,88,0.8); }
    }
    .card.stack-searching {
      overflow: visible;
      animation: stackSearchPulse 1.05s ease-in-out infinite !important;
    }
    .stack-search-badge {
      position: absolute; left: 50%; top: -25px; transform: translateX(-50%);
      z-index: 20; min-width: 72px; padding: 4px 9px;
      border: 2px solid #ffd45e; border-radius: 999px;
      background: rgba(5,7,12,0.96); color: #ffd45e;
      font-size: 11px; font-weight: 1000; text-align: center;
      white-space: nowrap; pointer-events: none;
      box-shadow: 0 0 12px rgba(255,212,94,0.7);
      transform-origin: 50% 50%;
    }
    @keyframes spectatorLivePulse { 50% { opacity:.48; box-shadow:0 0 16px #56ef80; } }

    /* Spectators use the ordinary Player 1 presentation. The only visual
       difference is that both hand rows are rendered as concealed card backs.
       Do not override #table here: sharing Player 1's normal table rules keeps
       the felt, edge glow, zone glow and divider visually identical. */
    body.spectator-mode #table .divider { display:block !important; }
    body.spectator-mode #handDock {
      display:flex;
      transform:translateY(0);
      pointer-events:none;
    }
    body.spectator-mode #opponentHandDock {
      display:flex;
      height:90px;
      pointer-events:none;
    }
    body.spectator-mode #opponentFan { height:90px; }
    body.spectator-mode .opp-card {
      width:52px;
      height:72px;
      opacity:.82;
      cursor:default;
      box-shadow:none;
    }
    /* Board zones stay inert, while visible cards accept only the spectator
       inspection click installed by attachCardHandlers(). */
    body.spectator-mode #table .zone { pointer-events:none !important; }
    body.spectator-mode #table .card {
      pointer-events:auto !important;
      cursor:pointer;
    }

    .hand-card.dragging { opacity: 0.25; }
    .hand-card.hand-reordering {
      opacity: 1;
      z-index: 9999 !important;
      pointer-events: none;
      transition: none;
      translate: 0 -24px;
      box-shadow: 0 18px 38px rgba(0,0,0,0.9), 0 0 18px rgba(255,215,106,0.28);
    }

    .hand-label { display: none !important; }

    .dbscg-card-back {
      position: absolute;
      inset: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 8%;
      overflow: hidden;
      border-radius: inherit;
      background:
        radial-gradient(circle at 50% 38%, rgba(255,132,22,0.34), transparent 38%),
        repeating-linear-gradient(135deg, rgba(255,255,255,0.025) 0 5px, transparent 5px 10px),
        linear-gradient(155deg, #2c0704, #080809 48%, #160201);
      box-shadow: inset 0 0 0 4px #050505, inset 0 0 0 6px rgba(214,66,24,0.75), inset 0 0 22px #000;
    }

    .dbscg-card-back.z-back {
      background:
        radial-gradient(circle at 50% 42%, rgba(89,198,255,0.38), transparent 40%),
        repeating-linear-gradient(135deg, rgba(255,255,255,0.04) 0 5px, transparent 5px 10px),
        linear-gradient(155deg, #06182d, #08090d 48%, #140528);
      box-shadow: inset 0 0 0 4px #050505, inset 0 0 0 6px rgba(92,192,255,0.78), inset 0 0 22px #000;
    }

    .dbscg-card-back .card-back-art {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      display: block;
      object-fit: fill;
      border-radius: inherit;
    }

    .back-orbs { display:grid; grid-template-columns:repeat(4, 1fr); gap:3px; width:64%; }
    .back-orb {
      aspect-ratio:1;
      border-radius:50%;
      display:grid;
      place-items:center;
      color:#b51b08;
      font-size:clamp(5px, 0.7em, 11px);
      font-weight:1000;
      background:radial-gradient(circle at 35% 28%, #fff8aa 0 8%, #ffba24 24%, #f2670a 68%, #8e1705 100%);
      box-shadow:0 0 7px rgba(255,135,22,0.85), inset -2px -2px 3px rgba(70,0,0,0.55);
    }
    .back-title { width:76%; text-align:center; color:#fff4dd; font-weight:1000; font-size:clamp(7px, 0.9em, 15px); line-height:0.96; letter-spacing:-0.04em; text-shadow:0 2px 2px #000, 0 0 7px #e34b13; }
    .z-back .back-title { color:#eaf8ff; text-shadow:0 2px 2px #000, 0 0 8px #36b8ff; }
    .z-back .back-orbs { display:none; }
    .z-mark { display:none; font-size:clamp(28px, 4em, 68px); font-weight:1000; font-style:italic; color:#fff; text-shadow:4px 4px 0 #4b26a8, 0 0 14px #36b8ff; }
    .z-back .z-mark { display:block; }

    /* ── Opponent hand (face-down strip at top) ── */
    #opponentHandDock {
      position: fixed;
      left: var(--game-left-gutter, 0px);
      right: var(--game-right-gutter, 0px);
      top: 0;
      height: 90px;
      z-index: 7900;
      pointer-events: auto;
      display: flex;
      justify-content: center;
      align-items: flex-start;
      padding: 6px 28px 0;
    }

    #opponentFan {
      position: relative;
      height: 90px;
      width: min(100%, 880px);
    }

    #opponentHandCount {
      position: absolute;
      top: 96px;
      left: 50%;
      transform: translate(-50%, -5px);
      padding: 5px 10px;
      border: 1px solid rgba(255, 214, 105, 0.38);
      border-radius: 999px;
      background: rgba(8, 10, 18, 0.94);
      color: #ffe6a0;
      font-size: 11px;
      font-weight: 900;
      letter-spacing: 0.04em;
      text-transform: uppercase;
      white-space: nowrap;
      opacity: 0;
      pointer-events: none;
      transition: opacity 120ms ease, transform 120ms ease;
      box-shadow: 0 6px 18px rgba(0,0,0,0.55);
    }

    #opponentHandDock:hover #opponentHandCount {
      opacity: 1;
      transform: translate(-50%, 0);
    }

    .opp-card {
      position: absolute;
      width: 52px;
      height: 72px;
      border-radius: 5px;
      border: 1px solid rgba(0,0,0,0.8);
      overflow: hidden;
      transform-origin: center top;
      opacity: 0.82;
    }

    .opp-card img {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    /* Fallback style if back.jpg not loaded */
    .opp-card .opp-back {
      width: 100%;
      height: 100%;
      background:
        radial-gradient(circle, rgba(255,255,255,0.06), transparent 35%),
        repeating-linear-gradient(45deg, #111, #111 4px, #1c0b0b 4px, #1c0b0b 8px);
    }

    body.spectator-mode #handDock {
      --hand-dock-reveal: 24px;
      --hand-dock-bottom-pad: 6px;
      --hand-dock-card-clearance: 18px;
      height: calc(72px + var(--hand-dock-card-clearance) + var(--hand-dock-bottom-pad));
      padding: 0 28px var(--hand-dock-bottom-pad);
    }
    body.spectator-mode #handFan {
      height: calc(72px + var(--hand-dock-card-clearance));
      width: min(100%, 880px);
    }
    body.spectator-mode .hand-card,
    body.spectator-mode .opp-card {
      width: 52px;
      height: 72px;
      border-radius: 5px;
      opacity: .82;
      cursor: default;
      box-shadow: none;
      pointer-events: none;
    }
    body.spectator-mode .hand-card:hover,
    body.spectator-mode .hand-card.hand-hover {
      --hand-shift-x: 0px;
      --hand-shift-y: 0px;
      scale: 1;
      translate: 0 0;
      box-shadow: none;
    }
    body.spectator-mode #opponentHandDock {
      height: 90px;
      pointer-events: none;
    }
    body.spectator-mode #opponentFan { height: 90px; }
    .multiplayer-private { margin-top:14px; }
    .multiplayer-private summary { cursor:pointer; color:#ffd76a; font-weight:850; padding:12px 14px; border:1px solid rgba(255,188,48,.24); border-radius:10px; background:rgba(255,255,255,.035); }
    .multiplayer-private[open] summary { margin-bottom:10px; }
    .multiplayer-private-content { padding:12px; border:1px solid rgba(255,255,255,.09); border-radius:10px; background:rgba(3,5,12,.55); }

    .panel {
      background: rgba(255,255,255,0.055);
      border: 1px solid rgba(255,255,255,0.13);
      border-radius: 8px;
      padding: 12px;
      margin-bottom: 12px;
    }

    .panel h2, .panel h3 { margin: 0 0 10px; letter-spacing: 0.5px; }
    .panel h2 { font-size: 20px; }
    .panel h3 { font-size: 15px; color: #e9e9e9; }
    .dev-tools-locked {
      opacity: 0.34;
      filter: grayscale(1);
      pointer-events: none;
      user-select: none;
    }
    .dev-tools-locked > summary { color: #aaa; cursor: not-allowed; }
    .dev-tools-locked > summary::after {
      content: 'LOCKED';
      float: right;
      padding: 2px 7px;
      border: 1px solid rgba(255,255,255,0.35);
      border-radius: 3px;
      color: #bbb;
      font-size: 9px;
      letter-spacing: 1px;
    }

    .row {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 8px;
      margin-bottom: 8px;
    }

    .row.three { grid-template-columns: 1fr 1fr 1fr; }
    .row.one { grid-template-columns: 1fr; }

    button, select, input, textarea {
      width: 100%;
      border: 1px solid rgba(255,255,255,0.25);
      background: linear-gradient(#2c2c34, #15151a);
      color: #fff;
      border-radius: 8px;
      padding: 9px 10px;
      font-weight: 800;
      outline: none;
    }

    button { cursor: pointer; text-transform: uppercase; font-size: 12px; }
    button:hover { filter: brightness(1.18); }
    button.active { background: linear-gradient(#ffcd43, #8b5d00); color: #111; }
    button.red { background: linear-gradient(#ff3333, #8e0505); }
    button.blue { background: linear-gradient(#2ca8ff, #034e90); }
    button.gold { background: linear-gradient(#ffd962, #8a6100); color: #161006; }

    input, textarea, select { font-weight: 700; text-transform: none; background: #101015; }

    textarea {
      min-height: 110px;
      resize: vertical;
      font-family: Consolas, monospace;
      font-size: 12px;
      user-select: text;
    }

    .small-note { color: var(--muted); font-size: 12px; line-height: 1.35; margin-top: 6px; }

    .audio-control {
      display: grid;
      grid-template-columns: auto minmax(160px, 1fr) 48px;
      align-items: center;
      gap: 12px;
    }
    .audio-control label {
      color: #eee;
      font-size: 12px;
      font-weight: 900;
      text-transform: uppercase;
      white-space: nowrap;
    }
    .audio-control input[type="range"] {
      height: 7px;
      padding: 0;
      border: 0;
      border-radius: 999px;
      appearance: none;
      background: linear-gradient(90deg, #1d93f2, #f23434);
      cursor: pointer;
    }
    .audio-control input[type="range"]::-webkit-slider-thumb {
      width: 18px;
      height: 18px;
      border: 2px solid #fff;
      border-radius: 50%;
      appearance: none;
      background: #1d93f2;
      box-shadow: 0 0 10px rgba(29,147,242,0.7);
    }
    .audio-control output {
      color: var(--gold);
      font-size: 12px;
      font-weight: 900;
      text-align: right;
    }

    .camera-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 8px;
      margin-bottom: 8px;
    }

    .camera-field span {
      display: block;
      margin: 0 0 4px;
      color: #ddd;
      font-size: 11px;
      font-weight: 900;
      text-transform: uppercase;
    }

    .counter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

    .counter {
      padding: 10px;
      border-radius: 8px;
      background: rgba(0,0,0,0.25);
      border: 1px solid rgba(255,255,255,0.12);
      text-align: center;
    }

    .counter .value { font-size: 42px; font-weight: 900; line-height: 1; }
    .counter.p1 .value { color: var(--p1); }
    .counter.p2 .value { color: var(--p2); }
    .counter .label { font-size: 11px; color: #ddd; font-weight: 900; text-transform: uppercase; }

    .meta-chip {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 7px 10px;
      border-radius: 999px;
      background: rgba(255,255,255,0.06);
      border: 1px solid rgba(255,255,255,0.10);
      color: #f3efe8;
      font-size: 12px;
      font-weight: 800;
      line-height: 1;
      white-space: nowrap;
    }

    .meta-chip .label {
      color: var(--gold);
      font-size: 10px;
      letter-spacing: 0.45px;
      text-transform: uppercase;
      font-weight: 900;
    }

    .energy-badge {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 22px;
      height: 22px;
      border-radius: 999px;
      color: #fff;
      font-size: 12px;
      font-weight: 900;
      box-shadow: inset 0 1px 0 rgba(255,255,255,0.24), 0 1px 6px rgba(0,0,0,0.22);
    }

    .energy-badge.red { background: #cf3d32; }
    .energy-badge.blue { background: #2e65cc; }
    .energy-badge.green { background: #2aa94e; }
    .energy-badge.yellow { background: #c79c1b; }
    .energy-badge.black { background: #222; border: 1px solid rgba(255,255,255,0.18); }
    .energy-badge.white { background: #b9b9c7; color: #111; }
    .energy-badge.gray { background: #666; }

    .skill-paragraph {
      margin: 0 0 12px;
    }

    .skill-paragraph:last-child { margin-bottom: 0; }

    .skill-chip {
      display: inline-block;
      margin: 0 8px 6px 0;
      white-space: nowrap;
      padding: 6px 12px;
      border-radius: 999px;
      color: #fff7e8;
      font-weight: 900;
      font-size: 13px;
      line-height: 1;
      vertical-align: middle;
      box-shadow: inset 0 1px 0 rgba(255,255,255,0.22), 0 4px 10px rgba(0,0,0,0.20);
      letter-spacing: 0.1px;
    }

    .skill-chip.auto { background: linear-gradient(180deg, #2f6fe7, #1d4fb2); }
    .skill-chip.activate { background: linear-gradient(180deg, #dc7727, #b85613); }
    .skill-chip.counter { background: linear-gradient(180deg, #21b56b, #15864d); }
    .skill-chip.permanent { background: linear-gradient(180deg, #e24aa6, #b8297c); }
    .skill-chip.limit { background: linear-gradient(180deg, #d84848, #aa2d2d); }
    .skill-chip.once { background: linear-gradient(180deg, #d84848, #aa2d2d); }
    .skill-chip.keyword { background: linear-gradient(180deg, #d84848, #aa2d2d); }
    .skill-chip.awaken { background: linear-gradient(180deg, #f0c33c, #c99416); color: #17110a; }
    .skill-chip.neutral { background: linear-gradient(180deg, #666c78, #4c525d); }
    .skill-chip.unison { background: linear-gradient(180deg, #707782, #555c66); }
    .skill-chip.field { background: linear-gradient(180deg, #27b56e, #168a4e); }
    .skill-chip.condition { background: linear-gradient(180deg, #d84848, #aa2d2d); }
    .card-ref { font-style: italic; color: rgba(255,255,255,0.9); }

    .inline-energy {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      min-width: 24px;
      height: 24px;
      padding: 0 6px;
      margin: 0 4px;
      border-radius: 999px;
      font-size: 13px;
      font-weight: 900;
      line-height: 1;
      color: #fff;
      vertical-align: baseline;
      box-shadow: inset 0 1px 0 rgba(255,255,255,0.25), 0 1px 6px rgba(0,0,0,0.24);
    }

    .inline-energy.red { background: #cf3d32; }
    .inline-energy.blue { background: #2e65cc; }
    .inline-energy.green { background: #2aa94e; }
    .inline-energy.yellow { background: #c79c1b; }
    .inline-energy.black { background: #222; border: 1px solid rgba(255,255,255,0.18); }
    .inline-energy.white { background: #b9b9c7; color: #111; }
    .inline-energy.gray {
      background: radial-gradient(circle at 35% 28%, #f2f2f2 0%, #d6d6d6 30%, #9a9a9a 62%, #5e6570 100%);
      color: #111;
      border: 1px solid rgba(255,255,255,0.35);
      text-shadow: none;
    }
    .die-player { display: flex; flex-direction: column; align-items: center; gap: 10px; }
    .die-player-label { font-size: 13px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.6px; }
    .die-player.red .die-player-label { color: #ff5a5a; }
    .die-player.blue .die-player-label { color: #58adff; }

    .simulated-die {
      width: 132px;
      height: 132px;
      display: grid;
      place-items: center;
      border-radius: 24px;
      color: #fff;
      font-family: Georgia, serif;
      font-size: 96px;
      line-height: 1;
      text-shadow: 0 4px 10px rgba(0,0,0,0.48);
      box-shadow: inset 0 2px 0 rgba(255,255,255,0.32), inset 0 -8px 18px rgba(0,0,0,0.30), 0 14px 30px rgba(0,0,0,0.46);
    }
    .simulated-die.red { background: linear-gradient(145deg, #ff5555, #9d1111); }
    .simulated-die.blue { background: linear-gradient(145deg, #51adff, #12509f); }
    .simulated-die.rolling { animation: dieShake 0.18s linear infinite alternate; }
    @keyframes dieShake {
      from { transform: translate(-3px, 2px) rotate(-4deg) scale(0.98); }
      to { transform: translate(3px, -2px) rotate(4deg) scale(1.02); }
    }
    .hidden { display: none !important; }

    /* Animated centre divider */
    @keyframes divShimmer {
      0%   { transform: translateX(-120%); }
      100% { transform: translateX(120%); }
    }

    /* Particle canvas overlay */
    #particleCanvas {
      position: absolute;
      inset: 0;
      display: block;
      width: 100%;
      height: 100%;
      pointer-events: none;
      z-index: 50;
    }

    /* Ki effects (Tab ping/beam) — same coordinate space as particleCanvas,
       but stacked above every card so bursts and beams read on top of the board. */
    #kiCanvas {
      position: absolute;
      inset: 0;
      display: block;
      width: 100%;
      height: 100%;
      pointer-events: none;
      z-index: 100000;
    }

    /* ─── Card animations ─── */
    .card { }

    @keyframes cardDrawIn {
      from { opacity: 0; filter: brightness(2.5); }
      to   { opacity: 1; filter: brightness(1); }
    }
    .card.anim-draw {
      animation: cardDrawIn 0.32s ease-out;
    }

    @keyframes cardPlayIn {
      0%   { opacity: 1; filter: brightness(2); }
      60%  { opacity: 1; filter: brightness(1.2); }
      100% { opacity: 1; filter: brightness(1); }
    }
    .card.anim-play {
      animation: cardPlayIn 0.28s ease-out;
    }

    @keyframes cardTapPop {
      0%   { filter: brightness(1); }
      30%  { filter: brightness(2.2); }
      100% { filter: brightness(1); }
    }
    .card.anim-tap {
      animation: cardTapPop 0.3s ease-out;
    }

    @keyframes cardFlipReveal {
      0%   { filter: brightness(1); }
      25%  { filter: brightness(3.5); }
      55%  { filter: brightness(3.5); }
      100% { filter: brightness(1); }
    }
    .card.anim-flip {
      animation: cardFlipReveal 0.38s ease-out;
    }

    @keyframes cardShuffleFront {
      0%   { translate: 0 0; rotate: 0deg; }
      42%  { translate: -18px -3px; rotate: 190deg; }
      100% { translate: 0 0; rotate: 360deg; }
    }
    @keyframes cardShuffleBack {
      0%, 16% { translate: 0 0; rotate: 0deg; }
      58%     { translate: 18px 3px; rotate: -190deg; }
      100%    { translate: 0 0; rotate: -360deg; }
    }
    .card.anim-shuffle-front { animation: cardShuffleFront 0.68s ease-in-out; }
    .card.anim-shuffle-back  { animation: cardShuffleBack 0.78s ease-in-out; }

    /* Better dragging feel */
    .card.dragging {
      box-shadow: 0 6px 14px rgba(0,0,0,0.6) !important;
      scale: 1.02;
      transition: scale 0.1s ease;
    }

    /* ── Union zone counter ── */
    .union-counter {
      position: absolute;
      bottom: -12px;
      left: 0;
      right: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 3px;
      z-index: 5;
      pointer-events: none;
      opacity: 0;
      will-change: opacity;
      transform: translateZ(0);
    }
    .union-counter button {
      width: 18px;
      height: 18px;
      padding: 0;
      border: 1px solid rgba(255,255,255,0.25);
      border-radius: 4px;
      background: rgba(10,10,16,0.82);
      color: rgba(255,255,255,0.85);
      font-size: 13px;
      font-weight: 900;
      line-height: 1;
      cursor: pointer;
      backdrop-filter: blur(4px);
      display: grid;
      place-items: center;
      transition: background 0.1s;
    }
    .union-counter button:hover { background: rgba(255,255,255,0.15); }
    .union-counter.readonly {
      opacity: 1;
    }
    .union-counter .uc-val {
      min-width: 22px;
      text-align: center;
      font-size: 12px;
      font-weight: 900;
      color: #fff;
      background: rgba(10,10,16,0.82);
      border: 1px solid rgba(255,255,255,0.2);
      border-radius: 4px;
      padding: 1px 3px;
      backdrop-filter: blur(4px);
    }

    /* Temporary power and skill markers attached to cards in play. */
    .card-modifier-anchor {
      position: absolute;
      width: 0;
      height: 0;
      transform-origin: center;
      pointer-events: none;
    }
    .card-modifier-markers {
      position: absolute;
      left: 0;
      top: 0;
      width: max-content;
      max-width: 150px;
      transform: translateX(-50%);
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      gap: 3px;
      pointer-events: none;
    }
    .card-modifier-marker {
      min-height: 18px;
      padding: 2px 6px;
      border: 1px solid rgba(255,255,255,.25);
      border-radius: 4px;
      background: rgba(10,10,16,.92);
      color: #fff;
      font-size: 10px;
      font-weight: 900;
      line-height: 1.15;
      white-space: nowrap;
      box-shadow: 0 3px 9px rgba(0,0,0,.65);
      backdrop-filter: blur(4px);
    }
    .card-modifier-marker.power.positive { color: #8cffb0; border-color: rgba(85,230,132,.5); }
    .card-modifier-marker.power.negative { color: #ff9999; border-color: rgba(255,92,92,.55); }
    .card-modifier-marker.skill { color: #fff; border-color: rgba(255,255,255,.7); }

    /* Dev selection box */
    .selection-box {
      position: absolute;
      pointer-events: none;
      border: 2px dashed rgba(255,214,107,0.85);
      background: rgba(255,214,107,0.05);
      z-index: 9999;
    }

    /* Card lasso selection box (non-dev) */
    .card-lasso-box {
      position: fixed;
      pointer-events: none;
      border: 2px dashed rgba(255,255,255,0.85);
      background: rgba(255,255,255,0.04);
      z-index: 9999;
    }

    /* Selected card highlight - outline is not affected by overflow:hidden */
    .card.card-selected,
    .hand-card.card-selected {
      outline: 2px solid rgba(255,255,255,0.95);
      outline-offset: 2px;
      box-shadow: 0 0 16px rgba(255,255,255,0.55), 0 0 4px rgba(255,255,255,0.3) !important;
    }
    #cardModifierOverlay {
      position: fixed;
      inset: 0;
      z-index: 99995;
      display: none;
      align-items: center;
      justify-content: center;
      background: rgba(0,0,0,0.65);
      backdrop-filter: blur(6px);
    }
    #cardModifierOverlay.show { display: flex; }
    #cardModifierOverlay {
      overflow: auto;
      padding: 32px 20px;
      box-sizing: border-box;
    }
    .deck-import-help {
      margin:0 0 8px;
      color:rgba(255,255,255,.68);
      font-size:12px;
      line-height:1.5;
    }
    /* Horizontal card images — rotating wrapper so img has no transform of its own,
       preventing double-composite blur when the card moves */
    .h-card-wrap {
      position: absolute;
      width: var(--card-h);
      height: var(--card-w);
      top: 50%;
      left: 50%;
      transform: translate3d(-50%, -50%, 0) rotate(90deg);
      overflow: hidden;
      z-index: 2;
      pointer-events: none;
      will-change: transform;
      backface-visibility: hidden;
    }
    .h-card-wrap img {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
    /* A horizontal-art card in Battle is represented by a tapped outer card.
       Counter-rotate the inner horizontal artwork so the two rotations cancel
       instead of making Z-Extras appear upside down on either player's mat. */
    .card.tapped .h-card-wrap {
      transform: translate3d(-50%, -50%, 0) rotate(-90deg);
    }

    .hand-reveal-badge {
      position: absolute;
      left: 50%;
      top: 2px;
      z-index: 9005;
      display: none;
      transform: translateX(-50%);
      min-width: 132px;
      padding: 5px 11px;
      border: 2px solid #ffd45e;
      border-radius: 999px;
      background: rgba(5,7,12,.97);
      color: #ffd45e;
      font-size: 11px;
      font-weight: 1000;
      text-align: center;
      text-transform: uppercase;
      white-space: nowrap;
      pointer-events: none;
      box-shadow: 0 0 14px rgba(255,212,94,.72);
      animation: stackSearchPulse 1.05s ease-in-out infinite;
    }
    .hand-reveal-badge.show { display: block; }
    #opponentHandDock.hand-is-revealed {
      height: 132px;
    }
    #opponentHandDock.hand-is-revealed .opp-card {
      width: 72px;
      height: 101px;
      opacity: 1;
      cursor: pointer;
      box-shadow: 0 8px 20px rgba(0,0,0,.75), 0 0 10px rgba(255,212,94,.2);
    }
    #opponentHandDock.hand-is-revealed #opponentHandCount { top: 118px; }
    :root {
      --playmat-ui-line: rgba(240,235,220,.92);
      --playmat-ui-bg: rgba(8,5,5,.96);
      --playmat-ui-label-bg: #080505;
      --playmat-ui-muted-line: rgba(240,235,220,.32);
    }
    .panel {
      border-radius: 0;
    }
    .panel {
      border-color: var(--playmat-ui-muted-line);
      background: rgba(255,255,255,.025);
      box-shadow: inset 0 0 12px rgba(255,255,255,.02);
    }
    .multiplayer-private summary,
    .multiplayer-private-content {
      border-radius: 0;
      border-color: var(--playmat-ui-muted-line);
      background: rgba(0,0,0,.26);
    }
    .multiplayer-private summary {
      color: #f0ebe0;
      text-transform: uppercase;
      letter-spacing: .06em;
    }
    .meta-chip {
      border-radius: 0;
      border-color: var(--playmat-ui-muted-line);
      background: rgba(255,255,255,.025);
    }

    /* Remaining playmat-style status UI */
    #opponentHandCount,
    .hand-reveal-badge {
      border: 2px solid var(--playmat-ui-line);
      border-radius: 0;
      color: #f0ebe0;
      background: var(--playmat-ui-bg);
      box-shadow: inset 0 0 12px rgba(255,255,255,.035), 0 0 12px rgba(255,255,255,.2);
      text-shadow: 0 1px 3px #000;
    }

    @keyframes stackSearchPulse {
      0%, 100% {
        filter: brightness(1);
        box-shadow: 0 0 8px rgba(255,255,255,.32);
      }
      50% {
        filter: brightness(1.22);
        box-shadow: 0 0 18px 5px rgba(255,255,255,.72);
      }
    }
    .card.stack-searching {
      animation: stackSearchPulse 1.05s ease-in-out infinite !important;
    }
    .stack-search-badge {
      border: 2px solid var(--playmat-ui-line);
      border-radius: 0;
      color: #f0ebe0;
      background: var(--playmat-ui-bg);
      box-shadow: 0 0 12px rgba(255,255,255,.48);
    }

    /*
      PLAYMAT-STYLE DICE LANES
      Each player gets the same square black field and exact seat color used
      by the corresponding playmat zones.
    */
    .die-player {
      position: relative;
      min-width: 0;
      padding: 24px 14px 14px;
      border: 2px solid var(--dice-seat-line);
      border-radius: 0;
      background: rgba(8,5,5,.96);
      box-shadow: inset 0 0 16px rgba(255,255,255,.035);
    }
    .die-player.red {
      --dice-seat-line: rgba(255,55,55,.95);
      --dice-seat-solid: #ff3737;
      --dice-seat-dark: #9a1717;
    }
    .die-player.blue {
      --dice-seat-line: rgba(30,155,255,.95);
      --dice-seat-solid: #1e9bff;
      --dice-seat-dark: #14558f;
    }
    .die-player-label {
      position: absolute;
      z-index: 4;
      top: -10px;
      left: 50%;
      transform: translateX(-50%);
      padding: 0 12px;
      color: var(--dice-seat-line) !important;
      background: #080505;
      line-height: 20px;
      white-space: nowrap;
    }

    /*
      The dice themselves use the playmat language too: a larger square black
      field with the exact red or blue seat outline.
    */
    .die-player .simulated-die {
      width: min(320px, 100%);
      height: auto;
      aspect-ratio: 1;
      border: 0;
      border-radius: 0;
      color: #fff;
      background: rgba(8,5,5,.96) !important;
      font-size: 280px;
      text-shadow: 0 2px 8px rgba(0,0,0,.65);
      box-shadow: none;
    }
    .card-modifier-marker.skill {
      color: #fff;
      border-color: rgba(255,255,255,.7);
    }

    .card-custom-counter {
      position: absolute;
      top: 0;
      left: 0;
      display: flex;
      align-items: center;
      gap: 3px;
      transform: translateX(-50%);
      pointer-events: auto;
    }
    .card-custom-counter button,
    .card-custom-counter span {
      display: grid;
      place-items: center;
      height: 18px;
      min-width: 18px;
      padding: 0 3px;
      border: 1px solid rgba(255,255,255,.25);
      border-radius: 4px;
      color: #fff;
      background: rgba(10,10,16,.9);
      font-size: 12px;
      font-weight: 900;
      line-height: 1;
      box-sizing: border-box;
      backdrop-filter: blur(4px);
    }
    .card-custom-counter button {
      width: 18px;
      cursor: pointer;
    }
    .card-custom-counter button:hover {
      border-color: #fff;
      background: rgba(255,255,255,.18);
    }
.die-player-label {
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  line-height: 1 !important;
}
.die-player-label {
  top: calc(-0.5em - 1px) !important;
}
:root { --game-toolbar-top: 72px; --game-toolbar-step: 64px; }
@media (max-width: 1100px) {
  :root { --game-toolbar-top: 68px; }
}
:root {
  --game-toolbar-top: 18px;
  --game-toolbar-step: 64px;
}
.zone,
.die-player {
  overflow: visible;
}

.die-player-label {
  position: absolute !important;
  top: 0 !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  margin: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  background: #080505 !important;
  line-height: 1 !important;
}

.die-player-label {
  z-index: 5 !important;
}
.die-player-label {
  white-space: nowrap;
}
.deck-import-divider {
  position: relative;
  height: 18px;
  margin: 2px 0 10px;
  border-top: 1px solid rgba(255,255,255,.34);
  text-align: center;
}
.deck-import-divider span {
  position: relative;
  top: -8px;
  padding: 0 10px;
  color: rgba(255,255,255,.65);
  background: #080505;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

    /* Spectators must always see both concealed hand rows. These final rules
       intentionally override the normal player's collapsible bottom hand and
       any older spectator prototype rules. */
    body.spectator-mode #handDock,
    body.spectator-mode #opponentHandDock {
      display: flex !important;
      visibility: visible !important;
      opacity: 1 !important;
    }
    body.spectator-mode #handDock {
      transform: translateY(0) !important;
      z-index: 9400;
    }
    body.spectator-mode #opponentHandDock {
      z-index: 7900;
    }

/* ── Board sync overlay ──────────────────────────────────────
   Shown to a joining player or spectator from the moment they commit to a
   room until the host's board has arrived and its artwork has decoded.
   Follows the required matched-window system: square two pixel white frame
   on the near-black playmat background, with a centred uppercase title
   interrupting the top frame. No rounded gold framing, no pill buttons.
────────────────────────────────────────────────────────── */
@keyframes boardSyncSweep {
  0%   { transform: translateX(-110%); }
  100% { transform: translateX(330%); }
}

/* ═══════════════════════════════════════════════════════════════
   V 0.284 — FIXED AUTHORED COMPOSITION
   The original UI was composed for a 2048×964 display. Title and
   persistent play UI now retain that exact geometry and scale together,
   producing letterboxing instead of independent responsive reflow.
═══════════════════════════════════════════════════════════════ */
:root {
  --dbts-title-scale: 1;
  --dbts-game-scale: 1;
}

#gameComposition {
  position: absolute;
  z-index: 1;
  left: 50%;
  top: 50%;
  width: 2048px;
  height: 964px;
  /* The board remains clipped by #viewport. The hand is a sibling that is
     allowed to extend through vertical letterboxing until #app clips it at
     the real browser bottom. */
  overflow: visible;
  transform: translate(-50%, -50%) scale(var(--dbts-game-scale));
  transform-origin: center center;
}

/* The popup layer remains full-browser-size and is deliberately not scaled. */
#app {
  overflow: hidden;
  background: #080505;
}

#gameComposition #viewport {
  width: 2048px;
  height: 964px;
}
/* Larger dice, with a visible three-second tumble while the shared roll is resolving. */
@keyframes dbtsDiceTumble {
  0%   { transform: rotate(-8deg) scale(.93); filter: brightness(.88); }
  25%  { transform: rotate(7deg) scale(1.04); filter: brightness(1.12); }
  50%  { transform: rotate(-5deg) scale(.97); filter: brightness(.96); }
  75%  { transform: rotate(9deg) scale(1.05); filter: brightness(1.15); }
  100% { transform: rotate(-8deg) scale(.93); filter: brightness(.88); }
}
/* Card searches leave the player's hand visible and usable. The search panel
   is lifted above the hand so neither UI surface covers the other. */
body.deck-search-active #handBrowserOverlay {
  z-index: 99997 !important;
}
body.deck-search-active #handDock {
  z-index: 99997 !important;
  transform: translateY(0) !important;
}
/* The regular search overlay blurs its entire backdrop. During a live
   deck/stack search the blur now continues to the bottom of the viewport.
   The player's hand stays crystal-clear because #handDock is promoted above
   the search overlay while the modal is open, rather than by cutting a hard
   unblurred strip out of the backdrop. */
body.deck-search-active #handDock {
  z-index: 99997 !important;
  filter: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

/* ═══════════════════════════════════════════════════════════════
   V 0.312 — chat / history order fix
   The live deck/stack search backdrop now blurs continuously behind the
   entire board instead of ending above the hand dock. Hand cards remain
   above the overlay and therefore stay sharp and interactive.
   ═══════════════════════════════════════════════════════════════ */
body.deck-search-active #handDock {
  z-index: 99997 !important;
  filter: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

/* V 0.324 — guarantee that the hand wrapper is clipped only by the browser.
   #app is full-viewport and overflow:hidden, so the cards disappear naturally
   at the physical bottom edge on every aspect ratio. */
#app > #handBrowserOverlay {
  top: auto !important;
  bottom: 0 !important;
}

/* ── V 0.358 Card motion (scripts/systems/22-card-motion.js) ──────────
   Cards moved by menus, hotkeys or synced remote actions fly between zones
   instead of teleporting. These rules only style the in-flight state. */
#table .card.card-in-flight {
  z-index: 60000 !important;
  will-change: transform;
  cursor: default;
}
#table .card.card-in-flight-p1,
.card.dbts-motion-ghost-p1 {
  box-shadow: 0 18px 30px rgba(0,0,0,0.62), 0 0 18px rgba(255,64,64,0.55) !important;
}
#table .card.card-in-flight-p2,
.card.dbts-motion-ghost-p2 {
  box-shadow: 0 18px 30px rgba(0,0,0,0.62), 0 0 18px rgba(60,160,255,0.55) !important;
}
#table .card.card-in-flight .pile-count { display: none !important; }
.card.dbts-motion-ghost {
  border-radius: 7px;
  overflow: hidden;
  will-change: transform;
  cursor: default;
}
.hand-card.motion-incoming,
.opp-card.motion-incoming {
  opacity: 0 !important;
  pointer-events: none !important;
}
body.fx-lite #table .card.card-in-flight-p1,
body.fx-lite #table .card.card-in-flight-p2,
body.fx-lite .card.dbts-motion-ghost {
  box-shadow: 0 10px 18px rgba(0,0,0,0.55) !important;
}

/* V 0.395 — searchable stack drag ordering */
.deck-search-card[draggable="true"] { cursor: grab; }
.deck-search-card.deck-search-dragging { opacity: .45; }
.deck-search-card.deck-search-drop-target { outline: 2px solid rgba(255,212,94,.95); outline-offset: -2px; }
