* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f4f1ea;
  color: #333;
  min-height: 100vh;
  /* 手机 Chrome 的 100vh 是按"地址栏收起后"的最大高度算的，比地址栏还显示着时
     实际看到的视口要高一些，导致内容明明没那么高，也会多出一截看不见但可以往下
     滚的空白（房间页内容少的时候尤其明显）。dvh 会跟着地址栏收起/展开动态更新，
     不支持的旧浏览器直接忽略这行，还是用上面的 100vh 兜底。 */
  min-height: 100dvh;
}
/* 预览层/分享全屏层打开时，禁止背后的页面跟着滚动（手机上尤其明显） */
body.no-scroll { overflow: hidden; height: 100vh; height: 100dvh; }

.view { display: none; }
.view.active { display: block; }

.error { color: #c0392b; min-height: 1.4em; margin-top: 10px; }
.hidden { display: none !important; }

/* ---------- 首页 ---------- */
#view-home.active {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  overflow: hidden;
  /* 图片墙加载出来之前（或者图库还没有照片时）的兜底背景 */
  background: linear-gradient(160deg, #2c3e50, #4ca1af);
}
/* 背景图片墙：随机抽一批图库照片铺满整个首页 */
.photo-wall {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
}
.photo-wall .tile { background-size: cover; background-position: center; }
/* 蒙层：从上到下渐深，越靠近卡片区域越暗，保证卡片文字清晰 */
.home-scrim {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(180deg, rgba(10,14,18,0.45) 0%, rgba(10,14,18,0.68) 45%, rgba(10,14,18,0.82) 100%);
}
/* 悬浮卡片：毛玻璃效果，半透明背景 + 高强度模糊，透出背后图片虚化的颜色 */
.home-card {
  position: relative;
  z-index: 2;
  background: rgba(255, 253, 248, 0.32);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 16px;
  padding: 44px 40px;
  width: min(400px, 92vw);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
}
.home-hero { display: flex; align-items: center; justify-content: center; gap: 22px; margin-bottom: 18px; }
.home-hero-text { text-align: left; }
.logo { font-size: 44px; letter-spacing: 12px; color: #2c3e50; text-shadow: 0 1px 12px rgba(255,255,255,0.5); margin: 0; }
.logo-sub { font-size: 13px; letter-spacing: 5px; color: #4a4438; margin: 6px 0 0; }
.home-header-image { max-height: 96px; width: auto; border-radius: 10px; flex-shrink: 0; }
.site-footer { position: fixed; bottom: 16px; left: 0; right: 0; text-align: center; color: rgba(255,255,255,0.75); font-size: 12px; z-index: 2; }
.tagline { color: #4a4438; margin: 12px 0 28px; font-size: 14px; }
.home-card input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 12px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  font-size: 16px;
  background: rgba(255, 255, 255, 0.55);
}
.join-row { display: flex; gap: 10px; margin-top: 6px; }
.join-row input { flex: 1; margin-bottom: 0; }
.join-row button { background: rgba(255, 255, 255, 0.55); color: #2c3e50; font-weight: 600; }

/* 「创建」与「加入」之间的 或 分隔线 */
.divider {
  display: flex;
  align-items: center;
  margin: 20px 0;
  color: #4a4438;
  font-size: 17px;
}
.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.5);
}
.divider span { padding: 0 18px; }

button {
  padding: 12px 18px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  background: #e8e2d5;
  color: #333;
}
button.primary {
  width: 100%;
  background: #2c3e50;
  color: #fff;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- 顶栏 / 底栏 ---------- */
.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.45), transparent);
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}
.bar.bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  top: auto;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px 16px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.45), transparent);
}
.bar-right { display: flex; align-items: center; gap: 14px; }
.btn-leave {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  padding: 6px 14px;
  font-size: 14px;
  border-radius: 6px;
}
.bar.bottom button.primary { width: min(400px, 90vw); background: #4ca1af; }

/* ---------- 选图页 ---------- */
/* 真正的瀑布流：JS 按"贪心最短列"算法摆放每张图（见 app.js layoutMasonry），
   这里只负责容器给出定位上下文，具体的 top/left/width/height 都是行内样式 */
.gallery {
  position: relative;
  padding: 24px 20px 110px;
  max-width: 1100px;
  margin: 0 auto;
}
.card {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  border: 3px solid transparent;
  transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s, top 0.2s, left 0.2s;
  background: #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}
.gallery .card {
  position: absolute;
  box-shadow: none;
  border-width: 1.5px; /* 白边（未选中时的透明边框）缩小一半，原来 3px */
}
.card:hover { transform: translateY(-4px); box-shadow: 0 12px 28px rgba(0, 0, 0, 0.16); }
/* 选图页取消悬浮效果：不上浮、不加阴影，避免同样的晕开问题 */
.gallery .card:hover { transform: none; box-shadow: none; }
.card img { width: 100%; display: block; aspect-ratio: 3/2; object-fit: cover; }
/* 瀑布流里每张卡片的宽高是 JS 算好的固定值，图片铺满裁切即可 */
.gallery .card img { width: 100%; height: 100%; aspect-ratio: auto; }
/* 卡片底部图片名称浮层：任何地方都不展示图片名字，只看图 */
.card-name {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 20px 12px 8px;
  color: #fff;
  font-size: 14px;
  letter-spacing: 2px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.55), transparent);
  pointer-events: none;
}
.card.selected { border-color: #e67e22; }
.card.selected::after {
  content: "✓";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #e67e22;
  color: #fff;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.select-tip { color: rgba(255, 255, 255, 0.75); font-size: 13px; }

/* ---------- 房间页：成员选择看板 ---------- */
.room-board {
  max-width: 900px;
  margin: 0 auto;
  padding: 22px 20px 44px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.member {
  position: relative;
  background: #fffdf8;
  border-radius: 14px;
  padding: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}
.member.mine { border: 2px solid #4ca1af; }
/* 昵称叠在图片左上角，不再单独占一行，把整块高度都让给图片 */
.member-head {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 56px);
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
  overflow: hidden;
}
.member-name {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.member-status { font-size: 11px; color: rgba(255, 255, 255, 0.85); flex-shrink: 0; }
.member-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
/* 房间页缩略图比原来 3:2 更接近正方形（但不完全是），昵称去掉单独一行之后腾出的空间正好给图片用 */
.member-cards .card img { aspect-ratio: 6 / 5; }
/* 未选好时的占位格 */
.card.placeholder {
  aspect-ratio: 6 / 5;
  background: #ece7db;
  box-shadow: none;
  cursor: default;
}
.card.placeholder:hover { transform: none; box-shadow: none; }
/* 「我的图片」：悬停显示点击分享提示 */
.card.shareable .share-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(44, 62, 80, 0.55);
  color: #fff;
  font-size: 15px;
  letter-spacing: 2px;
  opacity: 0;
  transition: opacity 0.18s;
}
.card.shareable:hover .share-hint { opacity: 1; }

/* ---------- 图片放大预览层（选图页） ---------- */
.preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 35px; /* "选择这张"按钮跟图片之间的距离拉大一些，不要紧贴着图片 */
  padding: 0 24px 24px;
}
.preview-image {
  max-width: min(calc(100vw - 150px), 1600px);
  max-height: 88vh;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
}
.preview-close {
  position: absolute;
  top: 18px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-close:hover { background: rgba(255, 255, 255, 0.24); }
.preview-select { font-size: 15px; }

/* ---------- 分享全屏层 ---------- */
.share-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 14px;
  padding: 0 16px 16px;
  /* 只在图片上禁用原生手势不够彻底：滑动切图之后，浏览器可能在整个弹层范围内还残留着
     "这是不是导航手势"的判断状态，导致紧接着点弹层里的按钮（比如"结束分享"）第一次
     点击事件都派发不出来。整个弹层都不让浏览器插手原生手势，彻底交给我们自己的 JS 处理。 */
  touch-action: none;
}
.share-overlay p { color: #fff; font-size: 20px; letter-spacing: 2px; }
/* 舞台跟着图片实际渲染尺寸收缩（inline-flex），而不是撑满一个固定宽度的
   盒子——之前 img 用 width:100% 撑满舞台会导致比例对不上时露出黑边。
   img 的 max-width 必须写成视口相关的绝对值，不能写成相对舞台的百分比：
   舞台本身靠 img 撑出大小（只有 max-width，没有确定的 width），如果 img
   的 max-width 又反过来百分比引用这个不确定的舞台宽度，会形成循环引用，
   在真实浏览器里图片直接渲染不出来（jsdom 测不出这个问题，因为它不会
   真正对图片做布局）。舞台不再需要自己的 max-width，跟着 img 收缩即可。 */
.share-stage {
  position: relative;
  display: inline-flex;
}
.share-overlay img {
  display: block;
  max-width: min(calc(100vw - 150px), 1600px);
  max-height: 88vh;
  width: auto;
  height: auto;
  border-radius: 12px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
  transition: opacity 0.5s ease, transform 0.5s ease;
  /* 左右滑动切图完全由 JS 的 touchstart/touchend 自己处理，不设这个的话，手机浏览器
     会尝试自己识别这个横向滑动手势（比如 Android Chrome 的"侧滑返回"），JS 处理完了
     浏览器自己的手势识别可能还没"结束"，导致紧跟着点的下一个按钮第一次点不生效，
     需要再点一次（或者先随便点一下图片）才能"解开"这个卡住的手势状态。 */
  touch-action: none;
}
/* 切图时的滑动过渡：当前图片先滑出，换成新图后再从另一侧滑入 */
.share-overlay img.share-slide-out-left { opacity: 0; transform: translateX(-30px); }
.share-overlay img.share-slide-out-right { opacity: 0; transform: translateX(30px); }
.share-overlay img.share-slide-in-from-right { transition: none; opacity: 0; transform: translateX(30px); }
.share-overlay img.share-slide-in-from-left { transition: none; opacity: 0; transform: translateX(-30px); }
/* 桌面端：左右切换按钮放在图片外侧，不盖在图片上面 */
.share-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#btn-share-prev { right: 100%; margin-right: 12px; }
#btn-share-next { left: 100%; margin-left: 12px; }
.share-nav:hover { background: rgba(0, 0, 0, 0.7); }
.share-dots { display: flex; gap: 10px; }
.share-dots .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
}
.share-dots .dot.on { background: #e67e22; }
/* 分享层"结束分享/换图"、预览层"选择这张"三个按钮视觉上是同一种半透明白底样式 */
.preview-select,
.share-overlay button#btn-stop-share,
.share-overlay button#btn-reselect-from-share { background: rgba(255, 255, 255, 0.15); color: #fff; padding: 10px 20px; }

/* ---------- 移动端适配（手机） ---------- */
@media (max-width: 560px) {
  /* 图库：手机上固定 2 列瀑布流（列数由 app.js 里的 layoutMasonry 判断视口宽度决定），
     避免一行一张导致图片过大 */
  .gallery { padding: 16px 2px 108px; } /* 左右留白跟列间距一致，图片贴边显示 */

  /* 手机屏幕太小，背景图片墙铺出来的效果看不出拼图感，不值得为了这个再加载一堆背景图，
     直接用纯色背景（跟按钮同色系的深藏青），桌面端不受影响 */
  .photo-wall, .home-scrim { display: none; }
  #view-home.active { background: #2c3e50; }

  .home-hero { gap: 12px; }
  .logo { font-size: 22px; letter-spacing: 3px; }
  .logo-sub { font-size: 9px; letter-spacing: 2px; }
  .home-header-image { max-height: 50px; }
  .home-card { padding: 26px 20px; width: min(320px, 78vw); }
  .tagline { font-size: 12px; margin: 8px 0 20px; }
  /* 卡片变窄之后，输入框和"加入房间"按钮挤在一行容易被裁切，字号和内边距一起收紧 */
  /* 字号必须 >=16px：手机 Safari/Chrome 在输入框字号小于 16px 时，点击聚焦会自动放大页面，
     放大过程中视口跟着聚焦的输入框滚动定位，卡片看起来就像被顶到别处去了（还经常带偏移）。
     字号保持 16px 就不会触发这个自动放大，卡片位置不会跟着输入焦点跑。 */
  .home-card input { font-size: 16px; padding: 10px 10px; }
  .join-row { gap: 6px; }
  .join-row button { padding: 10px 12px; font-size: 12.5px; }

  .bar { padding: 12px 16px; }
  .bar-right { gap: 10px; }
  .btn-leave { padding: 5px 12px; font-size: 13px; }

  .room-board { padding: 16px 14px 40px; gap: 16px; }
  .member { padding: 2px; }
  .member-head { top: 10px; left: 10px; padding: 3px 8px; gap: 6px; }
  .member-name { font-size: 12px; }
  .member-status { font-size: 10px; }
  .member-cards { gap: 2px; }
  /* 手机屏幕又长又窄，图片宽度被"一行3张"锁死，只能靠加高来放大——改成 9:10 略偏竖，
     桌面端不需要这个调整，维持原来更接近正方形的 6:5 */
  .member-cards .card img,
  .card.placeholder { aspect-ratio: 9 / 10; }

  /* 分享全屏：手机上没有空间放图片外侧的按钮，改成左右滑动切换，按钮直接隐藏。
     图片左右贴边占满整个屏幕宽度（去掉左右 padding、圆角、阴影——贴边之后
     这些反而显得多余），上下留一点空间放标题/圆点/按钮。 */
  /* 手机上保持垂直居中，背景跟桌面端一样改成纯黑 */
  .share-overlay { padding: 10px 0; gap: 8px; justify-content: center; background: #000; }
  .share-nav { display: none; }
  .share-overlay p { font-size: 15px; letter-spacing: 1px; text-align: center; padding: 0 12px; }
  .share-overlay img { max-width: 100vw; max-height: 90vh; border-radius: 0; box-shadow: none; }
  .share-dots .dot { width: 7px; height: 7px; }
  /* 手机屏幕又高又窄，"结束分享"/"换图"钉在屏幕最下方而不是跟着图片/圆点居中 */
  #btn-stop-share,
  #btn-reselect-from-share {
    position: absolute;
    bottom: 22px;
    left: 50%;
    transform: translateX(-50%);
    padding: 9px 18px;
    font-size: 14px;
  }

  /* 图片预览层：跟分享全屏一样，手机上贴边占满整个屏幕宽度 */
  /* 手机上同样保持垂直居中，背景改成纯黑 */
  .preview-overlay { padding: 10px 0; gap: 20px; justify-content: center; background: #000; }
  .preview-image { max-width: 100vw; max-height: 90vh; border-radius: 0; box-shadow: none; }
  .preview-close { width: 36px; height: 36px; font-size: 20px; top: 12px; right: 14px; }
  .preview-select { padding: 9px 18px; }
}
