/* EUCARI UI foundation v3
   One stable composition replaces the accumulated desktop layout patches. */

:root {
  --ui-space-1: 6px;
  --ui-space-2: 10px;
  --ui-space-3: 14px;
  --ui-space-4: 18px;
  --ui-space-5: 24px;
  --ui-space-6: 32px;
  --ui-radius: 6px;
  --ui-text: 16px;
  --ui-small: 14px;
  --ui-label: 13px;
}

body {
  min-width: 320px;
  font-size: var(--ui-text);
}

body.access-locked {
  overflow: hidden;
  background: #070909;
}

.access-gate {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 100dvh;
  padding: clamp(18px, 4vw, 54px);
  background:
    radial-gradient(circle at 50% 34%, rgba(198, 166, 101, 0.07), transparent 38%),
    #070909;
}

.access-panel {
  display: grid;
  gap: 24px;
  width: min(100%, 520px);
  padding: clamp(26px, 5vw, 48px);
  border: 1px solid rgba(205, 176, 116, 0.32);
  border-radius: 6px;
  background: #0b0e0d;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.58);
}

.access-brand {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(205, 176, 116, 0.2);
}

.access-brand strong {
  color: var(--gold-bright);
  font-family: var(--display);
  font-size: clamp(38px, 8vw, 58px);
  font-weight: 400;
  line-height: 0.9;
}

.access-brand span,
.access-copy > p,
.access-fields label > span {
  color: var(--muted);
}

.access-brand span {
  max-width: 150px;
  font-size: 12px;
  line-height: 1.35;
  text-align: right;
  text-transform: uppercase;
}

.access-copy {
  display: grid;
  gap: 8px;
}

.access-copy .eyebrow {
  margin: 0;
}

.access-copy h1 {
  margin: 0;
  color: var(--ink);
  font-family: var(--title);
  font-size: clamp(28px, 5vw, 38px);
  line-height: 1.08;
}

.access-copy > p:last-child {
  margin: 0;
  font-size: 16px;
}

.access-fields {
  display: grid;
  gap: 16px;
}

.access-fields label {
  display: grid;
  gap: 8px;
}

.access-fields label > span {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.access-fields input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid rgba(205, 176, 116, 0.28);
  border-radius: 4px;
  color: var(--ink);
  background: #090c0b;
  outline: 0;
}

.access-fields input:focus {
  border-color: rgba(229, 197, 128, 0.74);
  box-shadow: 0 0 0 3px rgba(205, 176, 116, 0.1);
}

.access-status {
  min-height: 20px;
  margin: -8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.access-status[data-tone="error"] { color: #d98689; }
.access-status[data-tone="success"] { color: #9fc494; }
.access-status[data-tone="pending"] { color: var(--gold-bright); }

.access-panel > button {
  min-height: 50px;
}

button,
input,
select,
textarea {
  font-size: 15px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(620px, 1.05fr) minmax(560px, 0.95fr);
  grid-template-rows: minmax(0, 1fr);
  gap: var(--ui-space-4);
  width: 100%;
  height: 100dvh;
  padding: var(--ui-space-4);
  overflow: hidden;
}

.board-section {
  position: relative;
  grid-column: 1;
  grid-row: 1;
  align-self: center;
  justify-self: center;
  width: min(100%, calc(100dvh - 36px));
  height: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid rgba(205, 176, 116, 0.26);
  border-radius: var(--ui-radius);
  background: #090b0a;
}

.board-zoom-control {
  position: absolute;
  z-index: 30;
  top: 12px;
  right: 12px;
  display: grid;
  grid-template-columns: auto 78px auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 38px;
  padding: 6px 9px;
  border: 1px solid rgba(205, 176, 116, 0.36);
  border-radius: 4px;
  background: rgba(7, 10, 10, 0.9);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.38);
  color: var(--muted);
  font-size: 12px;
  opacity: 0.82;
  transition: opacity 160ms ease, border-color 160ms ease;
}

.board-zoom-control:hover,
.board-zoom-control:focus-within {
  border-color: rgba(226, 195, 127, 0.66);
  opacity: 1;
}

.board-zoom-control input {
  width: 78px;
  margin: 0;
}

.board-zoom-control output {
  min-width: 34px;
  color: var(--ivory);
  text-align: right;
}

.board-stage,
.board-viewport {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

.board-stage {
  contain: layout paint;
}

.board-grid {
  contain: layout style;
}

.board-grid .cell {
  contain: layout style;
}

.board-grid .cell-icon {
  max-width: calc(100% - 16px) !important;
  max-height: calc(100% - 16px) !important;
  overflow: hidden;
  contain: layout paint style;
}

.board-grid .cell-icon > .asset-image,
.board-grid .cell-icon > img,
.board-grid .cell-icon > svg {
  display: block;
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  object-fit: contain;
  object-position: center;
}

.board-grid .feature-marks {
  max-width: calc(100% - 12px);
  overflow: hidden;
}

.board-grid .cell.hidden {
  border-color: rgba(205, 176, 116, 0.13);
  background: #121513;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.018),
    inset 0 -12px 22px rgba(0, 0, 0, 0.16);
}

.board-grid .cell.hidden .mystery-mark,
.board-grid .cell.hidden .cell-icon {
  display: none;
}

.board-grid .cell.hidden:hover {
  border-color: rgba(205, 176, 116, 0.28);
  background: #161a17;
}

.board-frame {
  width: 100%;
  height: 100%;
}

.game-sidebar {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(205, 176, 116, 0.2);
  border-radius: var(--ui-radius);
  background: rgba(7, 10, 10, 0.96);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.38);
}

.game-sidebar .topbar {
  position: relative;
  grid-column: auto;
  grid-row: auto;
  display: grid;
  grid-template-columns: minmax(150px, 0.7fr) minmax(300px, 1.3fr);
  grid-template-areas:
    "brand status"
    "corruption corruption";
  align-items: center;
  gap: var(--ui-space-2) var(--ui-space-4);
  width: 100%;
  height: auto;
  min-height: 94px;
  padding: var(--ui-space-3) var(--ui-space-4);
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: #080b0b;
  box-shadow: none;
}

.game-sidebar .brand-lockup {
  grid-area: brand;
  padding: 0;
}

.game-sidebar .brand-lockup h1 {
  font-size: 32px;
  line-height: 0.95;
}

.game-sidebar .brand-lockup p {
  margin: 6px 0 0;
  font-size: var(--ui-label);
  line-height: 1.2;
}

.game-sidebar .world-status {
  grid-area: status;
  justify-self: end;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--ui-space-2);
  min-width: 0;
}

.game-sidebar .status-line {
  min-width: 58px;
  padding: 0 0 0 var(--ui-space-2);
}

.game-sidebar .status-line span,
.game-sidebar .track-title {
  font-size: var(--ui-label);
}

.game-sidebar .status-line strong {
  margin-top: 3px;
  font-size: 13px;
}

.game-sidebar .new-game {
  min-width: 126px;
  min-height: 42px;
  padding: 0 var(--ui-space-3);
  font-size: var(--ui-label);
}

.game-sidebar .icon-button {
  width: 36px;
  height: 36px;
}

.game-sidebar .corruption-track {
  grid-area: corruption;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: var(--ui-space-3);
  width: 100%;
  padding: 0;
}

.game-sidebar .corruption-nodes {
  width: 100%;
}

.game-sidebar .corruption-node {
  width: 28px;
  height: 28px;
  font-size: var(--ui-label);
}

.game-sidebar .player-rail {
  grid-column: auto;
  grid-row: auto;
  display: flex;
  flex-flow: row nowrap;
  align-items: stretch;
  gap: var(--ui-space-2);
  min-width: 0;
  min-height: 0;
  padding: var(--ui-space-2) var(--ui-space-3);
  overflow-x: auto;
  overflow-y: hidden;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(7, 9, 9, 0.72);
}

.game-sidebar .rail-player {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-items: center;
  justify-items: start;
  gap: 2px var(--ui-space-2);
  flex: 1 0 124px;
  min-width: 124px;
  min-height: 58px;
  padding: 8px;
  border: 1px solid transparent;
  border-left: 3px solid color-mix(in srgb, var(--player), transparent 45%);
  border-radius: 4px;
  background: rgba(12, 15, 15, 0.78);
}

.game-sidebar .rail-player.active {
  border-color: color-mix(in srgb, var(--player), transparent 48%);
  border-left-color: var(--player);
  background: color-mix(in srgb, var(--player), rgba(10, 12, 12, 0.9) 86%);
  box-shadow: inset 0 0 20px color-mix(in srgb, var(--player), transparent 89%);
}

.game-sidebar .rail-player:not(.active) {
  cursor: pointer;
  transition: opacity 160ms ease, filter 160ms ease, border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.game-sidebar .rail-player:not(.active):hover,
.game-sidebar .rail-player:not(.active):focus-visible {
  opacity: 0.72;
  filter: saturate(0.78) brightness(0.92);
  border-color: color-mix(in srgb, var(--player), transparent 58%);
  border-left-color: var(--player);
  background: color-mix(in srgb, var(--player), rgba(12, 15, 15, 0.88) 91%);
  transform: translateY(-1px);
}

.game-sidebar .rail-player:not(.active):focus-visible {
  outline: 1px solid color-mix(in srgb, var(--player), #ffffff 14%);
  outline-offset: 2px;
}

.game-sidebar .rail-avatar {
  grid-column: 1;
  grid-row: 1 / 3;
  width: 42px;
  height: 42px;
  padding: 6px;
  aspect-ratio: 1;
  min-width: 42px;
  overflow: visible;
  flex: none;
}

.game-sidebar .rail-avatar svg,
.game-sidebar .rail-avatar img,
.game-sidebar .rail-avatar .asset-mask {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.game-sidebar .rail-name {
  align-self: end;
  font-size: 13px;
}

.game-sidebar .rail-player small {
  align-self: start;
  font-size: var(--ui-label);
}

.game-sidebar .right-panel {
  grid-column: auto;
  grid-row: auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 0;
  background: transparent;
}

.game-sidebar .board-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "title"
    "room";
  align-items: center;
  gap: 7px var(--ui-space-4);
  min-width: 0;
  min-height: 92px;
  padding: var(--ui-space-3) var(--ui-space-4);
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(10, 13, 13, 0.55);
}

.game-sidebar .board-toolbar-title strong {
  display: block;
  font-size: var(--ui-label);
}

.game-sidebar .board-toolbar-title span {
  display: none;
}

.game-sidebar .room-inspector {
  grid-area: room;
  min-width: 0;
  min-height: 46px;
  padding: 0;
  overflow: hidden;
}

.game-sidebar .room-inspector-body {
  grid-template-columns: 40px minmax(0, 1fr);
  gap: var(--ui-space-2);
  min-width: 0;
  padding: 0;
}

.game-sidebar .inspection-visual {
  width: 40px;
  height: 40px;
}

.game-sidebar .room-inspector-body > div:last-child {
  min-width: 0;
}

.game-sidebar .room-inspector-body strong {
  font-size: 14px;
  line-height: 1.2;
}

.game-sidebar .room-inspector-body p {
  margin-top: 3px;
  font-size: var(--ui-small);
  line-height: 1.35;
  -webkit-line-clamp: 2;
}

.game-sidebar .character-sheet {
  min-width: 0;
  min-height: 0;
  max-height: none;
  padding: var(--ui-space-4) var(--ui-space-5);
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: stable;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
}

.game-sidebar .sheet-panel {
  display: grid;
  align-items: start;
  min-width: 0;
  min-height: 100%;
  padding: 0;
}

.game-sidebar .sheet-layout {
  display: grid;
  grid-template-columns: minmax(230px, 0.92fr) minmax(270px, 1.08fr);
  grid-template-rows: auto auto;
  column-gap: var(--ui-space-5);
  row-gap: var(--ui-space-3);
  width: 100%;
  height: auto;
  min-width: 0;
  min-height: 0;
  align-content: start;
}

.game-sidebar .sheet-primary,
.game-sidebar .sheet-spiritual {
  min-width: 0;
}

.game-sidebar .sheet-spiritual {
  display: block;
  align-content: initial;
  padding-left: var(--ui-space-5);
  border-left: 1px solid var(--line-soft);
}

.game-sidebar .sheet-hero {
  grid-template-columns: 54px minmax(0, 1fr);
  gap: var(--ui-space-3);
  min-height: 62px;
  padding-bottom: var(--ui-space-2);
}

.game-sidebar .portrait-ring {
  width: 52px;
  height: 52px;
  padding: 10px;
}

.game-sidebar .sheet-identity h2 {
  margin: 4px 0 2px;
  font-size: 27px;
  line-height: 1;
}

.game-sidebar .sheet-identity p strong,
.game-sidebar .sheet-identity p em {
  font-size: var(--ui-small);
}

.game-sidebar .resource-rows {
  margin-top: var(--ui-space-2);
}

.game-sidebar .resource-rows > div,
.game-sidebar .resource-rows > button {
  grid-template-columns: 98px minmax(0, 1fr) 40px;
  gap: var(--ui-space-2);
  min-height: 34px;
}

.game-sidebar .resource-rows > div > span:first-child,
.game-sidebar .resource-rows > button > span:first-child {
  font-size: var(--ui-label);
}

.game-sidebar .resource-rows > div > strong,
.game-sidebar .resource-rows > button > strong,
.game-sidebar .checkpoint-marker b {
  font-size: var(--ui-label);
}

.game-sidebar .spiritual-goal {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 5px;
  margin-top: var(--ui-space-2);
  padding: 12px 0 11px;
  border-top: 1px solid var(--line-soft);
}

.game-sidebar .spiritual-goal span {
  font-size: 11px;
  line-height: 1.2;
}

.game-sidebar .spiritual-goal strong {
  font-size: 13px;
  line-height: 1.4;
  text-align: left;
}

/* Consolidate legacy compact rules behind the current readable scale. */
.game-sidebar .sheet-primary .spiritual-goal strong {
  font-size: 13px;
  line-height: 1.4;
  text-align: left;
}

.game-sidebar .sheet-spiritual .wound > div strong {
  font-size: 14px;
}

.game-sidebar .sheet-spiritual .wound p {
  font-size: var(--ui-small);
  line-height: 1.4;
}

.game-sidebar .sheet-spiritual .wound em {
  font-size: 11px;
}

.game-sidebar .resource-rows > div > strong,
.game-sidebar .resource-rows > button > strong,
.game-sidebar .checkpoint-marker b {
  font-size: var(--ui-label);
}

.game-sidebar .room-inspector-body p,
.game-sidebar .action-guidance strong {
  font-size: var(--ui-small);
}

.game-sidebar .action-guidance small {
  font-size: var(--ui-label);
}

/* Preserve artwork proportions. When space runs out, controls reflow or
   scroll instead of compressing their icon boxes. */
.game-sidebar .rail-avatar,
.game-sidebar .portrait-ring,
.game-sidebar .action-button span,
.game-sidebar .end-turn span,
.game-sidebar .card-sigil,
.game-sidebar .inspection-visual {
  aspect-ratio: 1;
  flex: 0 0 auto;
}

.game-sidebar .rail-avatar > *,
.game-sidebar .portrait-ring > *,
.game-sidebar .action-button span > *,
.game-sidebar .end-turn span > *,
.game-sidebar .card-sigil > *,
.game-sidebar .inspection-visual > * {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.game-sidebar .player-section {
  margin-top: 0;
  padding-top: 0;
}

.game-sidebar .player-section-title {
  margin-bottom: var(--ui-space-2);
}

.game-sidebar .player-section-title span {
  font-size: 14px;
}

.game-sidebar .player-section-title small {
  font-size: var(--ui-label);
}

.game-sidebar .sheet-spiritual .wound {
  grid-template-columns: 30px minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: var(--ui-space-2);
  row-gap: 3px;
  min-height: 60px;
  height: auto;
  padding: 8px 0;
}

.game-sidebar .sheet-spiritual .wound-icon {
  grid-column: 1;
  grid-row: 1 / 3;
  width: 28px;
  height: 28px;
}

.game-sidebar .sheet-spiritual .wound > div {
  grid-column: 2;
  grid-row: 1;
}

.game-sidebar .sheet-spiritual .wound > div strong {
  font-size: 13px;
}

.game-sidebar .sheet-spiritual .wound p {
  margin-top: 4px;
  font-size: var(--ui-small);
  line-height: 1.35;
  -webkit-line-clamp: 2;
}

.game-sidebar .sheet-spiritual .wound em {
  grid-column: 2;
  grid-row: 2;
  justify-self: start;
  max-width: none;
  font-size: 10px;
  line-height: 1.3;
  text-align: left;
}

.game-sidebar .sheet-layout > .treasures-section {
  grid-column: 1 / -1;
  grid-row: 2;
  min-width: 0;
  min-height: 96px;
  max-height: none;
  margin-top: 0;
  padding-top: var(--ui-space-3);
  border-top: 1px solid var(--line-soft);
}

.game-sidebar .sheet-layout > .treasures-section .treasure-list,
.game-sidebar .sheet-layout > .treasures-section .treasure-hand {
  width: 100%;
  min-height: 76px;
  height: auto;
}

.game-sidebar .sheet-layout > .treasures-section .treasure-hand {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: var(--ui-space-3);
  padding: 5px var(--ui-space-3) var(--ui-space-2);
  overflow-x: auto;
  overflow-y: visible;
}

.game-sidebar .sheet-layout > .treasures-section .treasure-card {
  flex: 0 0 78px;
  width: 78px;
  min-width: 78px;
  max-width: 78px;
  height: 88px;
  grid-template-rows: 29px auto auto;
  padding: 7px 6px;
}

.game-sidebar .treasure-card strong {
  font-size: 10px;
  line-height: 1.15;
}

.game-sidebar .treasure-card small {
  font-size: 8px;
}

.game-sidebar .card-sigil {
  width: 29px;
  height: 29px;
}

@media (min-width: 1600px) {
  .game-sidebar .sheet-panel {
    align-items: center;
  }

  .game-sidebar .sheet-layout {
    grid-template-columns: minmax(220px, 0.88fr) minmax(270px, 1.08fr) minmax(210px, 0.82fr);
    grid-template-rows: auto;
    align-items: center;
    column-gap: var(--ui-space-5);
  }

  .game-sidebar .sheet-layout > .treasures-section {
    grid-column: 3;
    grid-row: 1;
    align-self: stretch;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    align-content: center;
    min-height: 250px;
    padding: 0 0 0 var(--ui-space-5);
    border-top: 0;
    border-left: 1px solid var(--line-soft);
  }

  .game-sidebar .sheet-layout > .treasures-section .treasure-list {
    display: grid;
    align-items: center;
  }

  .game-sidebar .sheet-layout > .treasures-section .treasure-hand {
    display: grid;
    grid-template-columns: repeat(3, minmax(58px, 1fr));
    justify-content: start;
    align-content: center;
    gap: var(--ui-space-2);
    padding: var(--ui-space-3) 0;
    overflow: hidden;
  }

  .game-sidebar .sheet-layout > .treasures-section .treasure-card {
    flex: none;
    width: 100%;
    min-width: 0;
    max-width: none;
    height: auto;
    aspect-ratio: 0.8;
  }

  .game-sidebar .sheet-layout > .treasures-section .treasure-add {
    width: 40px;
    min-width: 40px;
  }
}

.game-sidebar .action-dock {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 68px;
  grid-template-rows: 68px auto;
  gap: 7px;
  min-width: 0;
  min-height: 0;
  padding: 10px var(--ui-space-3) 8px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: #090c0c;
}

.game-sidebar .action-buttons {
  display: grid;
  grid-template-columns: none;
  grid-auto-flow: column;
  grid-auto-columns: minmax(96px, 1fr);
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.game-sidebar .action-button {
  grid-template-rows: 34px auto;
  min-height: 66px;
  padding: 7px 6px;
  border-radius: 4px;
}

.game-sidebar .action-button span,
.game-sidebar .end-turn span {
  width: 33px;
  height: 33px;
  padding: 5px;
}

.game-sidebar .action-button strong,
.game-sidebar .end-turn strong {
  font-size: var(--ui-label);
  line-height: 1.15;
}

.game-sidebar .action-side,
.game-sidebar .end-turn {
  width: 68px;
  height: 66px;
  border-radius: 4px;
}

.game-sidebar .action-side {
  grid-column: 2;
  grid-row: 1;
}

.game-sidebar .action-guidance {
  grid-column: 1 / 3;
  grid-row: 2;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: var(--ui-space-2);
  min-height: 46px;
  height: auto;
  padding: 8px 0 2px;
}

.game-sidebar .guidance-mark {
  width: 21px;
  height: 21px;
}

.game-sidebar .action-guidance strong,
.game-sidebar .action-guidance small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-sidebar .action-guidance strong {
  font-size: var(--ui-small);
  line-height: 1.3;
}

.game-sidebar .action-guidance small {
  margin-top: 2px;
  font-size: var(--ui-label);
  line-height: 1.25;
}

.utility-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  min-height: 44px;
  padding: 7px var(--ui-space-3) 9px;
}

.utility-strip .events-toggle,
.utility-strip .ai-toggle,
.utility-strip .debug-toggle {
  position: relative;
  inset: auto;
  width: 100%;
  min-width: 0;
  min-height: 32px;
  padding: 0 var(--ui-space-2);
  font-size: var(--ui-label);
  border-radius: 4px;
}

body.cpu-turn .game-sidebar .action-button,
body.cpu-turn .game-sidebar .end-turn {
  opacity: 0.36;
  filter: saturate(0.45);
  cursor: not-allowed;
}

body.cpu-turn .board-token.active {
  pointer-events: none;
  cursor: default;
}

/* La ficha en turno ocupa el centro físico de la sala; las demás conservan
   su agrupación en la esquina cuando varios jugadores comparten casilla. */
.tokens {
  inset: 0;
  box-sizing: border-box;
  align-items: flex-start;
  padding: 5px 6px 0;
}

.tokens .board-token.active {
  position: absolute;
  top: 50%;
  left: 50%;
  margin-left: 0;
  transform: translate(-50%, -54%) rotateX(3deg);
}

.tokens .board-token.active:hover {
  transform: translate(-50%, -62%) rotateX(0deg) scale(1.07);
}

.tokens .board-token.active:active,
body.dragging-token .tokens .board-token.active {
  transform: translate(-50%, -66%) rotate(-2deg) scale(1.09);
}

body.turn-ending .tokens .board-token.active {
  transform: translate(-50%, -52%) rotateX(3deg) scale(0.82);
}

.wound.read-only {
  cursor: default;
}

/* Un estado resuelto puede ganar legibilidad al inspeccionarse, pero nunca
   recuperar el color que comunica que el elemento sigue activo. */
.board-grid .cell.resolved-primary:hover:not(:disabled) .cell-icon {
  opacity: 0.64;
  filter: grayscale(1) brightness(1.12) contrast(0.94);
  transform: translate(-50%, -52%);
}

.board-grid .cell.resolved-primary-icon:hover:not(:disabled) .cell-icon {
  opacity: 0.64;
  filter: grayscale(1) brightness(1.12) contrast(0.94);
  transform: translate(-50%, -52%);
}

.board-grid .cell:hover:not(:disabled) .feature-mark.resolved {
  opacity: 0.92;
  filter: grayscale(1) brightness(1.1);
}

.modal,
.encounter-panel,
.dice-panel {
  border-radius: var(--ui-radius);
}

.asset-image {
  object-fit: contain;
  object-position: center;
}

.encounter-visual .asset-image,
.encounter-visual img.svg-icon {
  display: block;
  width: min(136px, 58%);
  height: auto;
  max-width: 58%;
  max-height: 136px;
  object-fit: contain;
  object-position: center;
  opacity: 1;
  visibility: visible;
}

.modal h2,
.encounter-copy h2,
.dice-panel h2 {
  font-size: 30px;
  line-height: 1.12;
}

.modal-intro,
.mode-summary,
.encounter-description,
.encounter-condition,
.dice-panel > p:not(.eyebrow) {
  font-size: 15px;
  line-height: 1.55;
}

.registration-modal {
  display: grid;
  grid-template-columns: minmax(300px, 0.72fr) minmax(560px, 1.28fr);
  width: min(1180px, calc(100vw - 48px));
  max-width: 1180px;
  max-height: min(900px, calc(100dvh - 48px));
  overflow: hidden;
}

.registration-brand {
  min-height: 100%;
  padding: 54px 42px;
}

.registration-brand strong {
  font-size: 66px;
}

.registration-brand span {
  max-width: 260px;
  font-size: 15px;
  line-height: 1.55;
}

.registration-form {
  min-width: 0;
  padding: 42px 48px;
  overflow-y: auto;
}

.start-mode-tabs,
.online-mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: var(--ui-space-4) 0;
}

.start-mode-tabs button,
.online-mode-tabs button {
  min-height: 46px;
  padding: 0 var(--ui-space-3);
  border-radius: 4px;
}

.player-count-field,
.lobby-field {
  gap: 8px;
  font-size: 14px;
}

.player-count-field select,
.lobby-field input,
.lobby-field select {
  min-height: 48px;
  padding: 0 var(--ui-space-3);
  border-radius: 4px;
}

.count-field {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.count-picker {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  background: #080b0b;
}

.count-picker button {
  width: 44px;
  min-width: 0;
  height: 40px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  background: transparent;
}

.count-picker button:hover {
  color: var(--ivory);
  background: rgba(226, 195, 127, 0.06);
}

.count-picker button.active {
  border-color: rgba(226, 195, 127, 0.55);
  color: #0a0c0c;
  background: #e2c37f;
}

.cpu-difficulty-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.cpu-difficulty-picker button {
  display: grid;
  align-content: center;
  gap: 4px;
  min-width: 0;
  min-height: 68px;
  padding: 12px 14px;
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  color: var(--muted);
  text-align: left;
  background: rgba(255, 255, 255, 0.018);
}

.cpu-difficulty-picker button strong {
  color: var(--ivory);
  font-size: 15px;
}

.cpu-difficulty-picker button small {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
}

.cpu-difficulty-picker button:hover {
  border-color: rgba(226, 195, 127, 0.38);
  background: rgba(226, 195, 127, 0.05);
}

.cpu-difficulty-picker button.active {
  border-color: rgba(226, 195, 127, 0.72);
  background: rgba(226, 195, 127, 0.1);
  box-shadow: inset 3px 0 0 #e2c37f;
}

.cpu-difficulty-picker button.active strong {
  color: #e9cd8c;
}

.solo-color-picker {
  display: grid;
  grid-template-columns: repeat(4, 48px);
  gap: 10px;
}

.solo-color-picker button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 8px;
  border: 1px solid rgba(205, 176, 116, 0.2);
  border-radius: 6px;
  color: var(--swatch);
  background: rgba(10, 12, 12, 0.72);
  cursor: pointer;
}

.solo-color-picker button span,
.solo-color-picker button svg {
  width: 28px;
  height: 28px;
}

.solo-color-picker button.active {
  border-color: var(--swatch);
  background: color-mix(in srgb, var(--swatch), transparent 88%);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--swatch), transparent 82%);
}

.encounter-condition ul {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.encounter-condition li {
  position: relative;
  padding-left: 17px;
}

.encounter-condition li::before {
  content: "";
  position: absolute;
  top: 0.66em;
  left: 1px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--gold-bright);
  transform: translateY(-50%);
}

.registration-rows {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--ui-space-2);
  margin-top: var(--ui-space-3);
}

.registration-player {
  min-height: 70px;
  padding: var(--ui-space-2) var(--ui-space-3);
  border-radius: 4px;
}

.registration-copy input {
  min-height: 34px;
  font-size: 16px;
}

.registration-copy small {
  font-size: var(--ui-label);
}

.local-name-status {
  min-height: 20px;
  margin: var(--ui-space-2) 0 0;
  color: #c79875;
  font-size: var(--ui-small);
}

.local-name-status.ready {
  color: #8eac79;
}

.registration-form #startGameBtn:disabled {
  border-color: rgba(205, 176, 116, 0.18);
  color: rgba(234, 222, 197, 0.38);
  background: rgba(255, 255, 255, 0.018);
  box-shadow: none;
  opacity: 1;
  filter: saturate(0.25);
  cursor: not-allowed;
}

#setupOverlay .modal {
  width: min(1240px, calc(100vw - 48px));
  max-width: 1240px;
  max-height: calc(100dvh - 48px);
  padding: 36px 40px;
  overflow-y: auto;
}

.setup-player {
  margin: var(--ui-space-4) 0;
}

.setup-player h3 {
  font-size: 22px;
}

.setup-player p {
  margin-bottom: 0;
  font-size: 14px;
}

.draft-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--ui-space-3);
}

.draft-card {
  min-height: 210px;
  padding: var(--ui-space-4);
  border-radius: 4px;
}

.draft-card strong {
  font-size: 18px;
}

.draft-card > span:not(.draft-wound-icon),
.draft-card em {
  font-size: 13px;
  line-height: 1.5;
}

.modal-actions {
  gap: var(--ui-space-2);
  margin-top: var(--ui-space-4);
}

.modal-actions button,
.modal-actions a,
.encounter-actions button {
  min-height: 48px;
  padding: 0 var(--ui-space-5);
  border-radius: 4px;
}

.encounter-copy {
  padding: 42px 44px;
}

.encounter-actions {
  gap: var(--ui-space-2);
}

/* CPU narration is informational. Its advance control has an independent row
   so it cannot cover results or look like a decision inside the card. */
.encounter-overlay.cpu-sequence-open {
  display: grid;
  grid-template-rows: auto auto;
  align-content: center;
  place-items: center;
  gap: var(--ui-space-3);
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  overflow: hidden;
}

.encounter-overlay.cpu-sequence-open.is-hidden {
  display: none;
}

.encounter-panel.cpu-sequence {
  position: relative;
  align-self: center;
  max-height: min(720px, calc(100dvh - 104px));
  margin: 0;
  overflow: hidden;
}

.encounter-panel.cpu-sequence .encounter-copy {
  min-height: 0;
  padding: 30px 38px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.encounter-panel.cpu-sequence .encounter-changes {
  margin-top: 16px;
}

.encounter-panel.cpu-sequence .encounter-change {
  min-height: 50px;
  padding: 7px 10px;
}

.encounter-panel.cpu-sequence .encounter-rule {
  margin-top: 16px;
  padding: 12px 0;
}

.encounter-panel.cpu-sequence .encounter-actions {
  display: none;
}

.encounter-sequence-actions {
  display: flex;
  justify-content: center;
  width: 100%;
}

.encounter-sequence-actions.is-hidden {
  display: none;
}

.encounter-sequence-actions .encounter-next {
  min-width: 240px;
  min-height: 52px;
  border-color: rgba(226, 195, 127, 0.68);
  background: #e2c37f;
  color: #0b0d0d;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.55);
}

.encounter-sequence-actions .encounter-next:hover:not(:disabled) {
  border-color: #f0d89d;
  background: #ecd08f;
}

.events-panel,
.ai-panel,
.debug-panel {
  right: var(--ui-space-4);
  bottom: 58px;
  left: auto;
  width: min(540px, calc(100vw - 36px));
  border-radius: var(--ui-radius);
}

@media (max-width: 1280px) and (min-width: 1101px) {
  .app-shell {
    grid-template-columns: minmax(600px, 1.02fr) minmax(500px, 0.98fr);
    gap: 12px;
    padding: 12px;
  }

  .board-section {
    width: min(100%, calc(100dvh - 24px));
  }

  .game-sidebar .topbar {
    min-height: 86px;
    padding: 10px 12px;
  }

  .game-sidebar .brand-lockup h1 {
    font-size: 28px;
  }

  .game-sidebar .new-game {
    min-width: 108px;
  }

  .game-sidebar .character-sheet {
    padding: 14px 16px;
  }

  .game-sidebar .sheet-layout {
    grid-template-columns: minmax(210px, 0.9fr) minmax(240px, 1.1fr);
    column-gap: 16px;
  }

  .game-sidebar .sheet-spiritual {
    padding-left: 16px;
  }
}

@media (max-width: 1100px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    height: auto;
    min-height: 100dvh;
    padding: 12px;
  }

  .board-section {
    grid-column: 1;
    grid-row: 1;
    width: min(100%, 860px);
  }

  .game-sidebar {
    grid-column: 1;
    grid-row: 2;
    height: auto;
    overflow: visible;
  }

  .game-sidebar .right-panel {
    overflow: visible;
  }

  .game-sidebar .character-sheet {
    overflow: visible;
  }

  .game-sidebar .sheet-layout {
    grid-template-columns: minmax(260px, 0.9fr) minmax(300px, 1.1fr);
  }
}

@media (max-width: 760px) {
  :root {
    --ui-text: 15px;
  }

  .modal-backdrop,
  .encounter-overlay,
  .dice-overlay {
    padding: 10px;
  }

  .app-shell {
    gap: 8px;
    padding: 6px;
  }

  .board-zoom-control {
    top: 8px;
    right: 8px;
    grid-template-columns: 64px auto;
  }

  .board-zoom-control > span {
    display: none;
  }

  .board-zoom-control input {
    width: 64px;
  }

  .start-playtest-access {
    top: 12px;
    bottom: auto;
    left: 12px;
  }

  .game-sidebar .topbar {
    grid-template-columns: 1fr;
    grid-template-areas:
      "brand"
      "status"
      "corruption";
  }

  .game-sidebar .world-status {
    justify-self: stretch;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .game-sidebar .player-rail {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .game-sidebar .rail-player {
    min-width: 0;
  }

  .game-sidebar .board-toolbar {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "title"
      "room"
      "zoom";
  }

  .game-sidebar .zoom-control {
    justify-content: flex-start;
  }

  .game-sidebar .sheet-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
  }

  .game-sidebar .sheet-spiritual {
    grid-row: 2;
    padding: var(--ui-space-4) 0 0;
    border-top: 0;
    border-left: 0;
  }

  .game-sidebar .sheet-layout > .treasures-section {
    grid-column: 1;
    grid-row: 3;
  }

  .registration-modal {
    display: block;
    width: calc(100vw - 30px);
    max-height: calc(100dvh - 20px);
    overflow-y: auto;
  }

  .registration-brand {
    min-height: 210px;
    padding: 36px 24px;
  }

  .registration-brand strong {
    font-size: 52px;
  }

  .registration-form {
    padding: 28px 22px;
    overflow: visible;
  }

  .registration-rows,
  .draft-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .count-field,
  .player-count-field {
    align-items: stretch;
    flex-direction: column;
  }

  .count-picker {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .count-picker button {
    width: auto;
  }

  .cpu-difficulty-picker {
    grid-template-columns: minmax(0, 1fr);
  }

  #setupOverlay .modal {
    width: calc(100vw - 30px);
    padding: 26px 20px;
  }

  .draft-card {
    min-height: 180px;
  }

  .encounter-panel {
    width: calc(100vw - 30px);
  }

  .encounter-visual .asset-image,
  .encounter-visual img.svg-icon {
    width: min(108px, 42%);
    height: auto;
    max-width: 42%;
    max-height: 108px;
  }

  .encounter-sequence-actions .encounter-next {
    width: min(240px, calc(100vw - 40px));
  }

  .encounter-copy {
    padding: 28px 22px;
  }
}

/* Encounter decisions keep the resources that matter visible without covering the board. */
.encounter-status-hud {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  margin-top: 18px;
  border-block: 1px solid rgba(207, 172, 96, 0.2);
  background: rgba(255, 255, 255, 0.015);
}

.encounter-status-hud > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: 12px 14px;
  border-right: 1px solid rgba(207, 172, 96, 0.14);
}

.encounter-status-hud > div:last-of-type {
  border-right: 0;
}

.encounter-status-hud span,
.encounter-status-hud em {
  color: var(--muted, #9e9787);
  font-size: 0.78rem;
  font-style: normal;
}

.encounter-status-hud strong {
  color: var(--ivory, #eee6d4);
  font-size: 0.9rem;
  white-space: nowrap;
}

.boss-damage-key {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 14px;
  border-top: 1px solid rgba(207, 172, 96, 0.14);
}

.boss-damage-key > span {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
}

.boss-damage-key b {
  color: var(--gold-bright, #e6c77e);
}

.boss-damage-key small {
  color: var(--muted, #9e9787);
  white-space: nowrap;
}

.encounter-wound-hints {
  margin-top: 18px;
  padding-top: 15px;
  border-top: 1px solid rgba(207, 172, 96, 0.18);
}

.encounter-wound-hint {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.encounter-wound-hint > span {
  width: 30px;
  height: 30px;
  color: #a66a66;
}

.encounter-wound-hint > span svg,
.encounter-wound-hint > span img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.encounter-wound-hint > div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.encounter-wound-hint small {
  color: var(--muted, #9e9787);
  line-height: 1.35;
}

.encounter-wound-hint em {
  color: #b28b6b;
  font-size: 0.72rem;
  font-style: normal;
  text-align: right;
}

.encounter-wound-hint.ready > span,
.encounter-wound-hint.ready > em {
  color: #c9d678;
}

@media (max-width: 700px) {
  .encounter-status-hud {
    grid-template-columns: 1fr;
  }

  .encounter-status-hud > div {
    border-right: 0;
    border-bottom: 1px solid rgba(207, 172, 96, 0.12);
  }

  .boss-damage-key {
    grid-column: 1;
    flex-wrap: wrap;
  }

  .encounter-wound-hint {
    grid-template-columns: 30px minmax(0, 1fr);
  }

  .encounter-wound-hint em {
    grid-column: 2;
    text-align: left;
  }
}

/* E5 remains the Eucari mechanically. When Corruption reaches its limit the
   board swaps only its artwork, keeping the sacred interaction available. */
.board-frame .cell.boss-awake-sanctum {
  color: #ff5a5a;
  border-color: rgba(255, 66, 66, 0.78);
  background:
    radial-gradient(circle at 50% 48%, rgba(181, 23, 31, 0.24), transparent 66%),
    #170d10;
  box-shadow:
    inset 0 0 24px rgba(190, 27, 38, 0.16),
    0 0 0 1px rgba(255, 91, 91, 0.12);
}

.board-frame .cell.boss-awake-sanctum .cell-icon {
  width: 84%;
  height: 84%;
  animation: none;
}

.board-frame .cell.boss-awake-sanctum .room-symbol-eucariCorrupt.asset-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0.9;
  filter:
    drop-shadow(0 0 6px rgba(233, 74, 87, 0.38))
    drop-shadow(0 0 13px rgba(159, 32, 54, 0.22));
  animation: corruptEucariFocus 2.8s ease-in-out infinite;
}

@keyframes corruptEucariFocus {
  0%,
  100% {
    opacity: 0.9;
    filter:
      drop-shadow(0 0 6px rgba(233, 74, 87, 0.38))
      drop-shadow(0 0 13px rgba(159, 32, 54, 0.22));
  }

  50% {
    opacity: 1;
    filter:
      drop-shadow(0 0 10px rgba(244, 91, 104, 0.52))
      drop-shadow(0 0 20px rgba(180, 38, 65, 0.3));
  }
}

.board-frame .cell.boss-awake-sanctum .room-label {
  color: #f2d8d8;
}

/* Character sheet: keep both information columns balanced inside the available
   panel instead of pinning the content to its upper-left corner. */
@media (min-width: 1101px) {
  .game-sidebar .character-sheet {
    display: grid;
    align-items: center;
  }

  .game-sidebar .sheet-panel {
    align-items: center;
  }

  .game-sidebar .sheet-layout {
    grid-template-columns: minmax(0, 0.94fr) minmax(0, 1.06fr);
    align-content: center;
    align-items: center;
    column-gap: clamp(26px, 3vw, 52px);
    width: min(100%, 780px);
    margin-inline: auto;
    padding-block: clamp(12px, 2.4vh, 28px);
  }

  .game-sidebar .sheet-primary,
  .game-sidebar .sheet-spiritual {
    width: 100%;
    max-width: 360px;
    justify-self: center;
  }

  .game-sidebar .sheet-spiritual {
    padding-left: clamp(20px, 2.4vw, 38px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .board-token {
    animation: none !important;
  }
}

/* Interaction surfaces */
.board-viewport,
.board-frame,
.board-grid,
.board-grid .cell,
.board-token {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.board-token.active {
  touch-action: none;
}

body.tap-placing-token .board-token.active {
  opacity: 1;
  transform: translate(-50%, -64%) rotate(-2deg) scale(1.06);
}

.action-button {
  position: relative;
}

.action-count {
  position: absolute;
  top: 7px;
  right: 8px;
  min-width: 28px;
  color: var(--gold-soft);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  text-align: right;
}

@media (max-width: 760px) {
  .access-gate {
    align-items: center;
    padding:
      max(16px, env(safe-area-inset-top))
      14px
      max(16px, env(safe-area-inset-bottom));
  }

  .access-panel {
    gap: 20px;
    padding: 24px 20px;
  }

  .access-brand {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .access-brand span {
    max-width: none;
    text-align: left;
  }

  .modal-backdrop,
  .encounter-overlay,
  .dice-overlay {
    align-items: flex-start;
    justify-items: center;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding:
      max(10px, env(safe-area-inset-top))
      10px
      max(26px, env(safe-area-inset-bottom));
  }

  .encounter-overlay {
    display: flex;
    align-items: flex-start;
    justify-content: center;
  }

  .encounter-overlay.cpu-sequence-open {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    align-content: stretch;
    padding:
      max(10px, env(safe-area-inset-top))
      10px
      max(10px, env(safe-area-inset-bottom));
    overflow: hidden;
  }

  .encounter-overlay.cpu-sequence-open.is-hidden {
    display: none;
  }

  .encounter-overlay.is-hidden {
    display: none;
  }

  .encounter-panel {
    flex: 0 0 auto;
    width: min(100%, 680px);
    max-height: none;
    margin: auto 0;
    overflow: visible;
  }

  .encounter-panel.cpu-sequence {
    align-self: stretch;
    max-height: 100%;
    margin: 0;
    overflow: hidden;
  }

  .encounter-panel.cpu-sequence .encounter-copy {
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .encounter-copy {
    min-width: 0;
  }
}

@media (max-width: 760px) {
  .board-token.active {
    width: 50px;
    height: 58px;
  }

  .board-token.active .player-symbol {
    width: 64%;
    height: 64%;
    margin: 18%;
  }

  .board-token:not(.active) {
    flex: 0 0 12px;
    width: 12px;
    min-width: 12px;
    height: 12px;
    margin: 1px 0 0 4px;
    border: 2px solid color-mix(in srgb, var(--player), #ffffff 28%);
    border-radius: 50%;
    background: var(--player) !important;
    box-shadow: 0 0 0 2px rgba(3, 5, 5, 0.78), 0 2px 4px rgba(0, 0, 0, 0.5) !important;
    opacity: 0.9;
    transform: none;
  }

  .board-token + .board-token {
    margin-left: 4px;
  }

  .board-token:not(.active) .player-symbol,
  .board-token:not(.active)::before,
  .board-token:not(.active)::after {
    display: none;
  }

  body.dragging-token .tokens .board-token.active,
  body.tap-placing-token .tokens .board-token.active {
    opacity: 0.62;
    transform: translate(-50%, -64%) rotate(-2deg) scale(1.04);
  }
}


/* Keep controls reachable when screen resolution or browser zoom reduces height.
   The registration grid must shrink its row so the form owns the overflow. */
.registration-modal {
  grid-template-rows: minmax(0, 1fr);
}

.registration-brand,
.registration-form {
  min-height: 0;
}

/* Safe centering keeps the top reachable when a dialog exceeds the viewport. */
.access-gate,
.modal-backdrop,
.dice-overlay,
.encounter-overlay:not(.cpu-sequence-open) {
  overflow-x: hidden;
  overflow-y: auto;
  align-items: safe center;
  overscroll-behavior: contain;
}

/* CPU results scroll as a whole; Continue remains in its separate row. */
.encounter-panel.cpu-sequence {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.encounter-panel.cpu-sequence .encounter-copy {
  overflow-y: visible;
}

@media (min-width: 761px) {
  .modal-backdrop { padding: 24px; }
}

@media (max-width: 760px) {
  .registration-modal { max-height: calc(100dvh - 36px); }
}

/* Tile-relative artwork follows both viewport resizing and board zoom.
   Mobile keeps the larger touch target while scaling the visible pawn. */
.board-grid {
  container-type: size;
}

@media (min-width: 761px) {
  .board-grid .board-token {
    flex-shrink: 0;
    width: calc(62cqw / var(--map-size, 9));
    height: calc(81cqw / var(--map-size, 9));
  }

  .board-grid .board-token + .board-token {
    margin-left: calc(-35cqw / var(--map-size, 9));
  }

  .board-grid .board-token.active {
    margin-left: 0;
  }
}

@media (max-width: 760px) {
  .board-grid .board-token.active .player-symbol {
    position: absolute;
    left: 50%;
    top: 50%;
    width: calc(62cqw / var(--map-size, 9));
    height: calc(81cqw / var(--map-size, 9));
    margin: 0;
    transform: translate(-50%, -50%);
  }
}

/* Center a short sheet, but never place overflowing content above scrollTop 0. */
@media (min-width: 1101px) {
  .game-sidebar .character-sheet,
  .game-sidebar .sheet-panel {
    align-items: safe center;
  }
}