/* ===== CSS 变量 ===== */
:root {
  --bg-primary: #0F1115;
  --bg-secondary: #15181E;
  --card-bg: #1A1D24;
  --card-bg-hover: #22262F;
  --border: #2A2E38;
  --border-active: #3A3F4D;
  --text-primary: #F5F5F7;
  --text-secondary: #8B8F99;
  --accent: #E8B86D;
  --accent-soft: rgba(232, 184, 109, 0.12);
  --gap-sm: 6px;
  --gap-md: 8px;
  --radius: 12px;
  --radius-sm: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ===== 基础重置 ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

/* 阻止微信对图片的长按菜单 */
img {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  pointer-events: none;
}

body {
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(232, 184, 109, 0.06), transparent 70%),
    radial-gradient(ellipse 60% 40% at 50% 100%, rgba(232, 184, 109, 0.03), transparent 70%),
    var(--bg-primary);
}

/* ===== 页面容器 ===== */
.page {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.page[hidden] {
  display: none;
}

/* ===== 工作台主页 ===== */
.page-home {
  padding: var(--safe-top) 12px var(--safe-bottom);
  gap: var(--gap-sm);
}

/* ===== 区域1：标题 ===== */
.area-title {
  flex-shrink: 0;
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border-active);
  border-radius: var(--radius);
}

.title-text {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 4px;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(232, 184, 109, 0.25);
}

.title-divider {
  width: 40px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  border-radius: 1px;
}

/* ===== 中间区域通用 ===== */
.area {
  min-height: 0;
}

.area-2,
.area-3,
.area-4,
.area-5 {
  display: flex;
  border: 1px solid var(--border-active);
  border-radius: var(--radius);
  padding: 8px;
}

/* 按行数分配空间，保证各方块大小接近一致 */
.area-2 { flex: 2 1 0; }
.area-3 { flex: 3 1 0; }
.area-4 { flex: 1 1 0; }
.area-5 { flex: 1 1 0; }

/* ===== 网格 ===== */
.grid {
  flex: 1;
  display: grid;
  gap: var(--gap-md);
  min-height: 0;
}

.grid-4cols {
  grid-template-columns: repeat(4, 1fr);
}

.grid-2rows {
  grid-template-rows: repeat(2, 1fr);
}

.grid-3rows {
  grid-template-rows: repeat(3, 1fr);
}

/* ===== 单元格（正方形卡片） ===== */
.cell {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    0 2px 8px rgba(0, 0, 0, 0.3);
  min-height: 0;
  min-width: 0;
}

.cell::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.02), transparent 50%);
  pointer-events: none;
  z-index: 1;
}

/* 占位图标（无图片时显示） */
.cell::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 22px;
  transform: translate(-50%, -50%);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='22' height='22' viewBox='0 0 24 24' fill='none' stroke='%23353942' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='3'/%3E%3Ccircle cx='8.5' cy='8.5' r='1.5'/%3E%3Cpath d='M21 15l-5-5L5 21'/%3E%3C/svg%3E") center / contain no-repeat;
  opacity: 0.7;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.cell:active {
  transform: scale(0.94);
  border-color: var(--border-active);
}

/* 拖动中的原元素样式 */
.cell.dragging,
.tab.dragging {
  opacity: 0.3;
  transform: scale(0.9);
}

/* 跟随手指的幽灵元素 */
.drag-ghost {
  border: 2px solid var(--accent) !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5) !important;
  border-radius: var(--radius);
  overflow: hidden;
}

/* 底部删除区 */
.delete-zone {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100px;
  background: rgba(15, 17, 21, 0.95);
  backdrop-filter: blur(10px);
  border-top: 2px dashed #ff6b6b;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #ff6b6b;
  font-size: 13px;
  font-weight: 500;
  z-index: 9998;
  opacity: 0;
  transform: translateY(100%);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.delete-zone.visible {
  opacity: 1;
  transform: translateY(0);
}

.delete-zone.active {
  background: rgba(255, 107, 107, 0.2);
  border-top: 2px solid #ff6b6b;
  color: #fff;
  transform: translateY(0) scale(1.02);
}

.delete-zone svg {
  transition: transform 0.2s ease;
}

.delete-zone.active svg {
  transform: scale(1.2);
}

.cell.has-image::after {
  opacity: 0;
}

.cell.has-image {
  border-color: var(--border-active);
}

/* 图片显示 */
.cell-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(1.05); }
  to { opacity: 1; transform: scale(1); }
}

/* ===== 可跳转标记 ===== */
.cell-navigable {
  border-color: rgba(232, 184, 109, 0.25);
}

.cell-navigable.has-image {
  border-color: rgba(232, 184, 109, 0.4);
}

.nav-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  border: 1px solid rgba(232, 184, 109, 0.35);
  border-radius: 50%;
  color: var(--accent);
  z-index: 2;
  backdrop-filter: blur(4px);
}

/* ===== 区域6：Tab Bar ===== */
.area-tabbar {
  flex-shrink: 0;
  padding-top: 4px;
}

.tabbar {
  display: flex;
  gap: var(--gap-md);
  height: 56px;
}

.tab {
  position: relative;
  flex: 1;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.2s ease;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    0 2px 8px rgba(0, 0, 0, 0.3);
}

.tab::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  transform: translate(-50%, -50%);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23353942' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3C/svg%3E") center / contain no-repeat;
  opacity: 0.7;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.tab:active {
  transform: scale(0.94);
}

.tab.has-image::after {
  opacity: 0;
}

.tab.has-image {
  border-color: var(--border-active);
}

.tab .cell-img {
  border-radius: 0;
}

/* ===== 子页面（页面B / 页面C） ===== */
.page-sub {
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(232, 184, 109, 0.04), transparent 70%),
    var(--bg-primary);
  padding: var(--safe-top) 0 0;
}

.sub-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.2s ease;
}

.back-btn:active {
  background: var(--accent-soft);
}

.sub-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
}

.sub-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.placeholder-text {
  color: var(--text-secondary);
  font-size: 14px;
  letter-spacing: 1px;
}

/* ===== 页面切换动画 ===== */
.page {
  animation: pageIn 0.3s ease;
}

@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== 超小屏适配 ===== */
@media (max-height: 640px) {
  .title-text { font-size: 22px; letter-spacing: 2px; }
  .area-title { padding: 6px 4px 4px; }
  .tabbar { height: 48px; }
  .grid { gap: 5px; }
}

@media (max-width: 340px) {
  .grid { gap: 5px; }
  .page-home { padding-left: 8px; padding-right: 8px; }
}
