:root {
  color-scheme: dark;
  --ui-text: #f8f5ff;
  --ui-muted: #c8bdd9;
  --ui-panel: #242031;
  --ui-inset: #1d1929;
  --ui-border: #655576;
  --ui-outline: #a78ace;
  --ui-hover: #3b3051;
  --ui-active: #59417f;
  --hero-accent: #f2bb91;
  --ui-kicker: #f5d579;
  --ui-positive: #9ee7c4;
  --ui-negative: #ffb5c6;
  --home-surface: #191725;
  --home-grid: #b1a9d619;
  --table-backdrop: #49366c;
  --table-surround: radial-gradient(ellipse at 50% 12%, #655084, #35264f 75%);
  --table-surface: radial-gradient(ellipse at 50% 32%, #29213b, #14131e 66%, #101019);
  --table-felt: radial-gradient(ellipse at 50% 16%, #4b3c66, #27223b 60%, #191825);
}
:root[data-theme="light"] {
  color-scheme: light;
  --ui-text: #261c38;
  --ui-muted: #5f536e;
  --ui-panel: #fffdf7;
  --ui-inset: #fff0c1;
  --ui-border: #a994bd;
  --ui-outline: #8560b0;
  --ui-hover: #eadbf7;
  --ui-active: #dbcbff;
  --hero-accent: #9a613f;
  --ui-kicker: #77501c;
  --ui-positive: #246346;
  --ui-negative: #a23255;
  --home-surface: #fff8ed;
  --home-grid: #825cc722;
  --table-backdrop: #ded0f0;
  --table-surround: radial-gradient(ellipse at 50% 12%, #fff1ff, #d8c4ee 80%);
  --table-surface: radial-gradient(ellipse at 50% 32%, #f0e3fc, #fffaf3 78%);
  --table-felt: radial-gradient(ellipse at 50% 16%, #eee5fb, #c3aadb 76%);
}

#themeToggle {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--ui-border);
  border-radius: 50%;
  background: var(--ui-panel);
  color: var(--ui-text);
  box-shadow: none;
  font: 800 21px/1 system-ui, sans-serif;
}
#themeToggle:hover { background: var(--ui-hover); }
:focus-visible { outline: 2px solid var(--ui-outline); outline-offset: 2px; }
@media (max-width: 680px) {
  #themeToggle { margin-left: auto; }
}
@media (max-height: 480px) and (min-width: 560px) {
  #themeToggle { margin-left: 0; }
}

:root[data-theme="dark"] body:not(:has(#home:not([hidden]))) {
  color: var(--ui-text);
  background-color: #191525;
}
:root[data-theme="dark"] body:not(:has(#home:not([hidden]))):not([data-game-scene]) {
  background-image: linear-gradient(#1c1827bd, #1c1827bd), url("game-doodles.svg");
  background-size: auto, 620px 480px;
}
:root[data-theme="dark"] body[data-game-scene][data-game-background="illustrated"]:not(:is([data-game-scene="thirteen"], [data-game-scene="poker"])) {
  background-image: linear-gradient(#211a2ea6, #211a2ea6), var(--game-art);
  background-size: auto, 360px 248px;
}
:root[data-theme="dark"] body[data-game-scene][data-game-background="arcade"] {
  background-color: #231a37;
  background-image: linear-gradient(#b98df52b 1px, transparent 1px),
    linear-gradient(90deg, #b98df52b 1px, transparent 1px);
}
:root[data-theme="dark"] body[data-game-scene][data-game-background="felt"] {
  background-color: #142c25;
  background-image: radial-gradient(circle, #92cbb546 .6px, transparent 1px);
}
:root[data-theme="dark"] body[data-game-scene][data-game-background="plain"] { background: #181522; }

:root[data-theme="dark"] :is(header, footer, .score-panel) { border-color: var(--ui-border); }
:root[data-theme="dark"] :is(#brand, footer span, .play-top) { color: var(--ui-text); }
:root[data-theme="dark"] body:has(#home:not([hidden])) dialog,
:root[data-theme="dark"] :is(dialog, #play .stage-card, #roomMain .stage-card:not(.card-game-stage)) {
  border: 1px solid var(--ui-border);
  border-radius: 16px;
  background: var(--ui-panel);
  color: var(--ui-text);
  box-shadow: 0 9px 24px #100b1c88;
}
:root[data-theme="dark"] body[data-game-scene][data-game-background="illustrated"] :is(#play, #roomMain) .stage-card:not(.card-game-stage) {
  background: linear-gradient(#242031d9, #242031d9), var(--game-art) var(--ui-panel);
  background-size: auto, 360px 248px;
}
:root[data-theme="dark"] :is(dialog, .stage-card) :is(h2, p:not(.prompt):not(.room-wait):not(.board-offer)),
:root[data-theme="dark"] :is(.profile-form, .board-controls) label { color: var(--ui-text); }
:root[data-theme="dark"] :is(dialog, #play, #roomMain, .game-background-picker) :is(input, textarea, select),
:root[data-theme="dark"] :is(.board-controls, .profile-shop, .game-background-picker) {
  border-color: var(--ui-border);
  background: var(--ui-inset);
  color: var(--ui-text);
}
:root[data-theme="dark"] :is(#headerMenu, .room-toolbar, .play-top, .score-panel) button,
:root[data-theme="dark"] dialog button:not(.dark),
:root[data-theme="dark"] .stage-card:not(.card-game-stage) button:not(.dark) {
  border: 1px solid var(--ui-border);
  border-radius: 9px;
  background: var(--ui-hover);
  color: var(--ui-text);
  box-shadow: none;
}
:root[data-theme="dark"] :is(.score-panel .score, .room-player-list > span),
:root[data-theme="dark"] :is(.board-dice, .island-hand span, .property-space, .property-centre, .board-cell, .prompt, .room-wait, .board-offer, .account-link, .chip) { color: #271b3c; }
:root[data-theme="dark"] .stage-card .board-offer p { color: #271b3c; }
:root[data-theme="dark"] dialog .skin-list button { border-left: 8px solid var(--skin); }
:root[data-theme="dark"] #homeHelp .how small { color: var(--ui-muted); }
:root[data-theme="dark"] #homeHelp .how > span { color: #271b3c; }

:root[data-theme="light"] #roomMain .card-game-stage .table-felt {
  box-shadow: 0 -4px 20px #a980cd80, inset 0 0 0 2px #ffffff68;
}
:root[data-theme="light"] #roomMain .card-game-stage .playing-card { box-shadow: 2px 4px 9px #57427240; }

body > header {
  position: sticky;
  top: 0;
  z-index: 6;
  width: 100%;
  max-width: none;
  margin: 0;
  padding-inline: clamp(12px, calc(2.4vw / var(--site-zoom, 1)), 42px);
  background: color-mix(in srgb, var(--ui-panel) 94%, transparent);
  backdrop-filter: blur(10px);
}
.game-controls-bar { top: calc(var(--site-header-height, 0px) + 8px); }
@media (min-width: 900px) {
  .thirteen-workspace .thirteen-history { top: calc(var(--site-header-height, 0px) + 64px); }
}
@media (max-width: 680px) {
  body:has(#home[hidden]) > header { min-height: 0; padding-block: 5px; gap: 5px; }
  body:has(#home[hidden]) #brand { font-size: 28px; }
  body:has(#home[hidden]) #headerMenu {
    display: grid;
    grid-template-columns: 1fr 1fr 1.4fr;
    gap: 6px;
    padding: 0 0 4px;
  }
  body:has(#home[hidden]) #headerMenu button { min-height: 40px; padding: 4px; font-size: 12px; }
}

#headerMenu #accountOpen:has(#headerProfileAvatar:not([hidden])) {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding-block: 5px;
}
#headerProfilePhoto, #headerProfileAvatar {
  flex: none;
  width: 31px;
  height: 31px;
  object-fit: cover;
  overflow: hidden;
  border: 1px solid var(--ui-border);
  border-radius: 7px;
}
#headerProfileAvatar svg { display: block; width: 100%; }
@media (max-width: 900px) {
  #headerProfileAvatar:not([hidden]) + #headerProfileLabel { display: none; }
}
@media (max-width: 680px) {
  #headerMenu #accountOpen:has(#headerProfileAvatar:not([hidden])) { gap: 4px; padding-inline: 4px; }
  #headerProfilePhoto, #headerProfileAvatar { width: 27px; height: 27px; }
}

/* Header: orange gradient in light mode, purple gradient in dark mode. */
html body > header {
  background: linear-gradient(100deg, #ffd166 0%, #ffad4d 35%, #ff8a3d 70%, #ff6b35 100%);
  border-bottom: 3px solid var(--ink, #252046) !important;
  box-shadow: 0 4px 14px #6d3df52e;
  backdrop-filter: none;
}
html[data-theme="dark"] body > header {
  background: linear-gradient(100deg, #3b1d78 0%, #5b2db8 40%, #7c3fe0 75%, #9a5cf5 100%);
  box-shadow: 0 4px 14px #1a0b3a66;
}
html body > header #brand { color: #20163a !important; text-shadow: 0 2px 0 #ffffff80; }
html[data-theme="dark"] body > header #brand { color: #fff !important; text-shadow: 0 2px 0 #00000055; }
html body > header .top-note { background: #ffffffcc !important; color: #2a1650 !important; border-radius: 999px; padding: 4px 12px; }

/* Dark mode: buttons outside cards that kept the cream base, and anything on a bright yellow/lime/lilac background,
   get colours that read (light text on dark buttons, dark text on bright fills). */
:root[data-theme="dark"] :is(.chat-quick, .hand-sort, .room-chat, .game-size, .story-show, .site-bg-picker, .thirteen-side) button:not(.dark):not([aria-pressed="true"]):not(.playing-card) {
  border: 1px solid var(--ui-border);
  background: var(--ui-hover);
  color: var(--ui-text);
}
:root[data-theme="dark"] :is(
  .game-pin[aria-pressed="true"], .favourite-star, .property-centre, .playing-card[aria-pressed="true"], .table-seat-active,
  .seat-bubble, .truth-mine b, .truth-card b, .story-show-on button, .match-pot, .shop-filters button[aria-pressed="true"],
  .wardrobe-tile[aria-pressed="true"], .basic-tile[aria-pressed="true"], .daily-button.daily-ready, #roomRejoin,
  .lobby-signin, .friend-favs li, .friend-stats span, .top-note,
  .story, .story-hidden, .game-size button:hover, .lobby-me
) { color: #241b2f !important; }
:root[data-theme="dark"] .story { background: #e4f2b0; }
:root[data-theme="dark"] #count { color: #241b2f !important; }
:root[data-theme="dark"] .story-show .story-show-on button { background: #f8d633 !important; }
html[data-theme="dark"] body > header #brand span { color: #ffe066; }

/* Header: menu and brand on the left; theme and language as round icons at the top right. */
html body > header #brand { order: 0; }
html body > header .top-note { order: 1; }
html body > header #headerMenu { order: 2; margin-left: auto; }
html body > header #themeToggle { order: 3; margin-left: 0; }
html body > header #langToggle { order: 4; }
html body > header #sidebarOpen { order: -1; margin-right: 4px; }
html body > header :is(#themeToggle, #langToggle, #sidebarOpen) {
  display: grid;
  place-items: center;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border: 2px solid #ffffffb0;
  border-radius: 50%;
  background: #ffffff59;
  color: #20163a;
  box-shadow: none;
  font: 800 19px/1 system-ui, sans-serif;
}
html body > header :is(#themeToggle, #langToggle, #sidebarOpen):hover { background: #ffffff99; transform: none; }
html[data-theme="dark"] body > header :is(#themeToggle, #langToggle, #sidebarOpen) { border-color: #ffffff55; background: #ffffff1f; color: #fff; }
html[data-theme="dark"] body > header :is(#themeToggle, #langToggle, #sidebarOpen):hover { background: #ffffff3a; }
/* Phones: icons stay on the first row next to the name, page buttons go to the row below. */
@media (max-width: 680px) {
  html body > header { flex-wrap: wrap; }
  html body > header #brand { margin-right: auto; }
  html body > header #headerMenu { order: 10; margin-left: 0; flex: 1 0 100%; }
  html body > header :is(#themeToggle, #langToggle, #sidebarOpen) { flex-basis: 38px; width: 38px; height: 38px; min-height: 38px; font-size: 18px; }
}
/* The menu button sits left of the logo and the side menu opens from the left, under it. */
#siteSidebar { inset: 0 auto 0 0; border-radius: 0 16px 16px 0; }
