/* The draw and discard reserves are distinct physical objects on the same table. */
#play-screen .db-immersive .db-sidepiles {
  --pile-edge: #b99860;
  align-items: center;
  gap: clamp(5px, 1.25dvh, 15px);
}
#play-screen .db-immersive .db-sidepiles button[data-cmd="pile"] {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "emblem emblem" "name count";
  align-content: center;
  align-items: center;
  justify-items: center;
  gap: 4px;
  width: min(100%, 80px);
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 5px 1px 3px;
  border: 0;
  border-radius: 4px;
  background: none;
  box-shadow: none;
  color: #fff1cd;
  text-shadow: 0 1px 4px #020805, 0 0 8px #061511;
  text-decoration: none;
  line-height: 1;
  cursor: pointer;
}
#play-screen .db-shell .db-pile-emblem {
  position: relative;
  grid-area: emblem;
  display: block;
  isolation: isolate;
  inline-size: min(89%, clamp(36px, 7.4dvh, 76px));
  aspect-ratio: 5 / 7;
  margin-block-end: 3px;
  transform: rotate(-5deg);
  filter: drop-shadow(1px 4px 4px #0308069c);
  transition: transform .18s ease, filter .18s ease;
  pointer-events: none;
}
#play-screen .db-shell .db-pile-emblem::before,
#play-screen .db-shell .db-pile-emblem::after,
#play-screen .db-shell .db-pile-print {
  position: absolute;
  display: block;
  inset: 0;
  border: 1px solid var(--pile-edge);
  border-radius: 6%;
}
#play-screen .db-shell .db-pile-emblem::before,
#play-screen .db-shell .db-pile-emblem::after {
  content: "";
  background: linear-gradient(115deg, #213c35, #0a1b19);
  box-shadow: inset 0 0 0 1px #15241b;
}
#play-screen .db-shell .db-pile-emblem::before { translate: 3px 4px; }
#play-screen .db-shell .db-pile-emblem::after { translate: 1px 2px; }
#play-screen .db-shell .db-pile-print {
  z-index: 1;
  overflow: hidden;
  background-position: center;
  background-size: cover;
  box-shadow: inset 0 0 0 1px #fff1b84f;
}
#play-screen .db-shell .db-grave .db-pile-emblem { transform: rotate(6deg); }
#play-screen .db-shell .db-grave .db-pile-print {
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 30% 15%, #315044, #142720 70%);
  border-color: #a99069;
  color: #ecd59b;
}
#play-screen .db-shell .db-pile-print img { inline-size: 100%; block-size: 100%; object-fit: cover; object-position: 50% 32%; }
#play-screen .db-shell .db-grave[data-empty="true"] .db-pile-emblem { transform: none; }
#play-screen .db-shell [data-empty="true"] .db-pile-emblem::before,
#play-screen .db-shell [data-empty="true"] .db-pile-emblem::after { content: none; }
#play-screen .db-shell [data-empty="true"] .db-pile-print { opacity: .78; }
#play-screen .db-shell .db-grave[data-empty="true"] .db-pile-print {
  background: linear-gradient(125deg, #1b332d9e, #091a17b8);
  outline: 1px solid #a8905b66;
  outline-offset: -4px;
}
#play-screen .db-shell .db-pile-print .icon { width: 50%; height: auto; max-height: 60%; }
#play-screen .db-shell .db-pile-caption {
  grid-area: name;
  font: 600 clamp(.7rem, .9vw, .84rem)/1 var(--rh-inscription, Georgia, serif);
  letter-spacing: .02em;
}
#play-screen .db-shell .db-pile-count {
  grid-area: count;
  min-width: 1.3em;
  padding: .18em .22em;
  border-radius: 3px;
  border: 1px solid #ad915b80;
  color: #ffebb6;
  background: #071914e8;
  font: 700 clamp(.7rem, .85vw, .85rem)/1 var(--rh-reading, system-ui, sans-serif);
  font-variant-numeric: tabular-nums;
  text-align: center;
}
#play-screen .db-immersive .db-sidepiles button:focus-visible,
#play-screen .db-shell .db-pile-list button:focus-visible {
  outline: 2px solid #ffe0a0;
  outline-offset: 3px;
}
@media (hover: hover) {
  #play-screen .db-immersive .db-sidepiles button:hover .db-pile-emblem {
    transform: translateY(-2px) rotate(0);
    filter: drop-shadow(0 0 5px #f9cd6f82);
  }
}

/* A single reader keeps the same pile and list position throughout inspection. */
#play-screen .db-shell dialog.db-dialog[data-kind="pile"] {
  inline-size: min(58rem, calc(100vw - 28px));
  max-block-size: calc(100dvh - 22px);
}
#play-screen .db-shell dialog.db-dialog[data-kind="pile"] .db-dialog-body {
  min-block-size: 0;
  padding-block-start: 0;
}
#play-screen .db-shell .db-pile-inspector {
  display: grid;
  grid-template-columns: minmax(0, 1.22fr) minmax(0, 1fr);
  gap: clamp(14px, 2.5vw, 32px);
  min-block-size: 0;
}
#play-screen .db-shell .db-pile-reading,
#play-screen .db-shell .db-pile-shelf {
  min-inline-size: 0;
  min-block-size: 0;
}
#play-screen .db-shell .db-pile-reading {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 14px;
  overflow-y: auto;
  max-block-size: min(65dvh, 590px);
  padding: 4px 5px;
  scrollbar-width: thin;
  scrollbar-color: #ae925a #0a201b;
}
#play-screen .db-shell .db-pile-portrait {
  display: grid;
  place-items: center;
  width: min(100%, clamp(100px, 26dvh, 205px));
  background: radial-gradient(ellipse, #b29b5426, transparent 72%);
}
#play-screen .db-shell .db-pile-portrait > .tc-card {
  width: 100%; max-width: 100%; height: auto; aspect-ratio: 5 / 7;
  pointer-events: none; box-shadow: 0 5px 14px #01080580;
}
#play-screen .db-shell .db-pile-record { width: 100%; }
#play-screen .db-shell .db-pile-record h4 {
  margin: 4px 0 8px;
  font: 600 clamp(1.15rem, 2.2vw, 1.65rem)/1.15 var(--rh-inscription, Georgia, serif);
  color: #ffe9b4;
}
#play-screen .db-shell .db-pile-record p { margin: 0; overflow-wrap: anywhere; }
#play-screen .db-shell .db-dialog[data-kind="pile"] .db-pile-inspector .db-pile-record .db-pile-rules {
  font: 400 .94rem/1.48 var(--rh-reading, system-ui, sans-serif);
  margin-block-start: 10px;
  color: #f0ecdd;
}
#play-screen .db-shell .db-pile-shelf {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  align-self: start;
}
#play-screen .db-shell dialog.db-dialog[data-kind="pile"] .db-pile-inspector .db-pile-summary {
  padding: 2px 0 10px;
  margin: 0;
  color: #e5d5aa;
  font: 600 .8rem/1.35 var(--rh-reading, system-ui, sans-serif);
}
#play-screen .db-shell .db-pile-list {
  display: flex;
  flex-direction: column;
  max-block-size: min(59dvh, 540px);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: #9d8658 #10231d;
  scrollbar-width: thin;
  padding: 4px;
  border-block: 1px solid #ad99594b;
}
#play-screen .db-shell dialog.db-dialog[data-kind="pile"] .db-pile-entry {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: clamp(44px, 4.7vw, 63px) minmax(0, 1fr) auto;
  grid-template-rows: 1fr;
  align-items: center;
  gap: clamp(6px, .9vw, 14px);
  min-height: 55px;
  padding: 5px 7px;
  margin: 0;
  border: 1px solid transparent;
  border-block-end-color: #b8a66a32;
  background: transparent;
  color: #eeebd9;
  text-align: start;
  text-shadow: none;
  box-shadow: none;
  border-radius: 2px;
}
#play-screen .db-shell .db-pile-entry .db-pile-thumb {
  inline-size: 100%;
  block-size: 50px;
  object-fit: cover;
  object-position: 50% 32%;
  border: 1px solid #a28c61a6;
  border-radius: 2px;
}
#play-screen .db-shell .db-pile-row-copy { display: grid; gap: 3px; }
#play-screen .db-shell .db-pile-row-copy strong {
  color: #f7e8c9; font: 600 1rem/1.15 var(--rh-inscription, Georgia, serif);
}
#play-screen .db-shell .db-pile-row-copy small,
#play-screen .db-shell .db-pile-note {
  font: 500 .76rem/1.25 var(--rh-reading, system-ui, sans-serif);
  color: #cecdb9;
}
#play-screen .db-shell .db-pile-note { color: #ffe5ab; font-variant-numeric: tabular-nums; }
#play-screen .db-shell dialog.db-dialog[data-kind="pile"] .db-pile-entry:is(:hover, [aria-pressed="true"]) {
  background: linear-gradient(95deg, #52745752, #29483c40);
  border-color: #cbaf718c;
  text-decoration: none;
}
#play-screen .db-shell .db-pile-empty {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 22px 10px;
  text-align: center;
}
#play-screen .db-shell dialog.db-dialog[data-kind="pile"]:has(.db-pile-empty) { inline-size: min(30rem, calc(100vw - 28px)); }
#play-screen .db-shell .db-pile-private-print {
  width: 64px; aspect-ratio: 5 / 7; display: block;
  background-size: cover; background-position: center;
  border: 1px solid #bba16c; border-radius: 4px;
  box-shadow: 2px 2px 0 #17271d, 3px 3px 0 #ac966a;
  transform: rotate(-5deg);
}
#play-screen .db-shell .db-pile-empty-mark {
  display: grid; place-items: center; width: 60px; aspect-ratio: 1;
  border: 1px solid #a78e57; border-radius: 50%; color: #f4d798;
}
#play-screen .db-shell .db-pile-empty-mark .icon { width: 30px; height: 30px; }
#play-screen .db-shell .db-pile-empty p { margin: 0; }

/* Match the existing lesson glass on the other duel instruments. Keep all printed card inks intact. */
#play-screen .db-shell dialog.db-dialog:is([data-kind="card"], [data-kind="history"], [data-kind="options"]) { inline-size: min(46rem, calc(100vw - 28px)); }
#play-screen .db-shell dialog.db-dialog:is([data-kind="info"], [data-kind="history"], [data-kind="options"], [data-kind="attack-or-cast"], [data-kind="prophecy"], [data-kind="card"], [data-kind="pile"]) .db-dialog-body h4 {
  color: #ffe9b4;
}
#play-screen .db-shell dialog.db-dialog:is([data-kind="card"], [data-kind="options"], [data-kind="pile"]) .db-dialog-body .db-card-category,
#play-screen .db-shell dialog.db-dialog[data-kind="options"] .db-dialog-body .db-choice-copy :is(small, .db-choice-type, .db-choice-stats) { color: #e7d29f; }
#play-screen .db-shell .db-dialog:is([data-kind="card"], [data-kind="pile"]) .db-card-stats { gap: 5px; margin: 6px 0; }
#play-screen .db-shell .db-dialog:is([data-kind="card"], [data-kind="pile"]) .db-card-stats span {
  border: 1px solid #bba16b55;
  background: #132f28bd;
  color: #f6edcf;
  padding: 3px 6px;
  font: 500 .77rem/1.35 var(--rh-reading, system-ui, sans-serif);
}
#play-screen .db-shell .db-dialog:is([data-kind="card"], [data-kind="pile"]) .db-card-stats .icon { color: #eace8d; }
#play-screen .db-shell .db-dialog[data-kind="options"] :is(.db-read-choice, .db-choice-tab),
#play-screen .db-shell .db-dialog:is([data-kind="info"], [data-kind="prophecy"], [data-kind="attack-or-cast"]) :is(.db-list-row, .db-choice) {
  background: linear-gradient(110deg, #21483b92, #0c262192);
  border-color: #c1aa7270;
  color: #f5edda;
  box-shadow: none;
}
#play-screen .db-shell .db-dialog[data-kind="options"] .db-choice-tab { min-height: 44px; }
#play-screen .db-shell .db-dialog[data-kind="options"] .db-choice-tab:is(:focus-visible,[aria-pressed="true"]) {
  background: #365242ab; border-color: #efd69c; color: #fff0c9; outline: 1px solid #efd69c; outline-offset: 1px;
}
#play-screen .db-shell .db-dialog[data-kind="options"] :is(.db-choice-copy p,.db-choice-instruction,.db-choice-tab small),
#play-screen .db-shell .db-dialog:is([data-kind="info"], [data-kind="prophecy"]) :is(.db-private, .db-vision, .wr-shrine-record) { color: #efe8d3; }
#play-screen .db-shell .db-dialog[data-kind="history"] .wr-duel-report {
  padding: 12px;
  color: #ebe7d5;
  background: #071c18a3;
  border: 1px solid #c2aa6d62;
  border-inline-start: 2px solid #d8bd7a;
  font: 400 .88rem/1.55 var(--rh-reading, system-ui, sans-serif);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
#play-screen .db-shell .db-dialog[data-kind="history"] summary {
  display: list-item;
  padding-block: 12px;
  min-height: 44px;
  color: #f5dfa6;
  font: 600 .95rem/1.35 var(--rh-inscription, Georgia, serif);
  cursor: pointer;
}

/* In a narrow shrine band the reserves are two horizontal controls, each a full touch target. */
@media (max-width: 650px), (max-height: 510px) and (orientation: landscape) {
  #play-screen .db-immersive .db-sidepiles { gap: 2px; }
  #play-screen .db-immersive .db-sidepiles button[data-cmd="pile"] {
    width: min(100%, 75px);
    height: 44px;
    grid-template-columns: 26px minmax(0, 1fr);
    grid-template-rows: auto auto;
    grid-template-areas: "emblem name" "emblem count";
    gap: 1px 4px;
    padding: 2px;
  }
  #play-screen .db-shell .db-pile-emblem { inline-size: 23px; margin: 0; }
  #play-screen .db-shell .db-pile-caption { font-size: .62rem; }
  #play-screen .db-shell .db-pile-count { font-size: .69rem; }
}
@media (max-width: 650px) and (orientation: portrait) {
  #play-screen .db-immersive .db-side { grid-template-columns: minmax(0, 1fr) clamp(61px, 16vw, 74px) 102px; }
}
@media (max-width: 620px) {
  #play-screen .db-shell dialog.db-dialog[data-kind="pile"] {
    inline-size: min(100%, calc(100vw - 14px));
    padding: 13px;
    max-block-size: calc(100dvh - 14px);
  }
  #play-screen .db-shell .db-pile-inspector { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  #play-screen .db-shell .db-pile-reading {
    grid-template-columns: clamp(60px, 22vw, 100px) minmax(0, 1fr);
    align-items: start;
    justify-items: start;
    gap: 10px;
    max-block-size: 29dvh;
    padding: 3px;
  }
  #play-screen .db-shell .db-pile-portrait { width: 100%; }
  #play-screen .db-shell .db-pile-record h4 { font-size: 1.05rem; margin-block: 2px 4px; }
  #play-screen .db-shell .db-dialog[data-kind="pile"] .db-pile-inspector .db-pile-record .db-pile-rules { font-size: .85rem; line-height: 1.35; margin-block-start: 5px; }
  #play-screen .db-shell .db-pile-list { max-block-size: 42dvh; }
  #play-screen .db-shell dialog.db-dialog[data-kind="pile"] .db-pile-inspector .db-pile-summary { padding-block-end: 6px; }
}
@media (max-height: 560px) and (orientation: landscape) {
  #play-screen .db-shell dialog.db-dialog[data-kind="pile"] { max-block-size: calc(100dvh - 10px); padding: 10px 14px; }
  #play-screen .db-shell dialog.db-dialog[data-kind="pile"] .db-dialog-head { margin-bottom: 5px; padding-bottom: 4px; }
  #play-screen .db-shell .db-pile-inspector { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 12px; }
  #play-screen .db-shell .db-pile-reading { grid-template-columns: minmax(53px, .5fr) minmax(0, 1fr); align-items: start; gap: 8px; max-block-size: 65dvh; }
  #play-screen .db-shell .db-pile-list { max-block-size: 58dvh; }
  #play-screen .db-shell .db-dialog[data-kind="pile"] .db-pile-inspector .db-pile-record .db-pile-rules { font-size: .85rem; }
}
@media (prefers-reduced-motion: reduce) {
  #play-screen .db-shell .db-pile-emblem { transition: none; }
  #play-screen .db-immersive .db-sidepiles button:hover .db-pile-emblem { transform: none; }
}
@media (forced-colors: active) {
  #play-screen .db-shell :is(.db-pile-count,.db-pile-emblem,.db-pile-entry,.db-pile-private-print) { border: 1px solid ButtonText; }
  #play-screen .db-shell .db-pile-entry[aria-pressed="true"] { outline: 2px solid Highlight; outline-offset: -3px; }
}

html[data-rh-motion="reduced"] #play-screen .db-pile-emblem { transition: none; }
html[data-rh-motion="reduced"] #play-screen .db-immersive .db-sidepiles button:hover .db-pile-emblem { transform: none; }
