.homepage-lobby {
  --home-gutter: clamp(14px, 3vw, 32px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 0;
  min-height: 100dvh;
  padding: max(14px, env(safe-area-inset-top)) var(--home-gutter) max(22px, env(safe-area-inset-bottom));
  text-align: center;
}
.screen-center.homepage-lobby { display: flex; align-items: center; }
.home-group-photo {
  position: relative;
  isolation: isolate;
  width: min(100%, 1100px);
  aspect-ratio: 16 / 10;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid #806526;
  border-radius: clamp(12px, 2vw, 22px);
  background: #070908;
  box-shadow: 0 18px 42px #0007;
  text-align: left;
}
.home-group-photo > picture {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}
.home-group-photo > picture > img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}
.home-group-photo::after {
  position: absolute;
  z-index: 0;
  inset: 0;
  background: linear-gradient(180deg, #0008 0%, transparent 34%, transparent 53%, #0004 70%, #020807ed 100%);
  content: "";
  pointer-events: none;
}
.home-group-photo-title {
  position: absolute;
  z-index: 1;
  top: 14px;
  left: 14px;
  display: grid;
  gap: 1px;
  padding: 4px 9px 6px;
  border-radius: 10px;
  background: linear-gradient(90deg, #050504dc, #05050484 82%, transparent);
  text-shadow: 0 2px 10px #000;
}
.home-group-photo-title span { color: #f1cf75; font-size: 11px; font-weight: 900; letter-spacing: .16em; }
.home-group-photo-title strong { color: #fff0bd; font-family: "BiauKai", "DFKai-SB", "Noto Serif TC", serif; font-size: clamp(40px, 4vw, 46px); line-height: 1; letter-spacing: .1em; }
.home-group-photo-title small { color: #f5dfab; font-size: 10px; letter-spacing: .06em; }
.home-group-photo-seal {
  position: absolute;
  z-index: 1;
  top: clamp(12px, 2.4vw, 24px);
  right: clamp(12px, 2.4vw, 24px);
  display: grid;
  place-items: center;
  width: clamp(27px, 3.1vw, 36px);
  height: clamp(34px, 4vw, 44px);
  transform: rotate(-7deg);
  border: 2px solid #e21c54;
  border-radius: 7px;
  background: #ce1649;
  color: #20080e;
  font-family: "BiauKai", "DFKai-SB", serif;
  font-size: 13px;
  font-weight: 900;
  writing-mode: vertical-rl;
  box-shadow: 0 0 18px #e21c5480;
}
.home-music-start {
  position: absolute;
  z-index: 3;
  top: clamp(12px, 2.4vw, 24px);
  right: clamp(55px, 6vw, 70px);
  min-height: 44px;
  padding: 7px 12px;
  border: 1px solid #e9c36b;
  border-radius: 999px;
  background: #071a16e8;
  color: #ffe9af;
  font: 700 13px/1.2 system-ui, sans-serif;
  cursor: pointer;
}
.home-music-start[hidden] { display: none; }
.home-music-start:focus-visible { outline: 3px solid #fff0bb; outline-offset: 2px; }
.home-game-actions {
  position: absolute;
  z-index: 2;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 8px;
  padding: 12px clamp(12px, 2.4vw, 24px) 14px;
}
.home-game-actions > * {
  display: grid;
  min-width: 0;
  min-height: 44px;
  place-items: center;
  margin: 0;
  padding: 7px 5px;
  border: 1px solid #c8a85e;
  border-radius: 10px;
  background: #0d211feb;
  color: #f1e4c6;
  font-size: clamp(11px, 1.1vw, 13px);
  font-weight: 850;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.home-game-actions > .is-selected {
  width: auto;
  max-width: none;
  border-color: #ffe7a4;
  background: linear-gradient(#ffe28d, #d69a31);
  color: #2b1b0b;
  box-shadow: 0 3px 10px #0008, inset 0 1px #fff8d8;
  animation: home-mode-float 2.8s ease-in-out infinite;
}
.home-game-actions > .is-selected:hover { background: linear-gradient(#ffe28d, #d69a31); }
.home-game-actions > .primary-button:not(.is-selected),
.home-game-actions > .secondary-button:not(.is-selected) {
  border: 1px solid #c8a85e;
  background: #0d211feb;
  color: #f1e4c6;
  box-shadow: none;
}
@keyframes home-mode-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .home-game-actions > .is-selected { animation: none; } }
.home-game-actions > *:focus-visible { outline: 3px solid #fff0bb; outline-offset: 2px; }
.home-game-actions > :not(:disabled):not([aria-disabled="true"]):focus-visible {
  border-color: #ffe7a4;
  background: linear-gradient(#ffe28d, #d69a31);
  color: #2b1b0b;
  box-shadow: 0 3px 10px #0008, inset 0 1px #fff8d8;
}
@media (hover: hover) and (pointer: fine) {
  .home-game-actions > :not(:disabled):not([aria-disabled="true"]):hover {
    border-color: #ffe7a4;
    background: linear-gradient(#ffe28d, #d69a31);
    color: #2b1b0b;
    box-shadow: 0 3px 10px #0008, inset 0 1px #fff8d8;
  }
}
.home-utility-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(100%, 1100px);
  margin: 8px auto 0;
}
.home-utility-row > .home-hints {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "label" "text";
  align-content: center;
  gap: 3px;
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding: 4px 8px;
  color: #f4ecd9;
  text-align: left;
}
.home-utility-row .home-hints-label { grid-area: label; color: #f0c978; font-size: 12px; white-space: nowrap; }
.home-utility-row .home-hints p { grid-area: text; min-width: 0; margin: 0; line-height: 1.4; overflow-wrap: anywhere; }
.home-utility-row > .lobby-settings { flex: 0 0 auto; margin: 0; }
.home-utility-row > .lobby-settings > summary { min-width: 56px; min-height: 44px; }
.home-utility-row .lobby-settings .settings-card {
  top: auto;
  right: 0;
  bottom: calc(100% + 6px);
  left: auto;
  transform: none;
}
.homepage-lobby > .select-panel { width: min(100%, 1060px); }
.homepage-lobby > .lobby-learning { width: min(100%, 680px); margin-top: 12px; }
.homepage-lobby > #beginner-village:not([open]) { display: none; }
#beginner-village > .commit-card { margin: 0 12px 12px; }
.homepage-lobby > .lobby-settings { margin-top: 10px; }
.home-account-link { appearance: none; }
.home-account-panel {
  width: min(100%, 1060px);
  margin: 14px auto 0;
  padding: 14px;
  border: 1px solid #d5b65e80;
  border-radius: 14px;
  background: #061d19d9;
  color: #f5ecd8;
  text-align: left;
}
.home-account-panel:not([open]) { display: none; }
.home-account-panel > summary { cursor: pointer; color: #ffe19a; font-weight: 800; }
.home-account-panel #home-account-message { color: #ffb6a8; }
.home-account-panel > details { margin-top: 10px; }
.home-ranking-panel {
  width: min(100%, 1060px);
  margin: 14px auto 0;
  padding: clamp(14px, 2vw, 24px);
  border: 1px solid #d5b65e80;
  border-radius: 16px;
  background: #071c19ef;
  color: #f5ecd8;
  text-align: left;
  scroll-margin-top: 16px;
}
.home-ranking-panel:not([open]) { display: none; }
.home-ranking-panel > summary { cursor: pointer; color: #ffe19a; font-size: clamp(18px, 2.2vw, 24px); font-weight: 850; }
.home-ranking-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 10px 0 16px; }
.home-ranking-heading p { margin: 0; color: #c6d5ca; }
.home-ranking-heading button { min-height: 44px; padding: 8px 16px; border: 1px solid #d5b65e; border-radius: 10px; background: #173e35; color: #fff0bd; font: inherit; cursor: pointer; }
.home-ranking-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; max-width: 720px; margin-inline: auto; }
.home-ranking-grid > section { min-width: 0; padding: 18px; border: 1px solid #d6bd81; border-radius: 13px; background: #fffaf0; color: #193b32; }
.home-ranking-grid h2 { margin: 0; color: #193b32; font-size: clamp(18px, 2vw, 22px); }
.home-ranking-grid section > p { margin: 4px 0 12px; color: #5a6d63; font-size: 14px; }
.home-ranking-grid section > p[role=status] { color: #7d5932; }
.home-ranking-grid .rank-entry { display: grid; grid-template-columns: 2rem 44px minmax(0, 1fr); align-items: center; gap: 10px; min-height: 64px; padding: 10px 0; border-bottom: 1px solid #e7ddc8; }
.home-ranking-grid .rank-position { text-align: center; font-weight: 900; font-variant-numeric: tabular-nums; }
.home-ranking-grid .rank-avatar { display: grid; width: 44px; height: 44px; place-items: center; border-radius: 50%; background: #eadfca; color: #163f36; object-fit: contain; font-weight: 800; }
.home-ranking-grid .rank-entry .rank-copy { display: grid; min-width: 0; gap: 8px; }
.home-ranking-grid .rank-primary { display: flex; min-width: 0; align-items: flex-start; justify-content: space-between; gap: 10px; }
.home-ranking-grid .rank-identity { display: grid; min-width: 0; gap: 2px; }
.home-ranking-grid .rank-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home-ranking-grid .rank-game-count { color: #465b50; font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.home-ranking-grid .rank-rating { flex: 0 0 auto; color: #163f36; font-size: clamp(18px, 2vw, 22px); font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.15; white-space: nowrap; }
.home-ranking-grid .rank-details { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; min-width: 0; }
.home-ranking-grid .rank-rate { display: grid; min-width: 0; gap: 2px; }
.home-ranking-grid .rank-rate-label { color: #5a6d63; font-size: 12px; line-height: 1.2; }
.home-ranking-grid .rank-rate-value { color: #193b32; font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.home-ranking-grid .rank-coverage { margin: -3px 0 0; color: #5a6d63; font-size: 11px; line-height: 1.35; overflow-wrap: anywhere; }
.home-footer { display: flex; justify-content: center; gap: 16px; flex-wrap: wrap; width: 100%; padding: 14px 0 0; color: #b9c9c3; font-size: 12px; }
.home-footer a { color: #ffe19a; }
.home-group-photo-fallback { display: grid; width: 100%; height: 100%; place-items: center; color: #ffe19a; font-size: 32px; }
@media (max-width: 700px) {
  .homepage-lobby { padding-inline: max(10px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-right)); }
  .home-group-photo { aspect-ratio: auto; border-radius: 14px; }
  .home-group-photo > picture { position: relative; inset: auto; display: block; width: 100%; height: auto; }
  .home-group-photo > picture > img { width: 100%; height: auto; aspect-ratio: 4 / 5; object-fit: contain; }
  .home-group-photo::after { display: none; }
  .home-group-photo-title { top: 6px; left: 6px; gap: 0; padding: 2px 4px 3px; }
  .home-group-photo-title span { font-size: 8px; }
  .home-group-photo-title strong { font-size: 18px; line-height: 1; }
  .home-group-photo-title small { font-size: 7px; }
  .home-group-photo-seal { top: 10px; right: 10px; }
  .home-utility-row { align-items: stretch; gap: 6px; margin-top: 7px; }
  .home-utility-row > .home-hints { gap: 2px; padding: 2px 4px; }
  .home-utility-row .home-hints-label { grid-area: label; font-size: 10px; }
  .home-utility-row .home-hints p { min-height: 4.1em; line-height: 1.3; }
  .home-utility-row > .lobby-settings { align-self: stretch; }
  .home-utility-row > .lobby-settings > summary { min-width: 56px; min-height: 44px; padding: 0 10px; }
  .home-utility-row .lobby-settings .settings-card { width: min(260px, calc(100vw - 28px)); }
  .home-game-actions { position: relative; inset: auto; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; padding: 8px; }
  .home-game-actions > * { min-height: 44px; padding: 5px 3px; font-size: clamp(10px, 2.8vw, 12px); }
  .home-account-panel { padding: 11px; }
  .home-ranking-heading { align-items: flex-start; }
  .home-ranking-grid { grid-template-columns: 1fr; }
  .home-ranking-grid > section { padding: 14px; }
  .home-ranking-grid .rank-entry { grid-template-columns: 1.75rem 40px minmax(0, 1fr); gap: 7px; }
  .home-ranking-grid .rank-avatar { width: 40px; height: 40px; }
  .home-ranking-grid .rank-entry .rank-copy { gap: 7px; }
  .home-ranking-grid .rank-primary { gap: 6px; }
  .home-ranking-grid .rank-rating { font-size: clamp(16px, 5vw, 20px); }
  .home-ranking-grid .rank-game-count { font-size: 13px; }
  .home-ranking-grid .rank-details { gap: 4px; }
  .home-ranking-grid .rank-rate-label { font-size: 10px; }
  .home-ranking-grid .rank-rate-value { font-size: 14px; }
}
@media (max-width: 500px) {
  /* Keep the compact title above the full eighteen-person portrait. */
  .home-game-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .home-game-actions > :last-child { grid-column: auto; }
  .home-game-actions > * { font-size: 13px; }
  .home-ranking-heading { display: grid; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .homepage-lobby { padding-top: max(8px, env(safe-area-inset-top)); }
  .home-group-photo { width: min(100%, 980px); max-height: none; }
  .home-group-photo-title { top: 6px; left: 6px; gap: 0; padding: 2px 6px 4px; }
  .home-group-photo-title span { font-size: 9px; }
  .home-group-photo-title strong { font-size: 34px; line-height: 1; }
  .home-group-photo-title small { font-size: 8px; }
  .home-game-actions { grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 6px; padding: 8px 12px; }
  .home-game-actions > * { min-height: 44px; font-size: 11px; }
}
@media (orientation: landscape) and (max-height: 500px) and (min-width: 700px) {
  .home-game-actions { grid-template-columns: repeat(9, minmax(0, 1fr)); }
}

/* 排行榜版面：桌機使用面板可用寬度，手機保留三欄結果的對齊空間。 */
.home-ranking-grid { width: 100%; max-width: 1000px; }
.home-ranking-grid .rank-entry { grid-template-columns: 2rem 56px minmax(0, 1fr); }
.home-ranking-grid .rank-avatar { width: 56px; height: 56px; object-fit: contain; }
.home-ranking-grid .rank-name { font-size: 22px; font-weight: 700; }
.home-ranking-grid .rank-game-count { font-size: 18px; font-weight: 650; }
.home-ranking-grid .rank-rating { font-size: 26px; font-weight: 900; }
.home-ranking-grid .rank-rate { grid-template-rows: minmax(2.4em, auto) auto; justify-items: center; text-align: center; }
.home-ranking-grid .rank-rate-label { font-size: 16px; line-height: 1.2; }
.home-ranking-grid .rank-rate-value { font-size: 20px; font-weight: 700; }
@media (max-width: 700px) {
  .home-ranking-grid .rank-entry { grid-template-columns: 1.75rem 40px minmax(0, 1fr); }
  .home-ranking-grid .rank-avatar { width: 40px; height: 40px; }
  .home-ranking-grid .rank-name { font-size: 18px; }
  .home-ranking-grid .rank-game-count { font-size: 15px; }
  .home-ranking-grid .rank-rating { font-size: 20px; }
  .home-ranking-grid .rank-rate { grid-template-rows: minmax(2.4em, auto) auto; }
  .home-ranking-grid .rank-rate-label { font-size: 13px; }
  .home-ranking-grid .rank-rate-value { font-size: 16px; }
}

.home-ranking-grid .rank-position,
.home-ranking-grid .rank-avatar { align-self: center; margin-top: 0; }

/* 排行榜單列：局數與舊紀錄覆蓋資訊保留於輔助文字與提示。 */
.home-ranking-grid { width: 100%; max-width: 1000px; }
.home-ranking-grid .rank-entry {
  position: relative;
  grid-template-columns: 2rem 64px minmax(115px, 1.1fr) minmax(0, 2.5fr) minmax(130px, auto);
  align-items: center;
  gap: 10px;
  min-height: 88px;
}
.home-ranking-grid .rank-position,
.home-ranking-grid .rank-avatar { align-self: center; margin-top: 0; }
.home-ranking-grid .rank-avatar { width: 64px; height: 64px; object-fit: contain; }
.home-ranking-grid .rank-identity { grid-column: 3; min-width: 0; }
.home-ranking-grid .rank-name { display: block; font-size: 24px; font-weight: 700; }
.home-ranking-grid .rank-details {
  grid-column: 4;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-self: stretch;
  align-items: stretch;
  gap: 8px;
  min-width: 0;
}
.home-ranking-grid .rank-rate {
  display: grid;
  grid-template-rows: minmax(2.4em, auto) auto;
  justify-items: center;
  align-content: center;
  gap: 2px;
  min-width: 0;
  text-align: center;
}
.home-ranking-grid .rank-rate-label { font-size: 18px; line-height: 1.15; }
.home-ranking-grid .rank-rate-value { font-size: 20px; font-weight: 800; }
.home-ranking-grid .rank-rating {
  grid-column: 5;
  justify-self: end;
  font-size: 25px;
  font-weight: 900;
}
.home-ranking-grid .rank-coverage.sr-only,
.home-ranking-grid .rank-game-count.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
@media (min-width: 701px) and (max-width: 999px) {
  .home-ranking-grid .rank-entry { grid-template-columns: 2rem 52px minmax(105px, 1fr) minmax(0, 2.3fr) minmax(112px, auto); gap: 7px; }
  .home-ranking-grid .rank-avatar { width: 52px; height: 52px; }
  .home-ranking-grid .rank-name { font-size: 20px; }
  .home-ranking-grid .rank-rate-label { font-size: 15px; }
  .home-ranking-grid .rank-rate-value { font-size: 18px; }
  .home-ranking-grid .rank-rating { font-size: 22px; }
}
@media (max-width: 700px) {
  .home-ranking-grid .rank-entry { grid-template-columns: 1.5rem 40px minmax(0, 1fr) minmax(78px, auto); grid-template-rows: auto auto; gap: 7px; min-height: 0; padding: 10px 0; }
  .home-ranking-grid .rank-position,
  .home-ranking-grid .rank-avatar { grid-row: 1; align-self: center; margin-top: 0; }
  .home-ranking-grid .rank-avatar { width: 40px; height: 40px; }
  .home-ranking-grid .rank-identity { grid-column: 3; grid-row: 1; }
  .home-ranking-grid .rank-name { font-size: 18px; }
  .home-ranking-grid .rank-rating { grid-column: 4; grid-row: 1; font-size: 20px; }
  .home-ranking-grid .rank-details { grid-column: 1 / -1; grid-row: 2; gap: 4px; }
  .home-ranking-grid .rank-rate { grid-template-rows: minmax(2.5em, auto) auto; }
  .home-ranking-grid .rank-rate-label { font-size: 13px; }
  .home-ranking-grid .rank-rate-value { font-size: 16px; }
}

/* Flat-row identity alignment: keep rank/avatar centered in the row and preserve full avatar framing. */
.home-ranking-grid .rank-entry > .rank-position { align-self: center; margin-top: 0; font-size: 24px; font-weight: 800; }
.home-ranking-grid .rank-entry > .rank-avatar { align-self: center; margin-top: 0; object-fit: contain; }
@media (max-width: 700px) {
  .home-ranking-grid .rank-entry > .rank-position { font-size: 18px; }
}
