:root { --selected-bar-height: 48px; }

body.dense-ui { --card-exposed-height: 48px; }
.density-toggle { min-width: 70px; }
.density-toggle[aria-pressed="true"] { color: #fff; background: #536b82 !important; }

.destinations { grid-template-columns: repeat(6, var(--card-width)); }
.destinations > .destination:first-child { grid-column: 2; }
.selected-card-bar { position: sticky; z-index: 15; bottom: 0; display: flex; gap: .6rem; align-items: center; min-height: var(--selected-bar-height); margin-top: .65rem; padding: .35rem .55rem; border: 1px solid #d7b15d; border-radius: .55rem; background: rgba(16,45,39,.97); color: #f8e9b5; box-shadow: 0 -3px 12px rgba(0,0,0,.25); }
.selected-card-preview { display: grid; place-items: center; flex: 0 0 36px; height: 36px; border: 2px dashed #9fb3c6; border-radius: .3rem; background: #174e40; font-size: .65rem; text-align: center; overflow: hidden; }
.selected-card-preview.association { border-style: solid; background: #fff7dd; color: #242018; }
.selected-card-preview.category { border-style: solid; background: #536b82; color: #fff; }
#selected-card-info { min-width: 0; line-height: 1.15; overflow-wrap: anywhere; }

.card.category,
.card.category.difficulty-yellow,
.card.category.difficulty-green,
.card.category.difficulty-blue,
.card.category.difficulty-purple { color: #f7fbff; background: #536b82; border-color: #9fb3c6; }
.card.category .card-header,
.card.category.difficulty-yellow .card-header,
.card.category.difficulty-green .card-header,
.card.category.difficulty-blue .card-header,
.card.category.difficulty-purple .card-header { color: #f7fbff; background: #536b82; border-bottom-color: rgba(255,255,255,.2); }
.category-counter { background: #23394d; }
.card.selected { z-index: 45 !important; outline: 3px solid #60a5fa; outline-offset: -2px; transform: none; }
.column .card.selected { transform: none; }
.card.valid-target, .destination.valid-target, .column.valid-target { outline: 3px solid #6ee7a0; }

.destination.expanded { position: fixed; z-index: 55; overflow: auto; max-height: min(72dvh, 580px); background: #536b82; box-shadow: 0 12px 40px rgba(0,0,0,.65); }
.destination.expanded .card { position: relative !important; left: auto !important; top: auto !important; transform: none !important; width: calc(100% - 8px); height: 34px; margin: 4px; }
.destination.expanded .card.category { height: var(--card-height); }
.destination.expanded .card:not(.category) .card-body,
.destination.expanded .card:not(.category) small,
.destination.expanded .card:not(.category) .definition-button { display: none; }
.destination.expanded .card:not(.category) .card-header { min-height: 32px; max-height: 32px; flex-basis: 32px; color: #242018; background: #fff7dd; border: 1px solid #d7b15d; border-radius: .35rem; }
.destination-dimmer { position: fixed; z-index: 50; inset: 0; background: rgba(0,18,14,.72); }

.touch-drag-ghost { position: fixed; z-index: 80; left: 0; top: 0; width: var(--card-width); pointer-events: none; filter: drop-shadow(0 7px 5px rgba(0,0,0,.6)); }
.touch-drag-ghost .card { position: absolute; left: 0; width: var(--card-width); }
.touch-dragging { touch-action: none !important; }

@media (min-width: 1200px) {
  :root { --card-width: clamp(128px, 9.2vw, 176px); --card-height: clamp(184px, 13.4vw, 256px); --destination-card-height: min(118px, var(--card-height)); --card-exposed-height: 48px; --board-gap: clamp(8px, .75vw, 12px); }
  .destinations, .play-area { overflow: visible; }
}

@media (max-width: 760px) {
  :root { --margin: 8px; --card-width: calc((100vw - 2 * var(--margin) - 4 * 3px) / 5); --card-height: 72px; --destination-card-height: 72px; --card-exposed-height: 22.4px; --board-gap: 3px; --card-radius: 6px; }
  html, body { max-width: 100%; }
  body.game-active { height: 100%; min-height: 100dvh; overflow: hidden; }
  body.game-active.dense-ui { --card-exposed-height: 18px; }
  body.game-active .topbar { height: 42px; padding: 3px var(--margin); }
  body.game-active .topbar > div:first-child { min-width: 78px; }
  body.game-active .topbar h1 { font-size: 13px; white-space: nowrap; }
  body.game-active .tagline { display: none; }
  body.game-active .controls { width: auto; flex: 1; flex-wrap: nowrap; justify-content: flex-end; gap: 3px; }
  body.game-active .controls button { min-width: 0; padding: 4px 5px; font-size: 8px; white-space: nowrap; }
  body.game-active #game-screen { position: relative; width: 100%; height: calc(100dvh - 42px); margin: 0; padding: 0 var(--margin) calc(var(--selected-bar-height) + env(safe-area-inset-bottom)); overflow: hidden; }
  .game-dashboard { height: 42px; margin: 0; padding: 2px; border-width: 0 0 1px; border-radius: 0; box-shadow: none; }
  .toolbar-left { display: none; }
  .toolbar-right { width: 100%; flex-wrap: nowrap; gap: 3px; }
  .hand-score-panel, .stats-button, .density-toggle { min-width: 0; min-height: 36px; flex: 1; padding: 2px 3px; font-size: 8px; }
  .hand-score-panel strong { font-size: 13px; }
  .recovery-actions { display: flex; flex: 2; gap: 3px; }
  .recovery-actions button { min-width: 0; flex: 1; font-size: 7.5px; }
  .recovery-actions small img { display: none; }
  #destinations-title, .tableau-area > h2, .draw-area > h2 { display: none; }
  #destinations { height: 75px; padding: 3px 0 0; overflow: visible; }
  .destinations { grid-template-columns: repeat(5, var(--card-width)); }
  .destinations > .destination:first-child { grid-column: 1; }
  .destination { min-height: var(--card-height); height: var(--card-height); border-radius: var(--card-radius); overflow: hidden; }
  .destination .card { top: 0; left: 0; transform: none; width: var(--card-width); height: var(--card-height); }
  .destination .card-header { flex-basis: 23px; min-height: 23px; max-height: 23px; padding: 1px; font-size: 7px; }
  .destination .card-body { padding: 1px; font-size: 7px; }
  .destination .category-counter { min-width: 18px; padding: 1px; font-size: 6px; }
  .destination .definition-button, .destination .card small { display: none; }
  .play-area { display: block; margin: 0; padding: 0; overflow: visible; }
  .tableau { position: absolute; z-index: 20; top: 119px; right: var(--margin); left: var(--margin); grid-template-columns: repeat(5, var(--card-width)); gap: var(--board-gap); }
  .column, .tableau-placeholder { min-height: 72px; border-radius: var(--card-radius); }
  .column .card { height: var(--card-height); border-width: 1px; }
  .card-header { flex-basis: var(--card-exposed-height); min-height: var(--card-exposed-height); max-height: var(--card-exposed-height); padding: 1px 2px; gap: 1px; font-size: 8px; line-height: 9px; border-bottom-width: 1px; }
  .category-counter { min-width: 18px; padding: 1px; font-size: 6px; }
  .definition-button { display: none; }
  .card-body { padding: 2px; font-size: 8px; line-height: 9px; }
  .card small { display: none; }
  .draw-area { position: fixed; z-index: 30; right: var(--margin); bottom: calc(var(--selected-bar-height) + env(safe-area-inset-bottom)); left: var(--margin); height: var(--card-height); }
  .draw-row { flex-direction: row; gap: var(--board-gap); height: var(--card-height); overflow: visible; }
  .stock { flex: 0 0 var(--card-width); width: var(--card-width); height: var(--card-height); border-width: 3px; font-size: 8px; }
  .stock span { font-size: 12px; }
  .stock small { margin: 1px 0 0; font-size: 6px; text-align: center; }
  .waste { flex: 0 0 calc(3 * var(--card-width) - 2 * clamp(18px, 6vw, 28px)); width: auto; min-width: 0; min-height: var(--card-height); height: var(--card-height); overflow: visible; }
  .waste .card { top: 0 !important; width: var(--card-width); height: var(--card-height); }
  .waste .card:nth-child(1) { left: 0; }
  .waste .card:nth-child(2) { left: clamp(18px, 6vw, 28px); }
  .waste .card:nth-child(3) { left: calc(2 * clamp(18px, 6vw, 28px)); }
  .selected-card-bar { position: fixed; z-index: 35; right: 0; bottom: 0; left: 0; height: calc(var(--selected-bar-height) + env(safe-area-inset-bottom)); min-height: 0; margin: 0; padding: 4px max(var(--margin), env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(var(--margin), env(safe-area-inset-left)); border-width: 1px 0 0; border-radius: 0; }
  .selected-card-preview { flex-basis: 34px; height: 34px; }
  #selected-card-info { max-height: 34px; font-size: 10px; overflow: hidden; }
  .help, .move-feedback { display: none; }
  .definition-panel { z-index: 70; }
  .destination.expanded { top: 45px !important; max-height: min(70dvh, 570px); }
}

@media (max-width: 390px) { :root { --margin: 6px; --board-gap: 2px; } }
