.theme-dialog { width: min(640px, calc(100% - 24px)); }

.theme-picker {
  display: grid;
  gap: .65rem;
  padding-block: .85rem;
  min-width: 0;
}

.theme-picker h3 {
  margin: 0;
  color: var(--theme-text, #30251b);
  font-family: var(--theme-heading-font, Georgia, serif);
  font-size: 1.15rem;
}

.theme-choice {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: .6rem;
  font-weight: 600;
}

.theme-picker select {
  flex: 1 1 10rem;
  width: auto;
  min-width: 0;
  font-family: var(--theme-ui-font, system-ui, sans-serif);
}
.theme-choice[hidden] { display: none; }

.theme-preview {
  overflow: hidden;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--theme-radius);
}

.theme-preview .island-board {
  width: 100%;
  height: 100%;
  touch-action: auto;
}

.theme-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .4rem;
}
.theme-actions button[hidden] { display: none; }
.theme-status { margin: 0; color: var(--theme-muted, #65523d); font-size: .875rem; }
.theme-status:empty { display: none; }

/* The printed hand uses the original card proportions at every viewport. */
:is([data-theme-style="tabletop"], [data-theme-style="atlas"], [data-theme-style="hybrid"], [data-theme-style="moonlit"]) .game {
  --printed-card-height: clamp(68px, 11.5vh, 105px);
}
:is([data-theme-style="tabletop"], [data-theme-style="atlas"], [data-theme-style="hybrid"], [data-theme-style="moonlit"]) :is(.hand .rcard, .devcards .dcard) {
  width: auto;
  height: var(--printed-card-height);
  aspect-ratio: 13 / 20;
  padding: 0;
  gap: 0;
  overflow: hidden;
  border: 0;
  box-shadow: none;
}
:is([data-theme-style="tabletop"], [data-theme-style="atlas"], [data-theme-style="hybrid"], [data-theme-style="moonlit"]) .hand .rcard {
  grid-template-rows: minmax(0, 1fr);
  border-radius: 3px;
}
:is([data-theme-style="tabletop"], [data-theme-style="atlas"], [data-theme-style="hybrid"], [data-theme-style="moonlit"]) .resource-name { position: absolute; clip-path: inset(100%); }
:is([data-theme-style="tabletop"], [data-theme-style="atlas"], [data-theme-style="hybrid"], [data-theme-style="moonlit"]) .rcard .resource-art {
  border: 0;
  border-radius: 0;
}
:is([data-theme-style="tabletop"], [data-theme-style="atlas"], [data-theme-style="hybrid"], [data-theme-style="moonlit"]) .rcard b {
  top: auto;
  bottom: 3px;
  right: 3px;
  border: 0;
  border-radius: 4px;
}
:is([data-theme-style="tabletop"], [data-theme-style="atlas"], [data-theme-style="hybrid"], [data-theme-style="moonlit"]) .rcard.zero { opacity: 1; }
:is([data-theme-style="tabletop"], [data-theme-style="atlas"], [data-theme-style="hybrid"], [data-theme-style="moonlit"]) .rcard.zero .resource-art { filter: saturate(.6); }
:is([data-theme-style="tabletop"], [data-theme-style="atlas"], [data-theme-style="hybrid"], [data-theme-style="moonlit"]) .dcard.new {
  opacity: 1;
  background: var(--panel);
  color: var(--muted);
}
:is([data-theme-style="tabletop"], [data-theme-style="atlas"], [data-theme-style="hybrid"], [data-theme-style="moonlit"]) .dcard.playable {
  background: var(--gold);
  color: var(--accent-ink);
}
.game-icon, .game-icon-fallback { display: inline-flex; align-items: center; flex: none; }
.game-icon-art { display: none; }
[data-theme-style]:not([data-theme-style="competitive"]) .game-icon-fallback { display: none; }
[data-theme-style]:not([data-theme-style="competitive"]) .game-icon-art { display: block; width: 18px; height: 18px; object-fit: contain; }
[data-theme-style]:not([data-theme-style="competitive"]) .pcard .stats .game-icon-art { width: var(--seat-stat-icon); height: var(--seat-stat-icon); }
[data-theme-style]:not([data-theme-style="competitive"]) .build-options .game-icon-art {
  width: var(--control-icon-size);
  height: var(--control-icon-size);
}

/* Six HUDs, sharing the game's controls and a common scale system. */
[data-theme-style="tabletop"] .game {
  --hud-rail-size: 23.2%;
  --hud-panel-font: var(--display);
  --hud-command-font: var(--display);
  --hud-frame-radius: 13px;
  --hud-paper: url("../assets/themes/tabletop/surface.webp");
  --hud-hand-ink: #3d261a;
  --hud-hand-border: #bcaa88;
  --hud-hand-art-opacity: .63;
  --hud-emblem: #48643a;
  --hud-button-surface: color-mix(in srgb, var(--panel), var(--line) 17%);
  --hud-button-edge: color-mix(in srgb, var(--line), var(--text) 23%);
  --card-wood: url("../assets/themes/tabletop/wood.webp");
  --card-brick: url("../assets/themes/tabletop/brick.webp");
  --card-sheep: url("../assets/themes/tabletop/sheep.webp");
  --card-wheat: url("../assets/themes/tabletop/wheat.webp");
  --card-ore: url("../assets/themes/tabletop/ore.webp");
}
[data-theme-style="tabletop"] .game .side { border-radius: 11px 0 0 11px; }
[data-theme-style="tabletop"] .turn-name { color: color-mix(in srgb, var(--turn-color, var(--text)), var(--text) 72%); }
[data-theme-style="tabletop"] .pcard { --hud-card-surface: color-mix(in srgb, var(--panel), var(--pc) 20%); }
[data-theme-style="tabletop"] .pcard .name { color: color-mix(in srgb, var(--pc), var(--text) 72%); }
[data-theme-style]:not([data-theme-style="competitive"]) .bank-info .game-icon-art {
  width: var(--bank-icon-size);
  height: var(--bank-icon-size);
}
[data-theme-style="tabletop"] .vp-symbol { width: max(19px, 1.15em); height: max(19px, 1.15em); }
[data-theme-style="tabletop"] .game .actionbar .act-end { background: linear-gradient(color-mix(in srgb, var(--hud-end-surface), #fff2cc 14%), var(--hud-end-surface)); }
[data-theme-style="tabletop"][data-theme-custom="false"] :is(.hand .rcard, .rcard .resource-art) {
  background: transparent;
  border-radius: 0;
}
[data-theme-style="tabletop"][data-theme-custom="false"] .rcard .resource-item[data-card-art] {
  object-fit: contain;
}
[data-theme-style="tabletop"][data-theme-custom="false"] .rcard[data-resource="brick"] .resource-item[data-card-art] {
  filter: saturate(1.3);
}
[data-theme-style="tabletop"][data-theme-custom="false"] .rcard.zero[data-resource="brick"] .resource-art {
  filter: saturate(.76);
}
[data-theme-style="competitive"] .game {
  --hud-rail-size: 28.3%;
  --hud-rail-pad: clamp(6px, .92vw, 15px);
  --hud-frame: color-mix(in srgb, var(--line) 73%, #242426);
  --hud-card-surface: color-mix(in srgb, var(--panel), var(--panel2) 70%);
  --hud-card-radius: 8px;
  --hud-hand-art-opacity: .26;
  --hud-hand-border: #c8bb9f;
  --hud-hand-inner: #f6ead3;
  --hud-button-surface: var(--green);
  --hud-button-edge: color-mix(in srgb, var(--green), #38271d 16%);
  --hud-button-ink: var(--action-ink);
  --card-wood: url("../assets/themes/competitive/wood.webp");
  --card-brick: url("../assets/themes/competitive/brick.webp");
  --card-sheep: url("../assets/themes/competitive/sheep.webp");
  --card-wheat: url("../assets/themes/competitive/wheat.webp");
  --card-ore: url("../assets/themes/competitive/ore.webp");
}
[data-theme-style="competitive"] .turn-name {
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text);
  background: color-mix(in srgb, var(--turn-color, var(--hud-header)) 25%, var(--hud-header));
}
[data-theme-style="competitive"] .pcard .avatar:not(.has-flag, :has(img.flag-img)) { clip-path: none; border-radius: 3px; }

[data-theme-style="competitive"] .rcard { grid-template-rows: minmax(0, 1fr) auto auto; }
[data-theme-style="competitive"] .rcard b {
  position: static;
  min-height: 0;
  padding: 0;
  border: 0;
  background: none;
  font-weight: 850;
}

[data-theme-style="atlas"] .game {
  --hud-rail-size: 23.7%;
  --hud-rail-pad: clamp(8px, 1.05vw, 18px);
  --hud-panel-font: var(--display);
  --hud-command-font: var(--display);
  --hud-frame: color-mix(in srgb, var(--line), #704d32 50%);
  --hud-frame-radius: 4px;
  --hud-paper: url("../assets/themes/atlas/surface.webp");
  --hud-paper-blend: soft-light;
  --hud-paper-size: 420px 420px;
  --hud-card-radius: 7px;
  --hud-hand-background: color-mix(in srgb, var(--panel), #c89f6c 28%);
  --hud-hand-border: #9d774f;
  --hud-hand-inner: #f7e4b5;
  --hud-hand-art-opacity: .59;
  --hud-button-surface: color-mix(in srgb, var(--panel), #bda172 19%);
  --hud-button-edge: #8f6842;
  --hud-emblem: #684733;
  --card-wood: url("../assets/themes/atlas/wood.webp");
  --card-brick: url("../assets/themes/atlas/brick.webp");
  --card-sheep: url("../assets/themes/atlas/sheep.webp");
  --card-wheat: url("../assets/themes/atlas/wheat.webp");
  --card-ore: url("../assets/themes/atlas/ore.webp");
}
[data-theme-style="atlas"] .pcard { --hud-card-surface: color-mix(in srgb, var(--panel), #ecba80 32%); }
[data-theme-style="atlas"] .rcard .resource-item { filter: sepia(.18) saturate(.9) drop-shadow(0 1px 1px #241e17b3); }
[data-theme-style="atlas"] .illustrated-icon { filter: sepia(.22) saturate(.85); }

[data-theme-style="hybrid"] .game {
  --hud-rail-size: 28.3%;
  --hud-header: color-mix(in srgb, var(--panel), #133826 26%);
  --hud-footer: color-mix(in srgb, var(--panel), #133826 22%);
  --hud-rail: color-mix(in srgb, var(--panel), #101515 47%);
  --hud-emblem: #b5c78e;
  --hud-title-color: #f9e4b8;
  --hud-card-radius: 9px;
  --hud-card-surface: color-mix(in srgb, var(--panel), #171d1e 47%);
  --hud-button-surface: color-mix(in srgb, var(--panel), #476942 35%);
  --hud-button-edge: color-mix(in srgb, var(--line), var(--green) 39%);
  --hud-button-ink: color-mix(in srgb, var(--text), var(--green) 32%);
  --hud-hand-art-opacity: .59;
  --card-wood: url("../assets/themes/hybrid/wood.webp");
  --card-brick: url("../assets/themes/hybrid/brick.webp");
  --card-sheep: url("../assets/themes/hybrid/sheep.webp");
  --card-wheat: url("../assets/themes/hybrid/wheat.webp");
  --card-ore: url("../assets/themes/hybrid/ore.webp");
  --hud-hand-ink: var(--text);
  --hud-hand-inner: var(--panel);
}
[data-theme-style="hybrid"] .game .brand { font-family: Spectral, Georgia, serif; }
[data-theme-style="hybrid"] .game .topbar { min-height: clamp(39px, 5.6vh, 56px); }
[data-theme-style="hybrid"] .game .actionbar .act-end { background: linear-gradient(color-mix(in srgb, var(--green), #fff3cf 17%), var(--green)); }
[data-theme-style="hybrid"] .pcard .avatar:not(.has-flag, :has(img.flag-img)) { width: 13px; height: 13px; clip-path: none; border-radius: 4px; }
[data-theme-style="hybrid"] .pcard .vp { padding: 4px 7px; background: var(--hud-card-surface); border-radius: 6px; }
[data-theme-style="hybrid"] .pcard .vp-symbol { display: none; }

[data-theme-style="gouache"] .game {
  --hud-rail-size: 25.6%;
  --hud-rail-pad: clamp(8px, .9vw, 16px);
  --hud-panel-font: var(--display);
  --hud-command-font: var(--display);
  --hud-paper: url("../assets/themes/gouache/surface.webp");
  --hud-frame: color-mix(in srgb, var(--line), var(--text) 15%);
  --hud-emblem: #62744d;
  --hud-button-surface: color-mix(in srgb, var(--panel), var(--line) 9%);
  --hud-card-radius: 7px;
  --hud-hand-art-opacity: .58;
  --card-wood: url("../assets/themes/gouache/wood.webp");
  --card-brick: url("../assets/themes/gouache/brick.webp");
  --card-sheep: url("../assets/themes/gouache/sheep.webp");
  --card-wheat: url("../assets/themes/gouache/wheat.webp");
  --card-ore: url("../assets/themes/gouache/ore.webp");
}
[data-theme-style="gouache"] .pcard {
  --hud-card-surface: color-mix(in srgb, var(--panel), var(--pc) 6%);
}
[data-theme-style="gouache"] .pcard .avatar:not(.has-flag, :has(img.flag-img)) { width: clamp(17px, 1.9vw, 31px); height: clamp(14px, 1.55vw, 24px); clip-path: none; border-radius: 4px; }
[data-theme-style="gouache"] .actionbar .act-end::before { display: none; }
[data-theme-style="gouache"] .actionbar .act-end > [aria-hidden="true"] { display: inline; }
[data-theme-style="gouache"] .rcard { grid-template-rows: minmax(0, 1fr); }
[data-theme-style="gouache"] .rcard b { top: auto; bottom: 4px; right: 4px; }
[data-theme-style="gouache"] .resource-name { position: absolute; clip-path: inset(100%); }

[data-theme-style="moonlit"] .game {
  --hud-rail-size: 26%;
  --hud-header: color-mix(in srgb, var(--panel), #080b10 28%);
  --hud-footer: var(--hud-header);
  --hud-rail: color-mix(in srgb, var(--panel), #0b0c11 24%);
  --hud-frame: color-mix(in srgb, var(--line), var(--gold) 31%);
  --hud-title-color: #f6d98b;
  --hud-card-radius: 5px;
  --hud-panel-font: var(--display);
  --hud-command-font: var(--display);
  --hud-card-surface: color-mix(in srgb, var(--panel2), #100e12 39%);
  --hud-button-surface: var(--hud-card-surface);
  --hud-button-edge: var(--hud-frame);
  --hud-hand-art-opacity: .57;
  --card-wood: url("../assets/themes/moonlit/wood.webp");
  --card-brick: url("../assets/themes/moonlit/brick.webp");
  --card-sheep: url("../assets/themes/moonlit/sheep.webp");
  --card-wheat: url("../assets/themes/moonlit/wheat.webp");
  --card-ore: url("../assets/themes/moonlit/ore.webp");
  --hud-hand-ink: var(--text);
  --hud-hand-inner: var(--panel);
}
[data-theme-style="moonlit"] .actionbar :is(.act-trade, .act-build)::before { color: var(--gold); }
[data-theme-style="moonlit"] .game .actionbar .act-end { background: linear-gradient(color-mix(in srgb, var(--green), #fff3cb 36%), var(--green) 65%, color-mix(in srgb, var(--green), #645125 22%)); }

[data-theme-mode="light"]:is([data-theme-style="hybrid"], [data-theme-style="moonlit"]) .game {
  --hud-header: var(--panel);
  --hud-footer: var(--panel);
  --hud-rail: color-mix(in srgb, var(--panel), var(--line) 9%);
  --hud-title-color: var(--text);
  --hud-emblem: var(--gold);
  --hud-card-surface: var(--panel2);
  --hud-button-surface: var(--panel2);
  --hud-button-ink: var(--text);
}
[data-theme-mode="light"]:is([data-theme-style="hybrid"], [data-theme-style="moonlit"]) .game .actionbar .act-end {
  background: var(--hud-end-surface);
}
[data-theme-mode="dark"]:is([data-theme-style="tabletop"], [data-theme-style="atlas"], [data-theme-style="gouache"]) .game {
  --hud-paper-blend: multiply;
  --hud-emblem: var(--gold);
}
[data-theme-mode="dark"][data-theme-style="atlas"] .pcard {
  --hud-card-surface: color-mix(in srgb, var(--panel), var(--line) 15%);
}
[data-theme-mode="light"]:is([data-theme-style="tabletop"], [data-theme-style="atlas"]) .pcard .name small {
  color: color-mix(in srgb, var(--muted) 80%, var(--text));
}

:is([data-theme-style="gouache"], [data-theme-style="atlas"], [data-theme-style="hybrid"], [data-theme-style="moonlit"]) .log div:has(.pname) > img.ui-icon:first-child { display: none; }
:is([data-theme-style="gouache"], [data-theme-style="atlas"], [data-theme-style="hybrid"], [data-theme-style="moonlit"]) .log .pname:first-of-type::before {
  content: "";
  display: inline-block;
  width: .57em;
  height: .57em;
  margin-inline-end: .40em;
  border-radius: 50%;
  background: var(--pc);
  vertical-align: .075em;
}

:is([data-theme-style="competitive"], [data-theme-style="hybrid"], [data-theme-style="gouache"], [data-theme-style="moonlit"]) .game .side-heading {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
:is([data-theme-style="competitive"], [data-theme-style="hybrid"], [data-theme-style="moonlit"]) .game .log {
  padding: 8px 9px;
  border-radius: var(--hud-card-radius);
  background: color-mix(in srgb, var(--hud-card-surface), var(--hud-rail) 38%);
}
:is([data-theme-style="tabletop"], [data-theme-style="atlas"], [data-theme-style="gouache"]) .game .top-actions { flex-direction: row-reverse; }

@media (max-width: 860px) {
  :is([data-theme-style="tabletop"], [data-theme-style="atlas"], [data-theme-style="hybrid"], [data-theme-style="moonlit"]) .game { --printed-card-height: 62px; }
  [data-theme-style] .game { --hud-card-radius: 6px; }
  [data-theme-style] .game .side-heading { display: none; }
  [data-theme-style] .game .log { padding: 2px 7px; border-radius: 0; }
  [data-theme-style="tabletop"] .game .side { border-radius: 0; }
  [data-theme-style="competitive"] .game .actionbar .rcard b { line-height: 1; font-size: 11px; }
}
