/* card-hand-dock.css: Elvi's standing hand dock (cardHandDock.js). Loaded after console-rails.css.
   html[data-card-dock="1"] is set by the renderer only while the console rails are on (PS1, landscape, keyboard / mouse or pad, no native frame, no inspect layout)
   and Elvi holds a card dungeon hand: portrait, the on-screen pad, Liz and the GB skin keep their existing hand drawer / spell book.
   The dock is a fixed strip at the foot of the screen. It never lies over the board: the board region keeps --card-dock-h free at its foot (padding-bottom, which
   SliceRenderer.layout() already subtracts) and the rails end above it (landscapeRails.js reads the dock's box; the guide keys use --card-dock-h below).
   Art: the plate is assets/ui/elvi-cards/v1/front.webp (384x576; zones as in elvi-cards.css: name y 13%, art y 24-67%, uses y 75-89%), the piles use back.webp,
   the panel / key chrome is the existing console rails kit (--crail-f-module / --crail-f-key from console-rails.css). No new bitmap is introduced. */

@media (orientation: landscape) {
  html[data-card-dock="1"] {
    --card-dock-h: calc(clamp(128px, 24vh, 200px) + var(--safe-b, 0px));
    --chd-cw: calc((clamp(128px, 24vh, 200px) - 28px) / 1.5);   /* card width: the card (1.5 x) fits the dock with 18px above (lift) and 10px below */
  }
  html[data-card-dock="1"] body .ui-field > .ui-map { box-sizing: border-box; padding-bottom: var(--card-dock-h); }
  /* the piles are in the dock now; the HUD keeps its count */
  html[data-card-dock="1"] body #fieldHud .card-hud__piles { display: none; }

  html body #cardHandDock.chd { display: none; }
  html[data-card-dock="1"][data-protagonist="elvi"] body #cardHandDock.chd:not([hidden]) {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; box-sizing: border-box; height: var(--card-dock-h); margin: 0;
    display: grid; grid-template-columns: auto minmax(0, 1fr) clamp(216px, 26vw, 360px) auto; align-items: stretch; column-gap: 10px;
    padding: 18px calc(var(--safe-r, 0px) + 12px) calc(var(--safe-b, 0px) + 10px) calc(var(--safe-l, 0px) + 12px);
    background: #030705 var(--crail-bay, none) 0 0 / 256px 256px repeat; border-top: 1px solid var(--crail-ink-2, #5aa878);
    color: var(--crail-ink, #9cf5b6); font: 400 12px/16px var(--crail-ff, var(--ff-ui, sans-serif));
    --ec-card-front: url("../../../assets/ui/elvi-cards/v1/front.webp"); --ec-card-back: url("../../../assets/ui/elvi-cards/v1/back.webp");
  }
  /* a modal surface (menu, scene, map, radio...) owns the screen: the dock keeps its room but goes dark and inert */
  html[data-card-dock="1"] body #cardHandDock.chd[data-modal="1"] { visibility: hidden; pointer-events: none; }

  /* ---- the fan ---- */
  .chd__fan { position: relative; display: flex; align-items: flex-end; justify-content: center; min-width: 0; height: 100%; container-type: inline-size; }
  .chd__empty { align-self: center; margin: 0; color: var(--crail-ink-2, #5aa878); }
  html[data-protagonist="elvi"] .chd-card {
    --step: clamp(22px, calc((100cqw - var(--chd-cw)) / max(var(--n, 1) - 1, 1)), calc(var(--chd-cw) * 1.06));
    position: relative; isolation: isolate; box-sizing: border-box; flex: none; display: block; padding: 0; border: 0; border-radius: 4px;
    width: var(--chd-cw); height: calc(var(--chd-cw) * 1.5); margin: 0; container-type: inline-size; overflow: visible;
    background: #030806; color: #e6fff0; font: inherit; text-align: left; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; outline: none;
    transform-origin: 50% 115%; transform: translateY(var(--drop, 0px)) rotate(var(--rot, 0deg)); filter: brightness(0.86);
    transition: transform 140ms cubic-bezier(0.22, 0.9, 0.3, 1), filter 140ms;
  }
  .chd__fan > .chd-card + .chd-card { margin-left: calc(var(--step) - var(--chd-cw)); }
  /* an opaque dark body under the frame image: a card never shows the text of the card beneath it */
  html[data-protagonist="elvi"] .chd-card::before {
    content: ""; position: absolute; inset: 0; z-index: 0; border-radius: 4px; pointer-events: none; background: var(--ec-card-front) center / 100% 100% no-repeat, #030806;
  }
  html[data-protagonist="elvi"] .chd-card > span { position: absolute; z-index: 1; margin: 0; pointer-events: none; }
  html[data-protagonist="elvi"] .chd-card__name {
    left: 11%; right: 11%; top: calc(13% - 7px); height: 14px; overflow: hidden; text-align: left; font-size: clamp(10px, 13cqw, 13px); font-weight: 700; line-height: 14px;
    white-space: nowrap; text-overflow: ellipsis; text-shadow: 0 0 3px #000, 0 0 2px #000, 0 1px 0 #000;
  }
  html[data-protagonist="elvi"] .chd-card__art { left: 15%; right: 15%; top: 24%; height: 43%; display: flex; align-items: center; justify-content: center; color: var(--ec-hi, #46f27a); }
  html[data-protagonist="elvi"] .chd-card__art > * { width: 100%; height: 100%; max-width: 100%; max-height: 100%; }
  html[data-protagonist="elvi"] .chd-card__art .ic-art { --ic-size: 100%; }
  html[data-protagonist="elvi"] .chd-card__art svg.ui-sym { fill: currentColor; width: 70%; height: 70%; }
  html[data-protagonist="elvi"] .chd-card__art .ec-q { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; font-size: clamp(26px, 44cqw, 48px); font-weight: 700; color: var(--ec-hi, #46f27a); }
  html[data-protagonist="elvi"] .chd-card__uses {
    left: 11%; right: 11%; top: 75%; height: 14%; display: flex; align-items: center; gap: 1px; font-variant-numeric: tabular-nums; text-shadow: 0 0 3px #000, 0 0 2px #000, 0 1px 0 #000;
  }
  html[data-protagonist="elvi"] .chd-card__uses b { font-size: clamp(14px, 22cqw, 22px); font-weight: 700; line-height: 1; color: var(--ec-hi, #46f27a); }
  html[data-protagonist="elvi"] .chd-card__uses i { align-self: flex-end; padding-bottom: 2px; font-size: clamp(10px, 12cqw, 13px); font-style: normal; line-height: 1; }
  /* states: hover lifts a little, selected stands up straight with the emerald edge, an aimed card keeps a dashed edge, a dragged one leaves a faint place */
  html[data-protagonist="elvi"] .chd-card:hover { z-index: 3; filter: brightness(1); transform: translateY(calc(var(--drop, 0px) - 6px)) rotate(var(--rot, 0deg)); }
  html[data-protagonist="elvi"] .chd-card[aria-selected="true"] {
    z-index: 5; filter: drop-shadow(0 0 7px var(--ec-glow, #27d97a)) brightness(1.08); transform: translateY(-12px) scale(1.06); outline: 2px solid var(--ec-hi, #46f27a); outline-offset: 1px;
  }
  html[data-protagonist="elvi"] .chd-card[data-aim="1"] { outline: 2px dashed var(--ec-hi, #46f27a); outline-offset: 3px; }
  html[data-protagonist="elvi"] .chd-card:focus-visible { outline: 2px solid var(--ec-hi, #46f27a); outline-offset: 2px; }
  html[data-protagonist="elvi"] .chd-card[aria-disabled="true"] { opacity: 0.6; filter: grayscale(0.6) brightness(0.7); cursor: default; }
  html[data-protagonist="elvi"] .chd-card[data-dragging="1"] { opacity: 0.3; transform: translateY(var(--drop, 0px)) rotate(var(--rot, 0deg)); }
  /* the plate that follows the pointer (a body-level clone: nothing under it receives the press) */
  html[data-protagonist="elvi"] .chd-ghost {
    position: fixed; left: 0; top: 0; z-index: 60; margin: 0; pointer-events: none; opacity: 0.92; cursor: grabbing; transition: none;
    filter: drop-shadow(0 8px 14px rgb(0 0 0 / 0.75)) brightness(1.1); outline: 2px solid var(--ec-hi, #46f27a); outline-offset: 1px;
  }
  body.chd-dragging, body.chd-dragging * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }

  /* ---- the piles ---- */
  html[data-protagonist="elvi"] #cardHandDock .chd-pile {
    appearance: none; box-sizing: border-box; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 2px; align-self: end;
    width: calc(var(--chd-cw) * 0.78); height: calc(var(--chd-cw) * 1.5); margin: 0; padding: 0; border: 0; background: none; color: #e6fff0; font: inherit; text-align: center; cursor: default;
  }
  html[data-protagonist="elvi"] #cardHandDock button.chd-pile { cursor: pointer; }
  html[data-protagonist="elvi"] #cardHandDock .chd-pile__stack { position: relative; flex: 1 1 0; min-height: 0; aspect-ratio: 2 / 3; max-width: 100%; margin-top: 3px; }
  html[data-protagonist="elvi"] #cardHandDock .chd-pile__stack i { position: absolute; inset: 0; border-radius: 3px; background: var(--ec-card-back) center / 100% 100% no-repeat, #030806; box-shadow: 0 1px 2px #000; }
  html[data-protagonist="elvi"] #cardHandDock .chd-pile__stack i:nth-child(1) { transform: translate(-3px, 3px); }
  html[data-protagonist="elvi"] #cardHandDock .chd-pile__stack i:nth-child(2) { transform: translate(-1.5px, 1.5px); }
  html[data-protagonist="elvi"] #cardHandDock .chd-pile--discard .chd-pile__stack i { filter: grayscale(0.7) brightness(0.8); }
  html[data-protagonist="elvi"] #cardHandDock .chd-pile--draw .chd-pile__stack::after {
    content: none; position: absolute; inset: 0; z-index: 4; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; color: #e6fff0; text-shadow: 0 0 6px #000, 0 0 8px var(--ec-hi, #46f27a);
  }
  html[data-protagonist="elvi"] #cardHandDock .chd-pile__name { font-size: 10px; font-weight: 700; line-height: 12px; white-space: nowrap; color: #e6fff0; text-shadow: 0 1px 0 #000; }
  html[data-protagonist="elvi"] #cardHandDock .chd-pile__n { font-size: 13px; font-weight: 700; line-height: 14px; font-variant-numeric: tabular-nums; color: var(--ec-hi, #46f27a); text-shadow: 0 1px 0 #000; }
  html[data-protagonist="elvi"] #cardHandDock .chd-pile__cmd { font-size: 9px; line-height: 11px; white-space: nowrap; color: var(--crail-ink-2, #5aa878); }
  html[data-protagonist="elvi"] #cardHandDock button.chd-pile:hover:not(:disabled) .chd-pile__stack { filter: brightness(1.25); }
  html[data-protagonist="elvi"] #cardHandDock button.chd-pile:focus-visible { outline: 2px solid var(--ec-hi, #46f27a); outline-offset: 2px; }
  html[data-protagonist="elvi"] #cardHandDock button.chd-pile:active:not(:disabled) { translate: 0 1px; }
  html[data-protagonist="elvi"] #cardHandDock button.chd-pile:disabled .chd-pile__stack { opacity: 0.45; filter: grayscale(0.6); }
  html[data-protagonist="elvi"] #cardHandDock button.chd-pile:disabled { cursor: default; }

  /* ---- the selected card's description (the module window of the rails) ---- */
  html[data-protagonist="elvi"] #cardHandDock .chd__info {
    box-sizing: border-box; display: flex; flex-direction: column; gap: 3px; min-width: 0; min-height: 0; margin: 0; padding: 6px 8px; overflow: hidden;
    border: 4px solid transparent; border-image: var(--crail-f-module, none); background: none;
  }
  html[data-ui-theme="console"][data-protagonist="elvi"] #cardHandDock .chd__info { border-width: 1px; padding: 5px 7px; }
  html[data-protagonist="elvi"] #cardHandDock .chd-info__name { flex: none; margin: 0; overflow: hidden; font-size: 13px; font-weight: 700; line-height: 16px; white-space: nowrap; text-overflow: ellipsis; color: var(--crail-ink, #9cf5b6); }
  html[data-protagonist="elvi"] #cardHandDock .chd-relics {
    appearance: none; display: flex; flex: none; align-items: center; justify-content: space-between; gap: 6px;
    min-width: 0; min-height: 24px; margin: 0 0 3px; padding: 2px 5px;
    border: 4px solid transparent; border-image: var(--crail-f-key, var(--ec-card-front) 64 fill / 4px stretch);
    background: none; color: var(--crail-ink, #9cf5b6); font: 700 10px/12px var(--crail-ff, inherit); cursor: pointer;
  }
  html[data-protagonist="elvi"] #cardHandDock .chd-relics span { font-weight: 400; white-space: nowrap; }
  html[data-protagonist="elvi"] #cardHandDock .chd-relics:focus-visible { outline: 2px solid var(--ec-hi, #46f27a); outline-offset: 1px; }
  html[data-protagonist="elvi"] #cardHandDock .chd-info__meta { flex: none; display: flex; flex-wrap: wrap; gap: 0 8px; margin: 0; overflow: hidden; max-height: 16px; color: var(--crail-ink-2, #5aa878); font-size: 11px; line-height: 16px; }
  html[data-protagonist="elvi"] #cardHandDock .chd-info__meta > span { white-space: nowrap; }
  html[data-protagonist="elvi"] #cardHandDock .chd-info__fx { flex: 1 1 auto; min-height: 0; margin: 0; overflow-y: auto; overscroll-behavior: contain; overflow-wrap: anywhere; color: var(--crail-ink, #9cf5b6); font-size: 12px; line-height: 16px; scrollbar-width: thin; }
  html[data-protagonist="elvi"] #cardHandDock .chd-info__hint { margin: auto 0; color: var(--crail-ink-2, #5aa878); font-size: 12px; line-height: 16px; }
  html[data-protagonist="elvi"] #cardHandDock .chd-info__acts { flex: none; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  html[data-protagonist="elvi"] #cardHandDock .chd-act {
    appearance: none; box-sizing: border-box; display: flex; align-items: center; justify-content: center; gap: 6px; min-width: 0; min-height: 30px; margin: 0; padding: 2px 4px; cursor: pointer;
    border: 9px solid transparent; border-image: var(--crail-f-key, none); border-radius: 0; background: none; box-shadow: none; outline: none;
    color: var(--crail-ink, #9cf5b6); font: 700 12px/16px var(--crail-ff, inherit); white-space: nowrap;
  }
  html[data-ui-theme="console"][data-protagonist="elvi"] #cardHandDock .chd-act { border-width: 1px; padding: 4px 5px; }
  html[data-protagonist="elvi"] #cardHandDock .chd-act small { color: var(--crail-ink-2, #5aa878); font-size: 10px; font-weight: 400; }
  html[data-protagonist="elvi"] #cardHandDock .chd-act:hover:not(:disabled) { filter: brightness(1.3); color: var(--crail-hi, #46f27a); }
  html[data-protagonist="elvi"] #cardHandDock .chd-act:focus-visible { filter: brightness(1.75) saturate(1.2); color: var(--crail-hi, #46f27a); }
  html[data-protagonist="elvi"] #cardHandDock .chd-act:active:not(:disabled) { filter: brightness(0.78); translate: 0 1px; }
  html[data-protagonist="elvi"] #cardHandDock .chd-act:disabled { opacity: 0.55; cursor: default; color: var(--crail-ink-2, #5aa878); }
}

/* a short or narrow window: a thinner dock and a narrower description */
@media (orientation: landscape) and (max-width: 1100px) {
  html[data-protagonist="elvi"] #cardHandDock .chd-info__fx { font-size: 11px; line-height: 14px; }
}

/* motion: the plates only change state, never loop; nothing moves under reduced motion / menu effect 0 */
html[data-menu-fx="0"] .chd-card, html[data-reduced-motion="1"] .chd-card, html[data-high-contrast="1"] .chd-card { transition: none !important; }
@media (prefers-reduced-motion: reduce) { .chd-card { transition: none !important; } }
