/* —— 液态玻璃 / 对折网格桌面 ——
 * 间距策略：--grid-unit 同时用于 gap、圆角、内边距（规则感）。
 * 嵌套子块与根级共用 --grid-unit，避免多重边距导致图片四边留白不一致。
 */
:root {
  --glass-bg: rgba(255, 255, 255, 0.08);
  --glass-shadow: 0 24px 80px rgba(0, 0, 0, 0.35),
    0 0 0 0.5px rgba(255, 255, 255, 0.08) inset;
  --text: rgba(255, 255, 255, 0.94);
  --text-dim: rgba(255, 255, 255, 0.55);
  --accent: #64d2ff;
  --radius-lg: 22px;
  --radius-sm: 12px;
  --blur-amount: 28px;
  --sat: 1.65;
  /** 根网格：gap = 内边距 = 圆角（同值建立韵律） */
  --grid-unit: clamp(6px, 0.85vmin, 12px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body {
  position: relative;
  background: #0a0c10;
}

.wallpaper {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-size: cover;
  background-position: center;
  transition: opacity 0.6s ease;
}

.wallpaper.is-gradient {
  background-image: none;
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(ellipse 85% 70% at 50% 45%, transparent 0%, rgba(0, 0, 0, 0.35) 100%);
}

.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  gap: 16px;
  transition: box-shadow 0.2s, background 0.2s;
}

/** 拖块到顶栏：左半删除 / 右半修改 */
.top-bar.is-drop-delete {
  box-shadow: 0 0 0 2px rgba(255, 80, 80, 0.65), 0 12px 40px rgba(255, 60, 60, 0.25);
  background: rgba(40, 20, 20, 0.45);
}

.top-bar.is-drop-edit {
  box-shadow: 0 0 0 2px rgba(80, 200, 255, 0.55), 0 12px 40px rgba(60, 180, 255, 0.2);
  background: rgba(15, 35, 50, 0.5);
}

.top-bar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  font-size: 15px;
  flex-wrap: wrap;
}

.top-bar__hint {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-dim);
}

.top-bar__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  box-shadow: 0 0 12px rgba(100, 210, 255, 0.6);
}

.top-bar__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.glass-panel {
  position: relative;
  border-radius: var(--radius-lg);
  background: var(--glass-bg);
  backdrop-filter: saturate(var(--sat)) blur(var(--blur-amount));
  -webkit-backdrop-filter: saturate(var(--sat)) blur(var(--blur-amount));
  box-shadow: var(--glass-shadow);
  overflow: hidden;
}

.glass-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1.5px;
  background: linear-gradient(
    145deg,
    rgba(255, 255, 255, 0.65) 0%,
    rgba(255, 255, 255, 0.08) 35%,
    rgba(255, 255, 255, 0.02) 50%,
    rgba(0, 0, 0, 0.18) 65%,
    rgba(255, 255, 255, 0.08) 100%
  );
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  z-index: 2;
}

.glass-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35),
    inset 0 -1px 0 rgba(0, 0, 0, 0.12);
  pointer-events: none;
  z-index: 1;
}

.glass-panel--toolbar {
  margin: 16px 18px 0;
  width: calc(100% - 36px);
}

.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  transition: background 0.2s, transform 0.15s;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.btn:active {
  transform: scale(0.98);
}

.btn--ghost {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.btn--primary {
  background: linear-gradient(180deg, rgba(100, 210, 255, 0.35), rgba(100, 210, 255, 0.15));
  border: 1px solid rgba(100, 210, 255, 0.35);
}

.btn--file {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

/* 多屏：横向滑动 + 每屏 8×8 网格 */
.stage-wrap {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  padding: 88px 28px 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.stage-viewport {
  width: min(100%, 1180px);
  max-width: calc(100vw - 56px);
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  scrollbar-width: thin;
}

.stage-viewport::-webkit-scrollbar {
  height: 6px;
}

.stage-viewport::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.stage-track {
  display: flex;
  flex-direction: row;
  align-items: stretch;
}

.stage--grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  gap: var(--grid-unit);
  flex: 0 0 var(--stage-page-w, min(100vw - 56px, 1180px));
  width: var(--stage-page-w, min(100vw - 56px, 1180px));
  max-height: calc(100vh - 140px);
  aspect-ratio: 1.68 / 1;
  padding: var(--grid-unit);
  border-radius: calc(var(--grid-unit) * 1.4);
  background: rgba(0, 0, 0, 0.12);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  position: relative;
  align-content: stretch;
  justify-content: stretch;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

.page-dots {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 12px;
  z-index: 15;
}

.page-dots:empty {
  display: none;
}

/* 拖动时：拖到下方切换屏（fixed 避免撑开主舞台、减少排版跳动） */
.screen-drop-bar {
  position: fixed;
  left: 50%;
  bottom: 64px;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: min(100%, 1180px);
  max-width: calc(100vw - 56px);
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 90;
  pointer-events: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

.screen-drop-bar[hidden] {
  display: none !important;
}

.screen-drop-bar__label {
  width: 100%;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
}

.screen-drop-bar__targets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.screen-drop-btn {
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.screen-drop-btn:hover,
.screen-drop-btn.is-hover {
  background: rgba(100, 210, 255, 0.2);
  border-color: rgba(100, 210, 255, 0.45);
}

.page-dot {
  width: 8px;
  height: 8px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
}

.page-dot:hover {
  background: rgba(255, 255, 255, 0.4);
}

.page-dot.is-active {
  background: var(--accent);
  transform: scale(1.25);
  box-shadow: 0 0 12px rgba(100, 210, 255, 0.5);
}

/* 内容块 */
.tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-radius: var(--grid-unit);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  z-index: 5;
  transition: box-shadow 0.2s ease, transform 0.15s ease;
  display: flex;
  flex-direction: column;
  container-type: size;
  container-name: tile;
}

/* 避免浏览器对 img 的默认拖拽抢走指针，导致只能拖边距区 */
.tile img {
  -webkit-user-drag: none;
  user-select: none;
  pointer-events: auto;
}

.tile:hover:not(.is-dragging) {
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14), 0 12px 36px rgba(0, 0, 0, 0.22);
  z-index: 6;
}

.tile.is-selected:not(.is-dragging) {
  box-shadow: 0 0 0 2px rgba(100, 210, 255, 0.55), 0 0 28px rgba(100, 210, 255, 0.22);
  z-index: 7;
}

.tile.is-dragging {
  z-index: 300;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.2);
  transform: scale(1.015);
  opacity: 0.96;
}

.tile__glow {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  z-index: 0;
  background-size: 200% 200%;
  animation: glow-shift 20s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes glow-shift {
  0% {
    background-position: 0% 40%;
  }
  50% {
    background-position: 100% 55%;
  }
  100% {
    background-position: 35% 100%;
  }
}

.tile__glass {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  z-index: 1;
  pointer-events: none;
  box-shadow: var(--glass-shadow);
}

.tile__glass::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(
    155deg,
    rgba(255, 255, 255, 0.5) 0%,
    rgba(255, 255, 255, 0.06) 45%,
    rgba(0, 0, 0, 0.12) 100%
  );
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
}

.tile__body {
  position: relative;
  z-index: 2;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: var(--grid-unit);
  gap: var(--grid-unit);
}

/** 嵌套内与根级使用同一套内边距，避免「边距叠边距」导致图片四边留白不一致 */
.tile[data-depth="1"] .tile__body,
.tile[data-depth="2"] .tile__body {
  padding: var(--grid-unit);
  gap: var(--grid-unit);
}

.tile__nest {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: var(--grid-unit);
  padding: 0;
  border-radius: var(--grid-unit);
  background: rgba(0, 0, 0, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.tile--empty .tile__body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  border-radius: var(--grid-unit);
  align-items: stretch;
  justify-content: flex-start;
  color: var(--text-dim);
  font-size: 12px;
}

.tile__placeholder {
  width: 100%;
  height: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.12);
  border-radius: inherit;
}

.tile.tile--empty[data-depth="1"] .tile__body,
.tile.tile--empty[data-depth="2"] .tile__body {
  border-radius: var(--grid-unit);
}

/* 已有子块时不再显示顶栏提示，整块留给子网格（见 app.js 不渲染 .tile__empty-hint） */
.tile--empty.tile--empty-filled .tile__body {
  justify-content: stretch;
}

/* 铺满图 */
.tile--full .tile__full-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: var(--grid-unit);
  overflow: hidden;
  background: rgba(0, 0, 0, 0.15);
}

.tile.tile--full[data-depth="1"] .tile__full-wrap,
.tile.tile--full[data-depth="2"] .tile__full-wrap {
  border-radius: var(--grid-unit);
}

.tile--full .tile__full-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tile--full .tile__full-wrap img[data-fit="contain"] {
  object-fit: contain;
}

.tile--full .tile__caption-under {
  position: absolute;
  left: var(--grid-unit);
  bottom: var(--grid-unit);
  right: var(--grid-unit);
  max-width: 90%;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.35;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}

.tile--full .tile__full-wrap:hover .tile__caption-under {
  opacity: 1;
  transform: translateY(0);
}

/* 横屏 16:9 */
.tile--h16 .tile__media-169 {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--grid-unit);
  overflow: hidden;
  background: rgba(0, 0, 0, 0.12);
  flex-shrink: 0;
}

.tile--h16 .tile__media-169 img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tile--h16 .tile__text {
  flex: 1;
  min-height: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-dim);
  overflow: auto;
}

/* 嵌套容器内：统一 body 内边距；图区 flex 充满剩余空间 + cover（不强制 16:9，避免窄条里被压扁） */
.tile.tile--h16[data-depth="1"] .tile__body,
.tile.tile--h16[data-depth="2"] .tile__body,
.tile.tile--v1[data-depth="1"] .tile__body,
.tile.tile--v1[data-depth="2"] .tile__body {
  gap: min(4px, calc(var(--grid-unit) * 0.55));
}

.tile.tile--h16[data-depth="1"] .tile__media-169,
.tile.tile--h16[data-depth="2"] .tile__media-169 {
  border-radius: var(--grid-unit);
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  aspect-ratio: unset;
  flex-shrink: 1;
}

.tile.tile--h16[data-depth="1"] .tile__media-169 img,
.tile.tile--h16[data-depth="2"] .tile__media-169 img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tile.tile--h16[data-depth="1"] .tile__text,
.tile.tile--h16[data-depth="2"] .tile__text {
  flex: 0 1 auto;
  max-height: 40%;
}

/* 竖屏 1:1（勿设 max-height，否则会与 width:100%+aspect-ratio 冲突导致变扁） */
.tile--v1 .tile__media-11 {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--grid-unit);
  overflow: hidden;
  background: rgba(0, 0, 0, 0.12);
  flex-shrink: 0;
}

.tile--v1 .tile__media-11 img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tile--v1 .tile__text {
  flex: 1;
  min-height: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-dim);
  overflow: auto;
}

.tile.tile--v1[data-depth="1"] .tile__media-11,
.tile.tile--v1[data-depth="2"] .tile__media-11 {
  border-radius: var(--grid-unit);
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  aspect-ratio: unset;
  flex-shrink: 1;
}

.tile.tile--v1[data-depth="1"] .tile__media-11 img,
.tile.tile--v1[data-depth="2"] .tile__media-11 img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tile.tile--v1[data-depth="1"] .tile__text,
.tile.tile--v1[data-depth="2"] .tile__text {
  flex: 0 1 auto;
  max-height: 40%;
}

/* 图标格：铺满可用区域（容器查询） */
.tile--icon .tile__body {
  padding: var(--grid-unit);
  gap: var(--grid-unit);
}

.tile--icon .tile__icon-inner {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--grid-unit);
  overflow: hidden;
}

.tile--icon .tile__icon-inner svg {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  flex-shrink: 0;
  object-fit: contain;
  fill: currentColor;
  stroke: currentColor;
}

.tile--icon .tile__icon-emoji {
  line-height: 1;
  font-size: clamp(28px, 18vmin, 200px);
}

@supports (font-size: 1cqmin) {
  .tile--icon .tile__icon-emoji {
    font-size: min(65cqmin, 200px);
  }
}

.tile.tile--icon[data-depth="1"] .tile__icon-inner,
.tile.tile--icon[data-depth="2"] .tile__icon-inner {
  border-radius: var(--grid-unit);
}

.tile--icon .tile__text {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.emoji-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.emoji-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}

.emoji-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.emoji-btn.is-active {
  border-color: rgba(100, 210, 255, 0.55);
  background: rgba(100, 210, 255, 0.12);
}

.field-hint {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.45;
}

.field-textarea {
  width: 100%;
  min-height: 88px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 12px;
  font-family: ui-monospace, monospace;
  resize: vertical;
  outline: none;
}

.field--row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field--row input[type="color"] {
  width: 48px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.field-select {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

.field--range {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
}

.field--range input[type="range"] {
  width: 100%;
}

.modal {
  border: none;
  padding: 0;
  max-width: 440px;
  width: calc(100% - 32px);
  border-radius: var(--radius-lg);
  color: var(--text);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
}

.modal__form {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal__title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dim);
}

.field input[type="text"],
.field input[type="file"] {
  font-size: 14px;
  color: var(--text);
}

.field input[type="text"] {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.25);
  outline: none;
}

.field input[type="text"]:focus {
  border-color: rgba(100, 210, 255, 0.6);
}

.field--sizes {
  border: none;
  padding: 0;
  margin: 0;
}

.field--sizes legend {
  padding: 0 0 8px;
  font-size: 13px;
  color: var(--text-dim);
}

.size-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.size-chip {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
}

.size-chip.is-active {
  border-color: rgba(100, 210, 255, 0.5);
  background: rgba(100, 210, 255, 0.12);
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  z-index: 400;
  padding: 12px 20px;
  border-radius: 999px;
  background: rgba(20, 22, 28, 0.85);
  backdrop-filter: blur(12px);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.is-hidden {
  display: none !important;
}

@media (max-width: 640px) {
  .top-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .stage-wrap {
    padding: 120px 14px 40px;
  }
}
