:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #e5e5e5;
  --header-height: 58px;
}

* {
  box-sizing: border-box;
}

html,
body,
.page {
  min-height: 100%;
  margin: 0;
}

body {
  overflow-x: hidden;
}

button {
  font: inherit;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.page {
  position: relative;
  width: 100%;
  min-height: 100svh;
  overflow: hidden;
}

.bg-image {
  position: fixed;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.mini-header {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 5;
  width: 100%;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(8px, env(safe-area-inset-top)) 16px 8px;
  color: #fff;
  background: #c91f2b;
}

.mini-header h1 {
  width: 100%;
  margin: 0;
  overflow: hidden;
  color: #fff;
  font-size: clamp(17px, 5.2vw, 22px);
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.title {
  position: absolute;
  top: calc(var(--header-height) + 12px);
  left: 0;
  z-index: 1;
  width: 100%;
  height: auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  text-align: center;
}

.title p {
  margin: 0;
}

.avatar-stage {
  position: absolute;
  left: 50%;
  top: calc(var(--header-height) + 54px);
  width: min(66.666vw, 360px);
  aspect-ratio: 1;
  transform: translateX(-50%);
  padding: 0;
  background: transparent;
}

.avatar-image,
.frame-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  pointer-events: none;
}

.frame-image {
  z-index: 2;
}

.frame-tip {
  position: absolute;
  top: calc(var(--header-height) + 48svh);
  left: 0;
  width: 100%;
  margin: 0;
  color: #fff;
  font-size: 12px;
  text-align: center;
}

.frame-strip {
  position: absolute;
  top: calc(var(--header-height) + 53svh);
  left: 0;
  display: flex;
  width: 100%;
  height: 100px;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0 0 8px;
  white-space: nowrap;
  scrollbar-width: none;
}

.frame-strip::-webkit-scrollbar {
  display: none;
}

.strip-spacer {
  flex: 0 0 min(16.666vw, 90px);
}

.frame-option {
  flex: 0 0 min(20vw, 80px);
  width: min(20vw, 80px);
  height: min(20vw, 80px);
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
}

.frame-option.is-selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.16);
}

.frame-option img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.action-area {
  position: absolute;
  top: calc(var(--header-height) + 70svh);
  left: 0;
  width: 100%;
  text-align: center;
}

.action-area p {
  margin: 0 0 10px;
  color: rgb(90, 90, 90);
  font-size: 12px;
}

.generate-button {
  width: min(40%, 220px);
  min-width: 132px;
  height: 42px;
  border-radius: 6px;
  color: #fff;
  background: #07c160;
  font-size: 16px;
}

.source-panel[hidden],
.result-panel[hidden],
.cropper[hidden],
.action-area[hidden] {
  display: none;
}

.panel-mask {
  position: fixed;
  inset: 0;
  z-index: 199;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.45);
}

.panel-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  padding: 16px 12px calc(16px + env(safe-area-inset-bottom));
  border-radius: 14px 14px 0 0;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 -6px 16px rgba(0, 0, 0, 0.18);
}

.panel-sheet h2 {
  margin: 0 0 10px;
  color: #666;
  font-size: 13px;
  font-weight: 400;
  text-align: center;
}

.panel-button {
  width: 100%;
  height: 44px;
  margin-bottom: 8px;
  border-radius: 10px;
  color: #333;
  background: #f5f5f5;
  font-size: 15px;
}

.panel-button.cancel {
  margin-top: 4px;
  margin-bottom: 0;
  color: #888;
  background: #ebebeb;
}

.result-mask {
  position: fixed;
  inset: 0;
  z-index: 249;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.72);
}

.result-sheet {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 250;
  width: min(86vw, 420px);
  max-height: min(86svh, 720px);
  transform: translate(-50%, -50%);
  padding: 18px 16px 16px;
  border-radius: 8px;
  background: #fff;
  text-align: center;
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.32);
}

.result-sheet h2 {
  margin: 0 0 6px;
  color: #222;
  font-size: 18px;
  line-height: 1.3;
}

.result-sheet p {
  margin: 0 0 14px;
  color: #666;
  font-size: 14px;
}

.result-image {
  display: block;
  width: 100%;
  max-height: calc(min(86svh, 720px) - 130px);
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: 4px;
  background: #f5f5f5;
  -webkit-touch-callout: default;
  user-select: auto;
}

.result-close {
  width: 100%;
  height: 42px;
  margin-top: 14px;
  border-radius: 6px;
  color: #fff;
  background: #c91f2b;
  font-size: 16px;
}

.cropper {
  position: fixed;
  inset: 0;
  z-index: 300;
  overflow: hidden;
  background: #111;
  touch-action: none;
  user-select: none;
}

.crop-area {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.crop-image {
  position: absolute;
  left: 0;
  top: 0;
  max-width: none;
  transform-origin: 0 0;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
}

.crop-mask {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) top / 100% calc((100% - 250px) / 2) no-repeat,
    linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) bottom / 100% calc((100% - 250px) / 2) no-repeat,
    linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) left / calc((100% - 250px) / 2) 250px no-repeat,
    linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) right / calc((100% - 250px) / 2) 250px no-repeat;
}

.crop-window {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 250px;
  height: 250px;
  transform: translate(-50%, -50%);
  border: 1px dashed #ddd;
  pointer-events: none;
}

.crop-tip {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 72px;
  margin: 0;
  color: #fff;
  font-size: 14px;
  text-align: center;
}

.crop-actions {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 15px;
  display: flex;
  justify-content: center;
  gap: 20px;
}

.crop-actions button {
  width: 120px;
  height: 32px;
  border: 1px solid #fff;
  border-radius: 0;
  color: #fff;
  background: transparent;
}

@media (min-width: 640px) {
  .page {
    max-width: 520px;
    margin: 0 auto;
  }
}

@media (max-height: 760px) {
  :root {
    --header-height: 52px;
  }

  .avatar-stage {
    width: min(60vw, 300px);
    top: calc(var(--header-height) + 44px);
  }

  .frame-tip {
    top: calc(var(--header-height) + 46svh);
  }

  .frame-strip {
    top: calc(var(--header-height) + 50svh);
  }

  .action-area {
    top: calc(var(--header-height) + 67svh);
  }
}
