:root {
  --font-display: "Trajan Pro 3", "Trajan Pro", Cinzel, "Times New Roman", serif;
  --font-body: "Adobe Caslon Pro", "Libre Caslon Text", "Palatino Linotype", Palatino, serif;
  --gold: #d4b36a;
  --gold-hi: #ecde8c;
  --gold-lo: #8a682a;
  --ivory: #f4ead6;
  --ink: #1a120c;
  --emerald: #0c241c;
  --emerald-deep: #07140f;
  --danger: #8c3a34;
  --hud-h: 72px;
  --tool-h: 76px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  width: 100%;
  background: var(--emerald-deep);
  color: var(--ivory);
  font-family: var(--font-body);
  overflow: hidden;
}

img {
  max-width: 100%;
  display: block;
}

button {
  font-family: var(--font-display);
  letter-spacing: 0.12em;
  cursor: pointer;
  border: 0;
  background: none;
  color: inherit;
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

#app {
  position: relative;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.view[hidden] {
  display: none !important;
}

.bg-cover {
  position: absolute;
  inset: 0;
  background: center / cover no-repeat;
  z-index: 0;
  overflow: hidden;
}

.bg-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.bg-video.is-ready {
  opacity: 1;
}

.bg-dim {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(8, 22, 16, 0.25), rgba(4, 10, 8, 0.62) 70%);
  z-index: 1;
}

.view > .content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 24px;
}

#view-loading .content {
  gap: 18px;
}

.emblem {
  width: min(180px, 36vw);
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.55));
}

.brand-heading {
  margin: 0;
  padding: 0;
  font-size: inherit;
  font-weight: inherit;
  line-height: 0;
}

.wordmark {
  width: min(420px, 78vw);
  filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.5));
}

.load-bar {
  width: min(320px, 70vw);
  height: 8px;
  border: 1px solid var(--gold-lo);
  border-radius: 99px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.4);
}

.load-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold-lo), var(--gold-hi));
  transition: width 0.2s ease;
}

.load-caption {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
}

.subtitle-mark {
  width: 72%;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.7));
}

.menu-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

#view-menu .content.menu-hang {
  justify-content: flex-start;
  align-items: center;
  padding: env(safe-area-inset-top, 0px) 12px
    max(12px, env(safe-area-inset-bottom, 12px));
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.menu-hang-fit {
  width: min(500px, 92vw);
  transform-origin: top center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hang {
  display: flex;
  flex-direction: column;
  align-items: center;
  transform-origin: top center;
  will-change: transform;
}

.hang-root,
.hang-mid,
.hang-low {
  --hang-sway: 0deg;
}

.hang-root {
  width: 100%;
  animation: menu-sway 8.4s ease-in-out infinite;
}

.hang-mid {
  width: 100%;
  z-index: 2;
  animation: menu-sway 6.6s ease-in-out infinite reverse;
  animation-delay: -1.4s;
}

.hang-low {
  width: 100%;
  z-index: 1;
  animation: menu-sway 5.4s ease-in-out infinite;
  animation-delay: -2.2s;
}

#view-menu.wind-live .hang-root,
#view-menu.wind-live .hang-mid,
#view-menu.wind-live .hang-low {
  animation: none;
  transform: rotate(var(--hang-sway));
}

@keyframes menu-sway {
  0%,
  100% {
    transform: rotate(-1.35deg);
  }
  50% {
    transform: rotate(1.35deg);
  }
}

.hang-chains {
  display: flex;
  justify-content: space-between;
  width: 48%;
  height: clamp(22px, 4.2dvh, 36px);
  pointer-events: none;
}

.hang-chains-long {
  width: 52%;
  height: clamp(28px, 7dvh, 64px);
}

.hang-join {
  width: 46%;
}

.hang-chains.hang-join-mid {
  height: clamp(28px, 6.4dvh, 58px);
  margin-top: clamp(-20px, -3.2dvh, -12px);
}

.hang-chains.hang-join-low {
  height: clamp(36px, 9dvh, 88px);
  margin-top: clamp(-20px, -3dvh, -12px);
}

.hang-chains i {
  display: block;
  width: 28px;
  height: 100%;
  background: url("https://media.elfmahjong.com/ui/menu/chain.png") center top / 100% auto no-repeat;
}

.sign {
  position: relative;
  overflow: visible;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
}

.sign-logo {
  z-index: 3;
  width: 100%;
  aspect-ratio: 2.02;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12% 10% 9%;
  background-image: url("https://media.elfmahjong.com/ui/menu/sign_logo.png");
}

.sign-logo .wordmark {
  width: 86%;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.7));
}

.sign-tag {
  z-index: 2;
  width: 94%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4.2% 8% 3.6%;
  background-image: url("https://media.elfmahjong.com/ui/menu/sign_plank.png");
}

.sign-menu {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14% 13% 11.5%;
  background-image: url("https://media.elfmahjong.com/ui/menu/sign_board.png");
}

.sign-menu .menu-stack {
  width: 100%;
  gap: 11px;
}

.sign-menu .primary-btn,
.sign-menu .secondary-btn,
.sign-menu .ghost-btn {
  min-width: 0;
  width: 100%;
  height: clamp(44px, 6.2dvh, 50px);
  font-size: clamp(0.78rem, 2.6vw, 1.05rem);
  white-space: nowrap;
}

.sign-menu .ghost-btn {
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

@media (prefers-reduced-motion: reduce) {
  .hang-root,
  .hang-mid,
  .hang-low {
    animation: none;
  }

  .bg-video {
    display: none;
  }
}

@media (max-width: 820px), (max-height: 780px) {
  .hang-root,
  .hang-mid,
  .hang-low {
    animation: none;
  }

  .menu-hang-fit {
    width: min(440px, 94vw);
  }

  .sign-menu .menu-stack {
    gap: 8px;
  }
}

@media (max-height: 699px) {
  .layouts-content {
    padding: 4px 8px max(6px, env(safe-area-inset-bottom, 6px));
  }

  .panel.panel-layouts {
    width: min(96vw, 640px);
    max-height: calc(100dvh - 8px);
    border-width: clamp(22px, 5.5vh, 40px);
    padding: 2px 8px 4px;
  }

  .panel.panel-layouts h2 {
    font-size: 1.05rem;
    letter-spacing: 0.12em;
    margin: 0 0 4px;
  }

  .panel.panel-layouts .panel-grid {
    grid-template-columns: repeat(3, minmax(0, 132px));
    justify-content: center;
    gap: 8px 12px;
    overflow: auto;
    padding: 2px 4px 6px;
  }

  .layout-card {
    width: 100%;
    max-width: 132px;
    aspect-ratio: 5 / 5.15;
    padding: 10% 9% 8%;
    gap: 3px;
  }

  .layout-card canvas {
    min-height: 28px;
    max-height: 50%;
  }

  .layout-card h3 {
    font-size: 0.7rem;
    letter-spacing: 0.06em;
  }

  .panel.panel-layouts .panel-actions .secondary-btn,
  .panel.panel-layouts .secondary-btn {
    height: 40px;
    width: min(200px, 78%);
  }

  .layout-pager {
    gap: 8px;
    margin: 2px 0 0;
  }

  .layout-page-btn {
    width: 36px;
    height: 36px;
    font-size: 1.35rem;
  }

  .layout-page-indicator {
    font-size: 0.72rem;
  }
}

@media (max-height: 699px) and (max-width: 620px) {
  .panel.panel-layouts {
    width: calc(100vw - 8px);
  }

  .panel.panel-layouts .panel-grid {
    grid-template-columns: repeat(2, minmax(0, 108px));
    gap: 8px 10px;
  }

  .layout-card {
    max-width: 108px;
    aspect-ratio: 4 / 4.7;
  }
}

@media (max-height: 699px) and (hover: none) {
  .layout-card .layout-blurb {
    display: none;
  }
}

@media (max-height: 700px) and (max-width: 900px),
  (orientation: landscape) and (max-height: 620px) {
  #view-menu .content.menu-hang {
    justify-content: center;
    padding-top: max(6px, env(safe-area-inset-top, 0px));
    padding-bottom: max(8px, env(safe-area-inset-bottom, 8px));
  }

  .menu-hang-fit {
    width: min(420px, 94vw);
  }

  .hang-root {
    flex-direction: column;
    align-items: center;
    gap: 8px;
  }

  .hang-chains-long,
  .hang-join-mid,
  .sign-tag,
  .hang-join-low {
    display: none;
  }

  .sign-logo {
    width: min(280px, 72vw);
    aspect-ratio: auto;
    padding: 0;
    background-image: none;
  }

  .sign-logo .wordmark {
    width: 100%;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.75));
  }

  .hang-mid,
  .hang-low {
    width: 100%;
  }

  .sign-menu {
    padding: 12% 12% 10%;
  }

  .sign-menu .primary-btn,
  .sign-menu .secondary-btn,
  .sign-menu .ghost-btn {
    height: clamp(40px, 8dvh, 48px);
  }
}

.primary-btn,
.secondary-btn {
  min-width: min(340px, 86vw);
  height: 64px;
  padding: 0 28px;
  font-size: 1.05rem;
  color: var(--ivory);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
}

.primary-btn {
  background-image: url("https://media.elfmahjong.com/ui/buttons/primary/primary_normal.png");
}

.primary-btn:hover {
  background-image: url("https://media.elfmahjong.com/ui/buttons/primary/primary_hover.png");
  color: var(--gold-hi);
}

.primary-btn:active {
  background-image: url("https://media.elfmahjong.com/ui/buttons/primary/primary_pressed.png");
}

.secondary-btn {
  background-image: url("https://media.elfmahjong.com/ui/buttons/secondary/secondary_normal.png");
}

.secondary-btn:hover {
  background-image: url("https://media.elfmahjong.com/ui/buttons/secondary/secondary_hover.png");
}

.ghost-btn {
  min-width: min(340px, 86vw);
  height: 44px;
  color: var(--gold);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.82rem;
}

.ghost-btn:hover {
  color: var(--gold-hi);
}

#view-game {
  background: #08140f;
}

#view-game .bg-cover {
  z-index: 0;
}

.hud {
  position: relative;
  z-index: 3;
  height: var(--hud-h);
  margin: 10px 14px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  min-width: 0;
  background: url("https://media.elfmahjong.com/ui/hud/hud.png") center / 100% 100% no-repeat;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-group.center {
  flex: 1;
  justify-content: center;
  gap: 22px;
}

.stat {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 86px;
}

.stat img {
  width: 28px;
  height: 28px;
}

.stat b {
  font-family: var(--font-display);
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  color: var(--gold-hi);
  font-weight: 600;
}

.stat span {
  display: block;
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(244, 234, 214, 0.7);
}

.layout-chip {
  font-family: var(--font-display);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: var(--gold);
  padding: 0 6px;
}

.icon-btn {
  width: 52px;
  height: 52px;
  background: url("https://media.elfmahjong.com/ui/buttons/icon/icon_normal.png") center / contain no-repeat;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.icon-btn img {
  width: 26px;
  height: 26px;
  pointer-events: none;
}

.icon-btn:hover {
  background-image: url("https://media.elfmahjong.com/ui/buttons/icon/icon_hover.png");
}

.icon-btn:active {
  background-image: url("https://media.elfmahjong.com/ui/buttons/icon/icon_pressed.png");
}

.icon-btn:disabled {
  background-image: url("https://media.elfmahjong.com/ui/buttons/icon/icon_disabled.png");
}

.table-wrap {
  position: relative;
  z-index: 2;
  flex: 1;
  min-height: 0;
  min-width: 0;
  margin: 8px 18px;
  display: flex;
}

.table {
  flex: 1;
  min-height: 0;
  min-width: 0;
  --felt: url("https://media.elfmahjong.com/textures/felt/emerald.png");
  background-color: #0c2418;
  background-image:
    linear-gradient(180deg, rgba(0, 0, 0, 0.14), rgba(0, 0, 0, 0.34)),
    var(--felt);
  background-position: center, center;
  background-size: auto, 240px 240px;
  background-repeat: no-repeat, repeat;
  border: 3px solid var(--gold-lo);
  box-shadow:
    0 0 0 1px #5a4018,
    0 16px 40px rgba(0, 0, 0, 0.5),
    inset 0 0 70px rgba(0, 16, 10, 0.32);
  border-radius: 16px;
  overflow: hidden;
}

#board {
  width: 100%;
  height: 100%;
  display: block;
  max-width: 100%;
  min-width: 0;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.toolbar {
  position: relative;
  z-index: 3;
  height: var(--tool-h);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 0 12px 12px;
  min-width: 0;
  overflow: hidden;
}

.layouts-dim {
  background: url("https://media.elfmahjong.com/ui/overlays/pause.png") center / cover no-repeat;
}

.layouts-content {
  justify-content: safe center;
  padding: max(8px, env(safe-area-inset-top, 0px)) 12px
    max(10px, env(safe-area-inset-bottom, 10px));
  min-height: 0;
}

.panel.panel-layouts {
  width: fit-content;
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - 16px);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-height: 0;
  padding: 4px 12px 8px;
  border-width: clamp(72px, 8vw, 100px);
}

.mode-switch {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 2px 0 8px;
  flex: 0 0 auto;
}

.mode-btn {
  min-width: 0;
  flex: 1 1 0;
  height: 40px;
  padding: 0 8px;
  font-size: 0.64rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
  border: 1px solid var(--gold-lo);
  border-radius: 6px;
  background: rgba(8, 16, 10, 0.48);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
}

.mode-btn:hover {
  color: var(--gold-hi);
  background: rgba(212, 179, 106, 0.16);
}

.mode-btn.selected {
  color: var(--gold-hi);
  border-color: var(--gold);
  background: rgba(212, 179, 106, 0.22);
}

.panel.panel-layouts h2 {
  flex: 0 0 auto;
  margin: 0 0 10px;
}

.panel.panel-layouts .panel-grid {
  width: 100%;
  max-height: none;
  flex: 1 1 auto;
  min-height: 0;
  grid-template-columns: repeat(3, minmax(160px, 196px));
  justify-content: center;
}

.panel.panel-layouts .panel-actions {
  flex: 0 0 auto;
  margin-top: 4px;
}

.layout-card[hidden] {
  display: none !important;
}

.layout-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex: 0 0 auto;
  margin: 6px 0 2px;
}

.layout-pager[hidden] {
  display: none !important;
}

.layout-page-btn {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1px solid var(--gold-lo);
  color: var(--gold-hi);
  font-size: 1.55rem;
  line-height: 1;
  background: rgba(8, 16, 10, 0.5);
}

.layout-page-btn:hover:not(:disabled) {
  background: rgba(212, 179, 106, 0.2);
}

.layout-page-indicator {
  min-width: 5.5em;
  font-family: var(--font-display);
  letter-spacing: 0.14em;
  font-size: 0.82rem;
  color: var(--gold-hi);
  text-transform: uppercase;
}

.panel.panel-layouts[data-page-size="12"] .panel-grid {
  grid-template-columns: repeat(4, minmax(140px, 176px));
}

.panel.panel-layouts[data-page-size="4"] .panel-grid {
  grid-template-columns: repeat(2, minmax(0, 148px));
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  overflow: auto;
  padding: 2px 4px 8px;
}

.layout-card {
  position: relative;
  aspect-ratio: 5 / 6.6;
  min-height: 0;
  padding: 16% 15% 14%;
  background: url("https://media.elfmahjong.com/ui/layout-cards/card_normal.png") center / 100% 100% no-repeat;
  text-align: center;
  color: var(--ivory);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  overflow: hidden;
}

.layout-card:hover {
  background-image: url("https://media.elfmahjong.com/ui/layout-cards/card_hover.png");
}

.layout-card.selected {
  background-image: url("https://media.elfmahjong.com/ui/layout-cards/card_selected.png");
}

.layout-card h3 {
  margin: 0;
  font-family: var(--font-display);
  letter-spacing: 0.08em;
  font-size: clamp(0.72rem, 1.3vw, 0.92rem);
  font-weight: 600;
  color: var(--gold-hi);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  max-width: 100%;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.layout-card .layout-blurb {
  position: absolute;
  left: 11%;
  right: 11%;
  bottom: 9%;
  z-index: 2;
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(8, 16, 10, 0.9);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  font-size: clamp(0.72rem, 1.2vw, 0.86rem);
  line-height: 1.35;
  color: rgba(244, 234, 214, 0.95);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.16s ease, transform 0.16s ease;
  pointer-events: none;
  text-wrap: pretty;
}

.layout-card:hover .layout-blurb,
.layout-card:focus-visible .layout-blurb {
  opacity: 1;
  transform: none;
}

@media (hover: none) {
  .layout-card .layout-blurb {
    position: static;
    opacity: 1;
    transform: none;
    background: none;
    box-shadow: none;
    padding: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 0.7rem;
  }
}

.layout-card canvas {
  width: 100%;
  flex: 1 1 auto;
  min-height: 56px;
  max-height: 46%;
}

.view-title {
  font-family: var(--font-display);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: clamp(1.3rem, 3vw, 2rem);
  color: var(--gold-hi);
  margin: 0 0 8px;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.55);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: url("https://media.elfmahjong.com/ui/overlays/pause.png") center / cover no-repeat;
}

.overlay[hidden] {
  display: none !important;
}

.panel {
  width: min(640px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  min-height: 0;
  padding: 8px 14px 12px;
  border: clamp(64px, 9vw, 88px) solid transparent;
  border-image-source: url("https://media.elfmahjong.com/ui/panels/dialog.png");
  border-image-slice: 280 fill;
  border-image-repeat: stretch;
  background: none;
  color: var(--ivory);
  text-align: center;
}

.panel.victory {
  border-image-source: url("https://media.elfmahjong.com/ui/panels/victory.png");
  color: var(--ink);
}

.panel h2 {
  font-family: var(--font-display);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 1.6rem;
  margin: 0 0 16px;
  color: var(--gold-hi);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.panel.victory h2 {
  color: #5a3f16;
  text-shadow: none;
}

.panel p {
  margin: 0 0 18px;
  font-size: 1.05rem;
  color: var(--ivory);
}

.panel.victory p {
  color: var(--ink);
}

.panel-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.panel-actions-row {
  flex-direction: row;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
}

.panel-actions-row .primary-btn,
.panel-actions-row .secondary-btn {
  width: min(260px, 48%);
  flex: 1 1 200px;
  white-space: nowrap;
  letter-spacing: 0.08em;
  font-size: 0.95rem;
}

.panel .primary-btn,
.panel .secondary-btn {
  color: var(--ivory);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.65);
  min-width: 0;
  width: min(280px, 100%);
  max-width: 100%;
  height: 56px;
}

.panel .ghost-btn {
  color: var(--gold-hi);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  min-width: 0;
  width: min(280px, 100%);
  max-width: 100%;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 7px 0;
  font-size: 1.05rem;
  text-align: left;
  color: var(--ivory);
}

.settings-row span {
  flex: 1;
  min-width: 0;
}

.settings-row small {
  display: block;
  margin-top: 4px;
  font-family: var(--font-body);
  font-size: 0.78rem;
  letter-spacing: 0;
  line-height: 1.35;
  opacity: 0.82;
  color: var(--ivory);
}

.settings-row em {
  font-style: normal;
  color: var(--gold-hi);
  margin-left: 0.35em;
}

.settings-row input[type="range"]:disabled {
  opacity: 0.4;
  cursor: default;
}

.settings-row select {
  font-family: var(--font-body);
  color-scheme: dark;
  background: #12261e;
  color: var(--ivory);
  border: 1px solid var(--gold);
  padding: 8px 10px;
  border-radius: 6px;
  min-width: 0;
  max-width: 58%;
  font-size: 0.95rem;
}

.settings-row select option {
  background: #12261e;
  color: var(--ivory);
}

.settings-row input[type="range"] {
  width: 42%;
  accent-color: var(--gold);
  cursor: pointer;
}

.panel-pause {
  width: min(640px, calc(100vw - 24px));
}

.panel.panel-settings {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 24px);
  padding: 4px 8px 8px 18px;
}

.panel.panel-settings h2 {
  flex: 0 0 auto;
}

.panel.panel-settings .panel-actions {
  flex: 0 0 auto;
}

.settings-page {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.settings-page[hidden] {
  display: none !important;
}

.settings-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.settings-nav .primary-btn,
.settings-nav .secondary-btn {
  width: min(280px, 100%);
  max-width: min(280px, 100%);
}

.settings-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  max-height: min(52vh, 420px);
  margin-right: 10px;
  padding-right: 14px;
  text-align: left;
}

.gold-scroll,
.settings-body {
  scrollbar-width: thin;
  scrollbar-color: var(--gold-lo) transparent;
}

.gold-scroll::-webkit-scrollbar,
.settings-body::-webkit-scrollbar {
  width: 8px;
}

.gold-scroll::-webkit-scrollbar-track,
.settings-body::-webkit-scrollbar-track {
  background: transparent;
  margin: 8px 0;
}

.gold-scroll::-webkit-scrollbar-thumb,
.settings-body::-webkit-scrollbar-thumb {
  background: var(--gold-lo);
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.toggle {
  width: 48px;
  height: 26px;
  border-radius: 99px;
  background: #6a5a40;
  position: relative;
  border: 1px solid var(--gold-lo);
}

.toggle.on {
  background: #2f5a3a;
}

.toggle i {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--ivory);
  transition: left 0.15s ease;
}

.toggle.on i {
  left: 24px;
}

.panel.panel-stats {
  width: min(640px, 94vw);
  max-height: calc(100dvh - 24px);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-height: 0;
  padding: 6px 28px 12px;
}

.stats-scroll {
  overflow-x: hidden;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  max-height: min(56vh, 520px);
  margin: 0 2px 4px;
  padding: 0 16px 8px 8px;
  text-align: left;
}

.stats-grid {
  min-width: 0;
}

.stats-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 8rem 3.2rem;
  gap: 8px;
  align-items: center;
  padding: 7px 2px;
  border-bottom: 1px solid rgba(212, 179, 106, 0.28);
  font-size: 0.92rem;
  color: var(--ivory);
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

.stats-row > span {
  min-width: 0;
}

.stats-row span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.stats-row span:not(:first-child) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.stats-head {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--emerald);
  color: var(--gold-hi);
  font-family: var(--font-display);
  letter-spacing: 0.04em;
  border-bottom-color: rgba(212, 179, 106, 0.5);
}

.stats-head span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats-row.stats-group {
  margin-top: 10px;
  padding-top: 10px;
  color: var(--gold-hi);
  font-family: var(--font-display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.78rem;
  border-bottom-color: rgba(212, 179, 106, 0.5);
}

.stats-row.stats-group:first-child {
  margin-top: 0;
  padding-top: 7px;
}

.how-to {
  text-align: left;
  max-height: 42vh;
  overflow: auto;
  color: var(--ivory);
}

.how-to li {
  margin: 0 0 8px;
}

@media (max-width: 820px) {
  :root {
    --hud-h: 64px;
    --tool-h: 70px;
  }

  .hud {
    padding: 0 8px;
    gap: 4px;
  }

  .hud-group.center {
    gap: 10px;
  }

  .stat {
    min-width: 0;
  }

  .stat span {
    display: none;
  }

  .layout-chip {
    display: none;
  }

  .primary-btn,
  .secondary-btn,
  .ghost-btn {
    min-width: min(300px, 90vw);
    height: 58px;
  }

  .panel .primary-btn,
  .panel .secondary-btn,
  .panel .ghost-btn {
    min-width: 0;
    width: min(240px, 92%);
    max-width: 92%;
    height: 52px;
  }

  .hang-chains i {
    width: 22px;
  }

  .table-wrap {
    margin: 6px 8px;
  }

  .panel-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
  }

  .panel.panel-layouts {
    width: min(100%, 440px);
    border-width: clamp(36px, 8vw, 56px);
    padding: 2px 6px 6px;
  }

  .mode-btn {
    height: 36px;
    font-size: 0.64rem;
  }

  .panel.panel-layouts .panel-grid {
    grid-template-columns: repeat(2, minmax(0, 148px));
    justify-content: center;
    gap: 10px 14px;
    width: 100%;
    overflow: auto;
    padding: 4px 8px 8px;
  }

  .layout-card {
    width: 100%;
    max-width: 148px;
    aspect-ratio: 4 / 5.2;
    padding: 12% 10% 10%;
    gap: 4px;
  }

  .layout-card canvas {
    max-height: 52%;
  }
}

@media (max-width: 560px) {
  .panel {
    border-width: 48px;
    padding: 6px 10px 10px;
  }

  .panel-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .panel.panel-layouts {
    width: calc(100vw - 8px);
    max-height: calc(100dvh - 8px);
    border-width: 28px;
    padding: 2px 4px 4px;
  }

  .panel.panel-layouts h2 {
    font-size: 1.05rem;
    letter-spacing: 0.1em;
    margin-bottom: 6px;
  }

  .mode-btn {
    height: 34px;
    font-size: 0.6rem;
    padding: 0 6px;
  }

  .panel.panel-layouts .panel-grid {
    grid-template-columns: repeat(2, minmax(0, 118px));
    justify-content: center;
    gap: 10px 12px;
    padding: 4px 6px 8px;
  }

  .panel.panel-stats {
    width: calc(100vw - 8px);
    max-height: calc(100dvh - 8px);
    border-width: 48px;
    padding: 2px 10px 8px;
  }

  .stats-scroll {
    max-height: min(58vh, 420px);
    padding: 0 6px 8px;
  }

  .stats-row.stats-head {
    display: none;
  }

  .stats-row {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 12px;
    padding: 8px 2px 10px;
    font-size: 0.86rem;
  }

  .stats-row span:first-child {
    flex: 1 1 100%;
    color: var(--gold-hi);
    font-family: var(--font-display);
    letter-spacing: 0.06em;
  }

  .stats-row span:not(:first-child) {
    flex: 0 0 auto;
    text-align: left;
  }

  .stats-row span:not(:first-child)::before {
    content: attr(data-label) " ";
    color: var(--gold-hi);
    font-family: var(--font-display);
    letter-spacing: 0.04em;
    font-size: 0.78em;
  }

  .layout-card {
    max-width: 118px;
    aspect-ratio: 4 / 5.25;
    padding: 11% 9% 9%;
  }

  .layout-card h3 {
    font-size: 0.68rem;
    letter-spacing: 0.05em;
  }

  .layout-card canvas {
    min-height: 40px;
  }

  .view-title {
    font-size: 1.15rem;
    letter-spacing: 0.14em;
  }

  .toggle {
    width: 42px;
    height: 24px;
  }

  .toggle i {
    width: 18px;
    height: 18px;
  }

  .toggle.on i {
    left: 20px;
  }

  .icon-btn {
    width: 46px;
    height: 46px;
  }

  .icon-btn img {
    width: 22px;
    height: 22px;
  }

  .hud-group.center .stat:nth-child(3) {
    display: none;
  }

  .toolbar [data-action="fullscreen"] {
    display: none;
  }

  #btn-sound,
  #btn-music {
    display: none;
  }
}

@media (max-height: 699px) {
  .layouts-content {
    padding: 4px 8px max(6px, env(safe-area-inset-bottom, 6px));
  }

  .panel.panel-layouts {
    width: min(96vw, 640px);
    max-height: calc(100dvh - 8px);
    border-width: clamp(22px, 5.5vh, 40px);
    padding: 2px 8px 4px;
  }

  .panel.panel-layouts h2 {
    font-size: 1.05rem;
    letter-spacing: 0.12em;
    margin: 0 0 4px;
  }

  .panel.panel-layouts .panel-grid {
    grid-template-columns: repeat(3, minmax(0, 132px));
    justify-content: center;
    gap: 8px 12px;
    overflow: auto;
    padding: 2px 4px 6px;
  }

  .layout-card {
    width: 100%;
    max-width: 132px;
    aspect-ratio: 5 / 5.15;
    padding: 10% 9% 8%;
    gap: 3px;
  }

  .layout-card canvas {
    min-height: 28px;
    max-height: 50%;
  }

  .layout-card h3 {
    font-size: 0.7rem;
    letter-spacing: 0.06em;
  }

  .panel.panel-layouts .panel-actions .secondary-btn,
  .panel.panel-layouts .secondary-btn {
    height: 40px;
    width: min(200px, 78%);
  }

  .layout-pager {
    gap: 8px;
    margin: 2px 0 0;
  }

  .layout-page-btn {
    width: 36px;
    height: 36px;
    font-size: 1.35rem;
  }

  .layout-page-indicator {
    font-size: 0.72rem;
  }
}

@media (max-height: 699px) and (max-width: 620px) {
  .panel.panel-layouts {
    width: calc(100vw - 8px);
  }

  .panel.panel-layouts .panel-grid {
    grid-template-columns: repeat(2, minmax(0, 108px));
    gap: 8px 10px;
  }

  .layout-card {
    max-width: 108px;
    aspect-ratio: 4 / 4.7;
  }
}

@media (max-height: 699px) and (hover: none) {
  .layout-card .layout-blurb {
    display: none;
  }
}
