:root {
  --dm-common-header-min-height: 58px;
  --dm-common-header-height: var(--dm-common-header-min-height);
  --dm-common-header-account-width: 120px;
  --dm-common-header-bg: #fffdf8;
  --dm-common-header-ink: #18202c;
  --dm-common-header-muted: #667085;
  --dm-common-header-line: #ddd8cc;
  --dm-common-header-accent: #ef4b40;
  --dm-common-header-focus: #f4b400;
}

[data-dm-common-header],
.dm-common-header-mount {
  position: relative;
  z-index: 100;
  display: block;
  min-width: 0;
  /* Reserve the header before the deferred script creates its contents. */
  min-height: var(--dm-common-header-min-height);
}

[data-dm-common-header]:not([data-dm-common-ready="true"]) > [data-dm-common-action] {
  visibility: hidden;
}

.dm-common-header {
  box-sizing: border-box;
  height: var(--dm-common-header-min-height);
  border-bottom: 1px solid var(--dm-common-header-line);
  background: var(--dm-common-header-bg);
  color: var(--dm-common-header-ink);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
}

.dm-common-header__inner {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  width: min(1440px, calc(100% - 32px));
  height: 100%;
  margin: 0 auto;
}

.dm-common-header__left,
.dm-common-header__end,
.dm-common-header__actions,
.dm-common-header__user {
  display: flex;
  min-width: 0;
  align-items: center;
}

.dm-common-header__left {
  gap: 16px;
  justify-self: start;
}

.dm-common-header__end {
  gap: 10px;
  justify-self: end;
}

.dm-common-header__actions,
.dm-common-header__user {
  gap: 8px;
}

.dm-common-header__user {
  /* Session checks change the label, never the surrounding layout. */
  flex: 0 0 var(--dm-common-header-account-width);
  width: var(--dm-common-header-account-width);
  max-width: min(230px, 100%);
}

.dm-common-header__brand,
.dm-common-header__catalog-link,
.dm-common-header__my-page {
  background: #fff;
  color: inherit;
  font-weight: 900;
  text-decoration: none;
}

.dm-common-header__brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  letter-spacing: .02em;
}

.dm-common-header__brand-mark {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--dm-common-header-accent);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .35);
}

.dm-common-header__brand-name {
  font-size: 16px;
  line-height: 1;
  white-space: nowrap;
}

.dm-common-header__catalog-link,
.dm-common-header__my-page,
.dm-common-header__action {
  flex-shrink: 0;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 999px;
  font-size: 12px;
}

.dm-common-header__catalog-link {
  flex: 0 0 auto;
  padding: 8px 12px;
  border: 1px solid var(--dm-common-header-line);
  background: #fff;
  white-space: nowrap;
}

.dm-common-header__catalog-label--mobile {
  display: none;
}

.dm-common-header__title {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 900;
  line-height: 1.3;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dm-common-header__action {
  min-width: 0;
  margin: 0;
  padding: 8px 13px;
  border: 1px solid var(--dm-common-header-line);
  background: #fff;
  color: var(--dm-common-header-ink);
  font-family: inherit;
  font-weight: 900;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
}

.dm-common-header .dm-common-header__action {
  /* Game-specific ID rules must not shrink the shared touch target. */
  min-height: 44px !important;
}

.dm-common-header__user[hidden],
.dm-common-header__actions:empty {
  display: none;
}

.dm-common-header__user-name {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.dm-common-header__my-page {
  width: 100%;
  gap: 6px;
  min-width: 44px;
  max-width: 220px;
  padding: 8px 11px;
  border: 1px solid var(--dm-common-header-line);
  overflow: hidden;
}

.dm-common-header__account-icon {
  flex: 0 0 auto;
  font-size: 14px;
  line-height: 1;
}

.dm-common-header__account-icon[hidden] {
  display: none;
}

.dm-common-header__account-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dm-common-header__brand:hover,
.dm-common-header__catalog-link:hover,
.dm-common-header__my-page:hover {
  color: var(--dm-common-header-accent);
}

.dm-common-header__brand:focus-visible,
.dm-common-header__catalog-link:focus-visible,
.dm-common-header__my-page:focus-visible,
.dm-common-header__action:focus-visible {
  outline: 3px solid var(--dm-common-header-focus);
  outline-offset: 2px;
}

@media (max-width: 680px) {
  :root {
    --dm-common-header-min-height: 50px;
    --dm-common-header-account-width: 100px;
  }

  .dm-common-header {
    height: auto;
    min-height: var(--dm-common-header-min-height);
  }

  .dm-common-header__inner {
    box-sizing: border-box;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 4px 8px;
    width: calc(100% - 16px);
    height: auto;
    min-height: calc(var(--dm-common-header-min-height) - 1px);
    padding: 2px 0;
  }

  .dm-common-header__left,
  .dm-common-header__end,
  .dm-common-header__actions {
    gap: 5px;
  }

  .dm-common-header__end {
    max-width: 100%;
    margin-left: auto;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .dm-common-header__actions {
    flex-wrap: wrap;
  }

  .dm-common-header__brand {
    min-height: 44px;
  }

  .dm-common-header__brand-mark {
    width: 29px;
    height: 29px;
    border-radius: 8px;
    font-size: 13px;
  }

  .dm-common-header__brand-name {
    font-size: 14px;
  }

  .dm-common-header__catalog-label--desktop {
    display: none;
  }

  .dm-common-header__catalog-label--mobile {
    display: inline;
  }

  .dm-common-header__catalog-link,
  .dm-common-header__action,
  .dm-common-header__my-page {
    min-height: 44px;
    padding: 6px 8px;
    font-size: 11px;
  }

  .dm-common-header__title {
    flex: 1 1 80px;
    font-size: 12px;
    text-align: left;
  }

  .dm-common-header__user {
    max-width: min(43vw, 170px);
  }

  .dm-common-header__my-page {
    max-width: 100%;
  }

}

@media (max-width: 480px) {
  /* Keep the site, catalogue and account actions readable on narrow screens. */
  .dm-common-header__title { display: none; }
}

@media (max-width: 390px) {
  .dm-common-header__inner {
    gap: 5px;
    width: calc(100% - 10px);
  }

  .dm-common-header__brand {
    gap: 5px;
  }

  .dm-common-header__brand-name {
    font-size: 13px;
  }

  .dm-common-header__action,
  .dm-common-header__catalog-link {
    padding-inline: 6px;
  }
}

@media (max-width: 340px) {
  :root {
    --dm-common-header-account-width: 88px;
  }

  .dm-common-header__user {
    max-width: min(52vw, 160px);
  }

}

@media print {
  [data-dm-common-header],
  .dm-common-header-mount,
  .dm-common-header {
    display: none;
  }
}

/* Background saves are silent. Non-empty warnings and retry actions remain visible. */
:is(#save-status, #history-status, #global-status, #startup, #start-save-status, #storage-status, #identity):empty,
:is(.system-status, .save-area, .save-line, #save-panel):has(> #save-status:empty),
.system-status:has(> #global-status:empty),
.mb-save-box:has(> #save-status:empty):has(> #history-status:empty),
#save-status:empty + #retry-save,
#startup:empty + #connection-retry {
  display: none !important;
}
