* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: #f6d5e6;
  color: #111;
  overscroll-behavior: none;
  overflow-x: hidden;
  overflow-y: auto;
}

#app {
  min-height: 100%;
  height: 100%;
  width: 100vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 0 calc(10px + env(safe-area-inset-bottom, 0px)) 0;
  overflow: hidden;
}

.main {
  position: relative;
  width: min(100vw, 520px);
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #f6d5e6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.loading-overlay.hidden {
  display: none;
}

.loading-cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: blur(8px);
  opacity: 0.6;
  z-index: 0;
}

/* Cocos-like loading UI */
.cocos-loading {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 280px;
  background: rgba(255, 255, 255, 0.85);
  padding: 24px;
  border-radius: 16px;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.app,
html,
body {
  min-height: 100%;
  background: #f6d5e6;
}
body {
  background-image: url('./cover.png');
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

.cocos-logo {
  width: min(180px, 46vw);
  height: min(180px, 46vw);
  border-radius: 18px;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.85), rgba(255,255,255,0.55) 60%, rgba(255,255,255,0.35) 100%);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.05), 0 8px 30px rgba(0,0,0,0.08);
}
.cocos-bar {
  width: min(520px, 80vw);
  height: 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(0,0,0,0.08);
  overflow: hidden;
}
.cocos-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff8ac1, #ff69b4);
  transition: width 0.15s ease;
}
.cocos-percent {
  font-size: 14px;
  color: rgba(0,0,0,0.75);
}
.cocos-tip {
  font-size: 12px;
  color: rgba(0,0,0,0.55);
}

@keyframes shimmer {
  0% {
    transform: translateX(-60%);
  }
  100% {
    transform: translateX(160%);
  }
}

.status {
  display: block;
  max-width: 220px;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid rgba(0, 0, 0, 0.08);
  color: rgba(0, 0, 0, 0.7);
}

.status.hidden {
  display: none;
}

.stage {
  position: relative;
  z-index: 0;
  flex: 0 0 auto;
  height: 50vh;
  max-height: 50vh;
  min-height: 160px;
  display: grid;
  place-items: center;
  padding: 0 10px;
}

.stage-inner {
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  height: auto;
  aspect-ratio: 9 / 16;
  border-radius: 18px;
  overflow: hidden;
  background: #fdebf4;
  border: 1px solid rgba(0, 0, 0, 0.06);
  position: relative;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.stage-inner canvas {
  position: absolute;
  left: 50%;
  top: 50%;
  display: block;
  background: transparent;
  transform-origin: center center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

.stage-no-save {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.hud {
  position: absolute;
  top: 12px;
  right: 12px;
  pointer-events: none;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.hud > .hud-btn {
  pointer-events: auto;
}

.hud-actions {
  pointer-events: auto;
  display: flex;
  gap: 8px;
}

.hud-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.75);
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#randomBtn {
  width: auto;
  padding: 0 10px;
  font-size: 12px;
  line-height: 1;
  letter-spacing: 0.2px;
}

.hud-btn:active {
  transform: scale(0.98);
}

.hud-icon {
  width: 22px;
  height: 22px;
  display: block;
}

.panel {
  position: relative;
  z-index: 10;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(246, 213, 230, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 6px 10px calc(10px + env(safe-area-inset-bottom, 0px)) 10px;
  max-height: none;
  overflow: hidden;
  margin-top: var(--panel-shift, 0px);
}

.panel-handle {
  align-self: center;
  width: 44px;
  height: 5px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.14);
  margin: 2px 0 6px 0;
  touch-action: none;
}

.tabs-wrap {
  background: #f3cbe0;
  border-radius: 14px;
  padding: 6px 8px;
  overflow: hidden;
  position: relative;
  z-index: 100;
  margin-bottom: 4px;
  flex: 0 0 auto;
}

.tabs {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  overscroll-behavior-x: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  border: 2px solid rgba(0, 0, 0, 0.06);
  background: rgba(255, 255, 255, 0.35);
  width: 88px;
  height: 50px;
  padding: 7px 10px;
  border-radius: 14px;
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  display: grid;
  grid-template-columns: 20px 1fr;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  touch-action: manipulation;
}

.tab.active {
  border-color: #ff69b4;
  background: rgba(255, 255, 255, 0.65);
}

.tab-icon {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(0, 0, 0, 0.06);
  object-fit: contain;
}

.tab-label {
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.colors {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  padding: 2px 6px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  touch-action: pan-x;
  overscroll-behavior-x: contain;
  flex: 0 0 auto;
  align-items: center;
  min-height: 36px;
  min-width: 0;
  position: relative;
  z-index: 50;
  margin-top: 8px;
}

.colors::-webkit-scrollbar {
  display: none;
}

.color {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 2px solid rgba(0, 0, 0, 0.12);
  cursor: pointer;
  touch-action: manipulation;
}

.color.active {
  box-shadow: inset 0 0 0 3px #ff69b4;
}

.grid {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, 72px);
  grid-auto-rows: 72px;
  align-content: start;
  gap: 8px;
  padding: 0 6px;
  -webkit-overflow-scrolling: touch;
  max-height: none;
  position: relative;
  z-index: 10;
}

.cell {
  border: 2px solid rgba(0, 0, 0, 0.06);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.35);
  padding: 6px;
  cursor: pointer;
  user-select: none;
  display: grid;
  place-items: center;
  min-height: 60px;
  min-width: 0;
  aspect-ratio: 1;
  overflow: hidden;
  touch-action: manipulation;
}

.cell.active {
  border-color: #ff69b4;
  box-shadow: 0 0 0 3px rgba(255, 105, 180, 0.18);
}

/* Constrain cell content (image/canvas) to the cell area */
.cell canvas,
.cell img {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  vertical-align: middle;
}
