:root { --selected-bar-height: 48px; }

.dictionary-toggle { min-width: 70px; }
.dictionary-toggle[aria-pressed="true"] { color: #fff; background: #536b82 !important; }

.destinations { grid-template-columns: repeat(6, var(--card-width)); }
.destinations > .destination:first-child { grid-column: 1; }
.column { background: transparent; }
.tableau-placeholder { background: transparent; outline: none; }
.move-description { min-width: 0; }
#move-description { display: block; opacity: .85; }
.column.empty::after, .destination.empty::after { content: none; }
.destination:not(.locked) { border: 0; }
.destination:not(.locked):not(.empty):not(.expanded) { background: transparent; }
.game-dashboard { border: 0; box-shadow: none; background: transparent; }
.play-area .draw-area { grid-column: 6; grid-row: 1; }
.play-area .tableau-area { grid-column: 1 / 6; grid-row: 1; }
#hand-diagnostic { width: 100%; }
.move-source { touch-action: none; -webkit-touch-callout: none; cursor: grab; }
.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 { outline: 4px solid #47c5ff; outline-offset: -2px; transform: none; }
.column .card.selected { transform: none; }
.destination .card.selected { transform: translateX(-50%); }
.destination:not(.expanded) .card.association { display: none; }
.destination:not(.expanded) .destination-latest { display: block; margin: auto 3px 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.destination.expanded .destination-latest { display: none; }

.destination.expanded { position: fixed; z-index: 55; height: auto; 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); }
body:has(.destination.expanded) .selected-card-bar { z-index: 51; pointer-events: none; }
.modal { z-index: 60; }
.definition-panel { z-index: 70; }
#game-overlays {
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
}
#game-overlays .modal,
#game-overlays dialog[open] { pointer-events: auto; }
#game-overlays .modal-card,
#game-overlays .definition-panel {
  background: #fff5d4;
  color: #281b08;
  border: 2px solid #ffd976;
  border-radius: .7rem;
  padding: clamp(.85rem, 4vw, 1.5rem);
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
  min-width: 0;
  max-width: calc(100vw - 2rem);
  max-height: calc(100dvh - 2rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow: auto;
}
#game-overlays dialog {
  inset: 0;
  margin: auto;
  width: min(440px, calc(100vw - 2rem));
}
#game-overlays dialog::backdrop, #game-overlays .modal { background: rgba(0,15,12,.7); }
#game-overlays h2 { margin-top: 0; letter-spacing: normal; text-transform: none; }
.decision-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: .5rem; }
.decision-actions button {
  border: 1px solid #a57b36;
  border-radius: .45rem;
  padding: .5rem .8rem;
  background: #fffaf0;
  color: #281b08;
}
#decision-confirm { background: #ffd976; font-weight: 700; }

.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; }
.touch-dragging #game-screen, .touch-dragging #game-screen * { cursor: grabbing; }

@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 #game-screen, body.game-active .topbar { touch-action: manipulation; }
  body.game-active .topbar { flex-direction: row; align-items: center; gap: 4px; 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; flex-wrap: nowrap; margin: 0; padding: 2px; border-width: 0 0 1px; border-radius: 0; box-shadow: none; }
  .toolbar-left { display: none; }
  .toolbar-right { flex: 1 1 auto; width: 100%; flex-wrap: nowrap; gap: 3px; }
  .hand-score-panel, .stats-button, .dictionary-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)); gap: var(--board-gap); }
  .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.selected { transform: none; }
  .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; }
  .destination:not(.expanded) .destination-latest { font-size: 7px; }
  .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:not(.expanded) { min-height: 72px !important; }
  .destination.expanded { height: auto; }
  .destination.locked { font-size: 9px; }
  .destination.locked b { font-size: 12px; }
  .card-header > span { min-width: 0; }
  .category-counter { flex-shrink: 0; }
}

@media (max-width: 390px) { :root { --margin: 6px; --board-gap: 2px; } }

@media (max-width: 760px) {
  .stock { touch-action: manipulation; }
  .stock > * { pointer-events: none; }
  .toolbar-right > button, .toolbar-right .recovery-actions > button {
    height: 36px;
    min-height: 36px;
    padding: 2px 3px;
    border: 1px solid #819d8e !important;
    border-radius: 5px;
    background: #28483e !important;
    color: #fff7dd;
    font: 700 9px/1.15 system-ui;
    text-transform: none;
    text-align: center;
  }
  .toolbar-right button strong, .toolbar-right button span,
  .toolbar-right button small { color: inherit; font-size: inherit; letter-spacing: normal; text-transform: none; }
  .toolbar-right .dictionary-toggle[aria-pressed="true"] { background: #425e7c !important; }
  .destination .card-body { font-size: 6px; line-height: 1.1; }
  .card.category .card-body { display: none; }
  .card.category .card-header > span {
    font-size: 8px;
    line-height: 9px;
    overflow-wrap: normal;
    word-break: normal;
  }
  .destination .card.category .card-header {
    flex: 1 1 auto;
    max-height: none;
    min-height: 23px;
    border-bottom: 0;
  }
  .destination .card.category .card-header > span { -webkit-line-clamp: 3; }
  .selected-card-bar { border-top-color: rgba(255,255,255,.18); }
  .destination:not(.expanded) .destination-latest {
    flex: 0 0 auto;
    margin: 0 2px 2px;
    padding: 3px 2px;
    border-radius: 3px;
    background: #fff7dd;
    color: #242018;
    font: 700 8px/10px system-ui;
    text-align: center;
  }
  #move-description { font-size: 9px; line-height: 1.1; }
}
