/* A separate home for commanders. Only cards actually in the command zone
   receive the raised card treatment; all actions remain engine-owned. */
#game.command-table.ct-hand-command {
  --ct-dock-art: calc(var(--ct-hand) + var(--ct-hand-extra) - 70px);
}
body.game-active #game.command-table.ct-hand-command[data-hand-size='large'] { --ct-hand-extra: 20px; }
body.game-active #game.command-table.ct-hand-command .handwrap {
  align-items: stretch;
  gap: 12px;
}
#game.command-table .ct-commander-dock {
  display: flex;
  flex-direction: column;
  flex: 0 0 148px;
  min-width: 0;
  min-height: 0;
  padding: 5px 7px;
  border: 1px solid rgba(218, 180, 99, .35);
  border-radius: 10px;
  background: radial-gradient(ellipse at 50% 76%, rgba(189, 137, 45, .14), transparent 72%), rgba(12, 14, 20, .66);
  box-shadow: inset 0 1px rgba(255, 227, 172, .07), 0 3px 12px #0003;
  box-sizing: border-box;
}
#game.command-table .ct-commander-dock.has-partners { flex-basis: 254px; }
#game.command-table .ct-command-heading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex: 0 0 16px;
  color: #e2c487;
  font: 700 9px/1 var(--ds-font-body);
  text-transform: uppercase;
  letter-spacing: .13em;
}
#game.command-table .ct-command-heading .gameicon { width: 12px; height: 12px; }
#game.command-table .ct-command-slots {
  display: flex;
  flex: 1;
  gap: 5px;
  min-width: 0;
  min-height: 0;
}
body.game-active #game.command-table .ct-commander-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  padding: 4px 2px 0;
  gap: 4px;
  isolation: isolate;
  border: 0;
  border-radius: 7px;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
}
body.game-active #game.command-table .ct-commander-card > img {
  position: relative;
  z-index: 1;
  width: calc(var(--ct-dock-art) / 1.4);
  height: var(--ct-dock-art);
  max-width: 100%;
  object-fit: contain;
  border-radius: 5px;
  transform-origin: center 80%;
  transition: transform 220ms cubic-bezier(.2, .8, .2, 1.15), box-shadow 220ms ease, filter 220ms ease, opacity 220ms ease;
}
#game.command-table .ct-commander-card[data-command-state='command'] > img {
  transform: perspective(500px) rotateY(-14deg) rotateX(6deg) rotateZ(-3deg) translateY(-2px);
  box-shadow: 1px 1px 0 #e9cb84, 2px 2px 0 #745320, 3px 3px 0 #b88f43,
    7px 9px 10px #0009, 0 0 14px #c8983938;
}
#game.command-table .ct-commander-card[data-command-state='command']::before {
  content: '';
  position: absolute;
  z-index: -1;
  pointer-events: none;
  inset: 0 0 22px;
  border-radius: 50%;
  background: radial-gradient(ellipse, #e1b45830 0%, #d69b2f16 40%, transparent 72%);
  animation: ct-command-aura 4s ease-in-out infinite alternate;
}
#game.command-table .ct-commander-card[data-command-state='command']::after {
  content: '';
  position: absolute;
  pointer-events: none;
  z-index: -1;
  bottom: 29px;
  width: 74%;
  height: 12px;
  border: 1px solid #c99d494d;
  border-radius: 50%;
  background: radial-gradient(ellipse, #e4bc6340, #08090c40 68%);
  box-shadow: 0 2px 7px #0006;
}
/* Hover/focus: the card turns to face the player, rises out of the dock and
   the aura brightens. The large card preview follows the pointer (data-cname). */
#game.command-table .ct-commander-card[data-command-state='command']:is(:hover, :focus-visible) > img {
  transform: perspective(500px) rotateY(0deg) rotateX(0deg) translateY(-6px) scale(1.05);
  box-shadow: 1px 1px 0 #ffe3a2, 2px 2px 0 #b88f43, 9px 16px 18px #000a, 0 0 28px #f0c25e8c;
  filter: brightness(1.08) saturate(1.08);
}
#game.command-table .ct-commander-card[data-command-state='command']:is(:hover, :focus-visible)::before {
  inset: -6px -4px 16px;
  background: radial-gradient(ellipse, #f3c55f5c 0%, #d69b2f2e 44%, transparent 74%);
  animation-duration: 1.4s;
}
#game.command-table .ct-commander-card[data-command-state='command']:is(:hover, :focus-visible)::after {
  border-color: #f0cd8699;
  box-shadow: 0 2px 9px #0007, 0 0 14px #e6b84f55;
}
#game.command-table .ct-commander-card[data-command-state='command']:is(:hover, :focus-visible) .czname { color: #f5db9e; }
#game.command-table .ct-commander-card[data-command-state='away']:is(:hover, :focus-visible) > img {
  opacity: .75;
  filter: saturate(.75);
  transform: translateY(-3px);
}
#game.command-table .ct-commander-card:focus-visible { outline: 2px solid #f0cd86; outline-offset: -2px; }
#game.command-table .ct-commander-card .czinfo { flex: 0 0 auto; width: 100%; text-align: center; }
#game.command-table .ct-commander-card .czlabel { display: none; }
#game.command-table .ct-commander-card .czname { font: 650 11px/14px var(--ds-font-body) !important; letter-spacing: 0; }
#game.command-table .ct-commander-card .czcost {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  font-size: 10px;
  line-height: 14px;
}
#game.command-table .ct-commander-card .czcost .msym { width: 12px; height: 12px; min-width: 12px; margin: 0; font-size: 9px; }
/* Same badge treatment as CAST: a bare label at the card's left edge sat
   behind the tilted art and showed only "(tax". */
#game.command-table .ct-commander-card .tax {
  position: absolute;
  z-index: 2;
  left: 0;
  top: 7px;
  padding: 3px 5px;
  border: 1px solid #ead08c75;
  border-radius: 4px;
  background: #2c281ceb;
  color: #f5db9e;
  font: 800 9px/12px var(--ds-font-body);
  white-space: nowrap;
}
#game.command-table .ct-commander-card .czgo {
  position: absolute;
  z-index: 2;
  right: 0;
  top: 7px;
  padding: 3px 5px;
  border: 1px solid #ead08c75;
  border-radius: 4px;
  background: #2c281ceb;
  color: #f5db9e;
  font: 800 9px/12px var(--ds-font-body);
  box-shadow: 0 2px 6px #0008;
}
#game.command-table .ct-commander-card[data-command-state='away'] > img { opacity: .45; filter: saturate(.4); }
#game.command-table .ct-command-location { color: var(--ds-muted); font: 500 10px/14px var(--ds-font-body); }
#game.command-table .ct-hand-content {
  display: grid;
  grid-template-rows: 25px minmax(0, 1fr);
  flex: 1;
  min-width: 0;
  min-height: 0;
  border-left: 1px solid var(--ds-line);
  padding-left: 11px;
}
#game.command-table .ct-hand-content .handtools {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 0;
  gap: 8px;
  padding: 0 3px;
  box-sizing: border-box;
}
#game.command-table .ct-hand-content .handtoolstitle { flex-wrap: nowrap; white-space: nowrap; font-size: 11px; }
#game.command-table .ct-hand-content .handtoolstitle .gameicon { width: 14px; height: 14px; }
#game.command-table .ct-hand-content .handsortlabel { width: auto; margin: 0 0 0 auto; }
#game.command-table .ct-hand-content .handsortlabel > span { display: none; }
#game.command-table .ct-hand-content .handsort { width: 116px; height: 24px; min-height: 24px; padding: 1px 5px; font-size: 11px; background: transparent; border-color: transparent; }
#game.command-table .ct-hand-cards { display: flex; gap: 8px; min-width: 0; min-height: 0; }
body.game-active #game.command-table .ct-hand-cards .hand { justify-content: flex-start; }
#game.command-table .ct-command-extras { display: flex; min-width: 0; }
#game.command-table .ct-command-extras .ringcard { flex: 0 1 auto; min-height: 24px; padding: 1px 5px; gap: 5px; }
#game.command-table .ct-command-extras .ringart { width: 20px; height: 20px; }
#game.command-table .ct-command-extras .czlabel { font-size: 9px; letter-spacing: 0; }
#game.command-table .ct-command-extras :is(.czname, .czcost, .ringpips) { display: none; }
@keyframes ct-command-aura { from { opacity: .5; } to { opacity: 1; } }

@media (min-width: 901px) {
  body.game-active #game.command-table.ct-hand-command:has(.ct-commander-dock):is(.ct-grid-view, [data-table-view='focus']) { --ct-hand: 176px; }
  body.game-active #game.command-table.ct-hand-command .hcard {
    width: calc((var(--ct-hand) + var(--ct-hand-extra) - 49px) / 1.4) !important;
    height: calc(var(--ct-hand) + var(--ct-hand-extra) - 49px) !important;
  }
}
@media (min-width: 901px) and (max-height: 780px) {
  body.game-active #game.command-table.ct-hand-command:has(.ct-commander-dock):is(.ct-grid-view, [data-table-view='focus']) { --ct-hand: 142px; }
}
@media (max-width: 900px) {
  body.game-active #game.command-table.ct-hand-command { --ct-hand: 184px; --ct-dock-art: calc(var(--ct-hand) + var(--ct-hand-extra) - 112px); }
  body.game-active #game.command-table.ct-hand-command .handwrap {
    grid-template-columns: 92px minmax(0, 1fr);
    grid-template-rows: 44px minmax(0, 1fr);
    column-gap: 8px;
    row-gap: 0;
  }
  body.game-active #game.command-table.ct-hand-command .handwrap:has(.has-partners) { grid-template-columns: 132px minmax(0, 1fr); }
  #game.command-table .ct-hand-content { display: contents; }
  #game.command-table .ct-hand-content .handtools { grid-row: 1; grid-column: 1 / -1; }
  #game.command-table .ct-hand-content .handsort { min-height: 44px; width: 100px; font-size: 12px; }
  #game.command-table .ct-commander-dock { grid-row: 2; grid-column: 1; padding: 3px; }
  #game.command-table .ct-command-heading { flex-basis: 15px; font-size: 8px; letter-spacing: .04em; gap: 3px; }
  #game.command-table .ct-command-heading .gameicon { width: 10px; height: 10px; }
  #game.command-table .ct-command-slots { gap: 3px; }
  #game.command-table .ct-commander-card { gap: 3px; padding-inline: 2px; }
  #game.command-table .ct-commander-card .czname { font-size: 9px !important; line-height: 12px !important; }
  #game.command-table .ct-commander-card .czcost { font-size: 0; line-height: 12px; column-gap: 1px; row-gap: 0; }
  #game.command-table .ct-commander-card .tax { display: none; }
  #game.command-table .ct-commander-card .czgo { top: 2px; right: -1px; font-size: 8px; padding: 1px 2px; }
  #game.command-table .ct-command-location { font-size: 9px; line-height: 11px; }
  #game.command-table .ct-hand-cards { grid-row: 2; grid-column: 2; gap: 6px; overflow: hidden; }
  #game.command-table .ct-hand-cards .handzones { flex-basis: 76px; width: 76px; max-width: 40%; }
  #game.command-table .ct-command-extras .ringcard { min-height: 44px; }
  #game.command-table .ct-command-extras .czinfo { display: none; }
  body.game-active #game.command-table.ct-hand-command[data-mobile-view='hand'] .ct-commander-dock { align-self: start; min-height: 134px; }
  body.game-active #game.command-table.ct-hand-command[data-mobile-view='hand'] .ct-hand-cards { flex-direction: column; }
  body.game-active #game.command-table.ct-hand-command[data-mobile-view='hand'] .handzones { flex: 0 0 auto; width: 100%; max-width: none; max-height: 112px; }
  body.game-active #game.command-table.ct-hand-command[data-mobile-view='hand'] .hand { grid-template-columns: repeat(auto-fill, minmax(min(126px, 100%), 1fr)); }
}
/* Portrait phones: the full hand gets the whole width. Beside a 92px commander
   column only one stretched card fit per row, so the commander becomes a compact
   row above the cards. Landscape keeps the column: height is the scarce side. */
@media (max-width: 900px) and (orientation: portrait) {
  body.game-active #game.command-table.ct-hand-command[data-mobile-view='hand'] .handwrap {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 44px auto minmax(0, 1fr);
    row-gap: 6px;
  }
  body.game-active #game.command-table.ct-hand-command[data-mobile-view='hand'] .ct-commander-dock {
    grid-row: 2; grid-column: 1; align-self: stretch; min-height: 0; padding: 4px 8px 6px;
  }
  body.game-active #game.command-table.ct-hand-command[data-mobile-view='hand'] .ct-commander-card {
    flex-direction: row; justify-content: flex-start; gap: 10px; padding: 2px 4px;
  }
  body.game-active #game.command-table.ct-hand-command[data-mobile-view='hand'] .ct-commander-card > img { width: 46px; height: 64px; }
  /* The pedestal ring belongs under the card. In this row it was 74% of the
     row wide and ran through the commander's name. */
  body.game-active #game.command-table.ct-hand-command[data-mobile-view='hand'] .ct-commander-card[data-command-state='command']::after {
    left: 0; bottom: -2px; width: 56px; height: 10px;
  }
  body.game-active #game.command-table.ct-hand-command[data-mobile-view='hand'] .ct-commander-card .czinfo { width: auto; text-align: left; }
  body.game-active #game.command-table.ct-hand-command[data-mobile-view='hand'] .ct-commander-card .czname { font-size: 13px !important; line-height: 17px !important; }
  body.game-active #game.command-table.ct-hand-command[data-mobile-view='hand'] .ct-hand-cards { grid-row: 3; grid-column: 1; }
}
@media (max-width: 900px) and (max-height: 720px) {
  body.game-active #game.command-table.ct-hand-command { --ct-hand: 160px; --ct-dock-art: 56px; }
}
@media (min-width: 600px) and (max-width: 900px) and (max-height: 500px) {
  body.game-active #game.command-table.ct-hand-command .handwrap { grid-template-columns: 70px minmax(0, 1fr); column-gap: 5px; }
  body.game-active #game.command-table.ct-hand-command .handwrap:has(.has-partners) { grid-template-columns: 112px minmax(0, 1fr); }
  #game.command-table .ct-hand-content .handtools { gap: 2px; padding: 0; }
  #game.command-table .ct-hand-content .handtools:has(.ct-command-extras) .handtoolstitle { display: none; }
  #game.command-table .ct-hand-content .handsort { width: 80px; font-size: 10px; }
  /* The full-hand header spans the table, so the sort label is not cut short. */
  #game.command-table[data-mobile-view='hand'] .ct-hand-content .handsort { width: 100px; }
  #game.command-table .ct-hand-content .handexpand { padding-inline: 3px; font-size: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  #game.command-table .ct-commander-card::before { animation: none !important; }
  #game.command-table .ct-commander-card > img { transition: none !important; transform: none !important; }
}
body.reduced-motion #game.command-table .ct-commander-card::before { animation: none !important; }
body.reduced-motion #game.command-table .ct-commander-card > img { transition: none !important; transform: none !important; }

/* Phones: cards playable from exile, a graveyard or the library top lead the
   hand row as full cards (ui.js renderOffZoneHandCard). A ribbon names the
   zone and a footer the window or owner; the green frame still means
   "playable now". Desktop keeps the thumbnail tray beside the hand. */
#game .hand .offzonecard { --offzone: 74, 144, 217; }
#game .hand .offzonecard[data-zone='graveyard'] { --offzone: 168, 128, 208; }
#game .hand .offzonecard[data-zone='library'] { --offzone: 84, 194, 172; }
#game .hand .offzonecard:not(.castable) { border-color: rgba(var(--offzone), .8); }
#game .hand .offzonecard .offzoneribbon {
  position: absolute; inset: 0 0 auto; z-index: 4; display: flex; align-items: center; justify-content: center; gap: 3px;
  height: 16px; padding: 0 4px; overflow: hidden; background: rgba(var(--offzone), .94); color: #061019;
  font: 800 8px/1 var(--ds-font-display, sans-serif); letter-spacing: .1em; white-space: nowrap; pointer-events: none;
}
#game .hand .offzonecard .offzoneribbon .gameicon { flex: 0 0 auto; width: 10px; height: 10px; }
#game .hand .offzonecard .offzonenote {
  position: absolute; inset: auto 0 0; z-index: 4; padding: 3px 4px; background: rgba(6, 10, 14, .9); color: #eef3f7;
  font: 700 8px/1.2 var(--ds-font-body, sans-serif); text-align: center; overflow-wrap: anywhere; pointer-events: none;
}
/* The full hand is where cards are read: the ribbon and footer become bands
   above and below the image instead of covering its name and P/T. The card
   keeps the 5:7 box of its neighbours (command-table.css lets a loaded image
   set a card's height, which would leave the bands alone). */
#game[data-mobile-view='hand'] .hand .offzonecard { display: flex; flex-direction: column; aspect-ratio: 5 / 7 !important; height: auto; background: rgba(var(--offzone), .14); }
#game[data-mobile-view='hand'] .hand .offzonecard > img { flex: 1 1 0; min-height: 0; width: 100%; height: 0; object-fit: contain; }
#game[data-mobile-view='hand'] .hand .offzonecard .offzoneribbon { position: static; flex: 0 0 auto; order: -1; height: 22px; gap: 5px; font-size: 10px; }
#game[data-mobile-view='hand'] .hand .offzonecard .offzoneribbon .gameicon { width: 13px; height: 13px; }
#game[data-mobile-view='hand'] .hand .offzonecard .offzonenote { position: static; flex: 0 0 auto; padding: 4px 6px; font-size: 11px; }
@media (max-width: 900px) {
  /* The cards themselves are in the hand row, so their prompt shortcuts stay
     one swipeable line instead of a stack of full-width buttons. */
  #game.command-table .promptbar .btnrow.offzone { flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; }
  #game.command-table .promptbar .btnrow.offzone > .pbtn { flex: 0 0 auto; width: auto; max-width: 75%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* Views without the hand (Table, Combat, Stack) keep that line; the prompt
     grows by its height so the primary action is never cut off. */
  #game.command-table .ct-decision-rail:not(.has-review):not(.has-targets):has(.promptbar .btnrow.offzone) { max-height: 210px; }
  body.game-active #game.command-table .ct-decision-rail .promptbar:has(> .btnrow.offzone) { max-height: 180px; }
}
