/* App shell: sidebar, header, page, footer, phone tab bar and search menu.
   Desktop 1100px and up / tablet 768-1099px / phone 767px and below. */

/* Columns per shelf row. Kept here, not in tokens.css, so the media queries below override it. */
:root {
  --shelf-cols: 6;
}

/* Sidebar motion: a quick start and a soft landing, as long as the sidebar takes to fold. */
:root {
  --sidebar-ease: cubic-bezier(0.2, 0, 0, 1);
  --sidebar-fold: 0.2s;
}

.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  flex: 0 0 var(--sidebar-width);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: var(--sidebar-width);
  height: 100vh;
  overflow: hidden;
  padding: var(--space-3);
  background: var(--surface-0);
  transition: flex-basis var(--sidebar-fold) var(--sidebar-ease), width var(--sidebar-fold) var(--sidebar-ease);
}

/* The menu floats on a panel a shade lighter than the page, inside a fine line, and scrolls inside it.
   Its padding is only top and bottom, so the icons keep their line with the rail. */
.sidebar > .nav-menu {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: var(--space-2) 0 var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--surface-float);
  scrollbar-width: none;
}

.sidebar > .nav-menu::-webkit-scrollbar {
  display: none;
}

/* Every icon in the sidebar sits 38px from its left edge, the middle of the folded rail, so
   folding only narrows the sidebar and nothing moves. */
.sidebar__top {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-inline: var(--space-1);
}

/* Home and casino side by side at the top of the sidebar. */
.nav-switch {
  display: flex;
  gap: var(--space-1);
  margin-left: auto;
  padding: var(--space-1);
  border-radius: 13px;
  background: var(--surface-1);
}

.nav-switch__item {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-tab);
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
}

.nav-switch__item:hover {
  color: var(--ink);
}

.nav-switch__item[aria-pressed="true"] {
  background: var(--selected);
  color: var(--ink);
}

/* The menu shows one level at a time: the first, or the casino's. While one slides over the
   other, both sit in the same cell. */
.nav-menu {
  display: grid;
}

.nav-menu__level {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}

.nav-menu__level[hidden] {
  display: none;
}

/* The items sit straight on the panel, each 40px tall with a grey icon. The one under the pointer lifts a
   shade; the current one takes the accent's tint. */
.nav-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-1);
}

.nav-group__heading {
  padding: var(--space-2) var(--space-3) var(--space-1);
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  max-height: 40px;
  overflow: hidden;
  white-space: nowrap;
  transition: max-height var(--sidebar-fold) var(--sidebar-ease), padding var(--sidebar-fold) var(--sidebar-ease),
    opacity var(--sidebar-fold) var(--sidebar-ease), visibility var(--sidebar-fold);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: 40px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
}

button.nav-item {
  width: 100%;
  border: 0;
  background: transparent;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

.nav-item > .icon {
  color: var(--ink-muted);
}

.nav-item:hover {
  background: var(--surface-2);
}

.nav-item[aria-current="page"] {
  background: var(--selected);
  color: var(--ink);
}

.nav-item[aria-current="page"] > .icon {
  color: var(--ink);
}

.nav-item__chevron {
  margin-left: auto;
}

.nav-item__label,
.nav-item__chevron {
  transition: opacity var(--sidebar-fold) var(--sidebar-ease), visibility var(--sidebar-fold);
}

/* A name too long for the menu ends in an ellipsis. Under the pointer or the focus it slides along to its
   end (nav-menu controller), then eases back. */
.nav-item__label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity var(--sidebar-fold) var(--sidebar-ease), visibility var(--sidebar-fold), text-indent 0.2s var(--ease-standard);
}

.nav-item__label.is-sliding {
  text-indent: var(--slide);
  text-overflow: clip;
  transition: text-indent var(--slide-time) linear 0.15s;
}

/* The way back from the casino level reads as that level's title. Outside a group, it takes the
   group's inset as padding to keep its icon in line. */
.nav-item--back {
  padding-left: calc(var(--space-3) + var(--space-1));
  color: var(--ink);
  font-weight: 700;
}

.sidebar__footer,
.drawer__footer {
  display: flex;
  align-items: center;
  padding: var(--space-2) var(--space-1);
}

.sidebar__footer {
  margin-top: auto;
}

:is(.sidebar__footer, .drawer__footer) .language-select {
  flex: 1 1 0;
  min-width: 0;
  margin-right: var(--space-2);
  transition: opacity var(--sidebar-fold) var(--sidebar-ease), visibility var(--sidebar-fold),
    margin var(--sidebar-fold) var(--sidebar-ease);
}

:is(.sidebar__footer, .drawer__footer) > .icon-button {
  margin-left: auto;
}

/* The theme switch and support sit together at the end. */
:is(.sidebar__footer, .drawer__footer) > .theme-toggle + .icon-button {
  margin-left: 0;
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  border-bottom: 1px solid var(--line);
  background: var(--surface-0);
}

.topbar__logo {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
}

.topbar__logo-full {
  width: auto;
  height: var(--control-md);
}

.topbar__logo-mark {
  display: none;
  width: auto;
  height: 40px;
}

.topbar__logo {
  justify-self: start;
}

.topbar__end {
  display: flex;
  grid-column: 3;
  align-items: center;
  justify-self: end;
  gap: var(--space-2);
}

.wallet {
  display: flex;
  align-items: stretch;
  height: var(--control-md);
}

.wallet__menu {
  position: relative;
  display: flex;
}

.wallet__balance {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  border: 1px solid var(--line);
  border-right: 0;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  background: var(--surface-1);
  color: var(--ink);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: pointer;
}

.wallet__balance:hover {
  background: var(--surface-2);
}

/* While a real-play game is open the game frame marks the page, and the balance steps aside. */
.wallet__playing {
  display: none;
}

html[data-playing] #wallet-balance,
html[data-playing] .wallet__vault {
  display: none;
}

html[data-playing] .wallet__playing {
  display: inline;
}

.wallet__vault {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding-left: var(--space-2);
  border-left: 1px solid var(--line);
  color: var(--ink-muted);
  font-weight: 600;
}

.wallet__chevron {
  color: var(--ink-muted);
  transition: transform 0.15s;
}

.wallet__balance[aria-expanded="true"] .wallet__chevron {
  transform: rotate(180deg);
}

.wallet__action {
  height: auto;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.wallet__action-icon,
.avatar__icon {
  display: none;
}

.page {
  display: flex;
  flex-direction: column;
  gap: var(--space-9);
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-6);
  /* Room under the last line for the floating support launcher. Phone has no launcher. */
  padding-bottom: calc(var(--space-6) * 2 + var(--control-xl));
}

.footer {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding-top: var(--space-8);
  border-top: 1px solid var(--line);
  color: var(--ink-muted);
  font-size: 14px;
}

.footer__cols {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--space-8);
}

.footer__col > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 14px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  list-style: none;
  cursor: default;
}

.footer__col > summary::-webkit-details-marker {
  display: none;
}

.footer__chevron {
  display: none;
  color: var(--ink-muted);
  transition: rotate 0.15s var(--ease-standard);
}

.footer__links {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.footer__col a,
.footer__link {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: start;
  text-decoration: none;
  cursor: pointer;
}

.footer__col a:hover,
.footer__link:hover {
  color: var(--ink);
}

.footer__rate {
  color: var(--ink);
  font-weight: 600;
}

.footer__legal {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  font-size: 13px;
}

.footer__legal-end {
  display: flex;
  margin-left: auto;
  align-items: center;
  gap: var(--space-3);
}

.badge-18 {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font-weight: 700;
}

.bottom-nav,
.drawer {
  display: none;
}

/* Desktop: the hamburger collapses the sidebar into an icon rail. */
@media (min-width: 1100px) {
  .app.is-sidebar-collapsed .sidebar {
    flex-basis: var(--sidebar-rail);
    width: var(--sidebar-rail);
  }

  .app.is-sidebar-collapsed .sidebar .nav-switch {
    display: none;
  }

  .app.is-sidebar-collapsed .sidebar :is(.nav-item__label, .nav-item__chevron, .nav-group__heading, .language-select) {
    opacity: 0;
    visibility: hidden;
  }

  .app.is-sidebar-collapsed .sidebar .nav-group__heading {
    max-height: 0;
    padding-block: 0;
  }

  .app.is-sidebar-collapsed .sidebar .language-select {
    margin-right: 0;
  }

  /* The rail has room for one button at its foot. */
  .app.is-sidebar-collapsed .sidebar .theme-toggle {
    display: none;
  }
}

/* Tablet: the sidebar starts as an icon rail and the hamburger opens it. */
@media (min-width: 768px) and (max-width: 1099px) {
  :root {
    --shelf-cols: 5;
  }

  .app:not(.is-sidebar-expanded) .sidebar {
    flex-basis: var(--sidebar-rail);
    width: var(--sidebar-rail);
  }

  .app:not(.is-sidebar-expanded) .sidebar :is(.nav-item__label, .nav-item__chevron, .nav-group__heading, .language-select) {
    opacity: 0;
    visibility: hidden;
  }

  .app:not(.is-sidebar-expanded) .sidebar .nav-group__heading {
    max-height: 0;
    padding-block: 0;
  }

  .app:not(.is-sidebar-expanded) .sidebar .language-select {
    margin-right: 0;
  }

  .app:not(.is-sidebar-expanded) .sidebar .theme-toggle {
    display: none;
  }

  .topbar__logo-full {
    display: none;
  }

  .topbar__logo-mark {
    display: block;
  }

  .footer__cols {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Phone: no sidebar; a fixed tab bar and a full-screen search menu instead. */
@media (max-width: 767px) {
  :root {
    --shelf-cols: 3;
  }

  .sidebar {
    display: none;
  }

  /* The phone's header: the logo, the wallet in the middle of the screen, then the bell and the account
     as bare 36px icons. */
  .topbar {
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
  }

  .topbar__logo-full,
  .topbar__search,
  .topbar__chat,
  .wallet__vault {
    display: none;
  }

  .topbar__logo-mark {
    display: block;
  }

  .topbar__end {
    gap: 6px;
  }

  .wallet {
    gap: var(--space-1);
    height: auto;
    padding: var(--space-1);
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface-float);
  }

  .wallet__balance {
    height: 36px;
    padding: 0 var(--space-2);
    border: 0;
    border-radius: var(--radius-md);
    background: var(--track);
    font-size: 16px;
    font-weight: 600;
  }

  .wallet__action {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-md);
  }

  .wallet__action-label,
  .avatar__initial {
    display: none;
  }

  .wallet__action-icon,
  .avatar__icon {
    display: block;
  }

  .topbar__end .icon-button,
  .topbar__end .avatar {
    width: 36px;
    height: 36px;
    background: transparent;
  }

  .topbar__end :is(.icon-button, .avatar)[aria-expanded="true"] {
    background: color-mix(in srgb, var(--ink) 5%, transparent);
  }

  .page {
    gap: 28px;
    padding: var(--space-4) var(--space-4) calc(var(--bottom-nav-height) + var(--space-6) + env(safe-area-inset-bottom, 0px));
  }

  /* The footer on a phone: each group a 48px card that unfolds its links, then the copyright, the rate
     and the language down the middle. */
  .footer {
    padding-top: var(--space-6);
  }

  .footer__cols {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-3);
  }

  .footer__col {
    border-radius: var(--radius-md);
    background: var(--surface-2);
  }

  .footer__col > summary {
    min-height: 48px;
    margin: 0;
    padding: 0 var(--space-4);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
  }

  .footer__chevron {
    display: block;
  }

  .footer__col[open] .footer__chevron {
    rotate: 180deg;
  }

  .footer__links {
    gap: var(--space-3);
    padding: 0 var(--space-4) var(--space-4);
  }

  .footer__legal {
    flex-direction: column;
    gap: var(--space-4);
    padding-top: var(--space-6);
    border-top: 1px solid var(--line);
    text-align: center;
  }

  .footer__legal-end {
    flex-direction: column;
    margin-left: 0;
  }

  /* The phone's bar: two docks floating 8px in from the edges, each 8px of padding around 36px buttons
     with 20px icons, 8px apart. Only the docks take taps. */
  .bottom-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    padding: var(--space-2) var(--space-2) calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
    pointer-events: none;
  }

  .bottom-nav__pill {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-dock);
    background: var(--surface-float);
    box-shadow: 0 8px 24px rgb(0 0 0 / calc(0.35 * var(--shade)));
    pointer-events: auto;
  }

  .bottom-nav__item {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--ink);
    text-decoration: none;
    cursor: pointer;
  }

  .bottom-nav__item[aria-current] {
    background: var(--selected);
  }

  /* The way back to the top: a 44px button 16px above the bar and 16px in from the right. */
  .bottom-nav__to-top {
    position: absolute;
    right: var(--space-4);
    bottom: calc(100% + var(--space-4));
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface-float);
    color: var(--ink);
    box-shadow: 0 8px 24px rgb(0 0 0 / calc(0.35 * var(--shade)));
    cursor: pointer;
    pointer-events: auto;
  }

  .bottom-nav__to-top[hidden],
  .bottom-nav:has([aria-expanded="true"]) .bottom-nav__to-top {
    display: none;
  }

  /* An open card's button turns into its close. */
  .bottom-nav__close,
  .bottom-nav__item[aria-expanded="true"] .bottom-nav__open {
    display: none;
  }

  .bottom-nav__item[aria-expanded="true"] .bottom-nav__close {
    display: block;
  }

  /* The panels the bar opens: floating between the header and the bar, 8px in from the edges, inside
     a fine line. */
  .drawer:not([hidden]),
  .search-dialog[open],
  .chat-panel {
    position: fixed;
    top: calc(var(--phone-header-height) + var(--space-2));
    right: var(--space-2);
    bottom: calc(var(--bottom-nav-height) + var(--space-2) + env(safe-area-inset-bottom, 0px));
    left: var(--space-2);
    z-index: 35;
    width: auto;
    max-width: none;
    height: auto;
    max-height: none;
    margin: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius-panel);
    background: var(--surface-float);
    box-shadow: 0 16px 48px rgb(0 0 0 / calc(0.45 * var(--shade)));
  }

  .drawer:not([hidden]) {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    overflow-y: auto;
    padding: var(--space-3);
  }
}

/* Notices in the corner: good news about the player's chips, on whatever page is open. They sit
   left of the chat panel when it is open, and slim down during real play. */
.toasts {
  position: fixed;
  top: 76px;
  right: var(--space-6);
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: min(380px, calc(100vw - 2 * var(--space-4)));
  pointer-events: none;
}

body:has(.chat-panel:not([hidden])) .toasts {
  right: calc(var(--chat-panel-width) + var(--space-6));
}

.toast {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  overflow: hidden;
  padding: var(--space-3) var(--space-2) var(--space-4) var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  box-shadow: 0 16px 40px rgb(0 0 0 / calc(0.45 * var(--shade)));
  pointer-events: auto;
  animation: toast-in 0.2s ease-out;
}

.toast__icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgb(61 220 151 / 16%);
  color: var(--win);
}

/* The operators' announcements: a bar over every page, or a notice in the corner. */
.announcements {
  display: flex;
  flex-direction: column;
}

.announcement {
  --announcement: var(--accent);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  background: var(--announcement);
  color: var(--on-accent);
  font-size: 14px;
  font-weight: 600;
}

.announcement p {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.announcement .icon {
  flex: none;
}

.announcement__close {
  display: grid;
  flex: none;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.announcement__close:hover {
  background: rgb(0 0 0 / 18%);
}

.toast--announcement {
  --announcement: var(--accent);
}

.announcement--green {
  --announcement: #1f8a5b;
}

.announcement--amber {
  --announcement: #9a6406;
}

.announcement--red {
  --announcement: var(--danger-fill);
}

.toast--announcement .toast__icon {
  background: var(--announcement);
  color: var(--on-accent);
}

/* A rain that fell: its own colour. */
.toast--rain .toast__icon {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--focus);
}

/* A nudge to take a break, in the reminder's amber. */
.toast--nudge .toast__icon {
  background: rgb(245 165 36 / 16%);
  color: var(--tile-amber);
}

/* Something that couldn't be done. */
.toast--error .toast__icon {
  background: rgb(242 85 90 / 16%);
  color: var(--danger);
}

.toast__text {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  font-size: 14px;
  line-height: 1.5;
}

.toast__body,
.toast__in-game {
  color: var(--ink-muted);
  font-size: 13px;
}

.toast__in-game {
  display: none;
}

.toast__link {
  align-self: flex-start;
  margin-top: 2px;
  color: var(--focus);
  font-size: 13px;
}

.toast__close {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
}

.toast__close:hover {
  color: var(--ink);
}

.toast__timer {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 3px;
  background: var(--win);
  transform-origin: left;
  animation: toast-timer 8s linear forwards;
}

.toast.is-paused .toast__timer {
  animation-play-state: paused;
}

html[data-playing] .toast {
  padding-block: var(--space-2) var(--space-3);
}

html[data-playing] .toast__body,
html[data-playing] .toast__link {
  display: none;
}

html[data-playing] .toast__in-game {
  display: block;
}

.wallet__gain {
  color: var(--win);
  font-size: 13px;
  font-weight: 700;
  animation: wallet-gain 4s ease-out forwards;
}

html[data-playing] .wallet__gain {
  display: none;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
}

@keyframes toast-timer {
  to { transform: scaleX(0); }
}

@keyframes wallet-gain {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

@media (max-width: 767px) {
  .toasts,
  body:has(.chat-panel:not([hidden])) .toasts {
    top: calc(var(--phone-header-height) + var(--space-2));
    right: var(--space-3);
    left: var(--space-3);
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast,
  .wallet__gain {
    animation: none;
  }

  .toast__timer {
    display: none;
  }
}

.reduced-motion .toast,
.reduced-motion .wallet__gain {
  animation: none;
}

.reduced-motion .toast__timer {
  display: none;
}
